Skip to content

Commit

Permalink
티켓모듈 중간배포
Browse files Browse the repository at this point in the history
티켓모듈 중간배포
  • Loading branch information
ImNM authored Jul 20, 2022
2 parents 4dacd78 + a122e52 commit 03c5e8b
Show file tree
Hide file tree
Showing 41 changed files with 1,289 additions and 184 deletions.
14 changes: 0 additions & 14 deletions .env.local

This file was deleted.

5 changes: 5 additions & 0 deletions .github/workflows/test-in-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: create env file
run: |
touch .env
echo "${{ secrets.ENV_VARS }}" >> .env
# docker-compose를 활용해 테스트를 위한 컨테이너 환경을 구성합니다.
- name: Start containers
run: docker-compose -f "docker-compose.test.yml" up -d --build
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ services:
ports:
- '5432:5432'
env_file:
- .env.local
- .env
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"joi": "^17.6.0",
"jsonwebtoken": "^8.5.1",
"moment-timezone": "^0.5.34",
"nanoid": "^3.0.0",
"nest-winston": "^1.7.0",
"passport": "^0.6.0",
"passport-jwt": "^4.0.0",
Expand Down
5 changes: 4 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { ThrottlerModule } from '@nestjs/throttler';
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')
Expand All @@ -37,6 +36,10 @@ import { ThrottlerModule } from '@nestjs/throttler';
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(),
Expand Down
1 change: 0 additions & 1 deletion src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { RegisterTokenGuard } from './guards/RegisterToken.guard';
inject: [ConfigService]
}),
UsersModule,
SlackModule,
TypeOrmModule.forFeature([User]),
RedisModule.forRootAsync({
imports: [ConfigModule],
Expand Down
45 changes: 45 additions & 0 deletions src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { ConfigModule } from '@nestjs/config';
import { Test, TestingModule } from '@nestjs/testing';
import { TypeOrmModule } from '@nestjs/typeorm';
import { MockType } from 'src/common/funcs/mockType';
import { UserRepository } from 'src/database/repositories/user.repository';
import { RedisService } from 'src/redis/redis.service';
import { RedisTestService } from 'src/redis/redisTest.service';
import { SlackService } from 'src/slack/slack.service';
import { DataSource } from 'typeorm';
import { AuthService } from './auth.service';
import * as Joi from 'joi';
import { SlackModule } from 'src/slack/slack.module';

export const repositoryMockFactory: () => MockType<UserRepository> = jest.fn(
() => ({
Expand All @@ -11,17 +18,55 @@ export const repositoryMockFactory: () => MockType<UserRepository> = jest.fn(
})
);

const dataSourceFactory: () => MockType<DataSource> = jest.fn(() => ({
// ...
}));

describe('AuthService', () => {
let service: 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])],
providers: [
AuthService,
{
provide: UserRepository,
useFactory: repositoryMockFactory
},
{
provide: DataSource,
useFactory: dataSourceFactory
},
{
provide: RedisService,
useClass: RedisTestService
}
]
}).compile();
Expand Down
4 changes: 4 additions & 0 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
BadRequestException,
forwardRef,
Inject,
Injectable,
InternalServerErrorException,
Logger,
Expand Down Expand Up @@ -45,6 +47,8 @@ export class AuthService {
async requestPhoneValidationNumber(
requestPhoneNumberDto: RequestPhoneNumberDto
): Promise<ResponseRequestValidationDto> {
let test;
//console.log(test.adf.asdf);
//TODO : 전화번호 인증번호 발송 로직 추가 , 이찬진 2022.07.14
const userPhoneNumber = requestPhoneNumberDto.phoneNumber;
//유저가 이미 회원가입했는지확인한다.
Expand Down
15 changes: 14 additions & 1 deletion src/common/consts/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ enum PerformanceDate {
OB = 'OB'
}

enum PageOrder {
ASC = 'ASC',
DESC = 'DESC'
}

enum OrderStatus {
WAIT = '확인대기',
DONE = '입금확인',
Expand All @@ -30,4 +35,12 @@ enum JWTType {
REGISTER = 'REGISTER_SECRET'
}

export { Role, OrderDate, PerformanceDate, TicketStatus, OrderStatus, JWTType };
export {
Role,
OrderDate,
PerformanceDate,
TicketStatus,
PageOrder,
OrderStatus,
JWTType
};
19 changes: 19 additions & 0 deletions src/common/dtos/create-ticket.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ApiProperty, PartialType, PickType } from '@nestjs/swagger';
import { Expose } from 'class-transformer';
import { Ticket } from 'src/database/entities/ticket.entity';
import { UserProfileDto } from './user-profile.dto';

export class CreateTicketDto extends PickType(PartialType(Ticket), [
'date',
'order',
'user',
'createdAt',
'updatedAt'
] as const) {
// @ApiProperty({
// description: '주문한 유저에 대한 정보입니다.',
// type: () => UserProfileDto
// })
// @Expose()
// user: UserProfileDto;
}
6 changes: 6 additions & 0 deletions src/common/dtos/page/page-meta-dto.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { PageOptionsDto } from './page-options.dto';

export interface PageMetaDtoParameters {
pageOptionsDto: PageOptionsDto;
itemCount: number;
}
38 changes: 38 additions & 0 deletions src/common/dtos/page/page-meta.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ApiProperty } from '@nestjs/swagger';
import { Expose } from 'class-transformer';
import { PageMetaDtoParameters } from './page-meta-dto.interface';

export class PageMetaDto {
@ApiProperty()
@Expose()
readonly page: number;

@ApiProperty()
@Expose()
readonly take: number;

@ApiProperty()
@Expose()
readonly itemCount: number;

@ApiProperty()
@Expose()
readonly pageCount: number;

@ApiProperty()
@Expose()
readonly hasPreviousPage: boolean;

@ApiProperty()
@Expose()
readonly hasNextPage: boolean;

constructor({ pageOptionsDto, itemCount }: PageMetaDtoParameters) {
this.page = pageOptionsDto.page;
this.take = pageOptionsDto.take;
this.itemCount = itemCount;
this.pageCount = Math.ceil(this.itemCount / this.take);
this.hasPreviousPage = this.page > 1;
this.hasNextPage = this.page < this.pageCount;
}
}
40 changes: 40 additions & 0 deletions src/common/dtos/page/page-options.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import { Expose, Type } from 'class-transformer';
import { IsEnum, IsInt, IsOptional, Max, Min } from 'class-validator';
import { PageOrder } from 'src/common/consts/enum';

export class PageOptionsDto {
@ApiPropertyOptional({ enum: PageOrder, default: PageOrder.ASC })
@IsEnum(PageOrder)
@IsOptional()
@Expose()
readonly order: PageOrder = PageOrder.ASC;

@ApiPropertyOptional({
minimum: 1,
default: 1
})
@Type(() => Number)
@IsInt()
@Min(1)
@IsOptional()
@Expose()
readonly page: number = 1;

@ApiPropertyOptional({
minimum: 1,
maximum: 50,
default: 10
})
@Type(() => Number)
@IsInt()
@Min(1)
@Max(50)
@IsOptional()
@Expose()
readonly take: number = 10;

get skip(): number {
return (this.page - 1) * this.take;
}
}
21 changes: 21 additions & 0 deletions src/common/dtos/page/page.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ApiProperty } from '@nestjs/swagger';
import { Expose, Type } from 'class-transformer';
import { IsArray } from 'class-validator';
import { PageMetaDto } from './page-meta.dto';

export class PageDto<T> {
@IsArray()
@ApiProperty({ isArray: true })
@Expose()
readonly data: T[];

@ApiProperty({ type: () => PageMetaDto })
@Type(() => PageMetaDto)
@Expose()
readonly meta: PageMetaDto;

constructor(data: T[], meta: PageMetaDto) {
this.data = data;
this.meta = meta;
}
}
26 changes: 26 additions & 0 deletions src/common/dtos/ticket-find.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ApiProperty } from '@nestjs/swagger';
import { Expose } from 'class-transformer';
import { IsEnum, IsOptional } from 'class-validator';
import { PerformanceDate, TicketStatus } from '../consts/enum';

export class TicketFindDto {
@ApiProperty({
description: '티켓 상태',
enum: TicketStatus,
required: false
})
@IsEnum(TicketStatus)
@IsOptional()
@Expose()
readonly status: TicketStatus;

@ApiProperty({
description: '공연 날짜',
enum: PerformanceDate,
required: false
})
@IsEnum(PerformanceDate)
@IsOptional()
@Expose()
readonly date: PerformanceDate;
}
Loading

0 comments on commit 03c5e8b

Please sign in to comment.