- DTO 공용 코드 작업 완료
This commit is contained in:
@@ -26,7 +26,7 @@
|
|||||||
"drizzle-pull:prod": "dotenv -e .env.prod -- drizzle-kit pull"
|
"drizzle-pull:prod": "dotenv -e .env.prod -- drizzle-kit pull"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@baekyangdan/core-utils": "^1.0.21",
|
"@baekyangdan/core-utils": "^1.0.23",
|
||||||
"@fastify/cookie": "^11.0.2",
|
"@fastify/cookie": "^11.0.2",
|
||||||
"@nestjs/class-transformer": "^0.4.0",
|
"@nestjs/class-transformer": "^0.4.0",
|
||||||
"@nestjs/class-validator": "^0.13.4",
|
"@nestjs/class-validator": "^0.13.4",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Body, Controller, Get, Param, Post, Req, UseGuards } from "@nestjs/common";
|
import { Body, Controller, Get, Param, Post, Req, UseGuards } from "@nestjs/common";
|
||||||
import { JwtAccessAuthGuard } from "src/middleware/auth/guard/access-token.guard";
|
import { JwtAccessAuthGuard } from "src/middleware/auth/guard/access-token.guard";
|
||||||
import { ScheduleService } from "./schedule.service";
|
import { ScheduleService } from "./schedule.service";
|
||||||
import * as DTO from './dto';
|
import { SchedulerDTO as DTO } from '@baekyangdan/core-utils';
|
||||||
import { HttpApiUrl } from "@baekyangdan/core-utils";
|
import { HttpApiUrl } from "@baekyangdan/core-utils";
|
||||||
|
|
||||||
const ScheduleApi = HttpApiUrl.Schedule;
|
const ScheduleApi = HttpApiUrl.Schedule;
|
||||||
@@ -12,19 +12,19 @@ export class ScheduleController {
|
|||||||
constructor(private readonly scheduleService: ScheduleService) {}
|
constructor(private readonly scheduleService: ScheduleService) {}
|
||||||
|
|
||||||
@Post(ScheduleApi.getList)
|
@Post(ScheduleApi.getList)
|
||||||
async getList(@Req() req, @Body() data: DTO.ListRequest): Promise<DTO.ListResponse> {
|
async getList(@Req() req, @Body() data: DTO.ScheduleListRequest): Promise<DTO.ScheduleListResponse> {
|
||||||
const result = await this.scheduleService.getList(req.user.id, data);
|
const result = await this.scheduleService.getList(req.user.id, data);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(ScheduleApi.getDetail)
|
@Get(ScheduleApi.getDetail)
|
||||||
async getDetail(@Param('id') id: string): Promise<DTO.DetailResponse> {
|
async getDetail(@Param('id') id: string): Promise<DTO.ScheduleDetailResponse> {
|
||||||
const result = await this.scheduleService.getDetail(id);
|
const result = await this.scheduleService.getDetail(id);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post(ScheduleApi.create)
|
@Post(ScheduleApi.create)
|
||||||
async create(@Req() req, @Body() data: DTO.CreateRequest): Promise<DTO.CreateResponse> {
|
async create(@Req() req, @Body() data: DTO.ScheduleCreateRequest): Promise<DTO.ScheduleCreateResponse> {
|
||||||
const result = await this.scheduleService.create(req.user.id, data);
|
const result = await this.scheduleService.create(req.user.id, data);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ import { Inject, Injectable } from '@nestjs/common';
|
|||||||
import * as schema from 'drizzle/schema';
|
import * as schema from 'drizzle/schema';
|
||||||
import { countDistinct, and, eq, gt, gte, lte, like, inArray, or } from 'drizzle-orm';
|
import { countDistinct, and, eq, gt, gte, lte, like, inArray, or } from 'drizzle-orm';
|
||||||
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
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';
|
import { Converter } from 'src/util/converter';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ScheduleRepo {
|
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.ScheduleListRequest) {
|
||||||
const { date, startDate, endDate, name, status, styleList, typeList } = data;
|
const { date, startDate, endDate, name, status, styleList, typeList } = data;
|
||||||
const schedule = schema.schedule;
|
const schedule = schema.schedule;
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ export class ScheduleRepo {
|
|||||||
status: schedule.status,
|
status: schedule.status,
|
||||||
startDate: new Date(schedule.startDate),
|
startDate: new Date(schedule.startDate),
|
||||||
endDate: new Date(schedule.endDate)
|
endDate: new Date(schedule.endDate)
|
||||||
}
|
} as DTO.ScheduleList;
|
||||||
})
|
})
|
||||||
|
|
||||||
return resultData;
|
return resultData;
|
||||||
@@ -82,8 +82,8 @@ export class ScheduleRepo {
|
|||||||
async create(
|
async create(
|
||||||
accountId: string,
|
accountId: string,
|
||||||
name: string,
|
name: string,
|
||||||
startDate: string,
|
startDate: Date,
|
||||||
endDate: string,
|
endDate: Date,
|
||||||
startTime: string,
|
startTime: string,
|
||||||
endTime: string,
|
endTime: string,
|
||||||
style: string,
|
style: string,
|
||||||
@@ -97,8 +97,8 @@ export class ScheduleRepo {
|
|||||||
name: name,
|
name: name,
|
||||||
content: content,
|
content: content,
|
||||||
owner: accountId,
|
owner: accountId,
|
||||||
startDate: startDate,
|
startDate: Converter.formatDateToSqlDate(startDate),
|
||||||
endDate: endDate,
|
endDate: Converter.formatDateToSqlDate(endDate),
|
||||||
startTime: startTime,
|
startTime: startTime,
|
||||||
endTime: endTime,
|
endTime: endTime,
|
||||||
status: 'yet',
|
status: 'yet',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { ScheduleRepo } from "./schedule.repo";
|
import { ScheduleRepo } from "./schedule.repo";
|
||||||
import * as DTO from './dto';
|
import { SchedulerDTO as DTO } from '@baekyangdan/core-utils';
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import { DateFormat, TimeFormat } from "@baekyangdan/core-utils";
|
import { DateFormat, TimeFormat } from "@baekyangdan/core-utils";
|
||||||
import { ko } from "date-fns/locale";
|
import { ko } from "date-fns/locale";
|
||||||
@@ -11,22 +11,24 @@ export class ScheduleService {
|
|||||||
private readonly scheduleRepo: ScheduleRepo
|
private readonly scheduleRepo: ScheduleRepo
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async getList(accountId: string, data: DTO.ListRequest): Promise<DTO.ListResponse> {
|
async getList(accountId: string, data: DTO.ScheduleListRequest): Promise<DTO.ScheduleListResponse> {
|
||||||
const result = await this.scheduleRepo.getList(accountId, data);
|
const result = await this.scheduleRepo.getList(accountId, data);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
|
message: '일정 목록 탐색 완료',
|
||||||
data: result
|
data: result
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDetail(id: string) {
|
async getDetail(id: string): Promise<DTO.ScheduleDetailResponse> {
|
||||||
const result = await this.scheduleRepo.getDetail(id);
|
const result = await this.scheduleRepo.getDetail(id);
|
||||||
|
|
||||||
if (result.length < 1) {
|
if (result.length < 1) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: '존재하지 않는 일정입니다.'
|
error: '존재하지 않는 일정입니다.',
|
||||||
|
code: ''
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,16 +36,19 @@ export class ScheduleService {
|
|||||||
...result[0],
|
...result[0],
|
||||||
startDate: new Date(result[0].startDate),
|
startDate: new Date(result[0].startDate),
|
||||||
endDate: new Date(result[0].endDate),
|
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 {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data: data
|
data: data,
|
||||||
|
message: '일정을 가져왔습니다.'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(accountId: string, data: DTO.CreateRequest): Promise<DTO.CreateResponse> {
|
async create(accountId: string, data: DTO.ScheduleCreateRequest): Promise<DTO.ScheduleCreateResponse> {
|
||||||
const { name, content, startDate, endDate, startTime, endTime, style, type } = data;
|
const { name, content, startDate, endDate, startTime, endTime, style, type } = data;
|
||||||
|
|
||||||
const result = await this.scheduleRepo.create(
|
const result = await this.scheduleRepo.create(
|
||||||
@@ -61,12 +66,14 @@ export class ScheduleService {
|
|||||||
if (result.rowCount) {
|
if (result.rowCount) {
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "일정이 생성되었습니다."
|
message: "일정이 생성되었습니다.",
|
||||||
|
data: {}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: "일정 생성에 실패하였습니다."
|
error: "일정 생성에 실패하였습니다.",
|
||||||
|
code: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export class Converter {
|
|||||||
return bcrypt.compareSync(rawPassword, hashedPassword);
|
return bcrypt.compareSync(rawPassword, hashedPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
static formatDateToSqlDate(date: string): string {
|
static formatDateToSqlDate(date: Date): string {
|
||||||
const targetDate = new Date(date);
|
const targetDate = new Date(date);
|
||||||
const year = targetDate.getFullYear();
|
const year = targetDate.getFullYear();
|
||||||
const month = (targetDate.getMonth() + 1).toString().padStart(2, '0');
|
const month = (targetDate.getMonth() + 1).toString().padStart(2, '0');
|
||||||
|
|||||||
10
yarn.lock
10
yarn.lock
@@ -999,9 +999,9 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@baekyangdan/core-utils@npm:^1.0.21":
|
"@baekyangdan/core-utils@npm:^1.0.23":
|
||||||
version: 1.0.21
|
version: 1.0.23
|
||||||
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"
|
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:
|
dependencies:
|
||||||
"@swc/core": "npm:^1.15.5"
|
"@swc/core": "npm:^1.15.5"
|
||||||
class-transformer: "npm:^0.5.1"
|
class-transformer: "npm:^0.5.1"
|
||||||
@@ -1009,7 +1009,7 @@ __metadata:
|
|||||||
date-fns: "npm:^4.1.0"
|
date-fns: "npm:^4.1.0"
|
||||||
reflect-metadata: "npm:^0.2.2"
|
reflect-metadata: "npm:^0.2.2"
|
||||||
tsup: "npm:^8.5.1"
|
tsup: "npm:^8.5.1"
|
||||||
checksum: 10c0/52a3e70312ffdad0163f7c6954a8fa126583035500f505bacbd52045484ed9783a522f96661ab0572c0578cc97589fc767b877b9de1a06dad2fa537a79f778ef
|
checksum: 10c0/6d3310c53878b13c523abed37cdc492cf7f5e1e7cbad0272962520778b6acdc7061c1e0eef44c7d87ede26c7a882bff06f508fb2bccefe8a6e92219f323607f9
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@@ -4899,7 +4899,7 @@ __metadata:
|
|||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "back@workspace:."
|
resolution: "back@workspace:."
|
||||||
dependencies:
|
dependencies:
|
||||||
"@baekyangdan/core-utils": "npm:^1.0.21"
|
"@baekyangdan/core-utils": "npm:^1.0.23"
|
||||||
"@eslint/eslintrc": "npm:^3.2.0"
|
"@eslint/eslintrc": "npm:^3.2.0"
|
||||||
"@eslint/js": "npm:^9.18.0"
|
"@eslint/js": "npm:^9.18.0"
|
||||||
"@fastify/cookie": "npm:^11.0.2"
|
"@fastify/cookie": "npm:^11.0.2"
|
||||||
|
|||||||
Reference in New Issue
Block a user