Skip to content

Commit

Permalink
๐Ÿš€ ํ‹ฐ์ผ“, ์ฑ„ํŒ…๋ชจ๋“ˆ ๋ฐฐํฌ
Browse files Browse the repository at this point in the history
ํ‹ฐ์ผ“, ์ฑ„ํŒ…๋ชจ๋“ˆ ๋ฐฐํฌ
  • Loading branch information
ImNM authored Jul 25, 2022
2 parents 03c5e8b + c7fc168 commit 7463455
Show file tree
Hide file tree
Showing 38 changed files with 1,180 additions and 376 deletions.
150 changes: 77 additions & 73 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"@types/jest": "27.4.1",
"@types/jsonwebtoken": "^8.5.8",
"@types/node": "^16.0.0",
"@types/socket.io": "^3.0.2",
"@types/supertest": "^2.0.11",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.0.0",
Expand Down
47 changes: 18 additions & 29 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,10 @@ import { DatabaseModule } from './database/database.module';
import { UsersModule } from './users/users.module';
import { SmsModule } from './sms/sms.module';
import { ThrottlerModule } from '@nestjs/throttler';
import { CustomConfigModule } from './config/customConfig.module';

@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
validationSchema: Joi.object({
NODE_ENV: Joi.string()
.valid('dev', 'prod', 'test', 'provision')
.default('dev'),
PORT: Joi.number().default(8080),
ACCESS_SECRET: Joi.string(),
REGISTER_SECRET: Joi.string(),
SWAGGER_USER: Joi.string(),
SWAGGER_PASSWORD: Joi.string(),
REDIS_HOST: Joi.string(),
REDIS_PORT: Joi.number(),
POSTGRES_HOST: Joi.string().default('localhost'),
POSTGRES_PORT: Joi.number().default(5432),
POSTGRES_USER: Joi.string().default('gosrock'),
POSTGRES_PASSWORD: Joi.string().default('gosrock22th'),
POSTGRES_DB: Joi.string().default('ticket'),
SLACK_ORDER_CHANNELID: Joi.string(),
SLACK_ADMIN_CHANNELID: Joi.string(),
SLACK_BOT_TOKEN: Joi.string(),
SLACK_BACKEND_CHANNELID: Joi.string(),
NAVER_SERVICE_ID: Joi.string(),
NAVER_ACCESS_KEY: Joi.string(),
NAVER_SECRET_KEY: Joi.string(),
NAVER_CALLER: Joi.string()
})
}),
BullModule.forRootAsync({
imports: [ConfigModule],

Expand Down Expand Up @@ -74,14 +47,30 @@ import { ThrottlerModule } from '@nestjs/throttler';
ThrottlerModule.forRoot({
ttl: process.env.NODE_ENV === 'prod' ? 300 : 60,
limit: 3
}),
CustomConfigModule,
RedisModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
isTest: false,
logging: false,
redisConnectOption: {
url:
'redis://' +
configService.get('REDIS_HOST') +
':' +
configService.get('REDIS_PORT')
}
}),
inject: [ConfigService]
})
],

providers: [
{
provide: APP_FILTER,
useClass: AllExceptionsFilter
}
},
]
})
export class AppModule {}
20 changes: 3 additions & 17 deletions src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject, Logger, Module } from '@nestjs/common';
import { Global, Inject, Logger, Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from 'src/database/entities/user.entity';
Expand All @@ -13,6 +13,7 @@ import { AuthService } from './auth.service';
import { AccessTokenGuard } from './guards/AccessToken.guard';
import { RegisterTokenGuard } from './guards/RegisterToken.guard';

@Global()
@Module({
imports: [
SmsModule.forRootAsync({
Expand All @@ -23,22 +24,7 @@ import { RegisterTokenGuard } from './guards/RegisterToken.guard';
inject: [ConfigService]
}),
UsersModule,
TypeOrmModule.forFeature([User]),
RedisModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
isTest: false,
logging: false,
redisConnectOption: {
url:
'redis://' +
configService.get('REDIS_HOST') +
':' +
configService.get('REDIS_PORT')
}
}),
inject: [ConfigService]
})
TypeOrmModule.forFeature([User])
],
controllers: [AuthController],
providers: [
Expand Down
35 changes: 8 additions & 27 deletions src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { DataSource } from 'typeorm';
import { AuthService } from './auth.service';
import * as Joi from 'joi';
import { SlackModule } from 'src/slack/slack.module';
import { SmsFakeService } from 'src/sms/smsFake.service';
import { SmsService } from 'src/sms/sms.service';
import { CustomConfigModule } from 'src/config/customConfig.module';

export const repositoryMockFactory: () => MockType<UserRepository> = jest.fn(
() => ({
Expand All @@ -27,33 +30,7 @@ describe('AuthService', () => {

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
isGlobal: true,
// envFilePath: process.env.NODE_ENV === 'test' ? '.env.local' : '.env',
validationSchema: Joi.object({
NODE_ENV: Joi.string()
.valid('dev', 'prod', 'test', 'provision')
.default('dev'),
PORT: Joi.number().default(8080),
ACCESS_SECRET: Joi.string(),
REGISTER_SECRET: Joi.string(),
SWAGGER_USER: Joi.string(),
SWAGGER_PASSWORD: Joi.string(),
REDIS_HOST: Joi.string(),
REDIS_PORT: Joi.number(),
POSTGRES_HOST: Joi.string().default('localhost'),
POSTGRES_PORT: Joi.number().default(5432),
POSTGRES_USER: Joi.string().default('gosrock'),
POSTGRES_PASSWORD: Joi.string().default('gosrock22th'),
POSTGRES_DB: Joi.string().default('ticket'),
SLACK_ORDER_CHANNELID: Joi.string(),
SLACK_ADMIN_CHANNELID: Joi.string()
})
}),
SlackModule
],
// imports: [TypeOrmModule.forFeature([User])],
imports: [CustomConfigModule, SlackModule],
providers: [
AuthService,
{
Expand All @@ -67,6 +44,10 @@ describe('AuthService', () => {
{
provide: RedisService,
useClass: RedisTestService
},
{
provide: SmsService,
useClass: SmsFakeService
}
]
}).compile();
Expand Down
11 changes: 7 additions & 4 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { RequestAdminLoginDto } from './dtos/AdminLogin.request.dto';
import { ResponseAdminLoginDto } from './dtos/AdminLogin.response.dto';
import { SmsService } from 'src/sms/sms.service';
import { MessageDto } from 'src/sms/dtos/message.dto';
import { SlackValidationNumberDMDto } from 'src/slack/dtos/SlackValidationNumberDM.dto';

@Injectable()
export class AuthService {
Expand All @@ -47,7 +48,7 @@ export class AuthService {
async requestPhoneValidationNumber(
requestPhoneNumberDto: RequestPhoneNumberDto
): Promise<ResponseRequestValidationDto> {
let test;
console.log(this.dataSource);
//console.log(test.adf.asdf);
//TODO : ์ „ํ™”๋ฒˆํ˜ธ ์ธ์ฆ๋ฒˆํ˜ธ ๋ฐœ์†ก ๋กœ์ง ์ถ”๊ฐ€ , ์ด์ฐฌ์ง„ 2022.07.14
const userPhoneNumber = requestPhoneNumberDto.phoneNumber;
Expand Down Expand Up @@ -173,8 +174,8 @@ export class AuthService {
} catch (e) {
// ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ๋กค๋ฐฑ
await queryRunner.rollbackTransaction();
this.logger.error(e);
throw new InternalServerErrorException('์„œ๋ฒ„์—๋Ÿฌ');

throw e;
} finally {
// ์ง์ ‘ ์ƒ์„ฑํ•œ QueryRunner๋Š” ํ•ด์ œ์‹œ์ผœ ์ฃผ์–ด์•ผ ํ•จ
await queryRunner.release();
Expand Down Expand Up @@ -211,7 +212,9 @@ export class AuthService {
randomCode,
180
);
await this.slackService.sendDMwithValidationNumber(slaceUserId, randomCode);
await this.slackService.sendDMwithValidationNumber(
new SlackValidationNumberDMDto(slaceUserId, randomCode)
);

return { validationNumber: randomCode };
}
Expand Down
33 changes: 33 additions & 0 deletions src/common/decorators/ApiPaginatedDto.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { applyDecorators, Type } from '@nestjs/common';
import { ApiExtraModels, ApiOkResponse, getSchemaPath } from '@nestjs/swagger';
import { PageDto } from '../dtos/page/page.dto';

/**
* ์ œ๋„ค๋ฆญ์„ ํ™œ์šฉํ•œ swagger ์‘๋‹ต์„ ์ฃผ๊ธฐ์œ„ํ•œ ์šฉ๋„์ž…๋‹ˆ๋‹ค.
* @param props model : ์›๋ž˜ ์‘๋‹ตํ•  data์˜ ํƒ€์ž… , description ์‘๋‹ต ์„ค๋ช…
* @returns
*/
export const ApiPaginatedDto = <TModel extends Type<any>>(props: {
model: TModel;
description?: string;
}) => {
return applyDecorators(
ApiExtraModels(PageDto, props.model),
ApiOkResponse({
description: props.description,
schema: {
allOf: [
{ $ref: getSchemaPath(PageDto) },
{
properties: {
data: {
type: 'array',
items: { $ref: getSchemaPath(props.model) }
}
}
}
]
}
})
);
};
50 changes: 30 additions & 20 deletions src/common/dtos/user-profile.dto.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import { PickType, PartialType } from '@nestjs/swagger';
import { plainToInstance } from 'class-transformer';
import { PickType, PartialType, ApiProperty } from '@nestjs/swagger';
import { Expose, plainToInstance } from 'class-transformer';
import { User } from 'src/database/entities/user.entity';
import { Role } from '../consts/enum';

export class UserProfileDto extends PickType(PartialType(User), [
'name',
'phoneNumber',
'role',
'createdAt'
] as const) {
constructor(user: User) {
super();
this.name = user.name;
this.phoneNumber = user.phoneNumber;
this.role = user.role;
this.createdAt = user.createdAt;
}
export class UserProfileDto {
@ApiProperty({
description: '์œ ์ €์˜ ๊ณ ์œ  ์•„์ด๋””์ž…๋‹ˆ๋‹ค.',
type: Number
})
@Expose()
public id: number;

static convertFrom(user: User): UserProfileDto {
return plainToInstance(UserProfileDto, user, {
excludeExtraneousValues: true
});
}
@ApiProperty({
description: '์œ ์ €์˜ ์ž…๊ธˆ์ž๋ช…์ž…๋‹ˆ๋‹ค.',
type: String
})
@Expose()
public name: string;

@ApiProperty({
description: '์œ ์ €์˜ ํœด๋Œ€์ „ํ™”๋ฒˆํ˜ธ ์ž…๋‹ˆ๋‹ค.',
type: String
})
@Expose()
public phoneNumber: string;

@ApiProperty({
description: '์œ ์ €์˜ ๊ถŒํ•œ์ž…๋‹ˆ๋‹ค.',
enum: Role
})
@Expose()
public role: Role;
}
38 changes: 38 additions & 0 deletions src/config/customConfig.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Global, Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import * as Joi from 'joi';

@Global()
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
validationSchema: Joi.object({
NODE_ENV: Joi.string()
.valid('dev', 'prod', 'test', 'provision')
.default('dev'),
PORT: Joi.number().default(8080),
ACCESS_SECRET: Joi.string(),
REGISTER_SECRET: Joi.string(),
SWAGGER_USER: Joi.string(),
SWAGGER_PASSWORD: Joi.string(),
REDIS_HOST: Joi.string(),
REDIS_PORT: Joi.number(),
POSTGRES_HOST: Joi.string().default('localhost'),
POSTGRES_PORT: Joi.number().default(5432),
POSTGRES_USER: Joi.string().default('gosrock'),
POSTGRES_PASSWORD: Joi.string().default('gosrock22th'),
POSTGRES_DB: Joi.string().default('ticket'),
SLACK_ORDER_CHANNELID: Joi.string(),
SLACK_ADMIN_CHANNELID: Joi.string(),
SLACK_BOT_TOKEN: Joi.string(),
SLACK_BACKEND_CHANNELID: Joi.string(),
NAVER_SERVICE_ID: Joi.string(),
NAVER_ACCESS_KEY: Joi.string(),
NAVER_SECRET_KEY: Joi.string(),
NAVER_CALLER: Joi.string()
})
})
]
})
export class CustomConfigModule {}
9 changes: 6 additions & 3 deletions src/database/entities/order.entity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ApiProperty } from '@nestjs/swagger';
import { Expose, Transform } from 'class-transformer';
import { Expose, Transform, Type } from 'class-transformer';
import { MaxLength } from 'class-validator';
import { OrderStatus, OrderDate } from 'src/common/consts/enum';
import { UserProfileDto } from 'src/common/dtos/user-profile.dto';
import {
Column,
CreateDateColumn,
Expand Down Expand Up @@ -76,17 +77,19 @@ export class Order {

@ApiProperty({
description: '์ฃผ๋ฌธ์„ ์ง„ํ–‰ํ•œ ์œ ์ €์˜ ์™ธ๋ž˜ํ‚ค',
type: () => User
type: () => UserProfileDto
})
@Type(() => UserProfileDto)
@Expose()
@ManyToOne(type => User, user => user.order, { eager: false })
public user: User;

@ApiProperty({
description: '์ฃผ๋ฌธ์„ ์ฒ˜๋ฆฌํ•œ ์–ด๋“œ๋ฏผ์— ๋Œ€ํ•œ ์™ธ๋ž˜ํ‚ค์ž…๋‹ˆ๋‹ค.',
type: () => User,
type: () => UserProfileDto,
nullable: true
})
@Type(() => UserProfileDto)
@Expose()
@ManyToOne(type => User)
public admin: User;
Expand Down
Loading

0 comments on commit 7463455

Please sign in to comment.