-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/60-verification-code-seeder' into develop
# Conflicts: # src/database/factories/member.factory.ts # src/database/factories/refresh-token.factory.ts
- Loading branch information
Showing
9 changed files
with
158 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { setSeederFactory } from "typeorm-extension"; | ||
|
||
import { CategoryEntity } from "@APP/entities/category.entity"; | ||
|
||
export default setSeederFactory(CategoryEntity, async () => { | ||
const category = new CategoryEntity(); | ||
|
||
return category; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as bcrypt from "bcrypt"; | ||
import { setSeederFactory } from "typeorm-extension"; | ||
|
||
import { MemberEntity } from "../../entities/member.entity"; | ||
|
||
export default setSeederFactory(MemberEntity, async (faker) => { | ||
const hashedPassword = await bcrypt.hash("123456", 10); | ||
|
||
const member = new MemberEntity(); | ||
member.name = faker.person.firstName(); | ||
member.nickname = faker.person.lastName(); | ||
member.email = faker.internet.email(); | ||
member.password = hashedPassword; | ||
member.isEmailVerified = true; | ||
member.profileImage = Math.random() > 0.5 ? faker.image.avatar() : null; | ||
|
||
return member; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as bcrypt from "bcrypt"; | ||
import jwt from "jsonwebtoken"; | ||
import { setSeederFactory } from "typeorm-extension"; | ||
|
||
import { ENV_JWT_SECRET_KEY } from "@APP/common/constants/env-keys.const"; | ||
import { RefreshTokenEntity } from "@APP/entities/refresh-token.entity"; | ||
|
||
export default setSeederFactory(RefreshTokenEntity, async () => { | ||
const payload = { | ||
email: "[email protected]", | ||
sub: 8, | ||
type: "refresh", | ||
}; | ||
|
||
const secret = process.env[ENV_JWT_SECRET_KEY] || "secret"; | ||
const expiresIn = "3600"; | ||
|
||
const refreshToken = new RefreshTokenEntity(); | ||
|
||
const token = jwt.sign(payload, secret, { expiresIn }); | ||
refreshToken.token = await bcrypt.hash(token, 10); | ||
|
||
return refreshToken; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as crypto from "crypto"; | ||
import { setSeederFactory } from "typeorm-extension"; | ||
|
||
import { VerificationCodeEntity } from "@APP/entities/verification-code.entity"; | ||
|
||
export default setSeederFactory(VerificationCodeEntity, () => { | ||
const verificationCode = crypto | ||
.randomBytes(3) | ||
.toString("hex") | ||
.toUpperCase(); | ||
|
||
const verificationCodeEntity = new VerificationCodeEntity(); | ||
verificationCodeEntity.code = verificationCode; | ||
|
||
return verificationCodeEntity; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { DataSource } from "typeorm"; | ||
import { Seeder, SeederFactoryManager } from "typeorm-extension"; | ||
|
||
import { CategoryEntity } from "@APP/entities/category.entity"; | ||
|
||
const CATEGORY_NAMES = [ | ||
"치킨", | ||
"고기", | ||
"한식", | ||
"중식", | ||
"일식", | ||
"양식", | ||
"족발,보쌈", | ||
"찜,탕,찌개", | ||
"피자", | ||
"아시안", | ||
"도시락", | ||
"분식", | ||
"카페,디저트", | ||
"패스트푸드", | ||
"야식", | ||
"기타", | ||
]; | ||
|
||
export default class CategorySeeder implements Seeder { | ||
public async run( | ||
_dataSource: DataSource, | ||
factoryManager: SeederFactoryManager, | ||
): Promise<void> { | ||
const categoryFactory = factoryManager.get(CategoryEntity); | ||
|
||
await Promise.all( | ||
CATEGORY_NAMES.map((name) => categoryFactory.save({ name })), | ||
); | ||
|
||
console.log(`카테고리 생성 완료`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { DataSource } from "typeorm"; | ||
import { Seeder, SeederFactoryManager } from "typeorm-extension"; | ||
|
||
import { RefreshTokenEntity } from "@APP/entities/refresh-token.entity"; | ||
|
||
export default class RefreshTokenSeeder implements Seeder { | ||
public async run( | ||
_dataSource: DataSource, | ||
factoryManager: SeederFactoryManager, | ||
): Promise<void> { | ||
const refreshTokenFactory = factoryManager.get(RefreshTokenEntity); | ||
|
||
await refreshTokenFactory.save(); | ||
|
||
console.log(`리프레시토큰 생성 완료`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { DataSource } from "typeorm"; | ||
import { Seeder, SeederFactoryManager } from "typeorm-extension"; | ||
|
||
import { VerificationCodeEntity } from "@APP/entities/verification-code.entity"; | ||
|
||
export default class VerificationCodeSeeder implements Seeder { | ||
public async run( | ||
_dataSource: DataSource, | ||
factoryManager: SeederFactoryManager, | ||
): Promise<void> { | ||
const verificationCodeFactory = factoryManager.get( | ||
VerificationCodeEntity, | ||
); | ||
|
||
await verificationCodeFactory.save(); | ||
|
||
console.log(`인증코드 생성 완료`); | ||
} | ||
} |