Skip to content

Commit

Permalink
feat: make and get arrows
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeahxx19 committed Mar 21, 2024
1 parent 021d948 commit 8f002fc
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/event/event.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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<ArrowInfoResponseDto> {
const { id } = req.user as JwtPayload;
return await this.eventService.getArrows(id);
}

@UseGuards(AuthGuard('access'))
@Get('/group-info')
@ApiOperation({
Expand Down
31 changes: 31 additions & 0 deletions src/event/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
}
}

0 comments on commit 8f002fc

Please sign in to comment.