Skip to content

Commit

Permalink
πŸš€feat(user) : 전체 μœ μ € 쑰회 νŽ˜μ΄μ§€λ„€μ΄μ…˜ κ΅¬ν˜„, μœ μ €λ³„ ν‹°μΌ“μˆ˜ 확인, ν‹°μΌ“μˆ˜ 포함 μœ μ € 응닡 dto 생성 #57
Browse files Browse the repository at this point in the history
  • Loading branch information
chaeshee0908 committed Jul 31, 2022
2 parents 51e2a4f + 3ba98ca commit 86e5a16
Show file tree
Hide file tree
Showing 103 changed files with 4,058 additions and 582 deletions.
419 changes: 345 additions & 74 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
"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",
"prepare": "husky install",
"lint-staged": "lint-staged"
"lint-staged": "lint-staged",
"typeorm": "ts-node ./node_modules/typeorm/cli",
"typeorm:run-migrations": "npm run typeorm migration:run -- -d ./src/database/migrations/typeOrm.config.ts",
"typeorm:generate-migration": "npm run typeorm -- -d ./src/database/migrations/typeOrm.config.ts migration:generate ./src/database/migrations/$npm_config_name",
"typeorm:create-migration": "npm run typeorm -- migration:create ./src/database/migrations/$npm_config_name",
"typeorm:revert-migration": "npm run typeorm -- -d ./src/database/migrations/typeOrm.config.ts migration:revert"
},
"dependencies": {
"@nestjs/axios": "^0.1.0",
Expand Down Expand Up @@ -58,6 +63,7 @@
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"save": "^2.5.0",
"swagger-ui-express": "^4.4.0",
"typeorm": "^0.3.7",
"uuid": "^8.3.2",
Expand All @@ -77,12 +83,13 @@
"@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",
"@typescript-eslint/parser": "^5.0.0",
"codecov": "^3.8.3",
"eslint": "^8.0.1",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^8.0.1",
Expand All @@ -93,7 +100,7 @@
"supertest": "^6.1.3",
"ts-jest": "^27.0.3",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"ts-node": "^10.9.1",
"tsconfig-paths": "^3.10.1",
"typescript": "^4.3.5"
},
Expand Down
67 changes: 67 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {
BadRequestException,
Controller,
ForbiddenException,
Get,
HttpStatus,
UnauthorizedException
} from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { ThrottlerException } from '@nestjs/throttler';
import { AuthErrorDefine } from './auth/Errors/AuthErrorDefine';

import { ErrorResponse } from './common/decorators/ErrorResponse.decorator';
import { CustomValidationError } from './common/errors/ValidtionError';
@Controller()
@ApiTags('common')
export class CommonController {
@ErrorResponse(HttpStatus.BAD_REQUEST, [
{
model: BadRequestException,
exampleDescription: '400번 BadRequestException',
exampleTitle: '400 번의 BadRequestException',
message: 'μ—λŸ¬λ©”μ‹œμ§€ ν˜•μ‹μ΄ μ˜΅λ‹ˆλ‹€.'
},
{
model: CustomValidationError,
exampleDescription: '400번 ValidationError',
exampleTitle: '400번 ValidationError',
message: {
'κ²€μ¦μ˜€λ₯˜κ°€λ‚œ ν•„λ“œ': ['μ–΄λ–€μ—λŸ¬', 'μ–΄λ–€μ—λŸ¬2'],
'κ²€μ¦μ˜€λ₯˜κ°€λ‚œ ν•„λ“œ2': ['μ–΄λ–€μ—λŸ¬3', 'μ–΄λ–€μ—λŸ¬4']
}
}
])
@ErrorResponse(HttpStatus.UNAUTHORIZED, [
AuthErrorDefine['Auth-1000'],
AuthErrorDefine['Auth-1001'],
AuthErrorDefine['Auth-1002'],
AuthErrorDefine['Auth-1003']
])
@ErrorResponse(HttpStatus.FORBIDDEN, [AuthErrorDefine['Auth-3000']])
@ErrorResponse(HttpStatus.TOO_MANY_REQUESTS, [AuthErrorDefine['Auth-9000']])
@ApiOperation({ summary: '곡톡 였λ₯˜μ— λŒ€ν•΄μ„œ μ •μ˜ ν•©λ‹ˆλ‹€.' })
@Get()
commen() {}
}
// {
// κ²€μ¦μ˜€λ₯˜: {
// value: makeInstanceByApiProperty(
// ErrorCommonResponse<ValidationErrorResponseDto>,
// ValidationErrorResponseDto
// ),
// description:
// 'λ¦¬ν„΄λœ registerToken을 Bearer <registerToken> ν˜•μ‹μœΌλ‘œ μ§‘μ–΄λ„£μœΌμ‹œλ©΄λ©λ‹ˆλ‹€.'
// },
// 'http 였λ₯˜': {
// value: makeInstanceByApiProperty(
// ErrorCommonResponse<HttpExceptionErrorResponseDto>,
// HttpExceptionErrorResponseDto
// ),
// description:
// 'λ¦¬ν„΄λœ registerToken을 Bearer <registerToken> ν˜•μ‹μœΌλ‘œ μ§‘μ–΄λ„£μœΌμ‹œλ©΄λ©λ‹ˆλ‹€.'
// }
// // '이미 νšŒμ›κ°€μž…ν•œ μœ μ €μΌλ•Œ': {
// // value: makeInstanceByApiProperty(LoginResponseDto)
// // }
// }
51 changes: 21 additions & 30 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,11 @@ 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';
import { CommonController } from './app.controller';

@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 All @@ -55,7 +29,7 @@ import { ThrottlerModule } from '@nestjs/throttler';
port: Number(configService.get('REDIS_PORT')),
retryStrategy: times => {
// check connection
console.log('could not connect to redis!');
//console.log('could not connect to redis!');
process.exit(1);
}
}
Expand All @@ -74,6 +48,22 @@ 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]
})
],

Expand All @@ -82,6 +72,7 @@ import { ThrottlerModule } from '@nestjs/throttler';
provide: APP_FILTER,
useClass: AllExceptionsFilter
}
]
],
controllers: [CommonController]
})
export class AppModule {}
136 changes: 136 additions & 0 deletions src/auth/Errors/AuthErrorDefine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import {
BadRequestException,
ForbiddenException,
InternalServerErrorException,
UnauthorizedException
} from '@nestjs/common';
import { ThrottlerException } from '@nestjs/throttler';
import { ErrorResponseOption } from 'src/common/decorators/ErrorResponse.decorator';
type Keys =
| 'Auth-1000'
| 'Auth-1001'
| 'Auth-1002'
| 'Auth-1003'
| 'Auth-3000'
| 'Auth-9000'
| 'Auth-5000'
| 'Auth-0000'
| 'Auth-0001'
| 'Auth-0002'
| 'Auth-0003'
| 'Auth-0004'
| 'Auth-0005';

export const AuthErrorDefine: Record<
Keys,
ErrorResponseOption & { code: string }
> = {
//400
'Auth-0000': {
model: BadRequestException,
exampleDescription: '3λΆ„μ§œλ¦¬ 인증번호 κΈ°ν•œλ§Œλ£Œμ‹œμ— λ°œμƒν•˜λŠ” 였λ₯˜',
exampleTitle: '인증번호-κΈ°ν•œλ§Œλ£Œ',
message: 'μΈμ¦λ²ˆν˜Έκ°€ κΈ°ν•œλ§Œλ£Œ λ˜μ—ˆμŠ΅λ‹ˆλ‹€.',
code: 'Auth-0000'
},
'Auth-0001': {
model: BadRequestException,
exampleDescription: 'μΈμ¦λ²ˆν˜Έκ°€ μΌμΉ˜ν•˜μ§€ μ•ŠμœΌλ©΄ λ°œμƒν•˜λŠ” 였λ₯˜',
exampleTitle: '인증번호-뢈일치',
message: 'μΈμ¦λ²ˆν˜Έκ°€ μΌμΉ˜ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.',
code: 'Auth-0001'
},
'Auth-0002': {
model: BadRequestException,
exampleDescription: 'μ€‘λ³΅ν•΄μ„œ νšŒμ›κ°€μž…μ„ μ‹œλ„ν•˜λ©΄ λ§‰μŠ΅λ‹ˆλ‹€.',
exampleTitle: 'μ€‘λ³΅νšŒμ›κ°€μž…μš”μ²­',
message: '이미 νšŒμ›κ°€μž…ν•œ μœ μ €μž…λ‹ˆλ‹€.',
code: 'Auth-0002'
},

'Auth-0003': {
model: BadRequestException,
exampleDescription: 'μŠ¬λž™μ— λ“±λ‘λ˜μ§€μ•Šμ€ μœ μ €μΌλ•Œ λ°œμƒν•˜λŠ” 였λ₯˜',
exampleTitle: 'μ •λ³΄μ˜€λ₯˜-μœ μ €μ •λ³΄,μŠ¬λž™μ •λ³΄μ—†μŒ',
message: 'κ°€μž…ν•œ μœ μ €λ‚˜ μ–΄λ“œλ―Ό μœ μ €κ°€ μ•„λ‹™λ‹ˆλ‹€.',
code: 'Auth-0003'
},
'Auth-0004': {
model: BadRequestException,
exampleDescription: '받은 μŠ¬λž™μ΄λ©”μΌμ΄ μ˜¬λ°”λ₯΄μ§€μ•Šμ„κ²½μš°',
exampleTitle: 'μ •λ³΄μ˜€λ₯˜-μŠ¬λž™μ •λ³΄μ—†μŒ',
message: 'κ°€μž…ν•œ μŠ¬λž™ 이메일을 μ˜¬λ°”λ₯΄κ²Œ μž…λ ₯ν•΄ μ£Όμ„Έμš”',
code: 'Auth-0004'
},

'Auth-0005': {
model: BadRequestException,
exampleDescription: 'κ°€μž…ν•œ μœ μ €λ‚˜ μ–΄λ“œλ―Ό μœ μ €κ°€ μ•„λ‹λ•Œ',
exampleTitle: '인증번호-검증이후',
message: 'κ°€μž…ν•œ μœ μ €λ‚˜ μ–΄λ“œλ―Ό μœ μ €κ°€ μ•„λ‹™λ‹ˆλ‹€.',
code: 'Auth-0005'
},

//401
'Auth-1000': {
model: UnauthorizedException,
exampleDescription: '헀더 Bearer ν˜•μ‹μ„ 지킀지 μ•Šκ³  잘λͺ» μš”μ²­ λ³΄λƒˆμ„ λ•Œ',
exampleTitle: 'μ–΄μ„ΈμŠ€ν† ν°-잘λͺ»λœ 헀더 μš”μ²­',
message: '잘λͺ»λœ 헀더 μš”μ²­',
code: 'Auth-1000'
},

'Auth-1001': {
model: UnauthorizedException,
exampleDescription:
'μ†μƒλ˜κ±°λ‚˜ Bearer ν˜•μ‹μ€ λ§žμ·„λŠ”λ° 토큰이 μ΄μƒν•œ 토큰일 λ•Œ',
exampleTitle: 'μ–΄μ„ΈμŠ€ν† ν°-잘λͺ»λœ 토큰',
message: '잘λͺ»λœ 토큰',
code: 'Auth-1001'
},

'Auth-1002': {
model: UnauthorizedException,
exampleDescription: 'κΈ°ν•œμ΄ μ§€λ‚œ ν† ν°μΌλ•Œ',
exampleTitle: 'μ–΄μ„ΈμŠ€ν† ν°-κΈ°ν•œλ§Œλ£Œ',
message: 'κΈ°ν•œλ§Œλ£Œ',
code: 'Auth-1002'
},
'Auth-1003': {
model: UnauthorizedException,
exampleDescription:
'μ–΄μ„ΈμŠ€ν† ν°μ€ μ‚΄μ•„μžˆμ§€λ§Œ dbμ—μ„œ μœ μ €κ°€ μ‚­μ œλ˜μ—ˆμ„λ•Œ (ν…ŒμŠ€νŠΈν• λ•Œ λ°œμƒν• μˆ˜μžˆλŠ” 였λ₯˜)',
exampleTitle: 'μ–΄μ„ΈμŠ€ν† ν°-μœ μ €μ—†μŒ',
message: 'μ—†λŠ” μœ μ €μž…λ‹ˆλ‹€.',
code: 'Auth-1003'
},

//403
'Auth-3000': {
model: ForbiddenException,
exampleDescription: '일반 μœ μ €κ°€ κ΄€λ¦¬μžμ˜ λ©”μ†Œλ“œμ— μ ‘κ·Ό ν•˜λ €κ³  ν• λ•Œ',
exampleTitle: 'κ΄€λ¦¬μžλ©”μ†Œλ“œμ— μœ μ €κ°€ μ ‘κ·Ό',
message: 'κΆŒν•œμ΄ μ—†μŠ΅λ‹ˆλ‹€.',
code: 'Auth-3000'
},

//500
'Auth-5000': {
model: InternalServerErrorException,
exampleDescription: 'λ¬Έμžλ©”μ‹œμ§€ λ°œμ†‘μ΄ μ‹€νŒ¨ν•˜λ©΄ λ°œμƒν•©λ‹ˆλ‹€.',
exampleTitle: 'λ¬Έμžλ©”μ‹œμ§€ λ°œμ†‘μ‹€νŒ¨ 였λ₯˜',
message:
'λ¬Έμžλ©”μ‹œμ§€ λ°œμ†‘ μ‹€νŒ¨. 고슀락 μΉ΄μΉ΄μ˜€ν†‘ 채널을 ν™œμš©ν•΄μ„œ κ΄€λ¦¬μžν•œν…Œ 연락 λΆ€νƒλ“œλ¦½λ‹ˆλ‹€.',
code: 'Auth-5000'
},

// μŠ€λ‘œν‹€
'Auth-9000': {
model: ThrottlerException,
exampleDescription:
'κ³Όλ„ν•œ μš”μ²­μ„ λ³΄λ‚Όμ‹œμ— ( 인증문자 μš”μ²­ , κ΄€λ¦¬μž μŠ¬λž™ 인증 μš”μ²­',
exampleTitle: 'κ³Όλ„ν•œ μš”μ²­',
message: 'ThrottlerException: Too Many Requests',
code: 'Auth-9000'
}
};
Loading

0 comments on commit 86e5a16

Please sign in to comment.