Compare commits

...

14 Commits

Author SHA1 Message Date
geonhee-min
b06b331b44 issue #
All checks were successful
Test CI / build (push) Successful in 1m26s
- 도메인 bkdhome.p-e.kr -> ddoahh.kro.kr 로 변경
2025-12-19 12:50:35 +09:00
geonhee-min
e919350711 issue #
All checks were successful
Test CI / build (push) Successful in 1m37s
- 도메인 bkdhome.p-e.kr -> ddoahh.kro.kr 로 변경
2025-12-19 12:17:32 +09:00
geonhee-min
a30fb01add issue #
All checks were successful
Test CI / build (push) Successful in 1m23s
- DTO 공용 코드 작업 완료
2025-12-17 17:02:34 +09:00
geonhee-min
6fc4a0fe39 issue #
All checks were successful
Test CI / build (push) Successful in 1m26s
- DTO 패키지 레지스트리 전환 중
2025-12-16 17:26:36 +09:00
geonhee-min
17335a26e7 issue #63
All checks were successful
Test CI / build (push) Successful in 1m22s
- 일정 상세 조회 기능 구현 중
2025-12-15 17:35:35 +09:00
b7c8b0a4cf issue # 서버 이슈
All checks were successful
Test CI / build (push) Successful in 1m22s
2025-12-14 02:48:28 +09:00
f2083bd1a4 Merge branch 'main' of https://gitea.bkdhome.p-e.kr/baekyangdan/scheduler-back
All checks were successful
Test CI / build (push) Successful in 1m21s
2025-12-14 02:13:21 +09:00
7a7a159080 issue # 배포 서버 작업 2025-12-14 02:13:15 +09:00
geonhee-min
fd782626de issue #
Some checks failed
Test CI / build (push) Failing after 1m42s
공통 패키징 작업
2025-12-12 17:05:32 +09:00
geonhee-min
d580f53775 issue #63
All checks were successful
Test CI / build (push) Successful in 1m17s
- 일정 생성, 목록 조회, 당일 목록 조회 기능 구현
2025-12-11 17:04:19 +09:00
2237030257 issue # 63
All checks were successful
Test CI / build (push) Successful in 1m17s
- 일정 목록 조회 기능 구현 중
2025-12-10 20:57:11 +09:00
geonhee-min
34c33202c6 issue #63
All checks were successful
Test CI / build (push) Successful in 1m16s
- 일정 목록 조회 기능 구현 중
- 일정 상세 조회 기능 구현 필요
2025-12-10 17:15:15 +09:00
geonhee-min
bb79557876 issue #65
- 일정 생성 기능 1차 구현
2025-12-10 17:14:09 +09:00
geonhee-min
9578b37c64 issue #
- 디렉토리 구조 개선
2025-12-10 17:13:28 +09:00
37 changed files with 1444 additions and 174 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -1,2 +1,6 @@
yarnPath: .yarn/releases/yarn-4.11.0.cjs
npmScopes:
baekyangdan:
npmRegistryServer: "https://gitea.ddoahh.kro.kr/api/packages/baekyangdan/npm/"
npmAuthToken: "d39c7d88c52806df7522ce2b340b6577c5ec5082"
nodeLinker: node-modules

View File

@@ -1,7 +1,7 @@
import { defineConfig } from 'drizzle-kit';
import dotenv from 'dotenv';
dotenv.config();
dotenv.config({ path: `.env.${process.env.NODE_ENV}` });
export default defineConfig({
dialect: "postgresql",

View File

@@ -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().primaryKey().notNull(),
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(),
@@ -72,19 +72,20 @@ export const participant = pgTable("participant", {
]);
export const schedule = pgTable("schedule", {
id: uuid().primaryKey().notNull(),
name: varchar(),
startDate: date("start_date"),
endDate: date("end_date"),
status: varchar(),
id: uuid().default(sql`uuid_generate_v4()`).primaryKey().notNull(),
name: varchar().notNull(),
startDate: date("start_date").notNull(),
endDate: date("end_date").notNull(),
status: varchar().default('yet').notNull(),
content: text(),
isDeleted: boolean("is_deleted").default(false),
type: varchar(),
createdAt: date("created_at"),
owner: uuid(),
style: varchar(),
startTime: time("start_time"),
endTime: time("end_time"),
isDeleted: boolean("is_deleted").default(false).notNull(),
type: varchar().notNull(),
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(),
owner: uuid().notNull(),
style: varchar().notNull(),
startTime: time("start_time").notNull(),
endTime: time("end_time").notNull(),
dayList: varchar("day_list"),
}, (table) => [
index("schedule_enddatetime_idx").using("btree", table.endDate.asc().nullsLast().op("date_ops")),
index("schedule_name_idx").using("btree", table.name.asc().nullsLast().op("text_ops"), table.content.asc().nullsLast().op("text_ops")),
@@ -121,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) => [

View File

@@ -26,6 +26,7 @@
"drizzle-pull:prod": "dotenv -e .env.prod -- drizzle-kit pull"
},
"dependencies": {
"@baekyangdan/core-utils": "^1.0.23",
"@fastify/cookie": "^11.0.2",
"@nestjs/class-transformer": "^0.4.0",
"@nestjs/class-validator": "^0.13.4",
@@ -37,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",

View File

@@ -6,9 +6,10 @@ import { RedisModule } from './redis/redis.module';
import { AccountModule } from './modules/account/account.module';
import { MailerModule } from './util/mailer/mailer.module';
import { AppConfigModule } from './config/config.module';
import { ScheduleModule } from './modules/schedule/schedule.module';
@Module({
imports: [AppConfigModule, DbModule, RedisModule, MailerModule, AccountModule],
imports: [AppConfigModule, DbModule, RedisModule, MailerModule, AccountModule, ScheduleModule],
controllers: [AppController],
providers: [AppService],
})

View File

@@ -5,7 +5,9 @@ import {
HttpException,
HttpStatus
} from '@nestjs/common';
import { JsonWebTokenError, TokenExpiredError } from '@nestjs/jwt';
import { FastifyReply, FastifyRequest } from 'fastify';
import { UnauthorizedCode, UnauthorizedMessage, BadRequestCode, BadRequestMessage, InternalServerErrorCode, InternalServerErrorMessage } from '@baekyangdan/core-utils';
@Catch()
export class AllExceptionsFilter implements ExceptionFilter {
@@ -13,6 +15,39 @@ export class AllExceptionsFilter implements ExceptionFilter {
const ctx = host.switchToHttp();
const response = ctx.getResponse<FastifyReply>();
const request = ctx.getRequest<FastifyRequest>();
console.log(exception);
// TokenExpiredError
if (exception instanceof TokenExpiredError) {
const status = HttpStatus.UNAUTHORIZED;
const responseBody = {
statusCode: status,
message: UnauthorizedMessage.ACCESS_TOKEN_EXPIRED,
code: UnauthorizedCode.ACCESS_TOKEN_EXPIRED,
timestamp: new Date().toISOString(),
path: ctx.getRequest().url
};
response.status(status).send(responseBody);
return;
}
// JsonWebTokenError
if (exception instanceof JsonWebTokenError) {
const status = HttpStatus.UNAUTHORIZED;
const responseBody = {
statusCode: status,
message: UnauthorizedMessage.INVALID_TOKEN,
code: UnauthorizedCode.INVALID_TOKEN,
timestamp: new Date().toISOString(),
path: ctx.getRequest().url
};
response.status(status).send(responseBody);
return;
}
let status =
exception instanceof HttpException
@@ -22,7 +57,7 @@ export class AllExceptionsFilter implements ExceptionFilter {
let message =
exception instanceof HttpException
? exception.getResponse()
: 'Internal server error';
: InternalServerErrorMessage.INTERNAL_SERVER_ERROR;
if (typeof message === 'object' && (message as any).message) {
message = (message as any).message;
@@ -33,7 +68,8 @@ export class AllExceptionsFilter implements ExceptionFilter {
timestamp: new Date().toISOString(),
path: request.url,
statusCode: status,
error: message
message: message,
error: InternalServerErrorCode
});
}
}

View File

@@ -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 등) 허용
@@ -46,6 +57,6 @@ async function bootstrap() {
secret: process.env.JWT_SECRET
});
await app.listen(process.env.PORT ?? 3000, '0.0.0.0', () => { process.env.NODE_ENV !== 'prod' && console.log(`servier is running on ${process.env.PORT}`) });
// await app.listen(process.env.PORT || 3000, () => { process.env.NODE_ENV !== 'prod' && console.log(`service is running on ${process.env.PORT}`)});
}
bootstrap();

View File

@@ -6,7 +6,7 @@ export class AuthService {
constructor(private readonly jwtService: JwtService) {}
generateTokens(id: string) {
const accessToken = this.jwtService.sign({id: id}, { expiresIn: '5s' });
const accessToken = this.jwtService.sign({id: id}, { expiresIn: '5m' });
const refreshToken = this.jwtService.sign({id: id}, { expiresIn: '7d' });
return { accessToken, refreshToken };

View File

@@ -1,6 +1,6 @@
import { ExecutionContext, Injectable, UnauthorizedException } from "@nestjs/common";
import { Reflector } from "@nestjs/core";
import { TokenExpiredError } from "@nestjs/jwt";
import { JsonWebTokenError, TokenExpiredError } from "@nestjs/jwt";
import { AuthGuard } from "@nestjs/passport";
import { IS_PUBLIC_KEY } from "src/common/decorators/public.decorator";
@@ -23,23 +23,18 @@ export class JwtAccessAuthGuard extends AuthGuard('access-token') {
return super.canActivate(context);
}
handleRequest(err: any, user:any, info:any) {
if (info instanceof TokenExpiredError) {
throw new UnauthorizedException({
statusCode: 401,
message: 'Access Token Expired',
code: 'AccessTokenExpired'
});
}
handleRequest(err: any, user:any, info:any, context: ExecutionContext) {
if (err || !user) {
throw new UnauthorizedException({
statusCode: 401,
message: 'Invalid Token',
code: 'InvalidToken'
});
}
if (info instanceof TokenExpiredError) {
throw info;
}
if (info instanceof JsonWebTokenError) {
throw info;
}
throw err || new JsonWebTokenError('Unauthorized');
}
return user;
}
}

View File

@@ -2,10 +2,14 @@ import { Injectable, UnauthorizedException } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { PassportStrategy } from "@nestjs/passport";
import { ExtractJwt, Strategy } from "passport-jwt";
import { AccountRepo } from "src/modules/account/account.repo";
@Injectable()
export class JwtAccessStrategy extends PassportStrategy(Strategy, "access-token") {
constructor(configService: ConfigService) {
constructor(
configService: ConfigService,
private accountRepo: AccountRepo
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: configService.get<string>('JWT_SECRET')!
@@ -13,10 +17,11 @@ export class JwtAccessStrategy extends PassportStrategy(Strategy, "access-token"
}
async validate(payload: any) {
const token = ExtractJwt.fromAuthHeaderAsBearerToken();
if (!token) {
console.log(payload);
const user = await this.accountRepo.findById(payload.id);
if (!user) {
throw new UnauthorizedException();
}
return { id: payload.id };
return user;
}
}

View File

@@ -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;
}

View File

@@ -26,7 +26,7 @@ export class AccountRepo {
email: string,
password: string
) {
return this
return await this
.db
.insert(schema.account)
.values({
@@ -42,7 +42,7 @@ export class AccountRepo {
type: 'email' | 'accountId'
, id: string
) {
return this
return await this
.db
.select()
.from(schema.account)

View File

@@ -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: {}
};
}
}

View File

@@ -1,4 +1,4 @@
import { BaseResponseDto } from "../base-response.dto";
import { BaseResponseDto } from "../../../../common/dto/base-response.dto";
export class CheckDuplicationResponseDto extends BaseResponseDto {
isDuplicated: boolean;

View File

@@ -1,4 +1,4 @@
import { BaseResponseDto } from "../base-response.dto";
import { BaseResponseDto } from "../../../../common/dto/base-response.dto";
export class LoginResponseDto extends BaseResponseDto {
accessToken?: string;

View File

@@ -1,4 +1,4 @@
import { BaseResponseDto } from "../base-response.dto";
import { BaseResponseDto } from "../../../../common/dto/base-response.dto";
export class RefreshAccessTokenResponseDto extends BaseResponseDto{
accessToken: string;

View File

@@ -1,4 +1,4 @@
import { BaseResponseDto } from "../base-response.dto";
import { BaseResponseDto } from "../../../../common/dto/base-response.dto";
export class ResetPasswordResponseDto extends BaseResponseDto {

View File

@@ -1,4 +1,4 @@
import { BaseResponseDto } from "../base-response.dto";
import { BaseResponseDto } from "../../../../common/dto/base-response.dto";
export class SendEmailVerificationCodeResponseDto extends BaseResponseDto{
}

View File

@@ -1,4 +1,4 @@
import { BaseResponseDto } from "../base-response.dto";
import { BaseResponseDto } from "../../../../common/dto/base-response.dto";
export class SendResetPasswordCodeResponseDto extends BaseResponseDto {
}

View File

@@ -1,4 +1,4 @@
import { BaseResponseDto } from "../base-response.dto";
import { BaseResponseDto } from "../../../../common/dto/base-response.dto";
export class SignupResponseDto extends BaseResponseDto {
}

View File

@@ -1,4 +1,4 @@
import { BaseResponseDto } from "../base-response.dto";
import { BaseResponseDto } from "../../../../common/dto/base-response.dto";
export class VerifyEmailVerificationCodeResponseDto extends BaseResponseDto{
verified: boolean;

View File

@@ -1,4 +1,4 @@
import { BaseResponseDto } from "../base-response.dto";
import { BaseResponseDto } from "../../../../common/dto/base-response.dto";
export class VerifyResetPasswordCodeResponseDto extends BaseResponseDto {
verified: boolean;

View File

@@ -1,17 +1,14 @@
import { IsArray, IsDate, IsString } from '@nestjs/class-validator';
import { IsArray, IsDateString, IsString } from '@nestjs/class-validator';
export class CreateRequestDto {
@IsString()
name: string;
@IsDate()
startDate: Date;
@IsDateString()
startDate: string;
@IsDate()
endDate: Date;
@IsString()
status: string;
@IsDateString()
endDate: string;
@IsString()
content: string;

View File

@@ -0,0 +1,3 @@
import { BaseResponseDto } from "src/common/dto/base-response.dto";
export class CreateResponseDto extends BaseResponseDto {}

View File

@@ -0,0 +1,23 @@
import { BaseResponseDto } from "src/common/dto/base-response.dto";
class ScheduleDetail {
id: string;
name: string;
startDate: Date;
endDate: Date;
status: string;
content?: string | null;
isDeleted: boolean;
type: string;
createdAt: string | null;
owner: string;
style: string;
startTime: string;
endTime: string;
dayList?: string | null;
participantList?: string[] | null;
}
export class DetailResponseDto extends BaseResponseDto {
data?: ScheduleDetail | null;
}

View File

@@ -0,0 +1,7 @@
export { CreateRequestDto as CreateRequest } from './create/create-request.dto';
export { CreateResponseDto as CreateResponse } from './create/create-response.dto'
export { ListRequestDto as ListRequest } from './list/list-request.dto';
export { ListResponseDto as ListResponse } from './list/list-response.dto';
export { DetailResponseDto as DetailResponse } from './detail/detail-response.dto';

View File

@@ -0,0 +1,24 @@
import { IsArray, IsDateString, IsString } from "@nestjs/class-validator";
export class ListRequestDto {
@IsDateString()
date?: string;
@IsDateString()
startDate?: string;
@IsDateString()
endDate?: string;
@IsArray()
styleList?: string[];
@IsArray()
typeList?: string[];
@IsString()
status?: 'yet' | 'completed' | undefined;
@IsString()
name?: string;
}

View File

@@ -0,0 +1,15 @@
import { BaseResponseDto } from "src/common/dto/base-response.dto";
class ScheduleList {
name: string;
id: string;
startDate: Date;
endDate: Date;
type: string;
style: string;
status: string;
}
export class ListResponseDto extends BaseResponseDto {
data: ScheduleList[];
}

View File

@@ -0,0 +1,31 @@
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 { SchedulerDTO as DTO } from '@baekyangdan/core-utils';
import { HttpApiUrl } from "@baekyangdan/core-utils";
const ScheduleApi = HttpApiUrl.Schedule;
@UseGuards(JwtAccessAuthGuard)
@Controller(ScheduleApi.base)
export class ScheduleController {
constructor(private readonly scheduleService: ScheduleService) {}
@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(ScheduleApi.getDetail)
async getDetail(@Param('id') id: string): Promise<DTO.ScheduleDetailResponse> {
const result = await this.scheduleService.getDetail(id);
return result;
}
@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;
}
}

View File

@@ -0,0 +1,13 @@
import { forwardRef, Module } from "@nestjs/common";
import { AuthModule } from "src/middleware/auth/auth.module";
import { ScheduleController } from "./schedule.controller";
import { ScheduleService } from "./schedule.service";
import { ScheduleRepo } from "./schedule.repo";
@Module({
imports: [forwardRef(() => AuthModule)],
controllers: [ScheduleController],
providers: [ScheduleService, ScheduleRepo],
exports: [ScheduleService, ScheduleRepo]
})
export class ScheduleModule {}

View File

@@ -1,43 +1,109 @@
import { Inject, Injectable } from '@nestjs/common';
import * as schema from 'drizzle/schema';
import { countDistinct, and, eq } from 'drizzle-orm';
import { countDistinct, and, eq, gt, gte, lte, like, inArray, or } from 'drizzle-orm';
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
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) {
async getList(accountId: string, data: DTO.ScheduleListRequest) {
const { date, startDate, endDate, name, status, styleList, typeList } = data;
const schedule = schema.schedule;
const result = await this
.db
.select({
id: schedule.id,
name: schedule.name,
startDate: schedule.startDate,
endDate: schedule.endDate,
status: schedule.status,
style: schedule.style,
type: schedule.type,
})
.from(schedule)
.where(
and(
eq(schedule.owner, accountId),
(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,
status ? eq(schedule.status, status) : undefined,
eq(schedule.isDeleted, false)
)
)
const resultData = result.map((schedule) => {
return {
id: schedule.id,
name: schedule.name,
type: schedule.type,
style: schedule.style,
status: schedule.status,
startDate: new Date(schedule.startDate),
endDate: new Date(schedule.endDate)
} as DTO.ScheduleList;
})
return resultData;
}
async getDetail(id: string) {
const schedule = schema.schedule;
const result = await this
.db
.select()
.from(schema.schedule)
.from(schedule)
.where(
and(
eq(schema.schedule.owner, accountId),
eq(schema.schedule.isDeleted, false)
eq(schedule.id, id),
eq(schedule.isDeleted, false)
)
);
return result;
}
async getDetail(id: string) {
const result = await this
async create(
accountId: string,
name: string,
startDate: Date,
endDate: Date,
startTime: string,
endTime: string,
style: string,
content: string,
type: string
) {
return await this
.db
.select()
.from(schema.schedule)
.where(
and(
eq(schema.schedule.id, id),
eq(schema.schedule.isDeleted, false)
)
);
return result[0];
}
async create() {
.insert(schema.schedule)
.values({
name: name,
content: content,
owner: accountId,
startDate: Converter.formatDateToSqlDate(startDate),
endDate: Converter.formatDateToSqlDate(endDate),
startTime: startTime,
endTime: endTime,
status: 'yet',
style: style,
type: type
});
}
}

View File

@@ -0,0 +1,80 @@
import { Injectable } from "@nestjs/common";
import { ScheduleRepo } from "./schedule.repo";
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 {
constructor(
private readonly scheduleRepo: ScheduleRepo
) {}
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): Promise<DTO.ScheduleDetailResponse> {
const result = await this.scheduleRepo.getDetail(id);
if (result.length < 1) {
return {
success: false,
error: '존재하지 않는 일정입니다.',
code: ''
};
}
const data = {
...result[0],
startDate: new Date(result[0].startDate),
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,
message: '일정을 가져왔습니다.'
};
}
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(
accountId,
name,
startDate,
endDate,
startTime,
endTime,
style,
content,
type
);
if (result.rowCount) {
return {
success: true,
message: "일정이 생성되었습니다.",
data: {}
};
} else {
return {
success: false,
error: "일정 생성에 실패하였습니다.",
code: ''
}
}
}
}

View File

@@ -8,4 +8,13 @@ export class Converter {
static comparePassword(rawPassword: string, hashedPassword: string) {
return bcrypt.compareSync(rawPassword, hashedPassword);
}
static formatDateToSqlDate(date: Date): string {
const targetDate = new Date(date);
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}`;
}
}

964
yarn.lock

File diff suppressed because it is too large Load Diff