idz: Implement team member add/remove

This commit is contained in:
Tau
2019-11-06 17:28:30 -05:00
parent 2bd9ce919a
commit 3bee10d948
10 changed files with 92 additions and 0 deletions
+4
View File
@@ -35,6 +35,7 @@ import { unlockProfile } from "./unlockProfile";
import { updateProvisionalStoreRank } from "./updateProvisionalStoreRank";
import { updateResult } from "./updateResult";
import { updateStoryClearNum } from "./updateStoryClearNum";
import { updateTeamMember } from "./updateTeamMember";
import { updateTeamPoints } from "./updateTeamPoints";
import { updateUiReport } from "./updateUiReport";
import { updateUserLog } from "./updateUserLog";
@@ -158,6 +159,9 @@ export async function dispatch(
case "update_story_clear_num_req":
return updateStoryClearNum(w, req);
case "update_team_member_req":
return updateTeamMember(w, req);
case "update_team_points_req":
return updateTeamPoints(w, req);
+37
View File
@@ -0,0 +1,37 @@
import { _fixupPrevTeam } from "./_team";
import { UpdateTeamMemberRequest } from "../request/updateTeamMember";
import { UpdateTeamMemberResponse } from "../response/updateTeamMember";
import { Repositories } from "../repo";
export async function updateTeamMember(
w: Repositories,
req: UpdateTeamMemberRequest
): Promise<UpdateTeamMemberResponse> {
const now = new Date();
const profileId = await w.profile().find(req.aimeId);
const teamId = await w.teams().find(req.teamExtId);
switch (req.action) {
case "add":
const prevTeamId = await w.teamMembers().findTeam(profileId);
await w.teamMembers().join(teamId, profileId, now);
await _fixupPrevTeam(w, prevTeamId);
break;
case "remove":
// TODO store expulsion flag in db
await w.teamMembers().leave(teamId, profileId);
break;
default:
throw new Error("???");
}
return {
type: "update_team_member_res",
status: 0,
};
}