From 17335a26e7b3bd7b729468f3d4580ee433201d8f Mon Sep 17 00:00:00 2001 From: geonhee-min Date: Mon, 15 Dec 2025 17:35:35 +0900 Subject: [PATCH] =?UTF-8?q?issue=20#63=20-=20=EC=9D=BC=EC=A0=95=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- drizzle/schema.ts | 34 ++++++++++----------- package.json | 3 +- src/middleware/auth/auth.service.ts | 2 +- src/modules/account/account.controller.ts | 26 ++++++++-------- src/modules/schedule/schedule.controller.ts | 12 +++++--- src/modules/schedule/schedule.service.ts | 6 +++- yarn.lock | 11 ++++--- 7 files changed, 53 insertions(+), 41 deletions(-) diff --git a/drizzle/schema.ts b/drizzle/schema.ts index 5621f15..2154fc7 100644 --- a/drizzle/schema.ts +++ b/drizzle/schema.ts @@ -1,4 +1,4 @@ -import { pgTable, foreignKey, uuid, text, date, boolean, varchar, index, time, primaryKey, pgSequence } from "drizzle-orm/pg-core" +import { pgTable, varchar, date, boolean, timestamp, uuid, foreignKey, text, index, time, primaryKey, pgSequence } from "drizzle-orm/pg-core" import { sql } from "drizzle-orm" @@ -19,10 +19,23 @@ export const userBadgeIdSeq = pgSequence("user_badge_id_seq", { startWith: "1", export const userBlockingIdSeq = pgSequence("user_blocking_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) export const emailAddressIdSeq = pgSequence("email_address_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false }) +export const account = pgTable("account", { + name: varchar().notNull(), + email: varchar().notNull(), + password: varchar().notNull(), + birthday: date(), + accountId: varchar("account_id").notNull(), + nickname: varchar().notNull(), + status: varchar().default('active').notNull(), + isDeleted: boolean("is_deleted").default(false).notNull(), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), + id: uuid().default(sql`uuid_generate_v4()`).primaryKey().notNull(), +}); + export const comment = pgTable("comment", { id: uuid().default(sql`uuid_generate_v4()`).primaryKey().notNull(), content: text(), - createdAt: date("created_at"), + createdAt: timestamp("created_at", { mode: 'string' }), isDeleted: boolean("is_deleted").default(false), writerId: uuid("writer_id"), parentId: uuid("parent_id"), @@ -39,19 +52,6 @@ export const comment = pgTable("comment", { }), ]); -export const account = pgTable("account", { - name: varchar().notNull(), - email: varchar().notNull(), - password: varchar().notNull(), - birthday: date(), - accountId: varchar("account_id").notNull(), - nickname: varchar().notNull(), - status: varchar().default('active').notNull(), - isDeleted: boolean("is_deleted").default(false).notNull(), - createdAt: date("created_at").defaultNow().notNull(), - id: uuid().default(sql`uuid_generate_v4()`).primaryKey().notNull(), -}); - export const participant = pgTable("participant", { participantId: uuid("participant_id").notNull(), scheduleId: uuid("schedule_id").notNull(), @@ -80,7 +80,7 @@ export const schedule = pgTable("schedule", { content: text(), isDeleted: boolean("is_deleted").default(false).notNull(), type: varchar().notNull(), - createdAt: date("created_at"), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), owner: uuid().notNull(), style: varchar().notNull(), startTime: time("start_time").notNull(), @@ -122,7 +122,7 @@ export const follow = pgTable("follow", { isDeleted: boolean("is_deleted").default(false), isAccepted: boolean("is_accepted").default(false), isLinked: boolean("is_linked").default(false), - createdAt: date("created_at"), + createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), following: uuid().notNull(), follower: uuid().notNull(), }, (table) => [ diff --git a/package.json b/package.json index 09d04fe..031282e 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.4", + "@baekyangdan/core-utils": "^1.0.9", "@fastify/cookie": "^11.0.2", "@nestjs/class-transformer": "^0.4.0", "@nestjs/class-validator": "^0.13.4", @@ -38,6 +38,7 @@ "@nestjs/platform-express": "^11.0.1", "@nestjs/platform-fastify": "^11.1.9", "bcrypt": "^6.0.0", + "date-fns": "^4.1.0", "dotenv": "^17.2.3", "drizzle-kit": "^0.31.7", "drizzle-orm": "^0.44.7", diff --git a/src/middleware/auth/auth.service.ts b/src/middleware/auth/auth.service.ts index 940bac8..158afe8 100644 --- a/src/middleware/auth/auth.service.ts +++ b/src/middleware/auth/auth.service.ts @@ -6,7 +6,7 @@ export class AuthService { constructor(private readonly jwtService: JwtService) {} generateTokens(id: string) { - const accessToken = this.jwtService.sign({id: id}, { expiresIn: '1m' }); + const accessToken = this.jwtService.sign({id: id}, { expiresIn: '5m' }); const refreshToken = this.jwtService.sign({id: id}, { expiresIn: '7d' }); return { accessToken, refreshToken }; diff --git a/src/modules/account/account.controller.ts b/src/modules/account/account.controller.ts index 016a58f..32ecb33 100644 --- a/src/modules/account/account.controller.ts +++ b/src/modules/account/account.controller.ts @@ -5,67 +5,69 @@ import { Public } from "src/common/decorators/public.decorator"; import type { FastifyReply, FastifyRequest } from "fastify"; import { AuthGuard } from "@nestjs/passport"; import { JwtAccessAuthGuard } from "src/middleware/auth/guard/access-token.guard"; +import { HttpApiUrl } from '@baekyangdan/core-utils'; +const AccountApi = HttpApiUrl.Account; @UseGuards(JwtAccessAuthGuard) -@Controller('account') +@Controller(AccountApi.base) export class AccountController { constructor(private readonly accountService: AccountService) {} - @Get('/') + @Get(AccountApi.root) async test() { return "Test" } @Public() - @Get('check-duplication') + @Get(AccountApi.checkDuplication) async checkDuplication(@Query() query: DTO.CheckDuplicationRequest): Promise { return await this.accountService.checkDuplication(query); } @Public() - @Post('send-email-verification-code') + @Post(AccountApi.sendEmailVerificationCode) async sendEmailVerificationCode(@Body() body: DTO.SendEmailVerificationCodeRequest): Promise { const result = await this.accountService.sendVerificationCode(body); return result; } @Public() - @Post('verify-email-verification-code') - async verifyCode(@Body() body: DTO.VerifyEmailVerificationCodeRequest): Promise { + @Post(AccountApi.verifyEmailVerificationCode) + async verifyEmailVerificationCode(@Body() body: DTO.VerifyEmailVerificationCodeRequest): Promise { const result = await this.accountService.verifyCode(body); return result; } @Public() - @Post('send-reset-password-code') + @Post(AccountApi.sendResetPasswordCode) async sendResetPasswordCode(@Body() body: DTO.SendResetPasswordCodeRequest): Promise { const result = await this.accountService.sendResetPasswordCode(body); return result; } @Public() - @Post('verify-reset-password-code') + @Post(AccountApi.verifyResetPasswordCode) async verifyResetPasswordCode(@Body() body: DTO.VerifyResetPasswordCodeRequest): Promise { const result = await this.accountService.verifyResetPasswordCode(body); return result; } @Public() - @Post('reset-password') + @Post(AccountApi.resetPassword) async resetPassword(@Body() body: DTO.ResetPasswordRequest): Promise { const result = await this.accountService.resetPassword(body); return result; } @Public() - @Post('signup') + @Post(AccountApi.signup) async signup(@Body() body: DTO.SignupRequest): Promise { const result = await this.accountService.signup(body); return result; } @Public() - @Post('login') + @Post(AccountApi.login) async login(@Body() body: DTO.LoginRequest, @Res({ passthrough: true }) res: FastifyReply): Promise { const result = await this.accountService.login(body); if (result.success) { @@ -86,7 +88,7 @@ export class AccountController { @Public() @UseGuards(AuthGuard('refresh-token')) - @Get('refresh-access-token') + @Get(AccountApi.refreshAccessToken) async refreshAccessToken(@Req() req, @Res({ passthrough: true }) res: FastifyReply): Promise { const result = await this.accountService.refreshAccessToken(req.user.id); if (result.success) { diff --git a/src/modules/schedule/schedule.controller.ts b/src/modules/schedule/schedule.controller.ts index a55de23..4f563f3 100644 --- a/src/modules/schedule/schedule.controller.ts +++ b/src/modules/schedule/schedule.controller.ts @@ -2,24 +2,28 @@ import { Body, Controller, Get, Param, Post, Req, UseGuards } from "@nestjs/comm import { JwtAccessAuthGuard } from "src/middleware/auth/guard/access-token.guard"; import { ScheduleService } from "./schedule.service"; import * as DTO from './dto'; +import { HttpApiUrl } from "@baekyangdan/core-utils"; + +const ScheduleApi = HttpApiUrl.Schedule; + @UseGuards(JwtAccessAuthGuard) -@Controller('schedule') +@Controller(ScheduleApi.base) export class ScheduleController { constructor(private readonly scheduleService: ScheduleService) {} - @Post('/') + @Post(ScheduleApi.getList) async getList(@Req() req, @Body() data: DTO.ListRequest): Promise { const result = await this.scheduleService.getList(req.user.id, data); return result; } - @Get('/:id') + @Get(ScheduleApi.getDetail) async getDetail(@Param('id') id: string): Promise { const result = await this.scheduleService.getDetail(id); return result; } - @Post('/create') + @Post(ScheduleApi.create) async create(@Req() req, @Body() data: DTO.CreateRequest): Promise { const result = await this.scheduleService.create(req.user.id, data); return result; diff --git a/src/modules/schedule/schedule.service.ts b/src/modules/schedule/schedule.service.ts index 65a0fb4..5e9e2b7 100644 --- a/src/modules/schedule/schedule.service.ts +++ b/src/modules/schedule/schedule.service.ts @@ -1,6 +1,9 @@ import { Injectable } from "@nestjs/common"; import { ScheduleRepo } from "./schedule.repo"; import * as DTO from './dto'; +import { format } from "date-fns"; +import { DateFormat, TimeFormat } from "@baekyangdan/core-utils"; +import { ko } from "date-fns/locale"; @Injectable() export class ScheduleService { @@ -30,7 +33,8 @@ export class ScheduleService { const data = { ...result[0], 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 }) } return { diff --git a/yarn.lock b/yarn.lock index cd2e942..3768bfe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -999,14 +999,14 @@ __metadata: languageName: node linkType: hard -"@baekyangdan/core-utils@npm:^1.0.4": - version: 1.0.4 - resolution: "@baekyangdan/core-utils@npm:1.0.4::__archiveUrl=https%3A%2F%2Fgitea.bkdhome.p-e.kr%2Fapi%2Fpackages%2Fbaekyangdan%2Fnpm%2F%2540baekyangdan%252Fcore-utils%2F-%2F1.0.4%2Fcore-utils-1.0.4.tgz" +"@baekyangdan/core-utils@npm:^1.0.9": + version: 1.0.9 + resolution: "@baekyangdan/core-utils@npm:1.0.9::__archiveUrl=https%3A%2F%2Fgitea.bkdhome.p-e.kr%2Fapi%2Fpackages%2Fbaekyangdan%2Fnpm%2F%2540baekyangdan%252Fcore-utils%2F-%2F1.0.9%2Fcore-utils-1.0.9.tgz" dependencies: date-fns: "npm:^4.1.0" reflect-metadata: "npm:^0.2.2" tsup: "npm:^8.5.1" - checksum: 10c0/d183abf8b42ca265ede259274ed773e013bb4f178a74552c11541283d92446c70e09e5bdf12cb35b1972deec9dda4290fd3514ad0eb283b8592456516a5f58cb + checksum: 10c0/76c23a35dcc40856cd1be0b632a71ddbdb1740b397ddfcf4e2d8b307d0c127419382c0f89a0d92fc2546e9a3e313172d825942d78121d2d16cfde43a8729a7ca languageName: node linkType: hard @@ -4757,7 +4757,7 @@ __metadata: version: 0.0.0-use.local resolution: "back@workspace:." dependencies: - "@baekyangdan/core-utils": "npm:^1.0.4" + "@baekyangdan/core-utils": "npm:^1.0.9" "@eslint/eslintrc": "npm:^3.2.0" "@eslint/js": "npm:^9.18.0" "@fastify/cookie": "npm:^11.0.2" @@ -4785,6 +4785,7 @@ __metadata: "@types/supertest": "npm:^6.0.2" bcrypt: "npm:^6.0.0" cross-env: "npm:^10.1.0" + date-fns: "npm:^4.1.0" dotenv: "npm:^17.2.3" dotenv-cli: "npm:^11.0.0" drizzle-kit: "npm:^0.31.7"