Compare commits

...

65 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
f451306c90 issue #62
All checks were successful
Test CI / build (push) Successful in 1m19s
- 일정 관련 기능 구현 중
2025-12-09 22:00:46 +09:00
abee778691 issue #39
All checks were successful
Test CI / build (push) Successful in 1m23s
- 자동 로그인 로직 cookie 로 변경
2025-12-07 22:46:01 +09:00
91e4f987ea issue #
All checks were successful
Test CI / build (push) Successful in 1m17s
- 서버 호스트 0.0.0.0 설정
2025-12-06 00:20:05 +09:00
1611026688 issue #39
All checks were successful
Test CI / build (push) Successful in 1m17s
- 로그인 기능 오류 보완
2025-12-02 22:31:36 +09:00
e4048843e9 issue #41
- 비밀번호 초기화 로직 구현 및 테스트 완료
2025-12-02 22:31:10 +09:00
geonhee-min
0f0717fc79 issue #41
All checks were successful
Test CI / build (push) Successful in 1m21s
- 비밀번호 초기화 로직 1차 구현(테스트 필요)
2025-12-02 12:35:45 +09:00
58d092536e issue #39
All checks were successful
Test CI / build (push) Successful in 1m29s
- Access 토큰 만료 시 Refresh 토큰으로 Access 토큰 갱신 로직 구현 중
2025-12-01 22:36:01 +09:00
geonhee-min
56cee12c81 issue #39
All checks were successful
Test CI / build (push) Successful in 1m28s
- Access/Refresh 토큰 검증 및 허가 구현 중
2025-12-01 16:35:22 +09:00
43868489e0 issue #
All checks were successful
Test CI / build (push) Successful in 1m25s
- gitea-ci 파일 node_modules 캐싱 수정
2025-11-30 19:03:32 +09:00
be65742caa issue #
Some checks failed
Test CI / build (push) Failing after 23s
- gitea-ci 파일 node_modules 캐싱 수정
2025-11-30 18:58:27 +09:00
ab99d23de3 issue #39
Some checks failed
Test CI / build (push) Failing after 26s
- 로그인 이후 access/refresh token 생성 및 반환 로직 구현
- gitea 웹훅 테스트
2025-11-30 18:30:16 +09:00
5c79aa18f4 issue #39
Some checks failed
Test CI / build (push) Failing after 28s
- 로그인 이후 access/refresh token 생성 및 반환 로직 구현
2025-11-30 18:19:39 +09:00
geonhee-min
810b4c1fb0 issue # server pc change
All checks were successful
Test CI / build (push) Successful in 1m29s
2025-11-28 13:10:59 +09:00
geonhee-min
3bea9bca11 issue # server pc change
Some checks failed
Test CI / build (push) Failing after 3s
2025-11-28 13:08:11 +09:00
geonhee-min
115c5e61f0 issue # server pc change
Some checks failed
Test CI / build (push) Failing after 1m50s
2025-11-28 12:23:16 +09:00
geonhee-min
4365f29e27 issue # server pc change
Some checks failed
Test CI / build (push) Has been cancelled
2025-11-28 12:22:54 +09:00
geonhee-min
f71415d7c0 issue # caching and reload test
All checks were successful
Test CI / build (push) Successful in 3m9s
2025-11-26 16:56:54 +09:00
geonhee-min
ca1e6071cf issue # caching and reload test
All checks were successful
Test CI / build (push) Successful in 3m14s
2025-11-26 16:49:09 +09:00
geonhee-min
4d77d2689b issue # gitea ci cache test
All checks were successful
Test CI / build (push) Successful in 4m26s
2025-11-26 16:43:52 +09:00
geonhee-min
c58ee43112 issue # gitea cache test
Some checks failed
Test CI / build (push) Failing after 3m42s
2025-11-26 16:38:45 +09:00
geonhee-min
9bd7df97d4 issue # gitea cache test 2025-11-26 16:37:02 +09:00
geonhee-min
6d36fcab7e issue # graceful shutdown 구현 중
All checks were successful
Test CI / build (push) Successful in 3m22s
2025-11-26 16:32:51 +09:00
geonhee-min
3ed2975e04 issue # deploy test
All checks were successful
Test CI / build (push) Successful in 2m44s
2025-11-26 16:15:51 +09:00
geonhee-min
75d4173124 issue # gitea minio 연동 테스트. 이거 안 되면 그냥 로컬로 한다.
All checks were successful
Test CI / build (push) Successful in 2m39s
2025-11-26 15:33:32 +09:00
geonhee-min
ba70c32d34 issue # gitea minio caching 테스트
All checks were successful
Test CI / build (push) Successful in 7m43s
2025-11-26 14:52:46 +09:00
geonhee-min
ac5b6bdc52 issue # gitea ci test
All checks were successful
Test CI / build (push) Successful in 3m10s
2025-11-26 13:59:18 +09:00
geonhee-min
a951895850 issue # gitea minio integration 테스트
All checks were successful
Test CI / build (push) Successful in 2m55s
2025-11-26 13:30:46 +09:00
geonhee-min
778904ff6d issue # gitea minio integration 테스트
All checks were successful
Test CI / build (push) Successful in 1m19s
2025-11-26 13:13:40 +09:00
geonhee-min
d815dd73dd issue # gitea ci test
All checks were successful
Test CI / build (push) Successful in 1m17s
2025-11-26 12:53:13 +09:00
geonhee-min
36ea7a6be4 issue # gitea ci test
Some checks failed
Test CI / build (push) Has been cancelled
2025-11-26 12:23:57 +09:00
geonhee-min
4f6eba3430 issue # gitea ci test
Some checks failed
Test CI / build (push) Failing after 3m43s
2025-11-26 12:18:28 +09:00
geonhee-min
6f7aa2b309 issue # gitea ci test
Some checks failed
Test CI / build (push) Failing after 3m30s
2025-11-26 12:13:08 +09:00
geonhee-min
72fd7594c1 issue # gitea ci test
Some checks failed
Test CI / build (push) Failing after 3m41s
2025-11-26 12:06:12 +09:00
geonhee-min
0fa55acc14 issue # gitea ci test
All checks were successful
Test CI / build (push) Successful in 6m52s
2025-11-26 11:12:08 +09:00
geonhee-min
ea85899906 issue # gitea ci test
All checks were successful
Test CI / build (push) Successful in 2m13s
2025-11-26 08:45:51 +09:00
geonhee-min
3747838f9a issue # gitea ci test
All checks were successful
Test CI / build (push) Successful in 9s
2025-11-26 08:34:22 +09:00
geonhee-min
7035c7b7c3 issue # gitea ci test
All checks were successful
Test CI / build (push) Successful in 6s
2025-11-26 08:30:52 +09:00
geonhee-min
25c7c52dd4 issue # gitea ci test
All checks were successful
Test CI / build (push) Successful in 45s
2025-11-26 08:26:41 +09:00
92376b8aec issue # woodpecker ci 테스트 2025-11-25 22:11:58 +09:00
4a42080024 issue # woodpecker ci 테스트 2025-11-25 22:06:25 +09:00
ccfbdaffe2 issue # woodpecker ci 테스트 2025-11-25 22:03:25 +09:00
geonhee-min
ab74fd1a71 issue # gitlab-ci test 2025-11-24 11:16:51 +09:00
geonhee-min
7ea116dc8e issue # gitlab-ci 테스트 2025-11-24 10:47:40 +09:00
geonhee-min
5e65a70ce2 issue # gitlab-ci 테스트 2025-11-24 10:44:55 +09:00
geonhee-min
818aa659fc issue # yarn.lock 파일 gitignore 제외 2025-11-24 10:34:15 +09:00
geonhee-min
f810fc888d issue # gitlab-ci 테스트 2025-11-24 10:29:41 +09:00
geonhee-min
dbf96453b5 issue # gitlab-ci 테스트 2025-11-24 10:27:42 +09:00
geonhee-min
fb544e9e3a issue # gitignore 수정 2025-11-24 08:31:15 +09:00
민건희
dce509bad9 issue # 회원가입 로직 구현 완료 2025-11-23 23:02:45 +09:00
geonhee-min
8303a8ab19 issue # 이메일 인증 로직 구현 중 2025-11-21 16:31:33 +09:00
geonhee-min
6cd0361375 issue # 이메일 인증 코드 발송 로직 구현 2025-11-21 16:21:07 +09:00
71 changed files with 14085 additions and 177 deletions

28
.env
View File

@@ -1,28 +0,0 @@
# PostgreSQL 설정
PGHOST=bkdhome.p-e.kr
PGPORT=15454
PGDATABASE=scheduler
PGUSER=baekyangdan
PGPASSWORD=qwas745478!
PG_DATABASE_URL=postgres://baekyangdan:qwas745478!@bkdhome.p-e.kr:15454/scheduler
# Redis 설정
RD_HOST=bkdhome.p-e.kr
RD_PORT=16779
RD_URL=redis://bkdhome.p-e.kr:16779
# Express 서버 포트
PORT=3000
# Gmail SMTP 설정
GMAIL_USER=bkd.scheduler@gmail.com
GMAIL_PASS= # 앱 비밀번호 또는 OAuth2 토큰
GMAIL_CLIENT_ID=688417162908-iqvnj4ceb8t1dkbjr70dtcafo27m8kqe.apps.googleusercontent.com
GMAIL_CLIENT_SECRET=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
GMAIL_REFRESH_TOKEN=1//04_pSivNoGpPUCgYIARAAGAQSNwF-L9IrO0Kx6jSzq_eQNjdl65f0O2iqKSNpFeZ3gtIGMhOk0oiZsnKrPfWs8jvuEic1NhUoZ0g
# SMTP 추가 옵션
SMTP_AUTH=true
SMTP_STARTTLS_ENABLE=true
SMTP_STARTTLS_REQUIRED=true
SMTP_AUTH_MECHANISMS=XOAUTH2

14
.env.common Normal file
View File

@@ -0,0 +1,14 @@
# Gmail SMTP 설정
GMAIL_USER=bkd.scheduler@gmail.com
GMAIL_PASS= # 앱 비밀번호 또는 OAuth2 토큰
GMAIL_CLIENT_ID=688417162908-iqvnj4ceb8t1dkbjr70dtcafo27m8kqe.apps.googleusercontent.com
GMAIL_CLIENT_SECRET=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
GMAIL_REFRESH_TOKEN=1//04P8ekVQmkdtnCgYIARAAGAQSNwF-L9IrqPOyH8oYB-mdjUqw9jGHienVLBTWFdiZgpRnPgFmYnAdbjnstd9RkRVeJErB0NRAwg4
# SMTP 추가 옵션
SMTP_AUTH=true
SMTP_STARTTLS_ENABLE=true
SMTP_STARTTLS_REQUIRED=true
SMTP_AUTH_MECHANISMS=XOAUTH2
JWT_SECRET=96612b08364bbd9f275f29f86d39c18225e3cb3f31551434d5a84a88f5b01e627b5aafac902e0769bda4f1574b2f84ffb26e659b1a672182015a180c086cb911

14
.env.dev Normal file
View File

@@ -0,0 +1,14 @@
PORT=8088
# PostgreSQL 설정
PGHOST=bkdhome.p-e.kr
PGPORT=15454
PGDATABASE=scheduler
PGUSER=baekyangdan
PGPASSWORD=qwas745478!
PG_DATABASE_URL=postgres://baekyangdan:qwas745478!@bkdhome.p-e.kr:15454/scheduler
# Redis 설정
RD_HOST=bkdhome.p-e.kr
RD_PORT=16779
RD_URL=redis://bkdhome.p-e.kr:16779

12
.env.local Normal file
View File

@@ -0,0 +1,12 @@
HOST=0.0.0.0
PORT=3000
# PostgreSQL 설정
PGUSER=baekyangdan
PGPASSWORD=qwas745478!
PG_DATABASE_URL=postgres://192.168.219.103:5454/scheduler
# Redis 설정
RD_HOST=192.168.219.103
RD_PORT=6779
RD_URL=redis://192.168.219.103:6779

14
.env.prod Normal file
View File

@@ -0,0 +1,14 @@
PORT=3000
# PostgreSQL 설정
PGHOST=db
PGPORT=5432
PGDATABASE=scheduler
PGUSER=baekyangdan
PGPASSWORD=qwas745478!
PG_DATABASE_URL=postgres://baekyangdan:qwas745478!@db:5432/scheduler
# Redis 설정
RD_HOST=redis
RD_PORT=6379
RD_URL=redis://redis:6379

View File

@@ -0,0 +1,67 @@
name: Test CI
on:
push:
branches: [main]
jobs:
build:
runs-on: rpi5
env:
DOCKER_VOLUME: ${{ vars.DOCKER_VOLUME }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check PWD
run: |
echo "Docker volume: $DOCKER_VOLUME"
echo "PWD: $PWD"
ls -lRa ./.yarn
- name: Validate Node and Yarn Environment
run: |
if ! command -v node &> /dev/null
then
echo "Error: Node.js not found"
exit 1
fi
echo "Node.js version: $(node -v)"
if ! command -v yarn &> /dev/null
then
echo "Error: Yarn.js not found"
exit 1
fi
echo "yarn version: $(yarn -v)"
- name: Restore Yarn cache
uses: actions/cache@v4
with:
path: |
.yarn/cache
.yarn/unplugged
.yarn/install-state.gz
.pnp.cjs
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock','package.json') }}
- name: Install Dependencies with yarn
run: |
yarn install --immutable
ls .
- name: Build Nestjs project
run: |
yarn build
ls .
- name: Deploy dist
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

13
.gitignore vendored
View File

@@ -3,11 +3,18 @@ node_modules/
npm-debug.log* npm-debug.log*
yarn-error.log* yarn-error.log*
package-lock.json package-lock.json
yarn.lock # yarn.lock
# Yarn Berry
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
.pnp.* .pnp.*
.pnp.loader.mjs # .pnp.loader.mjs
.yarn/install-state.gz # .yarn/install-state.gz
# TypeScript # TypeScript
dist/ dist/

View File

@@ -1,43 +0,0 @@
# # This file is a template, and might need editing before it works on your project.
# # This is a sample GitLab CI/CD configuration file that should run without any modifications.
# # It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
# # it uses echo commands to simulate the pipeline execution.
# #
# # A pipeline is composed of independent jobs that run scripts, grouped into stages.
# # Stages run in sequential order, but jobs within stages run in parallel.
# #
# # For more information, see: https://docs.gitlab.com/ee/ci/yaml/#stages
# #
# # You can copy and paste this template into a new `.gitlab-ci.yml` file.
# # You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword.
# #
# # To contribute improvements to CI/CD templates, please follow the Development guide at:
# # https://docs.gitlab.com/development/cicd/templates/
# # This specific template is located at:
# # https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml
# stages: # List of stages for jobs, and their order of execution
# - build
# cache:
# key:
# files:
# - package-lock.json
# paths:
# - node_modules/
# build: # This job runs in the build stage, which runs first.
# stage: build
# tags:
# - local-runner
# before_script:
# script:
# - echo "Compiling the code..."
# - echo $DOCKER_VOLUME
# - echo $DOCKER_COMPOSE_VOLUME
# - npm install
# - npm run build
# - sudo cp -r $PWD/dist/. $DOCKER_VOLUME/scheduler/back/dist
# - sudo cp $PWD/package.json $DOCKER_VOLUME/scheduler/back/dist
# - docker compose -f $DOCKER_COMPOSE_VOLUME/scheduler/docker-compose.yaml up -d back
# - echo "Compile complete."

942
.yarn/releases/yarn-4.11.0.cjs vendored Normal file

File diff suppressed because one or more lines are too long

6
.yarnrc.yml Normal file
View File

@@ -0,0 +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

28
certs/localhost+2-key.pem Normal file
View File

@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC1GqPn9O+FRM+a
hQvEAjgjI7HXdRdeRJsX3K2BqNGYBR8Lat4fMskY4Es7WYNCDl9d/fFQd+K/gpjj
sRnX0Bf3CYjVNlhTqdwoOFBPGUQ4i8fuSRM4rDvAq4enb+7RVWjE53MGgqQ0RdRQ
Hyx95pEWTz0FzpNlzOzEGEdv8zBwbwgZBU73F4aCDNY0FLaaKepr1/NqdUA8xZYo
sAbJvIkWJ/QS2F2/WwQZYQ3TLWtg4/2uDpGWbpQUwRnWZ7ma+Gcz/hJwQhoml4q4
bHXrIAsCz/NFNYs7K5wCmIdTjLw2PcETJSEQMbGSk7CMIuiUd0ShVDfpBROIAlmF
XAheZ/lNAgMBAAECggEAT1H7t/xva89XnjXnkVHnhHx9yABg28jwpOLim4d1RT/4
+Oc1ojR8H4kdakEqXCQvYNt4deYMShTJIfDPgNaDqI9kfv3ucbZT1snTYtGOL7YJ
OzSGVqwY/6ohIBTGZKkj2hoFJzTQ9pQfCXid5Aa4RS0vbPutU0kN6lU39LBu5s79
8MGGu70Qcd63BRpyOxKbbWCbZ0S/7JRShng0GA8ILBvMCZdzZ7RZktpa+bA7Q6i7
PM5zxxmxygmFQXOAizTB2KoeLEu/qb44kypK6aw9nMKEZebqzuF5bOFMlCR67Cfx
QblFW0JQckef7DCc4ThPEnAXwEPSlsv2P//dbX1TgQKBgQDctIA/GZmzSXVtsUws
aPPeAvKMWGFSGsq/9rcy2G7KBTHBQW5/763T6N7HKVpZwRaabiSxgrZekd6d9oTP
XWpmnFQZgtLRtXLPXilCK8Udoi6HejGuXWvviFdfPUqhPh3tw6uCaFO7qT4pUiwO
hTq4W5Cm+xy/q12m7cEDfoPeMwKBgQDSEOdQY5f5C6YrZvG2zrTZUvS8VW4NFhkY
vSZBGqiACYGKq/7erMoAdtLrcYBnEMiLufn+tSInflw2I+ALEo4r2lcBAQncXuWj
gnpM+DpTwRfZmGYs3jXA5eVRRzG0FBFLFyiBE62f0tvJjALB7V7vfpCswJGvPIyb
p2P16jZKfwKBgQCn4VkoJlYGzZrYTKPvqAnQV5ed7+BfbufIq2dg8scbPmZBZX8j
K/KinaFQB4Glgj2qTJv2tsH4H6chqxINFjbIRKOoIB4yzH2/hRWHMvomd2ZDQUyn
IILo2mHznRC2pCRp5owAj1EaDzusfMfsZ6Vp9KSMj7inhzeesX0/Ji4yhwKBgHgh
sJc5jYSgU9RIV/0qcyRBm7JEzN3xAEM0kLb0rt4iEZIjUGs5t3/SdEavLzZB096M
adpu7exWCBfyJkNOxj1v7Qem92OuZXc/u/9eicSyDZij3fLU1TrOfnkf1N3eCBHA
WaqPfWCELqsxRbZvsDYYVFZm/imP3/14GeNdoNSzAoGALFD3YdZ5bIETcD8hwXd7
P9HXPQZag919fFe0dhPDauC5dgvgfLF2d88q0MPCqMK6ngTMVzrMh4X/u0XH1N3v
LiQEBp4P0EX1z5DEj8eLajV0JgOyt1zzymZ3Jk7DDyfcYl+bVetB2R9Gd3MuV98t
Sz72wO/jh1/w+SN07F9VS0w=
-----END PRIVATE KEY-----

26
certs/localhost+2.pem Normal file
View File

@@ -0,0 +1,26 @@
-----BEGIN CERTIFICATE-----
MIIETjCCAragAwIBAgIQJ0x1ttig1msjzZOJWJwnITANBgkqhkiG9w0BAQsFADB7
MR4wHAYDVQQKExVta2NlcnQgZGV2ZWxvcG1lbnQgQ0ExKDAmBgNVBAsMH+uwse2W
peuLqFxiYWVreWFuZ2RhbkDrsLHtlqXri6gxLzAtBgNVBAMMJm1rY2VydCDrsLHt
lqXri6hcYmFla3lhbmdkYW5A67Cx7Zal64uoMB4XDTI1MTIwNzEwMDIyNVoXDTI4
MDMwNzEwMDIyNVowUzEnMCUGA1UEChMebWtjZXJ0IGRldmVsb3BtZW50IGNlcnRp
ZmljYXRlMSgwJgYDVQQLDB/rsLHtlqXri6hcYmFla3lhbmdkYW5A67Cx7Zal64uo
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtRqj5/TvhUTPmoULxAI4
IyOx13UXXkSbF9ytgajRmAUfC2reHzLJGOBLO1mDQg5fXf3xUHfiv4KY47EZ19AX
9wmI1TZYU6ncKDhQTxlEOIvH7kkTOKw7wKuHp2/u0VVoxOdzBoKkNEXUUB8sfeaR
Fk89Bc6TZczsxBhHb/MwcG8IGQVO9xeGggzWNBS2minqa9fzanVAPMWWKLAGybyJ
Fif0Ethdv1sEGWEN0y1rYOP9rg6Rlm6UFMEZ1me5mvhnM/4ScEIaJpeKuGx16yAL
As/zRTWLOyucApiHU4y8Nj3BEyUhEDGxkpOwjCLolHdEoVQ36QUTiAJZhVwIXmf5
TQIDAQABo3YwdDAOBgNVHQ8BAf8EBAMCBaAwEwYDVR0lBAwwCgYIKwYBBQUHAwEw
HwYDVR0jBBgwFoAU9/lqZ9lo2f1oLg+JnBYubfpE4OEwLAYDVR0RBCUwI4IJbG9j
YWxob3N0hwR/AAABhxAAAAAAAAAAAAAAAAAAAAABMA0GCSqGSIb3DQEBCwUAA4IB
gQBNsZYSSGE6m3ve8bPGISSdlSU/pi1GVqOC4xxVD8JUeGNZeYAv8AJQ6w/496wK
KTFL6PDOavHW37mWBEgz+fZe2AjOZK/hz/eOcKHTFhVRZo1snt5VuLk4PtAGmgn8
xyyQUz/2wwlTqb0AgLrt1hLTnbSIWvBnFl3VdCnH0E2xsIPZUMFzcjVHTERJWvAS
IanurnpeO/W3uNduu7UmGk03GDzTG8dXwVsSSE/HoXxscXSIP9qMvKOPeQvucd+X
XkaYUkbjDhwoKqDB0rDmvbPkFcsAGuq8qpbPPavhoXgtdqO30lZfbTPWPq1qz99S
nW9ihMfmwarw5s/LCXiQO70nMbcZMZ6UAqEhX4UUfGD0j5jHe3fPOyT4v0lLfmxp
P4eoSiWoIfp/f9ZBn9zca5km9iGNT+n1Jrt6fOTIycPVu2gE7S4qXcHhVHWondle
bMFLGbjZ75Qwc9HdnoY7Do8Vj+CPvSfhAAPehPf8D1GVlazmiuHql4fny1qbGw//
YEQ=
-----END CERTIFICATE-----

View File

@@ -1,7 +1,7 @@
import { defineConfig } from 'drizzle-kit'; import { defineConfig } from 'drizzle-kit';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
dotenv.config(); dotenv.config({ path: `.env.${process.env.NODE_ENV}` });
export default defineConfig({ export default defineConfig({
dialect: "postgresql", dialect: "postgresql",
@@ -9,5 +9,13 @@ export default defineConfig({
out: "./drizzle", out: "./drizzle",
dbCredentials: { dbCredentials: {
url: process.env.PG_DATABASE_URL! url: process.env.PG_DATABASE_URL!
} },
tablesFilter: [
'account',
'schedule',
'comment',
'follow',
'favorite',
'participant'
]
}); });

View File

@@ -18,8 +18,8 @@ export const commentRelations = relations(comment, ({one, many}) => ({
export const accountRelations = relations(account, ({many}) => ({ export const accountRelations = relations(account, ({many}) => ({
comments: many(comment), comments: many(comment),
schedules: many(schedule),
participants: many(participant), participants: many(participant),
schedules: many(schedule),
favorites: many(favorite), favorites: many(favorite),
follows_follower: many(follow, { follows_follower: many(follow, {
relationName: "follow_follower_account_id" relationName: "follow_follower_account_id"
@@ -29,15 +29,6 @@ export const accountRelations = relations(account, ({many}) => ({
}), }),
})); }));
export const scheduleRelations = relations(schedule, ({one, many}) => ({
account: one(account, {
fields: [schedule.owner],
references: [account.id]
}),
participants: many(participant),
favorites: many(favorite),
}));
export const participantRelations = relations(participant, ({one}) => ({ export const participantRelations = relations(participant, ({one}) => ({
schedule: one(schedule, { schedule: one(schedule, {
fields: [participant.scheduleId], fields: [participant.scheduleId],
@@ -49,6 +40,15 @@ export const participantRelations = relations(participant, ({one}) => ({
}), }),
})); }));
export const scheduleRelations = relations(schedule, ({one, many}) => ({
participants: many(participant),
account: one(account, {
fields: [schedule.owner],
references: [account.id]
}),
favorites: many(favorite),
}));
export const favoriteRelations = relations(favorite, ({one}) => ({ export const favoriteRelations = relations(favorite, ({one}) => ({
schedule: one(schedule, { schedule: one(schedule, {
fields: [favorite.scheduleId], fields: [favorite.scheduleId],

View File

@@ -1,12 +1,41 @@
import { pgTable, foreignKey, uuid, text, date, boolean, index, varchar, primaryKey } 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" import { sql } from "drizzle-orm"
export const versionIdSeq = pgSequence("version_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false })
export const accessTokenIdSeq = pgSequence("access_token_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false })
export const oauth2ApplicationIdSeq = pgSequence("oauth2_application_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false })
export const oauth2AuthorizationCodeIdSeq = pgSequence("oauth2_authorization_code_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false })
export const oauth2GrantIdSeq = pgSequence("oauth2_grant_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false })
export const loginSourceIdSeq = pgSequence("login_source_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false })
export const twoFactorIdSeq = pgSequence("two_factor_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false })
export const webauthnCredentialIdSeq = pgSequence("webauthn_credential_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false })
export const dbfsMetaIdSeq = pgSequence("dbfs_meta_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false })
export const dbfsDataIdSeq = pgSequence("dbfs_data_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false })
export const noticeIdSeq = pgSequence("notice_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false })
export const systemSettingIdSeq = pgSequence("system_setting_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false })
export const badgeIdSeq = pgSequence("badge_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false })
export const userBadgeIdSeq = pgSequence("user_badge_id_seq", { startWith: "1", increment: "1", minValue: "1", maxValue: "9223372036854775807", cache: "1", cycle: false })
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", { export const comment = pgTable("comment", {
id: uuid().primaryKey().notNull(), id: uuid().default(sql`uuid_generate_v4()`).primaryKey().notNull(),
content: text(), content: text(),
createdAt: date("created_at"), createdAt: timestamp("created_at", { mode: 'string' }),
isDeleted: boolean("is_deleted").default(false), isDeleted: boolean("is_deleted").default(false),
writerId: uuid("writer_id"), writerId: uuid("writer_id"),
parentId: uuid("parent_id"), parentId: uuid("parent_id"),
@@ -23,43 +52,6 @@ export const comment = pgTable("comment", {
}), }),
]); ]);
export const schedule = pgTable("schedule", {
id: uuid().primaryKey().notNull(),
name: varchar(),
startAt: date("start_at"),
endAt: date("end_at"),
status: varchar(),
content: text(),
isDeleted: boolean("is_deleted").default(false),
type: varchar(),
createdAt: date("created_at"),
owner: uuid(),
}, (table) => [
index("schedule_enddatetime_idx").using("btree", table.endAt.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")),
index("schedule_startdatetime_idx").using("btree", table.startAt.asc().nullsLast().op("date_ops")),
index("schedule_status_idx").using("btree", table.status.asc().nullsLast().op("text_ops")),
index("schedule_type_idx").using("btree", table.type.asc().nullsLast().op("text_ops")),
foreignKey({
columns: [table.owner],
foreignColumns: [account.id],
name: "schedule_user_fk"
}),
]);
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('wait').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", { export const participant = pgTable("participant", {
participantId: uuid("participant_id").notNull(), participantId: uuid("participant_id").notNull(),
scheduleId: uuid("schedule_id").notNull(), scheduleId: uuid("schedule_id").notNull(),
@@ -79,6 +71,34 @@ export const participant = pgTable("participant", {
}), }),
]); ]);
export const schedule = pgTable("schedule", {
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).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")),
index("schedule_startdatetime_idx").using("btree", table.startDate.asc().nullsLast().op("date_ops")),
index("schedule_status_idx").using("btree", table.status.asc().nullsLast().op("text_ops")),
index("schedule_type_idx").using("btree", table.type.asc().nullsLast().op("text_ops")),
foreignKey({
columns: [table.owner],
foreignColumns: [account.id],
name: "schedule_user_fk"
}),
]);
export const favorite = pgTable("favorite", { export const favorite = pgTable("favorite", {
isDeleted: boolean("is_deleted").default(false), isDeleted: boolean("is_deleted").default(false),
createdAt: date("created_at"), createdAt: date("created_at"),
@@ -102,7 +122,7 @@ export const follow = pgTable("follow", {
isDeleted: boolean("is_deleted").default(false), isDeleted: boolean("is_deleted").default(false),
isAccepted: boolean("is_accepted").default(false), isAccepted: boolean("is_accepted").default(false),
isLinked: boolean("is_linked").default(false), isLinked: boolean("is_linked").default(false),
createdAt: date("created_at"), createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(),
following: uuid().notNull(), following: uuid().notNull(),
follower: uuid().notNull(), follower: uuid().notNull(),
}, (table) => [ }, (table) => [

View File

@@ -1,8 +1,5 @@
{ {
"$schema": "https://json.schemastore.org/nest-cli", "$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics", "collection": "@nestjs/schematics",
"sourceRoot": "src", "sourceRoot": "src"
"compilerOptions": {
"deleteOutDir": true
}
} }

View File

@@ -6,29 +6,49 @@
"private": true, "private": true,
"license": "UNLICENSED", "license": "UNLICENSED",
"scripts": { "scripts": {
"build": "nest build", "build": "cross-env NODE_ENV=prod nest build",
"build:local": "cross-env NODE_ENV=local nest build",
"build:dev": "cross-env NODE_ENV=dev nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start", "start": "nest start",
"start:dev": "nest start --watch", "start:local": "cross-env NODE_ENV=local nest start --watch",
"start:dev": "cross-env NODE_ENV=dev nest start --watch",
"start:debug": "nest start --debug --watch", "start:debug": "nest start --debug --watch",
"start:prod": "node dist/main", "start:prod": "cross-env NODE_ENV=prod node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest", "test": "jest",
"test:watch": "jest --watch", "test:watch": "jest --watch",
"test:cov": "jest --coverage", "test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json" "test:e2e": "jest --config ./test/jest-e2e.json",
"drizzle-pull:local": "dotenv -e .env.local -- drizzle-kit pull",
"drizzle-pull:dev": "dotenv -e .env.dev -- drizzle-kit pull",
"drizzle-pull:prod": "dotenv -e .env.prod -- drizzle-kit pull"
}, },
"dependencies": { "dependencies": {
"@baekyangdan/core-utils": "^1.0.23",
"@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",
"@nestjs/common": "^11.0.1", "@nestjs/common": "^11.0.1",
"@nestjs/config": "^4.0.2",
"@nestjs/core": "^11.0.1", "@nestjs/core": "^11.0.1",
"@nestjs/jwt": "^11.0.1",
"@nestjs/passport": "^11.0.5",
"@nestjs/platform-express": "^11.0.1", "@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", "dotenv": "^17.2.3",
"drizzle-kit": "^0.31.7", "drizzle-kit": "^0.31.7",
"drizzle-orm": "^0.44.7", "drizzle-orm": "^0.44.7",
"fastify": "^5.6.2",
"fastify-cors": "^6.1.0",
"googleapis": "^166.0.0",
"ioredis": "^5.8.2", "ioredis": "^5.8.2",
"nodemailer": "^7.0.10",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
"pg": "^8.16.3", "pg": "^8.16.3",
"reflect-metadata": "^0.2.2", "reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1" "rxjs": "^7.8.1"
@@ -39,12 +59,18 @@
"@nestjs/cli": "^11.0.0", "@nestjs/cli": "^11.0.0",
"@nestjs/schematics": "^11.0.0", "@nestjs/schematics": "^11.0.0",
"@nestjs/testing": "^11.0.1", "@nestjs/testing": "^11.0.1",
"@types/bcrypt": "^6",
"@types/express": "^5.0.0", "@types/express": "^5.0.0",
"@types/ioredis": "^5.0.0", "@types/ioredis": "^5.0.0",
"@types/jest": "^30.0.0", "@types/jest": "^30.0.0",
"@types/node": "^22.10.7", "@types/node": "^22.10.7",
"@types/nodemailer": "^7.0.4",
"@types/passport": "^0",
"@types/passport-jwt": "^4.0.1",
"@types/pg": "^8.15.6", "@types/pg": "^8.15.6",
"@types/supertest": "^6.0.2", "@types/supertest": "^6.0.2",
"cross-env": "^10.1.0",
"dotenv-cli": "^11.0.0",
"eslint": "^9.18.0", "eslint": "^9.18.0",
"eslint-config-prettier": "^10.0.1", "eslint-config-prettier": "^10.0.1",
"eslint-plugin-prettier": "^5.2.2", "eslint-plugin-prettier": "^5.2.2",
@@ -76,5 +102,6 @@
], ],
"coverageDirectory": "../coverage", "coverageDirectory": "../coverage",
"testEnvironment": "node" "testEnvironment": "node"
} },
"packageManager": "yarn@4.11.0"
} }

View File

@@ -3,9 +3,13 @@ import { AppController } from './app.controller';
import { AppService } from './app.service'; import { AppService } from './app.service';
import { DbModule } from './db/db.module'; import { DbModule } from './db/db.module';
import { RedisModule } from './redis/redis.module'; 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({ @Module({
imports: [DbModule, RedisModule], imports: [AppConfigModule, DbModule, RedisModule, MailerModule, AccountModule, ScheduleModule],
controllers: [AppController], controllers: [AppController],
providers: [AppService], providers: [AppService],
}) })

View File

@@ -3,6 +3,6 @@ import { Injectable } from '@nestjs/common';
@Injectable() @Injectable()
export class AppService { export class AppService {
getHello(): string { getHello(): string {
return 'Hello World!'; return 'Hello World!\nReload Test!';
} }
} }

View File

@@ -0,0 +1,5 @@
import { SetMetadata } from "@nestjs/common";
export const IS_PUBLIC_KEY = 'isPublic345827';
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);

View File

@@ -0,0 +1,5 @@
export class BaseResponseDto {
success: boolean;
message?: string;
error?: string;
}

View File

@@ -0,0 +1,75 @@
import {
ExceptionFilter,
Catch,
ArgumentsHost,
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 {
catch(exception: unknown, host: ArgumentsHost) {
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
? exception.getStatus()
: HttpStatus.INTERNAL_SERVER_ERROR;
let message =
exception instanceof HttpException
? exception.getResponse()
: InternalServerErrorMessage.INTERNAL_SERVER_ERROR;
if (typeof message === 'object' && (message as any).message) {
message = (message as any).message;
}
response.status(status).send({
success: false,
timestamp: new Date().toISOString(),
path: request.url,
statusCode: status,
message: message,
error: InternalServerErrorCode
});
}
}

View File

@@ -0,0 +1,16 @@
import { Module } from "@nestjs/common";
import { ConfigModule } from '@nestjs/config';
import dotenv from 'dotenv';
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
envFilePath: [
`.env.${process.env.NODE_ENV}`,
'.env.common'
]
})
]
})
export class AppConfigModule{}

42
src/const/HttpResponse.ts Normal file
View File

@@ -0,0 +1,42 @@
export const HttpResponse: Record<string, {code: number, title: string, message: string}> = {
"ACCESS_TOKEN_EXPIRED": {
code: 401,
title: "ACCESS_TOKEN_EXPIRED",
message: "ACCESS TOKEN EXPIRED"
},
"INVALID_TOKEN": {
code: 401,
title: "INVALID_TOKEN",
message: "INVALID TOKEN"
},
"REFRESH_TOKEN_EXPIRED": {
code: 401,
title: "REFRESH_TOKEN_EXPIRED",
message: "REFRESH TOKEN EXPIRED"
},
"UNAUTHORIZED": {
code: 401,
title: "UNAUTHORIZED",
message: "UNAUTHORIZED"
},
"OK": {
code: 200,
title: "OK",
message: "OK"
},
"CREATED": {
code: 201,
title: "CREATED",
message: "CREATED"
},
"BAD_REQUEST": {
code: 400,
title: "BAD_REQUEST",
message: "BAD REQUEST"
},
"INTERNAL_SERVER_ERROR": {
code: 500,
title: "INTERNAL_SERVER_ERROR",
message: "INTERNAL SERVER ERROR"
}
} as const;

View File

@@ -1,22 +1,36 @@
import { Global, Module } from "@nestjs/common"; import { Global, Inject, Module, OnApplicationShutdown } from "@nestjs/common";
import { Pool } from "pg"; import { Pool } from "pg";
import { drizzle, NodePgDatabase } from "drizzle-orm/node-postgres"; import { drizzle, NodePgDatabase } from "drizzle-orm/node-postgres";
import { ConfigModule, ConfigService } from "@nestjs/config";
import * as schema from '../../drizzle/schema'; import * as schema from '../../drizzle/schema';
@Global() @Global()
@Module({ @Module({
imports: [ConfigModule],
providers: [ providers: [
{ {
provide: "DRIZZLE", provide: "DB_POOL",
useFactory: (): NodePgDatabase<typeof schema> => { useFactory: (configService: ConfigService) => {
const pool = new Pool({ return new Pool({
connectionString: process.env.PG_DATABASE_URL connectionString: configService.get<string>('PG_DATABASE_URL')
}); });
},
inject: [ConfigService]
},
{
provide: "DRIZZLE",
useFactory: (pool: Pool): NodePgDatabase<typeof schema> => {
return drizzle(pool, { schema: schema }); return drizzle(pool, { schema: schema });
} },
inject: ["DB_POOL"]
} }
], ],
exports: ["DRIZZLE"] exports: ["DRIZZLE"]
}) })
export class DbModule {} export class DbModule implements OnApplicationShutdown {
constructor(@Inject('DB_POOL') private readonly pool: Pool) {}
async onApplicationShutdown(signal?: string) {
await this.pool.end();
}
}

View File

@@ -1,8 +1,62 @@
import { NestFactory } from '@nestjs/core'; import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module'; import { AppModule } from './app.module';
import {
FastifyAdapter,
NestFastifyApplication
} from '@nestjs/platform-fastify';
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() { async function bootstrap() {
const app = await NestFactory.create(AppModule); const isProd = process.env.NODE_ENV === 'prod';
await app.listen(process.env.PORT ?? 3000); let httpsOptions = {};
if (!isProd) {
const certPath = path.join(__dirname, "..\\..", "certs");
httpsOptions = {
key: fs.readFileSync(path.join(certPath, 'localhost+2-key.pem')),
cert: fs.readFileSync(path.join(certPath, 'localhost+2.pem'))
};
}
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
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 등) 허용
if (!origin) return callback(null, true);
// 특정 도메인만 막고 싶은 경우 whitelist 가능
const whitelist = ["http://localhost:5173", "http://192.168.219.105:5185", "https://scheduler.bkdhome.p-e.kr"];
if (whitelist.includes(origin)) {
return callback(null, true);
}
// 그 외 모든 도메인 허용 → 사실상 wildcard
return callback(null, true);
},
credentials: true,
});
app.enableShutdownHooks();
app.useGlobalFilters(new AllExceptionsFilter());
app.register(fastifyCookie, {
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(); bootstrap();

View File

@@ -0,0 +1,24 @@
import { forwardRef, Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { JwtModule } from '@nestjs/jwt';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AccountModule } from 'src/modules/account/account.module';
import { JwtAccessStrategy } from './strategy/access-token.strategy';
import { JwtRefreshStrategy } from './strategy/refresh-token.strategy';
@Module({
imports: [
ConfigModule,
JwtModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
secret: config.get<string>('JWT_SECRET')!,
signOptions: { expiresIn: '1h' }
})
}),
forwardRef(() => AccountModule)
],
providers: [AuthService, JwtAccessStrategy, JwtRefreshStrategy],
exports: [AuthService]
})
export class AuthModule{}

View File

@@ -0,0 +1,26 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
@Injectable()
export class AuthService {
constructor(private readonly jwtService: JwtService) {}
generateTokens(id: string) {
const accessToken = this.jwtService.sign({id: id}, { expiresIn: '5m' });
const refreshToken = this.jwtService.sign({id: id}, { expiresIn: '7d' });
return { accessToken, refreshToken };
}
refreshTokens(id: string) {
try {
return this.generateTokens(id);
} catch (e) {
throw new UnauthorizedException('Invalid Refresh Token');
}
}
validateToken(token: string) {
return this.jwtService.verify(token);
}
}

View File

@@ -0,0 +1,40 @@
import { ExecutionContext, Injectable, UnauthorizedException } from "@nestjs/common";
import { Reflector } from "@nestjs/core";
import { JsonWebTokenError, TokenExpiredError } from "@nestjs/jwt";
import { AuthGuard } from "@nestjs/passport";
import { IS_PUBLIC_KEY } from "src/common/decorators/public.decorator";
@Injectable()
export class JwtAccessAuthGuard extends AuthGuard('access-token') {
constructor(private reflector: Reflector) {
super();
}
canActivate(context: ExecutionContext) {
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
context.getHandler(),
context.getClass()
]);
if (isPublic) {
return true;
}
return super.canActivate(context);
}
handleRequest(err: any, user:any, info:any, context: ExecutionContext) {
if (err || !user) {
if (info instanceof TokenExpiredError) {
throw info;
}
if (info instanceof JsonWebTokenError) {
throw info;
}
throw err || new JsonWebTokenError('Unauthorized');
}
return user;
}
}

View File

@@ -0,0 +1,45 @@
import { ExecutionContext, Injectable, UnauthorizedException } from "@nestjs/common";
import { Reflector } from "@nestjs/core";
import { TokenExpiredError } from "@nestjs/jwt";
import { AuthGuard } from "@nestjs/passport";
import { IS_PUBLIC_KEY } from "src/common/decorators/public.decorator";
@Injectable()
export class JwtRefreshAuthGuard extends AuthGuard('refresh-token') {
constructor(private reflector: Reflector) {
super();
}
canActivate(context: ExecutionContext) {
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
context.getHandler(),
context.getClass()
]);
if (isPublic) {
return true;
}
return super.canActivate(context);
}
handleRequest(err: any, user:any, info:any) {
if (info instanceof TokenExpiredError) {
throw new UnauthorizedException({
statusCode: 401,
message: 'Refresh Token Expired',
code: 'RefreshTokenExpired'
});
}
if (err || !user) {
throw new UnauthorizedException({
statusCode: 401,
message: 'Invalid Token',
code: 'InvalidToken'
});
}
return user;
}
}

View File

@@ -0,0 +1,27 @@
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,
private accountRepo: AccountRepo
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: configService.get<string>('JWT_SECRET')!
});
}
async validate(payload: any) {
console.log(payload);
const user = await this.accountRepo.findById(payload.id);
if (!user) {
throw new UnauthorizedException();
}
return user;
}
}

View File

@@ -0,0 +1,33 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';
import { FastifyRequest } from 'fastify';
import { ExtractJwt, Strategy } from 'passport-jwt';
const extractJwtFromCookie = (req: FastifyRequest | any): string | null => {
if (req.cookies && req.cookies['refresh_token']) {
return req.cookies['refresh_token'];
}
return null;
}
@Injectable()
export class JwtRefreshStrategy extends PassportStrategy(Strategy, 'refresh-token') {
constructor(configService: ConfigService) {
super({
jwtFromRequest: ExtractJwt.fromExtractors([extractJwtFromCookie]),
secretOrKey: configService.get<string>('JWT_SECRET')!,
passReqToCallback: true
});
}
async validate(req: FastifyRequest, payload: any) {
const refreshToken = req.cookies['refresh_token'];
if (!refreshToken) throw new UnauthorizedException('Invalid Refresh Token');
return {
id: payload.id,
refreshToken
};
}
}

View File

@@ -1,14 +1,101 @@
import { Controller, Get, Post, Query } from "@nestjs/common"; import { Body, Controller, Get, Headers, Post, Query, Req, Res, UseGuards } from "@nestjs/common";
import { CheckDuplicationRequestDto } from "./dto/checkDuplication/check-duplication-request.dto";
import { CheckDuplicationResponseDto } from "./dto/checkDuplication/check-duplication-response.dto";
import { AccountService } from "./account.service"; import { AccountService } from "./account.service";
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';
@Controller('account') const AccountApi = HttpApiUrl.Account;
@UseGuards(JwtAccessAuthGuard)
@Controller(AccountApi.base)
export class AccountController { export class AccountController {
constructor(private readonly accountService: AccountService) {} constructor(private readonly accountService: AccountService) {}
@Get('check-duplication') @Get(AccountApi.root)
async checkDuplication(@Query() query: CheckDuplicationRequestDto): Promise<CheckDuplicationResponseDto> { async test() {
return this.accountService.checkDuplication(query); return "Test"
}
@Public()
@Get(AccountApi.checkDuplication)
async checkDuplication(@Query() query: DTO.CheckDuplicationRequest): Promise<DTO.CheckDuplicationResponse> {
return await this.accountService.checkDuplication(query);
}
@Public()
@Post(AccountApi.sendEmailVerificationCode)
async sendEmailVerificationCode(@Body() body: DTO.SendEmailVerificationCodeRequest): Promise<DTO.SendEmailVerificationCodeResponse> {
const result = await this.accountService.sendVerificationCode(body);
return result;
}
@Public()
@Post(AccountApi.verifyEmailVerificationCode)
async verifyEmailVerificationCode(@Body() body: DTO.VerifyEmailVerificationCodeRequest): Promise<DTO.VerifyEmailVerificationCodeResponse> {
const result = await this.accountService.verifyCode(body);
return result;
}
@Public()
@Post(AccountApi.sendPasswordResetCode)
async sendPasswordResetCode(@Body() body: DTO.SendPasswordResetCodeRequest): Promise<DTO.SendPasswordResetCodeResponse> {
const result = await this.accountService.sendPasswordResetCode(body);
return result;
}
@Public()
@Post(AccountApi.verifyPasswordResetCode)
async verifyPasswordResetCode(@Body() body: DTO.VerifyPasswordResetCodeRequest): Promise<DTO.VerifyPasswordResetCodeResponse> {
const result = await this.accountService.verifyPasswordResetCode(body);
return result;
}
@Public()
@Post(AccountApi.resetPassword)
async resetPassword(@Body() body: DTO.ResetPasswordRequest): Promise<DTO.ResetPasswordResponse> {
const result = await this.accountService.resetPassword(body);
return result;
}
@Public()
@Post(AccountApi.signup)
async signup(@Body() body: DTO.SignupRequest): Promise<DTO.SignupResponse> {
const result = await this.accountService.signup(body);
return result;
}
@Public()
@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.data.refreshToken!, {
httpOnly: true,
path: '/',
secure: true,
maxAge: 7 * 24 * 60 * 60 * 1000
});
}
return result;
}
@Public()
@UseGuards(AuthGuard('refresh-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.data.refreshToken!, {
httpOnly: true,
path: '/',
secure: true,
maxAge: 7 * 24 * 60 * 60 * 1000
});
return result;
}
return result;
} }
} }

View File

@@ -1,10 +1,12 @@
import { Module } from "@nestjs/common"; import { forwardRef, Module } from "@nestjs/common";
import { AccountController } from "./account.controller"; import { AccountController } from "./account.controller";
import { AccountRepo } from "./account.repo"; import { AccountRepo } from "./account.repo";
import { AccountService } from "./account.service"; import { AccountService } from "./account.service";
import { AuthModule } from 'src/middleware/auth/auth.module';
@Module({ @Module({
imports: [forwardRef(() => AuthModule)],
controllers: [AccountController], controllers: [AccountController],
providers: [AccountService, AccountRepo] providers: [AccountService, AccountRepo],
exports: [AccountService, AccountRepo]
}) })
export class AccountModule {} export class AccountModule {}

View File

@@ -1,13 +1,13 @@
import { Inject, Injectable } from "@nestjs/common"; import { Inject, Injectable } from "@nestjs/common";
import * as schema from "drizzle/schema"; import * as schema from "drizzle/schema";
import { countDistinct, and, eq } from 'drizzle-orm'; import { countDistinct, and, eq, not } from 'drizzle-orm';
import { NodePgDatabase } from "drizzle-orm/node-postgres"; import { NodePgDatabase } from "drizzle-orm/node-postgres";
@Injectable() @Injectable()
export class AccountRepo { export class AccountRepo {
constructor(@Inject('DRIZZLE') private readonly db: NodePgDatabase<typeof schema>) {} constructor(@Inject('DRIZZLE') private readonly db: NodePgDatabase<typeof schema>) {}
async checkDuplication(type: 'email' | 'accountId', value: string) { async checkIdExists(type: 'email' | 'accountId', value: string) {
const result = await this const result = await this
.db .db
.select({ count: countDistinct(schema.account[type])}) .select({ count: countDistinct(schema.account[type])})
@@ -18,4 +18,68 @@ export class AccountRepo {
return result[0].count; return result[0].count;
} }
async signup(
accountId: string,
name: string,
nickname: string,
email: string,
password: string
) {
return await this
.db
.insert(schema.account)
.values({
accountId: accountId,
name: name,
nickname: nickname,
email: email,
password: password
});
}
async login(
type: 'email' | 'accountId'
, id: string
) {
return await this
.db
.select()
.from(schema.account)
.where(
and(
eq(schema.account[type], id),
eq(schema.account.isDeleted, false),
eq(schema.account.status, 'active')
)
);
}
async findById(id: string) {
return await this
.db
.select()
.from(schema.account)
.where(
and(
eq(schema.account.id, id),
eq(schema.account.isDeleted, false)
)
)
}
async updatePassword(type: 'email' | 'accountId', id: string, value: string) {
return await this
.db
.update(schema.account)
.set({
password: value
})
.where(
and(
eq(schema.account[type], id),
eq(schema.account.isDeleted, false)
)
);
}
} }

View File

@@ -1,15 +1,215 @@
import { Injectable } from "@nestjs/common"; import { Inject, Injectable } from "@nestjs/common";
import { AccountRepo } from "./account.repo"; import { AccountRepo } from "./account.repo";
import { CheckDuplicationRequestDto } from "./dto/checkDuplication/check-duplication-request.dto"; import { SchedulerDTO as DTO } from '@baekyangdan/core-utils';
import { CheckDuplicationResponseDto } from "./dto/checkDuplication/check-duplication-response.dto"; import { MailerService } from "src/util/mailer/mailer.service";
import { Generator } from "src/util/generator";
import Redis from "ioredis";
import { Converter } from "src/util/converter";
import { AuthService } from "src/middleware/auth/auth.service";
@Injectable() @Injectable()
export class AccountService { export class AccountService {
constructor(private readonly accountRepo: AccountRepo) {} constructor(
private readonly accountRepo: AccountRepo
, private readonly mailerService: MailerService
, private readonly authService: AuthService
, @Inject("REDIS") private readonly redis: Redis
) {}
async checkDuplication(data: CheckDuplicationRequestDto): Promise<CheckDuplicationResponseDto> { async checkDuplication(data: DTO.CheckDuplicationRequest): Promise<DTO.CheckDuplicationResponse> {
const count = await this.accountRepo.checkDuplication(data.type, data.value); const { type, value } = data;
const count = await this.accountRepo.checkIdExists(type, value);
return { isDuplicated: count > 0 }; return { success: true, message: '중복 체크 완료', data: { isDuplicated: count > 0 }};
}
async sendVerificationCode(data: DTO.SendEmailVerificationCodeRequest): Promise<DTO.SendEmailVerificationCodeResponse> {
const { email } = data;
const code = Generator.getVerificationCode();
const html = `<p>Your verification code is: <strong style="font-size:16px;">${code}</strong></p>`;
const result = await this.mailerService.sendMail(email, "<Scheduler> 이메일 인증 코드", html);
if (result.rejected.length > 0) {
return { success: false, error: result.response, code: '' }
} else {
await this.redis.set(`verify:${email}`, code, 'EX', 600);
return { success: true, message: "이메일 발송 완료", data: {} };
}
}
async verifyCode(data: DTO.VerifyEmailVerificationCodeRequest): Promise<DTO.VerifyEmailVerificationCodeResponse> {
const { email, code } = data;
const storedCode = await this.redis.get(`verify:${email}`);
if (!storedCode) {
return { success: false, error: '잘못된 이메일이거나 코드가 만료되었습니다.', code: ''};
}
if (storedCode !== code) {
return { success: true, message: "잘못된 코드입니다.", data: { verified: false } };
}
await this.redis.del(`verify:${email}`);
return { success: true, message: "이메일 인증이 완료되었습니다.", data: { verified: true } };
}
async signup(data: DTO.SignupRequest): Promise<DTO.SignupResponse> {
const { accountId, name, nickname, email, password } = data;
const hashedPassword = Converter.getHashedPassword(password);
const result = await this.accountRepo.signup(accountId, name, nickname, email, hashedPassword);
if (result.rowCount) {
return {
success: true,
message: "회원가입이 완료되었습니다.",
data: {}
};
} else {
return {
success: false,
error: "회원가입에 실패하였습니다.",
code: ''
};
}
}
async login(data: DTO.LoginRequest): Promise<DTO.LoginResponse> {
const { type, id, password } = data;
const queryResult = await this.accountRepo.login(type, id);
const typeValue = type === 'email' ? '이메일' : '아이디';
if (!queryResult || (queryResult.length < 1)) {
return {
success: false,
error: `존재하지 않는 ${typeValue} 입니다.`,
code: ''
};
}
const hashedPassword = queryResult[0].password;
const isPasswordMatch = Converter.comparePassword(password, hashedPassword);
if (!isPasswordMatch) {
return {
success: false,
error: `비밀번호가 맞지 않습니다.`,
code: ''
};
}
{
const { id } = queryResult[0];
const { accessToken, refreshToken } = this.authService.generateTokens(id);
return {
success: true,
data: {
accessToken: accessToken,
refreshToken: refreshToken
},
message: '로그인 성공'
};
}
}
async refreshAccessToken(id: string): Promise<DTO.RefreshAccessTokenResponse> {
const { accessToken, refreshToken } = this.authService.refreshTokens(id);
return {
success: true,
message: '토큰 갱신 완료',
data: {
accessToken: accessToken,
refreshToken: refreshToken
}
};
}
async sendPasswordResetCode(data: DTO.SendPasswordResetCodeRequest): Promise<DTO.SendPasswordResetCodeResponse> {
const { email } = data;
const count = await this.accountRepo.checkIdExists('email', email);
if (count === 0) {
return {
success: false,
error: "찾을 수 없는 사용자",
code: ''
};
}
const code = Generator.getResetPasswordCode();
const html =
`<p>Your Password Reset Code is: <strong>${code}</strong></p>`
+ `<p>Please Enter this code in 5 minutes.</p>`;
const result = await this.mailerService.sendMail(email, "<Scheduler> 비밀번호 초기화 코드", html);
if (result.rejected.length > 0) {
return {
success: false,
error: result.response,
code: ''
};
}
await this.redis.set(`resetPassword:${email}`, code, 'EX', 300);
return {
success: true,
message: "비밀번호 초기화 코드 발송 완료",
data: {}
};
}
async verifyPasswordResetCode(data: DTO.VerifyPasswordResetCodeRequest): Promise<DTO.VerifyPasswordResetCodeResponse> {
const { email, code } = data;
const storedCode = await this.redis.get(`resetPassword:${email}`);
if (!storedCode) {
return {
success: false,
error: "잘못된 이메일이거나 코드가 만료되었습니다.",
code: ''
};
}
if (storedCode !== code) {
return {
success: false,
error: "잘못된 코드입니다.",
code: ''
};
}
await this.redis.del(`resetPassword:${email}`);
return {
success: true,
message: "비밀번호 초기화 코드 인증 완료",
data: { verified: true }
};
}
async resetPassword(data: DTO.ResetPasswordRequest): Promise<DTO.ResetPasswordResponse> {
const { email, password } = data;
const hashedPassword = Converter.getHashedPassword(password);
const result = await this.accountRepo.updatePassword('email', email, hashedPassword);
if (!result.rowCount || result.rowCount === 0) {
return {
success: false,
error: "비밀번호 초기화 실패",
code: ''
};
}
return {
success: true,
message: "비밀번호 초기화 성공",
data: {}
};
} }
} }

View File

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

View File

@@ -0,0 +1,27 @@
import { ResetPasswordRequestDto } from './resetPassword/reset-password-request.dto';
export { CheckDuplicationRequestDto as CheckDuplicationRequest } from './checkDuplication/check-duplication-request.dto';
export { CheckDuplicationResponseDto as CheckDuplicationResponse } from './checkDuplication/check-duplication-response.dto';
export { SendEmailVerificationCodeRequestDto as SendEmailVerificationCodeRequest } from './sendEmailVerificationCode/send-email-verification-code-request.dto';
export { SendEmailVerificationCodeResponseDto as SendEmailVerificationCodeResponse } from './sendEmailVerificationCode/send-email-verification-code-response.dto';
export { VerifyEmailVerificationCodeRequestDto as VerifyEmailVerificationCodeRequest } from './verifyEmailVerificationCode/verify-email-verification-code-request.dto';
export { VerifyEmailVerificationCodeResponseDto as VerifyEmailVerificationCodeResponse } from './verifyEmailVerificationCode/verify-email-verification-code-response.dto';
export { SignupRequestDto as SignupRequest } from './signup/signup-request.dto';
export { SignupResponseDto as SignupResponse } from './signup/signup-response.dto';
export { LoginRequestDto as LoginRequest } from './login/login-request.dto';
export { LoginResponseDto as LoginResponse } from './login/login-response.dto'
export { RefreshAccessTokenResponseDto as RefreshAccessTokenResponse } from './refreshAccessToken/refresh-access-token-response.dto';
export { SendResetPasswordCodeRequestDto as SendResetPasswordCodeRequest } from './sendResetPasswordCode/send-reset-password-code-request.dto';
export { SendResetPasswordCodeResponseDto as SendResetPasswordCodeResponse } from './sendResetPasswordCode/send-reset-password-code-response.dto';
export { VerifyResetPasswordCodeRequestDto as VerifyResetPasswordCodeRequest } from './verifyResetPasswordCode/verify-reset-password-code-request.dto';
export { VerifyResetPasswordCodeResponseDto as VerifyResetPasswordCodeResponse } from './verifyResetPasswordCode/verify-reset-password-code-response.dto'
export { ResetPasswordRequestDto as ResetPasswordRequest } from './resetPassword/reset-password-request.dto';
export { ResetPasswordResponseDto as ResetPasswordResponse } from './resetPassword/reset-password-response.dto';

View File

@@ -0,0 +1,11 @@
import { IsString } from "@nestjs/class-validator";
export class LoginRequestDto {
type: 'email' | 'accountId';
@IsString()
id: string;
@IsString()
password: string;
}

View File

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

View File

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

View File

@@ -0,0 +1,9 @@
import { IsEmail, IsString } from "@nestjs/class-validator";
export class ResetPasswordRequestDto {
@IsEmail()
email: string;
@IsString()
password: string;
}

View File

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

View File

@@ -0,0 +1,6 @@
import { IsEmail } from "@nestjs/class-validator";
export class SendEmailVerificationCodeRequestDto {
@IsEmail()
email: string;
}

View File

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

View File

@@ -0,0 +1,6 @@
import { IsEmail } from "@nestjs/class-validator";
export class SendResetPasswordCodeRequestDto {
@IsEmail()
email: string;
}

View File

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

View File

@@ -0,0 +1,18 @@
import { IsEmail, IsString } from "@nestjs/class-validator";
export class SignupRequestDto {
@IsEmail()
email: string;
@IsString()
name: string;
@IsString()
nickname: string;
@IsString()
accountId: string;
@IsString()
password: string;
}

View File

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

View File

@@ -0,0 +1,9 @@
import { IsEmail, IsString } from "@nestjs/class-validator";
export class VerifyEmailVerificationCodeRequestDto {
@IsEmail()
email: string;
@IsString()
code: string;
}

View File

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

View File

@@ -0,0 +1,9 @@
import { IsEmail, IsString } from "@nestjs/class-validator"
export class VerifyResetPasswordCodeRequestDto {
@IsEmail()
email: string;
@IsString()
code: string;
}

View File

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

View File

@@ -0,0 +1,33 @@
import { IsArray, IsDateString, IsString } from '@nestjs/class-validator';
export class CreateRequestDto {
@IsString()
name: string;
@IsDateString()
startDate: string;
@IsDateString()
endDate: string;
@IsString()
content: string;
@IsString()
type: string;
@IsString()
style: string;
@IsString()
startTime: string;
@IsString()
endTime: string;
@IsString()
dayList: string;
@IsArray()
participantList: 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

@@ -0,0 +1,109 @@
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 { 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.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(schedule)
.where(
and(
eq(schedule.id, id),
eq(schedule.isDeleted, false)
)
);
return result;
}
async create(
accountId: string,
name: string,
startDate: Date,
endDate: Date,
startTime: string,
endTime: string,
style: string,
content: string,
type: string
) {
return await this
.db
.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

@@ -1,4 +1,5 @@
import { Global, Module } from "@nestjs/common"; import { Global, Inject, Module, OnApplicationShutdown } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";
import Redis from "ioredis"; import Redis from "ioredis";
@Global() @Global()
@@ -6,14 +7,21 @@ import Redis from "ioredis";
providers: [ providers: [
{ {
provide: "REDIS", provide: "REDIS",
useFactory: () => { useFactory: (configService: ConfigService): Redis => {
return new Redis({ return new Redis({
host: process.env.RD_HOST!, host: configService.get<string>('RD_HOST')!,
port: Number(process.env.RD_PORT || 6779) port: configService.get<number>('RD_PORT')
}); });
} },
inject: [ConfigService]
}, },
], ],
exports: ["REDIS"] exports: ["REDIS"]
}) })
export class RedisModule{} export class RedisModule implements OnApplicationShutdown {
constructor(@Inject("REDIS") private readonly redis: Redis) {}
async onApplicationShutdown(signal?: string) {
await this.redis.quit();
}
}

20
src/util/converter.ts Normal file
View File

@@ -0,0 +1,20 @@
import bcrypt from 'bcrypt';
export class Converter {
static getHashedPassword(password: string) {
return bcrypt.hashSync(password, 10);
}
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}`;
}
}

37
src/util/generator.ts Normal file
View File

@@ -0,0 +1,37 @@
export class Generator {
static getVerificationCode() {
return Math.random().toString().slice(2, 8);
}
private static getRandomCharacter(string: string) {
return string[Math.floor(Math.random() * string.length)];
}
private static getShuffledString(string: string) {
let arr = string.split('');
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
return arr.join('');
}
static getResetPasswordCode() {
const alphabets = 'abcdefghijklmnopqrstuvwxyz';
const numbers = '0123456789';
const specials = '!@#$%^';
const all = alphabets + numbers + specials;
let resetPasswordCode = Generator.getRandomCharacter(alphabets);
let requiredNumber = Generator.getRandomCharacter(numbers);
let requiredSpecial = Generator.getRandomCharacter(specials);
let shuffledRestPart = Generator.getShuffledString(all).slice(0, 5);
let shuffledRestCode = Generator.getShuffledString(requiredNumber + requiredSpecial + shuffledRestPart);
return resetPasswordCode + shuffledRestCode;
}
}

View File

@@ -0,0 +1,9 @@
import { Module, Global } from '@nestjs/common';
import { MailerService } from './mailer.service';
@Global()
@Module({
providers: [MailerService],
exports: [MailerService]
})
export class MailerModule {}

View File

@@ -0,0 +1,57 @@
import { Injectable } from '@nestjs/common';
import nodemailer from 'nodemailer';
import { google } from 'googleapis';
import { OAuth2Client } from 'google-auth-library';
import SMTPTransport from 'nodemailer/lib/smtp-transport';
import { ConfigService } from '@nestjs/config';
@Injectable()
export class MailerService {
private oauth2Client: OAuth2Client;
private readonly gmailUser: string;
constructor(private readonly configService: ConfigService) {
const clientId = this.configService.get<string>('GMAIL_CLIENT_ID');
const clientSecret = this.configService.get<string>('GMAIL_CLIENT_SECRET');
const refreshToken = this.configService.get<string>('GMAIL_REFRESH_TOKEN');
this.gmailUser = this.configService.get<string>('GMAIL_USER')!;
this.oauth2Client = new google.auth.OAuth2(
clientId,
clientSecret,
'https://developers.google.com/oauthplayground'
);
this.oauth2Client.setCredentials({
refresh_token: refreshToken,
});
}
async sendMail(to: string, subject: string, html: string) {
const accessToken = await this.oauth2Client.getAccessToken();
const options: SMTPTransport.Options = {
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
type: "OAuth2",
user: this.gmailUser,
clientId: this.configService.get<string>('GMAIL_CLIENT_ID'),
clientSecret: this.configService.get<string>('GMAIL_CLIENT_SECRET'),
refreshToken: this.configService.get<string>('GMAIL_REFRESH_TOKEN'),
accessToken: accessToken?.token || '',
}
}
const transporter = nodemailer.createTransport(options);
return transporter.sendMail({
from: `Scheduler ${this.gmailUser}>`,
to,
subject,
html
})
}
}

View File

@@ -1,4 +1,12 @@
{ {
"compilerOptions": {
"noEmitOnError": true,
"sourceMap": false,
"incremental": false,
"noEmit": false,
"tsBuildInfoFile": ".tsbuildinfo",
"outDir": "./dist"
},
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"] "exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
} }

View File

@@ -14,12 +14,13 @@
"sourceMap": true, "sourceMap": true,
"outDir": "./dist", "outDir": "./dist",
"baseUrl": "./", "baseUrl": "./",
"incremental": true, "incremental": false,
"skipLibCheck": true, "skipLibCheck": true,
"strictNullChecks": true, "strictNullChecks": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"noImplicitAny": false, "noImplicitAny": false,
"strictBindCallApply": false, "strictBindCallApply": false,
"noFallthroughCasesInSwitch": false "noFallthroughCasesInSwitch": false,
"noEmit": false
} }
} }

11420
yarn.lock Normal file

File diff suppressed because it is too large Load Diff