Skip to content

Commit

Permalink
화살표 Day 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
overthestream committed Jan 27, 2024
1 parent 86fbe34 commit 83fc061
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
15 changes: 12 additions & 3 deletions src/blurting/blurting.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,17 @@ export class BlurtingController {
return await this.blurtingService.likeAnswer(id, answerId);
}
@UseGuards(AuthGuard('access'))
@Post('/arrow/:toId')
@Post('/arrow/:toId/:day')
@ApiParam({
description: '화살표 받을 사람 id',
name: 'toId',
type: Number,
})
@ApiParam({
description: 'day',
name: 'day, 1,2,3으로 보내주세요',
type: Number,
})
@ApiOperation({
summary: '화살표 보내기',
description: '화살표 보내기',
Expand All @@ -194,9 +199,13 @@ export class BlurtingController {
@ApiOkResponse({
description: '화살표 보내기 성공',
})
async makeArrow(@Req() req: Request, @Param('toId') toId: number) {
async makeArrow(
@Req() req: Request,
@Param('toId') toId: number,
@Param('day') day: number,
) {
const { id } = req.user as JwtPayload;
return await this.blurtingService.makeArrow(id, toId);
return await this.blurtingService.makeArrow(id, toId, day);
}
@UseGuards(AuthGuard('access'))
@Get('/arrow')
Expand Down
13 changes: 7 additions & 6 deletions src/blurting/blurting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ export class BlurtingService {
}
}

async makeArrow(userId: number, toId: number) {
async makeArrow(userId: number, toId: number, day: number) {
const user = await this.userService.findUserByVal('id', userId);

const arrow = await this.arrowRepository.findOne({
Expand All @@ -490,9 +490,10 @@ export class BlurtingService {
},
order: { no: 'DESC' },
});
let no = 1;
if (arrow) no = arrow.no + 1;

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 },
Expand All @@ -504,12 +505,12 @@ export class BlurtingService {

this.fcmService.sendPush(
toId,
`${user.userNickname}님이 당신에게 화살표를 보냈습니다!`,
`${user.userNickname}님이 당신에게 화살을 보냈습니다!`,
'blurting',
);
const newEntity = this.notificationRepository.create({
user: { id: userId },
body: `${user.userNickname}님이 당신에게 화살표를 보냈습니다!`,
body: `${user.userNickname}님이 당신에게 화살을 보냈습니다!`,
});
await this.notificationRepository.insert(newEntity);
}
Expand Down

0 comments on commit 83fc061

Please sign in to comment.