Skip to content

Commit

Permalink
feat: pokerId/goal 포커 목표 점수 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
w8385 committed Feb 4, 2024
1 parent 921c07c commit 0baf401
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
File renamed without changes.
4 changes: 4 additions & 0 deletions src/poker/dto/update-poker.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/swagger';
import { CreatePokerDto } from './create-poker.dto';

export class UpdatePokerDto extends PartialType(CreatePokerDto) {}
15 changes: 13 additions & 2 deletions src/poker/poker.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common';
import { PokerService } from './poker.service';
import { CreatePokerDto } from './dto/create-user.dto';
import { CreatePokerDto } from './dto/create-poker.dto';
import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
import { UpdatePokerDto } from './dto/update-poker.dto';

@Controller('poker')
@ApiTags('Poker')
Expand Down Expand Up @@ -37,6 +38,16 @@ export class PokerController {
return this.pokerService.get(pokerId);
}

@Patch(':pokerId/goal')
@ApiOperation({ summary: '포커 목표 점수 수정' })
@ApiParam({ name: 'pokerId', description: '포커 id' })
async updateGoal(
@Param('pokerId') pokerId: string,
@Body() updatePokerDto: UpdatePokerDto,
) {
return this.pokerService.updateGoal(pokerId, updatePokerDto);
}

@Get(':pokerId/calc')
@ApiOperation({ summary: '포커 결과 계산' })
@ApiParam({ name: 'pokerId', description: '포커 id' })
Expand Down
12 changes: 11 additions & 1 deletion src/poker/poker.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Inject, Injectable } from '@nestjs/common';
import { CreatePokerDto } from './dto/create-user.dto';
import { CreatePokerDto } from './dto/create-poker.dto';
import { UserService } from '../user/user.service';
import { v4 as uuidv4 } from 'uuid';
import { RedisClientType } from 'redis';
import { UpdatePokerDto } from './dto/update-poker.dto';

@Injectable()
export class PokerService {
Expand Down Expand Up @@ -65,6 +66,15 @@ export class PokerService {
return await this.redisClient.json.get(id);
}

async updateGoal(pokerId: string, updatePokerDto: UpdatePokerDto) {
const poker = await this.redisClient.json.get(pokerId);
for (const handle in updatePokerDto.participants) {
poker['participants'][handle].goal = updatePokerDto.participants[handle];
}

return await this.redisClient.json.set(pokerId, '.', poker);
}

async calc(pokerId: string) {
const poker = await this.redisClient.json.get(pokerId);
const result = {
Expand Down

0 comments on commit 0baf401

Please sign in to comment.