Skip to content

Commit

Permalink
fix: 코드리뷰 기반 수정 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
kMinsAlgorithm committed Aug 8, 2023
1 parent 2c3a572 commit f22c6d4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 35 deletions.
14 changes: 3 additions & 11 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}
Expand All @@ -12,29 +9,24 @@ datasource db {
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
}

// 여기에 모델들 정의하시면 됩니다.

// 정의 완료 후 'yarn prisma migrate dev' 명령 입력하셔서 migrate 진행하시면 됩니다.
model Room {
code String @id
dates String[]
dateOnly Boolean
startTime String?
endTime String?
users User[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
dates String[]
users User[]
}

model User {
id String @id @default(uuid())
username String @unique
password String
enableTimes String[]
room Room @relation(fields: [roomId], references: [code])
roomId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
room Room @relation(fields: [roomId], references: [code])
}

// 위의 코드에서 Room 모델에서 users 필드가 추가되었으며, User 모델에서는 room 필드를 옵셔널한 관계로 수정하였습니다.
2 changes: 1 addition & 1 deletion src/api/auth/jwt.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ExtractJwt, Strategy } from 'passport-jwt';
import { PassportStrategy } from '@nestjs/passport';
import { Inject, Injectable, UnauthorizedException } from '@nestjs/common';
import { Inject, Injectable } from '@nestjs/common';
import authConfig from 'src/config/authConfig';
import { ConfigType } from '@nestjs/config';

Expand Down
5 changes: 2 additions & 3 deletions src/api/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
Controller,
Post,
Body,
Req,
Patch,
UseGuards,
Param,
Expand Down Expand Up @@ -31,9 +30,9 @@ export class UsersController {
}

@UseGuards(AuthGuard('jwt'))
@Patch()
@Patch(':roomCode')
update(
@Query('roomCode') roomCode: string,
@Param('roomCode') roomCode: string,
@Body() updateUserDto: UpdateUserDto
) {
return this.usersService.update(roomCode, updateUserDto);
Expand Down
41 changes: 21 additions & 20 deletions src/api/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ export class UsersService {
private readonly roomService: RoomsService,
private authService: AuthService
) {}

private async isDateOnlyFormatValid(dateOnly: boolean, dates: string[]) {
let result = true;
if (!dateOnly) {
for (const date of dates) {
const [_, selectedTime] = date.split(' ');

Check warning on line 28 in src/api/users/users.service.ts

View workflow job for this annotation

GitHub Actions / CI

'_' is assigned a value but never used
if (!selectedTime) {
result = false;
}
}
}
return result;
}

async findOne(username: string): Promise<User> {
return this.prismaService.user.findUnique({
where: { username },
});
}

async createAppointment(createAppointmentDto: CreateAppointmentDto) {
const badRequestErros = [];
const notFoundErros = [];
Expand Down Expand Up @@ -50,7 +70,7 @@ export class UsersService {
if (badRequestErros.length > 0) {
throw new BadRequestException(badRequestErros);
}

console.log(roomCode);
if (!(await this.roomService.findOne(roomCode))) {
notFoundErros.push('Room does not exist');
}
Expand Down Expand Up @@ -78,25 +98,6 @@ export class UsersService {
return token;
}

async findOne(username: string): Promise<User> {
return this.prismaService.user.findUnique({
where: { username },
});
}

async isDateOnlyFormatValid(dateOnly: boolean, dates: string[]) {
let result = true;
if (!dateOnly) {
for (const date of dates) {
const [_, selectedTime] = date.split(' ');
if (!selectedTime) {
result = false;
}
}
}
return result;
}

async update(roomCode: string, updateUserDto: UpdateUserDto) {
const badRequestErros = [];
const notFoundErros = [];
Expand Down

0 comments on commit f22c6d4

Please sign in to comment.