From d580f537754b633cc36860a3c02b319ec13b2e1f Mon Sep 17 00:00:00 2001 From: geonhee-min Date: Thu, 11 Dec 2025 17:04:19 +0900 Subject: [PATCH] =?UTF-8?q?issue=20#63=20-=20=EC=9D=BC=EC=A0=95=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1,=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C,?= =?UTF-8?q?=20=EB=8B=B9=EC=9D=BC=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../schedule/dto/list/list-request.dto.ts | 3 +++ src/modules/schedule/schedule.repo.ts | 18 ++++++++++++++---- src/util/converter.ts | 6 +++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/modules/schedule/dto/list/list-request.dto.ts b/src/modules/schedule/dto/list/list-request.dto.ts index f6ae775..27a37c2 100644 --- a/src/modules/schedule/dto/list/list-request.dto.ts +++ b/src/modules/schedule/dto/list/list-request.dto.ts @@ -1,6 +1,9 @@ import { IsArray, IsDateString, IsString } from "@nestjs/class-validator"; export class ListRequestDto { + @IsDateString() + date?: string; + @IsDateString() startDate?: string; diff --git a/src/modules/schedule/schedule.repo.ts b/src/modules/schedule/schedule.repo.ts index 2b036f1..9499472 100644 --- a/src/modules/schedule/schedule.repo.ts +++ b/src/modules/schedule/schedule.repo.ts @@ -10,7 +10,7 @@ export class ScheduleRepo { constructor(@Inject('DRIZZLE') private readonly db: NodePgDatabase) {} async getList(accountId: string, data: DTO.ListRequest) { - const { startDate, endDate, name, status, styleList, typeList } = data; + const { date, startDate, endDate, name, status, styleList, typeList } = data; const schedule = schema.schedule; const result = await this @@ -22,14 +22,24 @@ export class ScheduleRepo { endDate: schedule.endDate, status: schedule.status, style: schedule.style, - type: schedule.style, + type: schedule.type, }) .from(schedule) .where( and( eq(schedule.owner, accountId), - startDate ? gte(schedule.startDate, Converter.formatDateToSqlDate(startDate)) : undefined, - endDate ? lte(schedule.endDate, Converter.formatDateToSqlDate(endDate)) : undefined, + (startDate && endDate) + ? and( + lte(schedule.startDate, Converter.formatDateToSqlDate(endDate)), + gte(schedule.endDate, Converter.formatDateToSqlDate(startDate)) + ) + : undefined, + date + ? and( + lte(schedule.startDate, Converter.formatDateToSqlDate(date)), + gte(schedule.endDate, Converter.formatDateToSqlDate(date)) + ) + : undefined, name ? like(schedule.name, `%${name}%`) : undefined, (typeList && typeList.length > 0) ? inArray(schedule.type, typeList) : undefined, (styleList && styleList.length > 0) ? inArray(schedule.style, styleList) : undefined, diff --git a/src/util/converter.ts b/src/util/converter.ts index c3ea70f..481c8a6 100644 --- a/src/util/converter.ts +++ b/src/util/converter.ts @@ -11,9 +11,9 @@ export class Converter { static formatDateToSqlDate(date: string): string { const targetDate = new Date(date); - const year = targetDate.getUTCFullYear(); - const month = (targetDate.getUTCMonth() + 1).toString().padStart(2, '0'); - const day = (targetDate.getUTCDate()).toString().padStart(2, '0'); + const year = targetDate.getFullYear(); + const month = (targetDate.getMonth() + 1).toString().padStart(2, '0'); + const day = (targetDate.getDate()).toString().padStart(2, '0'); return `${year}-${month}-${day}`; }