- 일정 생성, 목록 조회, 당일 목록 조회 기능 구현
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import { IsArray, IsDateString, IsString } from "@nestjs/class-validator";
|
import { IsArray, IsDateString, IsString } from "@nestjs/class-validator";
|
||||||
|
|
||||||
export class ListRequestDto {
|
export class ListRequestDto {
|
||||||
|
@IsDateString()
|
||||||
|
date?: string;
|
||||||
|
|
||||||
@IsDateString()
|
@IsDateString()
|
||||||
startDate?: string;
|
startDate?: string;
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export class ScheduleRepo {
|
|||||||
constructor(@Inject('DRIZZLE') private readonly db: NodePgDatabase<typeof schema>) {}
|
constructor(@Inject('DRIZZLE') private readonly db: NodePgDatabase<typeof schema>) {}
|
||||||
|
|
||||||
async getList(accountId: string, data: DTO.ListRequest) {
|
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 schedule = schema.schedule;
|
||||||
|
|
||||||
const result = await this
|
const result = await this
|
||||||
@@ -22,14 +22,24 @@ export class ScheduleRepo {
|
|||||||
endDate: schedule.endDate,
|
endDate: schedule.endDate,
|
||||||
status: schedule.status,
|
status: schedule.status,
|
||||||
style: schedule.style,
|
style: schedule.style,
|
||||||
type: schedule.style,
|
type: schedule.type,
|
||||||
})
|
})
|
||||||
.from(schedule)
|
.from(schedule)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
eq(schedule.owner, accountId),
|
eq(schedule.owner, accountId),
|
||||||
startDate ? gte(schedule.startDate, Converter.formatDateToSqlDate(startDate)) : undefined,
|
(startDate && endDate)
|
||||||
endDate ? lte(schedule.endDate, Converter.formatDateToSqlDate(endDate)) : undefined,
|
? 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,
|
name ? like(schedule.name, `%${name}%`) : undefined,
|
||||||
(typeList && typeList.length > 0) ? inArray(schedule.type, typeList) : undefined,
|
(typeList && typeList.length > 0) ? inArray(schedule.type, typeList) : undefined,
|
||||||
(styleList && styleList.length > 0) ? inArray(schedule.style, styleList) : undefined,
|
(styleList && styleList.length > 0) ? inArray(schedule.style, styleList) : undefined,
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ export class Converter {
|
|||||||
|
|
||||||
static formatDateToSqlDate(date: string): string {
|
static formatDateToSqlDate(date: string): string {
|
||||||
const targetDate = new Date(date);
|
const targetDate = new Date(date);
|
||||||
const year = targetDate.getUTCFullYear();
|
const year = targetDate.getFullYear();
|
||||||
const month = (targetDate.getUTCMonth() + 1).toString().padStart(2, '0');
|
const month = (targetDate.getMonth() + 1).toString().padStart(2, '0');
|
||||||
const day = (targetDate.getUTCDate()).toString().padStart(2, '0');
|
const day = (targetDate.getDate()).toString().padStart(2, '0');
|
||||||
|
|
||||||
return `${year}-${month}-${day}`;
|
return `${year}-${month}-${day}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user