diff --git a/src/blurting/blurting.consumer.ts b/src/blurting/blurting.consumer.ts index 5754614..a3c63da 100644 --- a/src/blurting/blurting.consumer.ts +++ b/src/blurting/blurting.consumer.ts @@ -21,11 +21,11 @@ export class BlurtingConsumer { @Process() async processNewBlurtingQuestion(job: Job) { const question: string = job.data.question; - if (question === null) { - const group = job.data.group; - await this.blurtingService.deleteGroup(group); - return; - } + // if (question === null) { + // const group = job.data.group; + // await this.blurtingService.deleteGroup(group); + // return; + // } const group: BlurtingGroupEntity = job.data.group; const users: number[] = job.data.users; await this.blurtingService.insertQuestionToGroup( diff --git a/src/blurting/blurting.controller.ts b/src/blurting/blurting.controller.ts index a0c58aa..7953db7 100644 --- a/src/blurting/blurting.controller.ts +++ b/src/blurting/blurting.controller.ts @@ -121,9 +121,10 @@ export class BlurtingController { @UseGuards(AuthGuard('access')) @Post('/register') @ApiCreatedResponse({ - description: '큐에 등록시 0 , 그룹이 있으면 1, 매칭 중이면 2', + description: + '큐에 등록시 0 , 그룹이 있으면 1, 매칭 중이면 2, 블러팅 끝났으면 3', }) - async registerGroupQueue(@Req() req: Request): Promise<0 | 1 | 2> { + async registerGroupQueue(@Req() req: Request): Promise<0 | 1 | 2 | 3> { const { id } = req.user as JwtPayload; return await this.blurtingService.registerGroupQueue(id); @@ -251,21 +252,57 @@ export class BlurtingController { description: '블러팅 탭 클릭 시 매칭 여부 반환', }) @ApiCreatedResponse({ - description: '매칭 완료 시 1, 전일 시 0, 매칭 중이면 2', + description: '매칭 전 0, 매칭 완료 1, 매칭 중 2, 블러팅 끝 3', }) async getMatching(@Req() req: Request) { const { id } = req.user as JwtPayload; const user = await this.userService.findUserByVal('id', id); - if (user.group) { + const isMatching = await this.blurtingService.isMatching(user); + + if ( + user.group && + user.group.createdAt < + new Date(new Date().getTime() - 1000 * 60 * 60 * 63) + ) { return 1; } - const isMatching = await this.blurtingService.isMatching(user); if (isMatching == true) { return 2; } + if (user.group) { + return 3; + } return 0; } + @UseGuards(AuthGuard('access')) + @Get('/result') + @ApiHeader({ + name: 'authorization', + required: true, + example: 'Bearer asdas.asdasd.asd', + }) + @ApiOperation({ + summary: '지난 블러팅', + description: '블러팅 끝나고 누구랑 매칭되었는지 반환', + }) + @ApiResponse({ + description: '매칭된 유저 정보 반환', + schema: { + properties: { + myname: { type: 'string' }, + mysex: { type: 'string' }, + othername: { type: 'string' }, + othersex: { type: 'string' }, + }, + }, + }) + async getBlurtingResult(@Req() req: Request) { + const { id } = req.user as JwtPayload; + const matchedUser = this.blurtingService.getFinalArrow(id); + return matchedUser; + } + @UseGuards(AuthGuard('access')) @Get('/:no') @ApiHeader({ diff --git a/src/blurting/blurting.service.ts b/src/blurting/blurting.service.ts index 65cd915..76f4feb 100644 --- a/src/blurting/blurting.service.ts +++ b/src/blurting/blurting.service.ts @@ -19,7 +19,7 @@ import { ReplyEntity, } from 'src/entities'; import { UserService } from 'src/user/user.service'; -import { In, Repository } from 'typeorm'; +import { Between, In, Repository } from 'typeorm'; import { Queue } from 'bull'; import { InjectQueue } from '@nestjs/bull'; import { Sex, SexOrient } from 'src/common/enums'; @@ -352,6 +352,13 @@ export class BlurtingService { async registerGroupQueue(id: number) { try { const user = await this.userService.findUserByVal('id', id); + if ( + user.group && + user.group.createdAt < + new Date(new Date().getTime() - 1000 * 60 * 60 * 63) + ) { + return 3; + } if (user.group) { return 1; } @@ -560,6 +567,39 @@ export class BlurtingService { }); return { iSended: sendDto, iReceived: receiveDto }; } + + async getFinalArrow(userId: number) { + const user = await this.userService.findUserByVal('id', userId); + const selectedUser = await this.arrowRepository.findOne({ + where: { from: { id: userId } }, + order: { no: 'DESC' }, + }); + if (selectedUser.to == null) { + return null; + } + + const arrow = await this.arrowRepository.findOne({ + where: { + from: { id: selectedUser.to.id }, + createdAt: Between( + user.group.createdAt, + new Date(user.group.createdAt.getTime() + 72 * 6 * 6 * 1000), + ), + no: 3, + }, + }); + if (arrow.to == null) { + return null; + } + + return { + myname: user.userNickname, + mysex: user.userInfo.sex, + othername: selectedUser.to.userNickname, + othersex: selectedUser.to.userInfo.sex, + }; + } + async getGroupInfo(userId: number): Promise { const groupUsers = await this.userService.getGroupUsers(userId);