Skip to content

Commit

Permalink
Merge pull request #6 from mju-likelion/feature/created-updated-at
Browse files Browse the repository at this point in the history
Room 과 User 에 createdAt updatedAt 추가
  • Loading branch information
ndaemy authored Jul 19, 2023
2 parents fc26889 + 5a6043c commit d33d9e0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Warnings:
- Added the required column `updatedAt` to the `Room` table without a default value. This is not possible if the table is not empty.
- Added the required column `updatedAt` to the `User` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Room" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL;

-- AlterTable
ALTER TABLE "User" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL;
12 changes: 8 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@ datasource db {

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

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

// 위의 코드에서 Room 모델에서 users 필드가 추가되었으며, User 모델에서는 room 필드를 옵셔널한 관계로 수정하였습니다.
14 changes: 12 additions & 2 deletions src/api/rooms/rooms.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import {
BadRequestException,
Injectable,
NotFoundException,
} from '@nestjs/common';
import { Room } from '@prisma/client';
import { customAlphabet } from 'nanoid';

Expand Down Expand Up @@ -84,9 +88,15 @@ export class RoomsService {
}

async findOne(code: string): Promise<Room> {
return this.prismaService.room.findUnique({
const room = this.prismaService.room.findUnique({
where: { code },
});

if (!room) {
throw new NotFoundException(`Room with code ${code} not found`);
}

return room;
}

getRoomSummary(code: string) {
Expand Down

0 comments on commit d33d9e0

Please sign in to comment.