Skip to content

Commit

Permalink
feat: get blurting result
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeahxx19 committed Feb 1, 2024
1 parent 4dfe59c commit c15b524
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/blurting/blurting.consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
47 changes: 42 additions & 5 deletions src/blurting/blurting.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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({
Expand Down
42 changes: 41 additions & 1 deletion src/blurting/blurting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<OtherPeopleInfoDto[]> {
const groupUsers = await this.userService.getGroupUsers(userId);

Expand Down

0 comments on commit c15b524

Please sign in to comment.