Compare commits
8 Commits
fd782626de
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b06b331b44 | ||
|
|
e919350711 | ||
|
|
a30fb01add | ||
|
|
6fc4a0fe39 | ||
|
|
17335a26e7 | ||
| b7c8b0a4cf | |||
| f2083bd1a4 | |||
| 7a7a159080 |
@@ -2,13 +2,13 @@ PORT=3000
|
||||
|
||||
# PostgreSQL 설정
|
||||
PGHOST=db
|
||||
PGPORT=5454
|
||||
PGPORT=5432
|
||||
PGDATABASE=scheduler
|
||||
PGUSER=baekyangdan
|
||||
PGPASSWORD=qwas745478!
|
||||
PG_DATABASE_URL=postgres://baekyangdan:qwas745478!@db:5454/scheduler
|
||||
PG_DATABASE_URL=postgres://baekyangdan:qwas745478!@db:5432/scheduler
|
||||
|
||||
# Redis 설정
|
||||
RD_HOST=redis
|
||||
RD_PORT=6779
|
||||
RD_URL=redis://redis:6779
|
||||
RD_PORT=6379
|
||||
RD_URL=redis://redis:6379
|
||||
@@ -61,5 +61,7 @@ jobs:
|
||||
run: |
|
||||
cp -r dist $DOCKER_VOLUME/scheduler/back/
|
||||
cp -r node_modules $DOCKER_VOLUME/scheduler/back/
|
||||
cp .env.prod $DOCKER_VOLUME/scheduler/back/
|
||||
cp .env.common $DOCKER_VOLUME/scheduler/back
|
||||
ls $DOCKER_VOLUME/scheduler/back
|
||||
docker exec -it scheduler_back pm2 reload scheduler-back
|
||||
# docker exec -it scheduler_back pm2 reload scheduler-back
|
||||
@@ -1,6 +1,6 @@
|
||||
yarnPath: .yarn/releases/yarn-4.11.0.cjs
|
||||
npmScopes:
|
||||
baekyangdan:
|
||||
npmRegistryServer: "https://gitea.bkdhome.p-e.kr/api/packages/baekyangdan/npm/"
|
||||
npmRegistryServer: "https://gitea.ddoahh.kro.kr/api/packages/baekyangdan/npm/"
|
||||
npmAuthToken: "d39c7d88c52806df7522ce2b340b6577c5ec5082"
|
||||
nodeLinker: node-modules
|
||||
@@ -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) => [
|
||||
|
||||
@@ -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.23",
|
||||
"@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",
|
||||
|
||||
13
src/main.ts
13
src/main.ts
@@ -8,6 +8,7 @@ import { AllExceptionsFilter } from './common/filters/all-exceptions.filter';
|
||||
import fastifyCookie from '@fastify/cookie';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
|
||||
async function bootstrap() {
|
||||
const isProd = process.env.NODE_ENV === 'prod';
|
||||
@@ -21,8 +22,18 @@ async function bootstrap() {
|
||||
}
|
||||
const app = await NestFactory.create<NestFastifyApplication>(
|
||||
AppModule,
|
||||
new FastifyAdapter({ https: httpsOptions })
|
||||
new FastifyAdapter(!isProd ? { https: httpsOptions } : undefined)
|
||||
);
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
transform: true,
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
transformOptions: {
|
||||
enableImplicitConversion: true
|
||||
}
|
||||
})
|
||||
)
|
||||
app.enableCors({
|
||||
origin: (origin, callback) => {
|
||||
// origin이 없는 경우(local file, curl 등) 허용
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -1,108 +1,100 @@
|
||||
import { Body, Controller, Get, Headers, Post, Query, Req, Res, UseGuards } from "@nestjs/common";
|
||||
import { AccountService } from "./account.service";
|
||||
import * as DTO from "./dto";
|
||||
import { SchedulerDTO as DTO } from "@baekyangdan/core-utils";
|
||||
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<DTO.CheckDuplicationResponse> {
|
||||
return await this.accountService.checkDuplication(query);
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Post('send-email-verification-code')
|
||||
@Post(AccountApi.sendEmailVerificationCode)
|
||||
async sendEmailVerificationCode(@Body() body: DTO.SendEmailVerificationCodeRequest): Promise<DTO.SendEmailVerificationCodeResponse> {
|
||||
const result = await this.accountService.sendVerificationCode(body);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Post('verify-email-verification-code')
|
||||
async verifyCode(@Body() body: DTO.VerifyEmailVerificationCodeRequest): Promise<DTO.VerifyEmailVerificationCodeResponse> {
|
||||
@Post(AccountApi.verifyEmailVerificationCode)
|
||||
async verifyEmailVerificationCode(@Body() body: DTO.VerifyEmailVerificationCodeRequest): Promise<DTO.VerifyEmailVerificationCodeResponse> {
|
||||
const result = await this.accountService.verifyCode(body);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Post('send-reset-password-code')
|
||||
async sendResetPasswordCode(@Body() body: DTO.SendResetPasswordCodeRequest): Promise<DTO.SendResetPasswordCodeResponse> {
|
||||
const result = await this.accountService.sendResetPasswordCode(body);
|
||||
@Post(AccountApi.sendPasswordResetCode)
|
||||
async sendPasswordResetCode(@Body() body: DTO.SendPasswordResetCodeRequest): Promise<DTO.SendPasswordResetCodeResponse> {
|
||||
const result = await this.accountService.sendPasswordResetCode(body);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Post('verify-reset-password-code')
|
||||
async verifyResetPasswordCode(@Body() body: DTO.VerifyResetPasswordCodeRequest): Promise<DTO.VerifyResetPasswordCodeResponse> {
|
||||
const result = await this.accountService.verifyResetPasswordCode(body);
|
||||
@Post(AccountApi.verifyPasswordResetCode)
|
||||
async verifyPasswordResetCode(@Body() body: DTO.VerifyPasswordResetCodeRequest): Promise<DTO.VerifyPasswordResetCodeResponse> {
|
||||
const result = await this.accountService.verifyPasswordResetCode(body);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Post('reset-password')
|
||||
@Post(AccountApi.resetPassword)
|
||||
async resetPassword(@Body() body: DTO.ResetPasswordRequest): Promise<DTO.ResetPasswordResponse> {
|
||||
const result = await this.accountService.resetPassword(body);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Public()
|
||||
@Post('signup')
|
||||
@Post(AccountApi.signup)
|
||||
async signup(@Body() body: DTO.SignupRequest): Promise<DTO.SignupResponse> {
|
||||
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<DTO.LoginResponse> {
|
||||
const result = await this.accountService.login(body);
|
||||
if (result.success) {
|
||||
res.setCookie('refresh_token', result.refreshToken!, {
|
||||
res.setCookie('refresh_token', result.data.refreshToken!, {
|
||||
httpOnly: true,
|
||||
path: '/',
|
||||
secure: true,
|
||||
maxAge: 7 * 24 * 60 * 60 * 1000
|
||||
});
|
||||
}
|
||||
return {
|
||||
success: result.success,
|
||||
message: result.message,
|
||||
error: result.error,
|
||||
accessToken: result.accessToken
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
@Public()
|
||||
@UseGuards(AuthGuard('refresh-token'))
|
||||
@Get('refresh-access-token')
|
||||
@Get(AccountApi.refreshAccessToken)
|
||||
async refreshAccessToken(@Req() req, @Res({ passthrough: true }) res: FastifyReply): Promise<DTO.RefreshAccessTokenResponse> {
|
||||
const result = await this.accountService.refreshAccessToken(req.user.id);
|
||||
if (result.success) {
|
||||
res.setCookie('refresh_token', result.refreshToken!, {
|
||||
res.setCookie('refresh_token', result.data.refreshToken!, {
|
||||
httpOnly: true,
|
||||
path: '/',
|
||||
secure: true,
|
||||
maxAge: 7 * 24 * 60 * 60 * 1000
|
||||
});
|
||||
|
||||
return {
|
||||
success: result.success,
|
||||
message: result.message,
|
||||
error: result.error,
|
||||
accessToken: result.accessToken
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Inject, Injectable } from "@nestjs/common";
|
||||
import { AccountRepo } from "./account.repo";
|
||||
import * as DTO from './dto';
|
||||
import { SchedulerDTO as DTO } from '@baekyangdan/core-utils';
|
||||
import { MailerService } from "src/util/mailer/mailer.service";
|
||||
import { Generator } from "src/util/generator";
|
||||
import Redis from "ioredis";
|
||||
@@ -20,7 +20,7 @@ export class AccountService {
|
||||
const { type, value } = data;
|
||||
const count = await this.accountRepo.checkIdExists(type, value);
|
||||
|
||||
return { isDuplicated: count > 0, success: true };
|
||||
return { success: true, message: '중복 체크 완료', data: { isDuplicated: count > 0 }};
|
||||
}
|
||||
|
||||
async sendVerificationCode(data: DTO.SendEmailVerificationCodeRequest): Promise<DTO.SendEmailVerificationCodeResponse> {
|
||||
@@ -30,11 +30,11 @@ export class AccountService {
|
||||
const result = await this.mailerService.sendMail(email, "<Scheduler> 이메일 인증 코드", html);
|
||||
|
||||
if (result.rejected.length > 0) {
|
||||
return { success: false, error: result.response }
|
||||
return { success: false, error: result.response, code: '' }
|
||||
} else {
|
||||
await this.redis.set(`verify:${email}`, code, 'EX', 600);
|
||||
|
||||
return { success: true, message: "이메일 발송 완료" };
|
||||
return { success: true, message: "이메일 발송 완료", data: {} };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,14 +44,14 @@ export class AccountService {
|
||||
const storedCode = await this.redis.get(`verify:${email}`);
|
||||
|
||||
if (!storedCode) {
|
||||
return { verified: false, success: true, error: '잘못된 이메일이거나 코드가 만료되었습니다.'};
|
||||
return { success: false, error: '잘못된 이메일이거나 코드가 만료되었습니다.', code: ''};
|
||||
}
|
||||
if (storedCode !== code) {
|
||||
return { verified: false, success: true, error: "잘못된 코드입니다." };
|
||||
return { success: true, message: "잘못된 코드입니다.", data: { verified: false } };
|
||||
}
|
||||
|
||||
await this.redis.del(`verify:${email}`);
|
||||
return { verified: true, success: true, message: "이메일 인증이 완료되었습니다." };
|
||||
return { success: true, message: "이메일 인증이 완료되었습니다.", data: { verified: true } };
|
||||
}
|
||||
|
||||
async signup(data: DTO.SignupRequest): Promise<DTO.SignupResponse> {
|
||||
@@ -62,12 +62,14 @@ export class AccountService {
|
||||
if (result.rowCount) {
|
||||
return {
|
||||
success: true,
|
||||
message: "회원가입이 완료되었습니다."
|
||||
message: "회원가입이 완료되었습니다.",
|
||||
data: {}
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: false,
|
||||
error: "회원가입에 실패하였습니다."
|
||||
error: "회원가입에 실패하였습니다.",
|
||||
code: ''
|
||||
};
|
||||
}
|
||||
|
||||
@@ -81,7 +83,8 @@ export class AccountService {
|
||||
if (!queryResult || (queryResult.length < 1)) {
|
||||
return {
|
||||
success: false,
|
||||
message: `존재하지 않는 ${typeValue} 입니다.`
|
||||
error: `존재하지 않는 ${typeValue} 입니다.`,
|
||||
code: ''
|
||||
};
|
||||
}
|
||||
|
||||
@@ -90,7 +93,8 @@ export class AccountService {
|
||||
if (!isPasswordMatch) {
|
||||
return {
|
||||
success: false,
|
||||
message: `비밀번호가 맞지 않습니다.`
|
||||
error: `비밀번호가 맞지 않습니다.`,
|
||||
code: ''
|
||||
};
|
||||
}
|
||||
|
||||
@@ -101,8 +105,11 @@ export class AccountService {
|
||||
|
||||
return {
|
||||
success: true,
|
||||
accessToken: accessToken,
|
||||
refreshToken: refreshToken
|
||||
data: {
|
||||
accessToken: accessToken,
|
||||
refreshToken: refreshToken
|
||||
},
|
||||
message: '로그인 성공'
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -110,13 +117,16 @@ export class AccountService {
|
||||
async refreshAccessToken(id: string): Promise<DTO.RefreshAccessTokenResponse> {
|
||||
const { accessToken, refreshToken } = this.authService.refreshTokens(id);
|
||||
return {
|
||||
accessToken: accessToken,
|
||||
refreshToken: refreshToken,
|
||||
success: true
|
||||
success: true,
|
||||
message: '토큰 갱신 완료',
|
||||
data: {
|
||||
accessToken: accessToken,
|
||||
refreshToken: refreshToken
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async sendResetPasswordCode(data: DTO.SendResetPasswordCodeRequest): Promise<DTO.SendResetPasswordCodeResponse> {
|
||||
async sendPasswordResetCode(data: DTO.SendPasswordResetCodeRequest): Promise<DTO.SendPasswordResetCodeResponse> {
|
||||
const { email } = data;
|
||||
|
||||
const count = await this.accountRepo.checkIdExists('email', email);
|
||||
@@ -124,7 +134,8 @@ export class AccountService {
|
||||
if (count === 0) {
|
||||
return {
|
||||
success: false,
|
||||
error: "찾을 수 없는 사용자"
|
||||
error: "찾을 수 없는 사용자",
|
||||
code: ''
|
||||
};
|
||||
}
|
||||
|
||||
@@ -138,7 +149,8 @@ export class AccountService {
|
||||
if (result.rejected.length > 0) {
|
||||
return {
|
||||
success: false,
|
||||
error: result.response
|
||||
error: result.response,
|
||||
code: ''
|
||||
};
|
||||
}
|
||||
|
||||
@@ -146,11 +158,12 @@ export class AccountService {
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "비밀번호 초기화 코드 발송 완료"
|
||||
message: "비밀번호 초기화 코드 발송 완료",
|
||||
data: {}
|
||||
};
|
||||
}
|
||||
|
||||
async verifyResetPasswordCode(data: DTO.VerifyResetPasswordCodeRequest): Promise<DTO.VerifyResetPasswordCodeResponse> {
|
||||
async verifyPasswordResetCode(data: DTO.VerifyPasswordResetCodeRequest): Promise<DTO.VerifyPasswordResetCodeResponse> {
|
||||
const { email, code } = data;
|
||||
|
||||
const storedCode = await this.redis.get(`resetPassword:${email}`);
|
||||
@@ -158,16 +171,16 @@ export class AccountService {
|
||||
if (!storedCode) {
|
||||
return {
|
||||
success: false,
|
||||
verified: false,
|
||||
error: "잘못된 이메일이거나 코드가 만료되었습니다."
|
||||
error: "잘못된 이메일이거나 코드가 만료되었습니다.",
|
||||
code: ''
|
||||
};
|
||||
}
|
||||
|
||||
if (storedCode !== code) {
|
||||
return {
|
||||
success: false,
|
||||
verified: false,
|
||||
error: "잘못된 코드입니다."
|
||||
error: "잘못된 코드입니다.",
|
||||
code: ''
|
||||
};
|
||||
}
|
||||
|
||||
@@ -175,8 +188,8 @@ export class AccountService {
|
||||
|
||||
return {
|
||||
success: true,
|
||||
verified: true,
|
||||
message: "비밀번호 초기화 코드 인증 완료"
|
||||
message: "비밀번호 초기화 코드 인증 완료",
|
||||
data: { verified: true }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -188,13 +201,15 @@ export class AccountService {
|
||||
if (!result.rowCount || result.rowCount === 0) {
|
||||
return {
|
||||
success: false,
|
||||
error: "비밀번호 초기화 실패"
|
||||
error: "비밀번호 초기화 실패",
|
||||
code: ''
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "비밀번호 초기화 성공"
|
||||
message: "비밀번호 초기화 성공",
|
||||
data: {}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,30 @@
|
||||
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;
|
||||
|
||||
@UseGuards(JwtAccessAuthGuard)
|
||||
@Controller('schedule')
|
||||
@Controller(ScheduleApi.base)
|
||||
export class ScheduleController {
|
||||
constructor(private readonly scheduleService: ScheduleService) {}
|
||||
|
||||
@Post('/')
|
||||
async getList(@Req() req, @Body() data: DTO.ListRequest): Promise<DTO.ListResponse> {
|
||||
@Post(ScheduleApi.getList)
|
||||
async getList(@Req() req, @Body() data: DTO.ScheduleListRequest): Promise<DTO.ScheduleListResponse> {
|
||||
const result = await this.scheduleService.getList(req.user.id, data);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Get('/:id')
|
||||
async getDetail(@Param('id') id: string): Promise<DTO.DetailResponse> {
|
||||
@Get(ScheduleApi.getDetail)
|
||||
async getDetail(@Param('id') id: string): Promise<DTO.ScheduleDetailResponse> {
|
||||
const result = await this.scheduleService.getDetail(id);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Post('/create')
|
||||
async create(@Req() req, @Body() data: DTO.CreateRequest): Promise<DTO.CreateResponse> {
|
||||
@Post(ScheduleApi.create)
|
||||
async create(@Req() req, @Body() data: DTO.ScheduleCreateRequest): Promise<DTO.ScheduleCreateResponse> {
|
||||
const result = await this.scheduleService.create(req.user.id, data);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -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<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 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',
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
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";
|
||||
|
||||
@Injectable()
|
||||
export class ScheduleService {
|
||||
@@ -8,38 +11,44 @@ export class ScheduleService {
|
||||
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);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: '일정 목록 탐색 완료',
|
||||
data: result
|
||||
};
|
||||
}
|
||||
|
||||
async getDetail(id: string) {
|
||||
async getDetail(id: string): Promise<DTO.ScheduleDetailResponse> {
|
||||
const result = await this.scheduleRepo.getDetail(id);
|
||||
|
||||
if (result.length < 1) {
|
||||
return {
|
||||
success: false,
|
||||
message: '존재하지 않는 일정입니다.'
|
||||
error: '존재하지 않는 일정입니다.',
|
||||
code: ''
|
||||
};
|
||||
}
|
||||
|
||||
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 }),
|
||||
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<DTO.CreateResponse> {
|
||||
async create(accountId: string, data: DTO.ScheduleCreateRequest): Promise<DTO.ScheduleCreateResponse> {
|
||||
const { name, content, startDate, endDate, startTime, endTime, style, type } = data;
|
||||
|
||||
const result = await this.scheduleRepo.create(
|
||||
@@ -57,12 +66,14 @@ export class ScheduleService {
|
||||
if (result.rowCount) {
|
||||
return {
|
||||
success: true,
|
||||
message: "일정이 생성되었습니다."
|
||||
message: "일정이 생성되었습니다.",
|
||||
data: {}
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
success: false,
|
||||
message: "일정 생성에 실패하였습니다."
|
||||
error: "일정 생성에 실패하였습니다.",
|
||||
code: ''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
180
yarn.lock
180
yarn.lock
@@ -999,14 +999,17 @@ __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.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"
|
||||
class-validator: "npm:^0.14.3"
|
||||
date-fns: "npm:^4.1.0"
|
||||
reflect-metadata: "npm:^0.2.2"
|
||||
tsup: "npm:^8.5.1"
|
||||
checksum: 10c0/d183abf8b42ca265ede259274ed773e013bb4f178a74552c11541283d92446c70e09e5bdf12cb35b1972deec9dda4290fd3514ad0eb283b8592456516a5f58cb
|
||||
checksum: 10c0/6d3310c53878b13c523abed37cdc492cf7f5e1e7cbad0272962520778b6acdc7061c1e0eef44c7d87ede26c7a882bff06f508fb2bccefe8a6e92219f323607f9
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -3499,6 +3502,138 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-darwin-arm64@npm:1.15.5":
|
||||
version: 1.15.5
|
||||
resolution: "@swc/core-darwin-arm64@npm:1.15.5"
|
||||
conditions: os=darwin & cpu=arm64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-darwin-x64@npm:1.15.5":
|
||||
version: 1.15.5
|
||||
resolution: "@swc/core-darwin-x64@npm:1.15.5"
|
||||
conditions: os=darwin & cpu=x64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-linux-arm-gnueabihf@npm:1.15.5":
|
||||
version: 1.15.5
|
||||
resolution: "@swc/core-linux-arm-gnueabihf@npm:1.15.5"
|
||||
conditions: os=linux & cpu=arm
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-linux-arm64-gnu@npm:1.15.5":
|
||||
version: 1.15.5
|
||||
resolution: "@swc/core-linux-arm64-gnu@npm:1.15.5"
|
||||
conditions: os=linux & cpu=arm64 & libc=glibc
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-linux-arm64-musl@npm:1.15.5":
|
||||
version: 1.15.5
|
||||
resolution: "@swc/core-linux-arm64-musl@npm:1.15.5"
|
||||
conditions: os=linux & cpu=arm64 & libc=musl
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-linux-x64-gnu@npm:1.15.5":
|
||||
version: 1.15.5
|
||||
resolution: "@swc/core-linux-x64-gnu@npm:1.15.5"
|
||||
conditions: os=linux & cpu=x64 & libc=glibc
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-linux-x64-musl@npm:1.15.5":
|
||||
version: 1.15.5
|
||||
resolution: "@swc/core-linux-x64-musl@npm:1.15.5"
|
||||
conditions: os=linux & cpu=x64 & libc=musl
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-win32-arm64-msvc@npm:1.15.5":
|
||||
version: 1.15.5
|
||||
resolution: "@swc/core-win32-arm64-msvc@npm:1.15.5"
|
||||
conditions: os=win32 & cpu=arm64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-win32-ia32-msvc@npm:1.15.5":
|
||||
version: 1.15.5
|
||||
resolution: "@swc/core-win32-ia32-msvc@npm:1.15.5"
|
||||
conditions: os=win32 & cpu=ia32
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core-win32-x64-msvc@npm:1.15.5":
|
||||
version: 1.15.5
|
||||
resolution: "@swc/core-win32-x64-msvc@npm:1.15.5"
|
||||
conditions: os=win32 & cpu=x64
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/core@npm:^1.15.5":
|
||||
version: 1.15.5
|
||||
resolution: "@swc/core@npm:1.15.5"
|
||||
dependencies:
|
||||
"@swc/core-darwin-arm64": "npm:1.15.5"
|
||||
"@swc/core-darwin-x64": "npm:1.15.5"
|
||||
"@swc/core-linux-arm-gnueabihf": "npm:1.15.5"
|
||||
"@swc/core-linux-arm64-gnu": "npm:1.15.5"
|
||||
"@swc/core-linux-arm64-musl": "npm:1.15.5"
|
||||
"@swc/core-linux-x64-gnu": "npm:1.15.5"
|
||||
"@swc/core-linux-x64-musl": "npm:1.15.5"
|
||||
"@swc/core-win32-arm64-msvc": "npm:1.15.5"
|
||||
"@swc/core-win32-ia32-msvc": "npm:1.15.5"
|
||||
"@swc/core-win32-x64-msvc": "npm:1.15.5"
|
||||
"@swc/counter": "npm:^0.1.3"
|
||||
"@swc/types": "npm:^0.1.25"
|
||||
peerDependencies:
|
||||
"@swc/helpers": ">=0.5.17"
|
||||
dependenciesMeta:
|
||||
"@swc/core-darwin-arm64":
|
||||
optional: true
|
||||
"@swc/core-darwin-x64":
|
||||
optional: true
|
||||
"@swc/core-linux-arm-gnueabihf":
|
||||
optional: true
|
||||
"@swc/core-linux-arm64-gnu":
|
||||
optional: true
|
||||
"@swc/core-linux-arm64-musl":
|
||||
optional: true
|
||||
"@swc/core-linux-x64-gnu":
|
||||
optional: true
|
||||
"@swc/core-linux-x64-musl":
|
||||
optional: true
|
||||
"@swc/core-win32-arm64-msvc":
|
||||
optional: true
|
||||
"@swc/core-win32-ia32-msvc":
|
||||
optional: true
|
||||
"@swc/core-win32-x64-msvc":
|
||||
optional: true
|
||||
peerDependenciesMeta:
|
||||
"@swc/helpers":
|
||||
optional: true
|
||||
checksum: 10c0/5517d998ad28b6812df46b6c6d9732b3abecb62e94a55d1151e8ede9792b5894b98260681e1de7c33da1a00726c495cff3080ebf97679765c88497e34a978e5a
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/counter@npm:^0.1.3":
|
||||
version: 0.1.3
|
||||
resolution: "@swc/counter@npm:0.1.3"
|
||||
checksum: 10c0/8424f60f6bf8694cfd2a9bca45845bce29f26105cda8cf19cdb9fd3e78dc6338699e4db77a89ae449260bafa1cc6bec307e81e7fb96dbf7dcfce0eea55151356
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@swc/types@npm:^0.1.25":
|
||||
version: 0.1.25
|
||||
resolution: "@swc/types@npm:0.1.25"
|
||||
dependencies:
|
||||
"@swc/counter": "npm:^0.1.3"
|
||||
checksum: 10c0/847a5b20b131281f89d640a7ed4887fb65724807d53d334b230e84b98c21097aa10cd28a074f9ed287a6ce109e443dd4bafbe7dcfb62333d7806c4ea3e7f8aca
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@tokenizer/inflate@npm:^0.3.1":
|
||||
version: 0.3.1
|
||||
resolution: "@tokenizer/inflate@npm:0.3.1"
|
||||
@@ -3919,6 +4054,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/validator@npm:^13.15.3":
|
||||
version: 13.15.10
|
||||
resolution: "@types/validator@npm:13.15.10"
|
||||
checksum: 10c0/3e2e65fcd37dd6961ca3fd0535293d0c42f5911dc3ca44b96f458835e6db2392b678ccbb0c9815d8c0a14e653439e6c62c7b8758a6cd1d6e390551c9e56618ac
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/yargs-parser@npm:*":
|
||||
version: 21.0.3
|
||||
resolution: "@types/yargs-parser@npm:21.0.3"
|
||||
@@ -4757,7 +4899,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.23"
|
||||
"@eslint/eslintrc": "npm:^3.2.0"
|
||||
"@eslint/js": "npm:^9.18.0"
|
||||
"@fastify/cookie": "npm:^11.0.2"
|
||||
@@ -4785,6 +4927,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"
|
||||
@@ -5139,6 +5282,24 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"class-transformer@npm:^0.5.1":
|
||||
version: 0.5.1
|
||||
resolution: "class-transformer@npm:0.5.1"
|
||||
checksum: 10c0/19809914e51c6db42c036166839906420bb60367df14e15f49c45c8c1231bf25ae661ebe94736ee29cc688b77101ef851a8acca299375cc52fc141b64acde18a
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"class-validator@npm:^0.14.3":
|
||||
version: 0.14.3
|
||||
resolution: "class-validator@npm:0.14.3"
|
||||
dependencies:
|
||||
"@types/validator": "npm:^13.15.3"
|
||||
libphonenumber-js: "npm:^1.11.1"
|
||||
validator: "npm:^13.15.20"
|
||||
checksum: 10c0/6d451c359aecb04479b95034b10cca02015d3b6f34480574c618c070e12f3676cb4cdfa76bfa61353356a483ff01326e9ce3f07ef584be6c31806190117f7fa4
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"cli-cursor@npm:^3.1.0":
|
||||
version: 3.1.0
|
||||
resolution: "cli-cursor@npm:3.1.0"
|
||||
@@ -8203,6 +8364,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"libphonenumber-js@npm:^1.11.1":
|
||||
version: 1.12.31
|
||||
resolution: "libphonenumber-js@npm:1.12.31"
|
||||
checksum: 10c0/6617f7c333ac027cc5969330fd094dbc27028f588f016cbc9c4d363b1d9d8162e5e556a48d66d7bdb7e836b7e29d80e8e2d5bd13fa15df355842c9e149c5515a
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"libphonenumber-js@npm:^1.9.43":
|
||||
version: 1.12.28
|
||||
resolution: "libphonenumber-js@npm:1.12.28"
|
||||
@@ -10986,7 +11154,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"validator@npm:^13.7.0":
|
||||
"validator@npm:^13.15.20, validator@npm:^13.7.0":
|
||||
version: 13.15.23
|
||||
resolution: "validator@npm:13.15.23"
|
||||
checksum: 10c0/22a05ec6a98d48d2b6fb34d43ce854af61d15842362d142e64cfca0325d4d0c2d1051d9f9d3a0f741e58ea888f73a35baf7a2a810f5aed0f89183bd5040f0177
|
||||
|
||||
Reference in New Issue
Block a user