From a30fb01add4075f8029e373330ae02c0f6dd930a Mon Sep 17 00:00:00 2001 From: geonhee-min Date: Wed, 17 Dec 2025 17:02:34 +0900 Subject: [PATCH] =?UTF-8?q?issue=20#=20-=20DTO=20=EA=B3=B5=EC=9A=A9=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=97=85=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/modules/schedule/schedule.controller.ts | 8 +++--- src/modules/schedule/schedule.repo.ts | 14 +++++------ src/modules/schedule/schedule.service.ts | 27 +++++++++++++-------- src/util/converter.ts | 2 +- yarn.lock | 10 ++++---- 6 files changed, 35 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 4621e94..d939f51 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "drizzle-pull:prod": "dotenv -e .env.prod -- drizzle-kit pull" }, "dependencies": { - "@baekyangdan/core-utils": "^1.0.21", + "@baekyangdan/core-utils": "^1.0.23", "@fastify/cookie": "^11.0.2", "@nestjs/class-transformer": "^0.4.0", "@nestjs/class-validator": "^0.13.4", diff --git a/src/modules/schedule/schedule.controller.ts b/src/modules/schedule/schedule.controller.ts index 4f563f3..412cc97 100644 --- a/src/modules/schedule/schedule.controller.ts +++ b/src/modules/schedule/schedule.controller.ts @@ -1,7 +1,7 @@ import { Body, Controller, Get, Param, Post, Req, UseGuards } from "@nestjs/common"; import { JwtAccessAuthGuard } from "src/middleware/auth/guard/access-token.guard"; import { ScheduleService } from "./schedule.service"; -import * as DTO from './dto'; +import { SchedulerDTO as DTO } from '@baekyangdan/core-utils'; import { HttpApiUrl } from "@baekyangdan/core-utils"; const ScheduleApi = HttpApiUrl.Schedule; @@ -12,19 +12,19 @@ export class ScheduleController { constructor(private readonly scheduleService: ScheduleService) {} @Post(ScheduleApi.getList) - async getList(@Req() req, @Body() data: DTO.ListRequest): Promise { + async getList(@Req() req, @Body() data: DTO.ScheduleListRequest): Promise { const result = await this.scheduleService.getList(req.user.id, data); return result; } @Get(ScheduleApi.getDetail) - async getDetail(@Param('id') id: string): Promise { + async getDetail(@Param('id') id: string): Promise { const result = await this.scheduleService.getDetail(id); return result; } @Post(ScheduleApi.create) - async create(@Req() req, @Body() data: DTO.CreateRequest): Promise { + async create(@Req() req, @Body() data: DTO.ScheduleCreateRequest): Promise { const result = await this.scheduleService.create(req.user.id, data); return result; } diff --git a/src/modules/schedule/schedule.repo.ts b/src/modules/schedule/schedule.repo.ts index 9499472..bf93179 100644 --- a/src/modules/schedule/schedule.repo.ts +++ b/src/modules/schedule/schedule.repo.ts @@ -2,14 +2,14 @@ import { Inject, Injectable } from '@nestjs/common'; import * as schema from 'drizzle/schema'; import { countDistinct, and, eq, gt, gte, lte, like, inArray, or } from 'drizzle-orm'; import { NodePgDatabase } from 'drizzle-orm/node-postgres'; -import * as DTO from './dto'; +import { SchedulerDTO as DTO } from '@baekyangdan/core-utils'; import { Converter } from 'src/util/converter'; @Injectable() export class ScheduleRepo { constructor(@Inject('DRIZZLE') private readonly db: NodePgDatabase) {} - async getList(accountId: string, data: DTO.ListRequest) { + async getList(accountId: string, data: DTO.ScheduleListRequest) { const { date, startDate, endDate, name, status, styleList, typeList } = data; const schedule = schema.schedule; @@ -57,7 +57,7 @@ export class ScheduleRepo { status: schedule.status, startDate: new Date(schedule.startDate), endDate: new Date(schedule.endDate) - } + } as DTO.ScheduleList; }) return resultData; @@ -82,8 +82,8 @@ export class ScheduleRepo { async create( accountId: string, name: string, - startDate: string, - endDate: string, + startDate: Date, + endDate: Date, startTime: string, endTime: string, style: string, @@ -97,8 +97,8 @@ export class ScheduleRepo { name: name, content: content, owner: accountId, - startDate: startDate, - endDate: endDate, + startDate: Converter.formatDateToSqlDate(startDate), + endDate: Converter.formatDateToSqlDate(endDate), startTime: startTime, endTime: endTime, status: 'yet', diff --git a/src/modules/schedule/schedule.service.ts b/src/modules/schedule/schedule.service.ts index 5e9e2b7..0cd44f4 100644 --- a/src/modules/schedule/schedule.service.ts +++ b/src/modules/schedule/schedule.service.ts @@ -1,6 +1,6 @@ import { Injectable } from "@nestjs/common"; import { ScheduleRepo } from "./schedule.repo"; -import * as DTO from './dto'; +import { SchedulerDTO as DTO } from '@baekyangdan/core-utils'; import { format } from "date-fns"; import { DateFormat, TimeFormat } from "@baekyangdan/core-utils"; import { ko } from "date-fns/locale"; @@ -11,22 +11,24 @@ export class ScheduleService { private readonly scheduleRepo: ScheduleRepo ) {} - async getList(accountId: string, data: DTO.ListRequest): Promise { + async getList(accountId: string, data: DTO.ScheduleListRequest): Promise { const result = await this.scheduleRepo.getList(accountId, data); return { success: true, + message: '일정 목록 탐색 완료', data: result }; } - async getDetail(id: string) { + async getDetail(id: string): Promise { const result = await this.scheduleRepo.getDetail(id); if (result.length < 1) { return { success: false, - message: '존재하지 않는 일정입니다.' + error: '존재하지 않는 일정입니다.', + code: '' }; } @@ -34,16 +36,19 @@ export class ScheduleService { ...result[0], startDate: new Date(result[0].startDate), endDate: new Date(result[0].endDate), - createdAt: format(result[0].createdAt, `${DateFormat.KOREAN} ${TimeFormat.KOREAN_SIMPLE}`, { locale: ko }) - } + createdAt: format(result[0].createdAt, `${DateFormat.KOREAN} ${TimeFormat.KOREAN_SIMPLE}`, { locale: ko }), + startTime: format(new Date(`2000-01-22T${result[0].startTime}`), `${TimeFormat.KOREAN_SIMPLE}`, { locale: ko }), + endTime: format(new Date(`2000-01-22T${result[0].endTime}`), `${TimeFormat.KOREAN_SIMPLE}`, { locale: ko }) + } as DTO.ScheduleDetail; return { success: true, - data: data + data: data, + message: '일정을 가져왔습니다.' }; } - async create(accountId: string, data: DTO.CreateRequest): Promise { + async create(accountId: string, data: DTO.ScheduleCreateRequest): Promise { const { name, content, startDate, endDate, startTime, endTime, style, type } = data; const result = await this.scheduleRepo.create( @@ -61,12 +66,14 @@ export class ScheduleService { if (result.rowCount) { return { success: true, - message: "일정이 생성되었습니다." + message: "일정이 생성되었습니다.", + data: {} }; } else { return { success: false, - message: "일정 생성에 실패하였습니다." + error: "일정 생성에 실패하였습니다.", + code: '' } } } diff --git a/src/util/converter.ts b/src/util/converter.ts index 481c8a6..030fab3 100644 --- a/src/util/converter.ts +++ b/src/util/converter.ts @@ -9,7 +9,7 @@ export class Converter { return bcrypt.compareSync(rawPassword, hashedPassword); } - static formatDateToSqlDate(date: string): string { + static formatDateToSqlDate(date: Date): string { const targetDate = new Date(date); const year = targetDate.getFullYear(); const month = (targetDate.getMonth() + 1).toString().padStart(2, '0'); diff --git a/yarn.lock b/yarn.lock index 1641b89..d2373cd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -999,9 +999,9 @@ __metadata: languageName: node linkType: hard -"@baekyangdan/core-utils@npm:^1.0.21": - version: 1.0.21 - resolution: "@baekyangdan/core-utils@npm:1.0.21::__archiveUrl=https%3A%2F%2Fgitea.bkdhome.p-e.kr%2Fapi%2Fpackages%2Fbaekyangdan%2Fnpm%2F%2540baekyangdan%252Fcore-utils%2F-%2F1.0.21%2Fcore-utils-1.0.21.tgz" +"@baekyangdan/core-utils@npm:^1.0.23": + version: 1.0.23 + resolution: "@baekyangdan/core-utils@npm:1.0.23::__archiveUrl=https%3A%2F%2Fgitea.bkdhome.p-e.kr%2Fapi%2Fpackages%2Fbaekyangdan%2Fnpm%2F%2540baekyangdan%252Fcore-utils%2F-%2F1.0.23%2Fcore-utils-1.0.23.tgz" dependencies: "@swc/core": "npm:^1.15.5" class-transformer: "npm:^0.5.1" @@ -1009,7 +1009,7 @@ __metadata: date-fns: "npm:^4.1.0" reflect-metadata: "npm:^0.2.2" tsup: "npm:^8.5.1" - checksum: 10c0/52a3e70312ffdad0163f7c6954a8fa126583035500f505bacbd52045484ed9783a522f96661ab0572c0578cc97589fc767b877b9de1a06dad2fa537a79f778ef + checksum: 10c0/6d3310c53878b13c523abed37cdc492cf7f5e1e7cbad0272962520778b6acdc7061c1e0eef44c7d87ede26c7a882bff06f508fb2bccefe8a6e92219f323607f9 languageName: node linkType: hard @@ -4899,7 +4899,7 @@ __metadata: version: 0.0.0-use.local resolution: "back@workspace:." dependencies: - "@baekyangdan/core-utils": "npm:^1.0.21" + "@baekyangdan/core-utils": "npm:^1.0.23" "@eslint/eslintrc": "npm:^3.2.0" "@eslint/js": "npm:^9.18.0" "@fastify/cookie": "npm:^11.0.2"