added server user create team (#84)

This commit is contained in:
Zai Shi 2024-06-19 15:34:06 +02:00 committed by GitHub
parent 53c5a87888
commit 29bb31fdbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 4 deletions

View File

@ -932,7 +932,7 @@ export class StackClientInterface {
};
}
async createClientTeam(
async createTeamForCurrentUser(
data: TeamCustomizableJson,
session: InternalSession,
): Promise<TeamJson> {

View File

@ -361,4 +361,23 @@ export class StackServerInterface extends StackClientInterface {
null,
);
}
async createServerTeamForUser(
userId: string,
data: ServerTeamCustomizableJson,
session: InternalSession,
): Promise<ServerTeamJson> {
const response = await this.sendClientRequest(
`/users/${userId}/teams?server=true`,
{
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify(data),
},
session,
);
return await response.json();
}
}

View File

@ -786,7 +786,7 @@ class _StackClientAppImpl<HasTokenStore extends boolean, ProjectId extends strin
return useMemo(() => teams.map((json) => app._teamFromJson(json)), [teams]);
},
async createTeam(data: TeamCustomizableJson) {
const teamJson = await app._interface.createClientTeam(data, session);
const teamJson = await app._interface.createTeamForCurrentUser(data, session);
await app._currentUserTeamsCache.refresh([session]);
return app._teamFromJson(teamJson);
},
@ -1361,8 +1361,10 @@ class _StackServerAppImpl<HasTokenStore extends boolean, ProjectId extends strin
useTeams() {
return app._useCheckFeatureSupport("useTeams() on ServerUser", {});
},
createTeam: async () => {
throw new Error();
createTeam: async (data: ServerTeamCustomizableJson) => {
const team = await app._interface.createServerTeamForUser(json.id, data, app._getSession());
await app._serverTeamsCache.refresh([]);
return app._serverTeamFromJson(team);
},
async listPermissions(scope: Team, options?: { direct?: boolean }): Promise<ServerPermission[]> {
const permissions = await app._serverTeamUserPermissionsCache.getOrWait([scope.id, json.id, 'team', !!options?.direct], "write-only");