Compare commits

...

35 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
63 changed files with 2987 additions and 191 deletions

View File

@@ -1,6 +1,3 @@
# Nestjs 서버 포트
PORT=3000
# Gmail SMTP 설정
GMAIL_USER=bkd.scheduler@gmail.com
GMAIL_PASS= # 앱 비밀번호 또는 OAuth2 토큰
@@ -13,3 +10,5 @@ SMTP_AUTH=true
SMTP_STARTTLS_ENABLE=true
SMTP_STARTTLS_REQUIRED=true
SMTP_AUTH_MECHANISMS=XOAUTH2
JWT_SECRET=96612b08364bbd9f275f29f86d39c18225e3cb3f31551434d5a84a88f5b01e627b5aafac902e0769bda4f1574b2f84ffb26e659b1a672182015a180c086cb911

View File

@@ -1,3 +1,5 @@
PORT=8088
# PostgreSQL 설정
PGHOST=bkdhome.p-e.kr
PGPORT=15454
@@ -8,5 +10,5 @@ PG_DATABASE_URL=postgres://baekyangdan:qwas745478!@bkdhome.p-e.kr:15454/schedule
# Redis 설정
RD_HOST=bkdhome.p-e.kr
RD_PORT=6779
RD_PORT=16779
RD_URL=redis://bkdhome.p-e.kr:16779

View File

@@ -1,12 +1,12 @@
HOST=0.0.0.0
PORT=3000
# PostgreSQL 설정
PGHOST=bkdhome.p-e.kr
PGPORT=15454
PGDATABASE=scheduler
PGUSER=baekyangdan
PGPASSWORD=qwas745478!
PG_DATABASE_URL=postgres://192.168.219.107:5454/scheduler
PG_DATABASE_URL=postgres://192.168.219.103:5454/scheduler
# Redis 설정
RD_HOST=bkdhome.p-e.kr
RD_HOST=192.168.219.103
RD_PORT=6779
RD_URL=redis://192.168.219.107:6779
RD_URL=redis://192.168.219.103:6779

View File

@@ -1,12 +1,14 @@
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

@@ -6,7 +6,7 @@ on:
jobs:
build:
runs-on: runner
runs-on: rpi5
env:
DOCKER_VOLUME: ${{ vars.DOCKER_VOLUME }}
@@ -17,21 +17,37 @@ jobs:
- name: Check PWD
run: |
echo $DOCKER_VOLUME
echo $PWD
ls .
echo "Docker volume: $DOCKER_VOLUME"
echo "PWD: $PWD"
ls -lRa ./.yarn
- name: Restore node_modules
id: cache-node
- 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: node_modules
key: ${{ runner.os }}-yarn-v1-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-v1-
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
if: steps.cache-node.outputs.cache-hit != 'true'
run: |
yarn install --immutable
ls .
@@ -45,9 +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
- name: Clean project
run: |
rm -rf node_modules
rm -rf dist
# docker exec -it scheduler_back pm2 reload scheduler-back

1
.gitignore vendored
View File

@@ -12,7 +12,6 @@ package-lock.json
!.yarn/releases
!.yarn/sdks
!.yarn/versions
.pnp.*
# .pnp.loader.mjs
# .yarn/install-state.gz

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

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 dotenv from 'dotenv';
dotenv.config();
dotenv.config({ path: `.env.${process.env.NODE_ENV}` });
export default defineConfig({
dialect: "postgresql",
@@ -9,5 +9,13 @@ export default defineConfig({
out: "./drizzle",
dbCredentials: {
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}) => ({
comments: many(comment),
schedules: many(schedule),
participants: many(participant),
schedules: many(schedule),
favorites: many(favorite),
follows_follower: many(follow, {
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}) => ({
schedule: one(schedule, {
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}) => ({
schedule: one(schedule, {
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"
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", {
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"),
@@ -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('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(),
@@ -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", {
isDeleted: boolean("is_deleted").default(false),
createdAt: date("created_at"),
@@ -102,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

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

View File

@@ -6,34 +6,49 @@
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "NODE_ENV=prod 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\"",
"start": "nest start",
"start:local": "NODE_ENV=local nest start --watch",
"start:dev": "NODE_ENV=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:prod": "NODE_ENV=prod node dist/main",
"start:prod": "cross-env NODE_ENV=prod node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"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": {
"@baekyangdan/core-utils": "^1.0.23",
"@fastify/cookie": "^11.0.2",
"@nestjs/class-transformer": "^0.4.0",
"@nestjs/class-validator": "^0.13.4",
"@nestjs/common": "^11.0.1",
"@nestjs/config": "^4.0.2",
"@nestjs/core": "^11.0.1",
"@nestjs/jwt": "^11.0.1",
"@nestjs/passport": "^11.0.5",
"@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",
"fastify": "^5.6.2",
"fastify-cors": "^6.1.0",
"googleapis": "^166.0.0",
"ioredis": "^5.8.2",
"nodemailer": "^7.0.10",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
"pg": "^8.16.3",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1"
@@ -50,8 +65,12 @@
"@types/jest": "^30.0.0",
"@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/supertest": "^6.0.2",
"cross-env": "^10.1.0",
"dotenv-cli": "^11.0.0",
"eslint": "^9.18.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-prettier": "^5.2.2",

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

@@ -3,6 +3,6 @@ import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
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

@@ -1,4 +1,4 @@
export class SendVerificationCodeResponseDto {
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

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

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,18 +1,46 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import dotenv from 'dotenv';
dotenv.config();
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() {
const app = await NestFactory.create(AppModule);
const isProd = process.env.NODE_ENV === 'prod';
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", "https://scheduler.bkdhome.p-e.kr"];
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);
}
@@ -24,8 +52,11 @@ async function bootstrap() {
});
app.enableShutdownHooks();
await app.listen(process.env.PORT ?? 3000);
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();

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,43 +1,101 @@
import { Body, Controller, Get, Post, Query } from "@nestjs/common";
import { Body, Controller, Get, Headers, Post, Query, Req, Res, UseGuards } from "@nestjs/common";
import { AccountService } from "./account.service";
import {
CheckDuplicationRequest, CheckDuplicationResponse,
SendVerificationCodeRequest, SendVerificationCodeResponse,
VerifyCodeRequest, VerifyCodeResponse,
LoginRequest, LoginResponse,
SignupRequest, SignupResponse
} 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';
@Controller('account')
const AccountApi = HttpApiUrl.Account;
@UseGuards(JwtAccessAuthGuard)
@Controller(AccountApi.base)
export class AccountController {
constructor(private readonly accountService: AccountService) {}
@Get('/')
@Get(AccountApi.root)
async test() {
return "Test"
}
@Get('check-duplication')
async checkDuplication(@Query() query: CheckDuplicationRequest): Promise<CheckDuplicationResponse> {
@Public()
@Get(AccountApi.checkDuplication)
async checkDuplication(@Query() query: DTO.CheckDuplicationRequest): Promise<DTO.CheckDuplicationResponse> {
return await this.accountService.checkDuplication(query);
}
@Post('send-verification-code')
async sendVerificationCode(@Body() body: SendVerificationCodeRequest): Promise<SendVerificationCodeResponse> {
@Public()
@Post(AccountApi.sendEmailVerificationCode)
async sendEmailVerificationCode(@Body() body: DTO.SendEmailVerificationCodeRequest): Promise<DTO.SendEmailVerificationCodeResponse> {
const result = await this.accountService.sendVerificationCode(body);
return result;
}
@Post('verify-code')
async verifyCode(@Body() body: VerifyCodeRequest): Promise<VerifyCodeResponse> {
console.log(body.email);
@Public()
@Post(AccountApi.verifyEmailVerificationCode)
async verifyEmailVerificationCode(@Body() body: DTO.VerifyEmailVerificationCodeRequest): Promise<DTO.VerifyEmailVerificationCodeResponse> {
const result = await this.accountService.verifyCode(body);
return result;
}
@Post('signup')
async signup(@Body() body: SignupRequest): Promise<LoginResponse> {
@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,11 +1,12 @@
import { Module } from "@nestjs/common";
import { forwardRef, Module } from "@nestjs/common";
import { AccountController } from "./account.controller";
import { AccountRepo } from "./account.repo";
import { AccountService } from "./account.service";
import { AuthModule } from 'src/middleware/auth/auth.module';
@Module({
imports: [forwardRef(() => AuthModule)],
controllers: [AccountController],
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 * 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";
@Injectable()
export class AccountRepo {
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
.db
.select({ count: countDistinct(schema.account[type])})
@@ -26,7 +26,7 @@ export class AccountRepo {
email: string,
password: string
) {
return this
return await this
.db
.insert(schema.account)
.values({
@@ -38,5 +38,48 @@ export class AccountRepo {
});
}
async
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,55 +1,57 @@
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";
import { Converter } from "src/util/converter";
import { AuthService } from "src/middleware/auth/auth.service";
@Injectable()
export class AccountService {
constructor(
private readonly accountRepo: AccountRepo
, private readonly mailerService: MailerService
, private readonly authService: AuthService
, @Inject("REDIS") private readonly redis: Redis
) {}
async checkDuplication(data: DTO.CheckDuplicationRequest): Promise<DTO.CheckDuplicationResponse> {
const { type, value } = data;
const count = await this.accountRepo.checkDuplication(type, value);
const count = await this.accountRepo.checkIdExists(type, value);
return { isDuplicated: count > 0 };
return { success: true, message: '중복 체크 완료', data: { isDuplicated: count > 0 }};
}
async sendVerificationCode(data: DTO.SendVerificationCodeRequest): Promise<DTO.SendVerificationCodeResponse> {
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 }
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: {} };
}
}
async verifyCode(data: DTO.VerifyCodeRequest): Promise<DTO.VerifyCodeResponse> {
async verifyCode(data: DTO.VerifyEmailVerificationCodeRequest): Promise<DTO.VerifyEmailVerificationCodeResponse> {
const { email, code } = data;
const storedCode = await this.redis.get(`verify:${email}`);
if (!storedCode) {
return { verified: false, error: '잘못된 이메일이거나 코드가 만료되었습니다.'};
return { success: false, error: '잘못된 이메일이거나 코드가 만료되었습니다.', code: ''};
}
if (storedCode !== code) {
return { verified: false, error: "잘못된 코드입니다." };
return { success: true, message: "잘못된 코드입니다.", data: { verified: false } };
}
await this.redis.del(`verify:${email}`);
return { verified: true, message: "이메일 인증이 완료되었습니다." };
return { success: true, message: "이메일 인증이 완료되었습니다.", data: { verified: true } };
}
async signup(data: DTO.SignupRequest): Promise<DTO.SignupResponse> {
@@ -60,14 +62,154 @@ export class AccountService {
if (result.rowCount) {
return {
success: true,
message: "회원가입이 완료되었습니다."
message: "회원가입이 완료되었습니다.",
data: {}
};
} else {
return {
success: false,
error: "회원가입에 실패하였습니다."
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;
}

View File

@@ -1,14 +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 { SendVerificationCodeRequestDto as SendVerificationCodeRequest } from './sendVerification/send-verification-code-request.dto';
export { SendVerificationCodeResponseDto as SendVerificationCodeResponse } from './sendVerification/send-verification-code-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 { VerifyCodeRequestDto as VerifyCodeRequest } from './verifyCode/verify-code-request.dto';
export { VerifyCodeResponseDto as VerifyCodeResponse } from './verifyCode/verify-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 { 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

@@ -1,5 +1,6 @@
export class LoginResponseDto {
success: boolean;
message?: string;
error?: string;
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

@@ -1,6 +1,6 @@
import { IsEmail } from "@nestjs/class-validator";
export class SendVerificationCodeRequestDto {
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

@@ -1,5 +1,4 @@
export class SignupResponseDto {
success: boolean;
message?: string;
error?: string;
import { BaseResponseDto } from "../../../../common/dto/base-response.dto";
export class SignupResponseDto extends BaseResponseDto {
}

View File

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

View File

@@ -1,6 +1,6 @@
import { IsEmail, IsString } from "@nestjs/class-validator";
export class VerifyCodeRequestDto {
export class VerifyEmailVerificationCodeRequestDto {
@IsEmail()
email: 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

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

View File

@@ -2,4 +2,36 @@ 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

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

View File

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

1683
yarn.lock

File diff suppressed because it is too large Load Diff