Skip to content

Commit

Permalink
Feat : 팀원 초대 로직 구현 [close #95]
Browse files Browse the repository at this point in the history
  • Loading branch information
Noelsky-code committed Nov 9, 2021
1 parent 333255f commit 8bcc1d2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
13 changes: 8 additions & 5 deletions server/src/api/team/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ export const createTeam = async (req, res, next) => {
const teamInfo = req.body;
try {
const result = await _createTeam({ teamInfo });
/*
if (!result) res.send({ error: "팀 생성 실패" });
if (result) res.send({ success: "팀 생성 성공" });
*/
} catch (error) {
next(error);
}
Expand All @@ -28,7 +26,12 @@ export const updateTeam = async (req, res, next) => {
};
export const inviteTeam = async (req, res, next) => {
// swagger에 잘못 나와있는거가틈. 팀 아이디가 없음
const gid = res.teamID;
const inviteID = res.inviteID;
await _inviteTeam({ gid, inviteID });
const inviteInfo = req.body;
try {
const result = await _inviteTeam({ inviteInfo });
if (!result) res.send({ error: "팀 초대 실패" });
if (result) res.send({ success: "팀 초대 성공" });
} catch (error) {
next(error);
}
};
18 changes: 17 additions & 1 deletion server/src/api/team/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,20 @@ export const _updateTeam = async ({ teamInfo }) => {
const gid = teamInfo.gid;
return await Team.update({ ...teamInfo }, { where: { gid } });
};
export const _inviteTeam = async ({ gid, inviteID }) => {};
export const _inviteTeam = async ({ inviteInfo }) => {
const gid = await _getGroupId({ teamName: inviteInfo.teamName });
try {
await Users.update({ gid: Number(gid) }, { where: { uid: inviteInfo.userId } });
return "success";
} catch (error) {
return new Error("업데이트 실패");
}
};

export const _getGroupId = async ({ teamName }) => {
const query = {
raw: true,
where: { name: teamName },
};
return await Team.findOne(query);
};

0 comments on commit 8bcc1d2

Please sign in to comment.