diff --git a/src/event/event.controller.ts b/src/event/event.controller.ts index 8496fba..73b4ed3 100644 --- a/src/event/event.controller.ts +++ b/src/event/event.controller.ts @@ -34,6 +34,7 @@ import { import { BlurtingService } from 'src/blurting/blurting.service'; import { UserProfileDto } from 'src/dtos/user.dto'; import { OtherPeopleInfoDto } from 'src/blurting/dtos/otherPeopleInfo.dto'; +import { ArrowInfoResponseDto } from 'src/blurting/dtos/arrowInfoResponse.dto'; @Controller('event') @ApiTags('event') @@ -147,6 +148,51 @@ export class EventController { return matchedUser; } + @UseGuards(AuthGuard('access')) + @Post('/arrow/:toId/:day') + @ApiParam({ + description: '화살표 받을 사람 id', + name: 'toId', + type: Number, + }) + @ApiParam({ + description: 'day', + name: 'day 0으로 보내주세요', + type: Number, + }) + @ApiOperation({ + summary: '화살표 보내기', + description: '화살표 보내기', + }) + @ApiUnauthorizedResponse({ description: '토큰 만료' }) + @ApiOkResponse({ + description: '화살표 보내기 성공', + }) + async makeArrow( + @Req() req: Request, + @Param('toId') toId: number, + @Param('day') day: number, + ) { + const { id } = req.user as JwtPayload; + return await this.eventService.makeArrow(id, toId, day); + } + + @UseGuards(AuthGuard('access')) + @Get('/arrow') + @ApiOperation({ + summary: '내 화살표 보기', + description: '내 화살표 보기', + }) + @ApiUnauthorizedResponse({ description: '토큰 만료' }) + @ApiOkResponse({ + description: '내 화살표 보기 성공', + type: ArrowInfoResponseDto, + }) + async getArrows(@Req() req: Request): Promise { + const { id } = req.user as JwtPayload; + return await this.eventService.getArrows(id); + } + @UseGuards(AuthGuard('access')) @Get('/group-info') @ApiOperation({ diff --git a/src/event/event.service.ts b/src/event/event.service.ts index 66eb8fc..2ca389c 100644 --- a/src/event/event.service.ts +++ b/src/event/event.service.ts @@ -321,4 +321,35 @@ export class EventService { }); return result; } + + async makeArrow(userId: number, toId: number, day: number) { + const user = await this.userService.findUserByVal('id', userId); + const eventUser = await this.getEventInfo(user); + + const arrow = await this.arrowRepository.findOne({ + where: { + from: { id: userId }, + group: eventUser.group, + }, + order: { no: 'DESC' }, + }); + const no = day; + if (arrow && arrow.no >= day) { + throw new BadRequestException('이미 화살표 존재'); + } + const newArrow = this.arrowRepository.create({ + from: { id: userId }, + to: toId === -1 ? null : { id: toId }, + group: eventUser.group, + no: no, + }); + + await this.arrowRepository.save(newArrow); + if (toId == -1 || toId == userId) return; + await this.fcmService.sendPush( + toId, + `${user.userNickname}님이 당신에게 화살을 보냈습니다!`, + 'blurting', + ); + } }