Skip to content

Commit

Permalink
Merge pull request #197 from TiimMate/feat/178
Browse files Browse the repository at this point in the history
[FEAT] 매칭내역 조회 리뷰 여부 추가
  • Loading branch information
ujiiin authored Feb 19, 2024
2 parents e8c76c5 + 87f58ba commit f12530e
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/controllers/matchings.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
readMatchingGuesting,
readMatchingHosting,
readHostingApplicantsTeamList,
readMatchingHostingGuestUser,
} from "../services/matchings.service";
import { addOpposingTeam } from "../services/teams.service";
import { updateGuestUserStatus } from "../services/guests.service";
Expand All @@ -18,6 +19,10 @@ export const matchingHostingPreview = async (req, res: Response, next) => {
res.send(response(status.SUCCESS, await readMatchingHosting(req.user.id, req.query)));
};

export const matchingHostingGuestUserPreview = async (req, res: Response, next) => {
res.send(response(status.SUCCESS, await readMatchingHostingGuestUser(req.user.id, req.params)));
};

export const ApplyGuestingUserPreview = async (req, res: Response, next) => {
res.send(response(status.SUCCESS, await readApplyGuestingUser(req.params)));
};
Expand Down
2 changes: 1 addition & 1 deletion src/daos/game.dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const findGameByTeamsAndGameTime = async (teamFilter, gameTime: string) => {
attributes: ["id", "name", "region", "gender", "ageGroup", "skillLevel"],
},
],
attributes: ["id", "gameTime"],
attributes: ["id", "opposingTeamId", "gameTime"],
});
for (const gameResult of gameResults) {
gameResult.type = MatchType.game;
Expand Down
27 changes: 27 additions & 0 deletions src/daos/guest-user.dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,30 @@ export const checkForDuplicateGuestUser = async (userId, guestId) => {
},
});
};

export const getGuestingUser = async (guestingId: number) => {
return await db.GuestUser.findAll({
raw: true,
where: {
guestId: guestingId,
status: 1,
},
include: [
{
model: db.User,
include: [
{
model: db.Profile,
attributes: ["position"],
},
],
attributes: ["nickname", "height", "avatarUrl"],
},
{
model: db.Guest,
attiributes: ["gametime"],
},
],
attiributes: ["userId"],
});
};
13 changes: 13 additions & 0 deletions src/dtos/matchings.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import { getAgeGroup } from "../constants/age-group.constant";
import { getTeamGender } from "../constants/gender.constant";
import { getGuestUserStatus } from "../constants/guest-status.constant";

export const readGuestingUserResponseDTO = (result) => {
return result.map((guestingUser) => ({
userId: guestingUser.userId,
nickname: guestingUser["User.nickname"],
height: guestingUser["User.height"],
avatarUrl: guestingUser["User.avatarUrl"],
position: guestingUser["User.Profiles.position"],
reviewStatus: guestingUser.reviewStatus,
}));
};

export const readApplyGuestingUserResponseDTO = (result) => {
return result.map((guestingUser) => ({
nickname: guestingUser["User.nickname"],
Expand Down Expand Up @@ -36,6 +47,7 @@ export const readMatchingResponseDTO = (guestings, games) => {
memberCount: match.memberCount,
ageGroup: getAgeGroup(match["Team.ageGroup"]),
skillLevel: match["Team.skillLevel"],
reviewStatus: match.reviewStatus,
};
} else {
return {
Expand All @@ -49,6 +61,7 @@ export const readMatchingResponseDTO = (guestings, games) => {
memberCount: match.memberCount,
ageGroup: getAgeGroup(match["HostTeam.ageGroup"]),
skillLevel: match["HostTeam.skillLevel"],
reviewStatus: match.reviewStatus,
};
}
});
Expand Down
3 changes: 3 additions & 0 deletions src/routes/matchings.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
modifyGuestStatus,
fetchHostingApplicantsTeamList,
gameApplicationApproval,
matchingHostingGuestUserPreview,
} from "../controllers/matchings.controller";
import { dateQuery } from "../schemas/fields";

Expand All @@ -20,6 +21,8 @@ matchingsRouter.get("/guesting", validate(dateQuery), asyncHandler(matchingGuest

matchingsRouter.get("/hosting", validate(dateQuery), asyncHandler(matchingHostingPreview));

matchingsRouter.get("/hosting/:guestingId", asyncHandler(matchingHostingGuestUserPreview));

matchingsRouter.get("/hosting/user/:guestingId", asyncHandler(ApplyGuestingUserPreview));

matchingsRouter.patch("/hosting/guest/:guestUserId", asyncHandler(modifyGuestStatus));
Expand Down
69 changes: 68 additions & 1 deletion src/services/matchings.service.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,55 @@
import { findGameByHostTeamsAndGameTime, findGameByOpposingTeamsAndGameTime } from "../daos/game.dao";
import { getApplyGuestingUser } from "../daos/guest-user.dao";
import { getApplyGuestingUser, getGuestingUser } from "../daos/guest-user.dao";
import { findGuestingByTeamsAndGameTime, findGuestingByUserAndGameTime } from "../daos/guest.dao";
import { getTeamsAppliedById } from "../daos/matching.dao";
import { getMemberCountByTeamId, addMemberCount } from "../daos/member.dao";
import { getExistingTeamReview } from "../daos/team-review.dao";
import { findTeamIdByLeaderId } from "../daos/team.dao";
import { getExistingUserReview } from "../daos/user-review.dao";
import {
readApplyGuestingUserResponseDTO,
readGuestingUserResponseDTO,
readHostingApplicantsTeamResponseDTO,
readMatchingResponseDTO,
} from "../dtos/matchings.dto";

export const readMatchingGuesting = async (userId, query) => {
const gameTime = query.date;
const matchingGuestings = await findGuestingByUserAndGameTime(userId, query.date);
for (const matchingGuesting of matchingGuestings) {
const guestReviewId = await getExistingTeamReview(
userId,
matchingGuesting["Team.id"],
undefined,
matchingGuesting.id,
);
if (new Date() < new Date(matchingGuesting.gameTime)) {
matchingGuesting.reviewStatus = "PENDING";
} else if (!guestReviewId) {
matchingGuesting.reviewStatus = "UNCOMPLETED";
} else {
matchingGuesting.reviewStatus = "COMPLETED";
}
}

const teamIds = await findTeamIdByLeaderId(userId);
const matchingGames = await findGameByOpposingTeamsAndGameTime(teamIds, gameTime);
for (const matchingGame of matchingGames) {
const gameReviewId = await getExistingTeamReview(
userId,
matchingGame["HostTeam.id"],
matchingGame.id,
undefined,
);
if (new Date() < new Date(matchingGame.gameTime)) {
matchingGame.reviewStatus = "PENDING";
} else if (!gameReviewId) {
matchingGame.reviewStatus = "UNCOMPLETED";
} else {
matchingGame.reviewStatus = "COMPLETED";
}
}

await addMemberCount(matchingGuestings);
await addMemberCount(matchingGames);
return readMatchingResponseDTO(matchingGuestings, matchingGames);
Expand All @@ -25,11 +60,43 @@ export const readMatchingHosting = async (userId: number, query) => {
const teamIds = await findTeamIdByLeaderId(userId);
const matchingGuestings = await findGuestingByTeamsAndGameTime(teamIds, gameTime);
const matchingGames = await findGameByHostTeamsAndGameTime(teamIds, gameTime);
for (const matchingGame of matchingGames) {
const gameReviewId = await getExistingTeamReview(
userId,
matchingGame.opposingTeamId,
matchingGame.id,
undefined,
);
if (new Date() < new Date(matchingGame.gameTime)) {
matchingGame.reviewStatus = "PENDING";
} else if (!gameReviewId) {
matchingGame.reviewStatus = "UNCOMPLETED";
} else {
matchingGame.reviewStatus = "COMPLETED";
}
}

await addMemberCount(matchingGuestings);
await addMemberCount(matchingGames);
return readMatchingResponseDTO(matchingGuestings, matchingGames);
};

export const readMatchingHostingGuestUser = async (userId: number, params) => {
const guestingId = params.guestingId;
const guestUsers = await getGuestingUser(guestingId);
for (const guestUser of guestUsers) {
const guestReviewId = await getExistingUserReview(userId, guestUser.userId, guestingId);
if (new Date() < new Date(guestUser["guest.gameTime"])) {
guestUser.reviewStatus = "PENDING";
} else if (!guestReviewId) {
guestUser.reviewStatus = "UNCOMPLETED";
} else {
guestUser.reviewStatus = "COMPLETED";
}
}
return readGuestingUserResponseDTO(guestUsers);
};

export const readApplyGuestingUser = async (params) => {
const guestingId = params.guestingId;
const applyGuestingUser = await getApplyGuestingUser(guestingId);
Expand Down

0 comments on commit f12530e

Please sign in to comment.