Skip to content

Commit

Permalink
주문 중간 배포 , 레디스 큐 관련 배포 v0.0.9
Browse files Browse the repository at this point in the history
주문 중간 배포 , 레디스 큐 관련 배포 v0.0.9
  • Loading branch information
ImNM authored Jul 26, 2022
2 parents 7463455 + 8f8c003 commit 7a12b6e
Show file tree
Hide file tree
Showing 33 changed files with 1,052 additions and 175 deletions.
479 changes: 365 additions & 114 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 9 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 @@ -57,6 +62,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 @@ -82,7 +88,7 @@
"@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 +99,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
5 changes: 4 additions & 1 deletion src/common/consts/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ enum OrderStatus {

enum TicketStatus {
DONE = '입장완료',
WAIT = '입장대기'
// 원래 WAIT = "입장대기" 였음 ENTERWAIT이라고 생각하면될듯
ENTERWAIT = '입금확인',
ORDERWAIT = '확인대기',
EXPIRE = '기한만료'
}

enum JWTType {
Expand Down
10 changes: 10 additions & 0 deletions src/common/pipes/orderId-validation.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { PipeTransform } from '@nestjs/common';

export class OrderIdValidationPipe implements PipeTransform {

transform(value: any) {
value = value - 10000;
return value;
}

}
2 changes: 1 addition & 1 deletion src/common/pipes/ticket-status-validation.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import e from 'express';
import { TicketStatus } from '../consts/enum';

export class TicketStatusValidationPipe implements PipeTransform {
readonly StatusOptions = [TicketStatus.DONE, TicketStatus.WAIT];
readonly StatusOptions = [TicketStatus.DONE, TicketStatus.ENTERWAIT];

transform(value: any) {
if (typeof value === 'object') {
Expand Down
2 changes: 1 addition & 1 deletion src/database/entities/comment.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { Exclude, Expose, Transform } from 'class-transformer';
import { Role } from 'src/common/consts/enum';
import { Role } from '../../common/consts/enum';

import {
Column,
Expand Down
4 changes: 2 additions & 2 deletions src/database/entities/order.entity.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ApiProperty } from '@nestjs/swagger';
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 { OrderStatus, OrderDate } from '../../common/consts/enum';
import { UserProfileDto } from '../../common/dtos/user-profile.dto';
import {
Column,
CreateDateColumn,
Expand Down
6 changes: 3 additions & 3 deletions src/database/entities/ticket.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { Exclude, Expose, Type } from 'class-transformer';
import { PerformanceDate, TicketStatus } from 'src/common/consts/enum';
import { PerformanceDate, TicketStatus } from '../../common/consts/enum';
import {
AfterLoad,
BeforeInsert,
Expand All @@ -16,7 +16,7 @@ import {
import { Order } from './order.entity';
import { User } from './user.entity';
import { nanoid } from 'nanoid';
import { UserProfileDto } from 'src/common/dtos/user-profile.dto';
import { UserProfileDto } from '../../common/dtos/user-profile.dto';

@Entity()
export class Ticket {
Expand Down Expand Up @@ -55,7 +55,7 @@ export class Ticket {
@Column({
type: 'enum',
enum: TicketStatus,
default: TicketStatus.WAIT
default: TicketStatus.ORDERWAIT
})
public status: TicketStatus;

Expand Down
2 changes: 1 addition & 1 deletion src/database/entities/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { Exclude, Expose } from 'class-transformer';
import { Role } from 'src/common/consts/enum';
import { Role } from '../../common/consts/enum';
import {
Column,
CreateDateColumn,
Expand Down
78 changes: 78 additions & 0 deletions src/database/migrations/1658837628780-TicketStatusAddEnum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class TicketStatusAddEnum1658837628780 implements MigrationInterface {
name = 'TicketStatusAddEnum1658837628780';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TYPE "public"."ticket_status_enum" RENAME TO "ticket_status_enum_old"`
);

await queryRunner.query(
`CREATE TYPE "public"."ticket_status_enum_migration" AS ENUM('입장완료', '입금확인', '확인대기', '기한만료' ,'입장대기')`
);
await queryRunner.query(
`CREATE TYPE "public"."ticket_status_enum" AS ENUM('입장완료', '입금확인', '확인대기', '기한만료' )`
);
await queryRunner.query(
`ALTER TABLE "ticket" ALTER COLUMN "status" DROP DEFAULT`
);

await queryRunner.query(
`ALTER TABLE "ticket" ALTER COLUMN "status" TYPE "public"."ticket_status_enum_migration" USING "status"::"text"::"public"."ticket_status_enum_migration"`
);
await queryRunner.query(
`UPDATE "ticket"
SET status = '확인대기'
WHERE status = '입장대기' ;`
);

await queryRunner.query(
`ALTER TABLE "ticket" ALTER COLUMN "status" TYPE "public"."ticket_status_enum" USING "status"::"text"::"public"."ticket_status_enum"`
);
await queryRunner.query(
`ALTER TABLE "ticket" ALTER COLUMN "status" SET DEFAULT '확인대기'`
);

await queryRunner.query(`DROP TYPE "public"."ticket_status_enum_old"`);
await queryRunner.query(
`DROP TYPE "public"."ticket_status_enum_migration"`
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "public"."ticket_status_enum_old" AS ENUM('입장완료', '입장대기')`
);
await queryRunner.query(
`CREATE TYPE "public"."ticket_status_enum_migration" AS ENUM('입장완료', '입금확인', '확인대기', '기한만료' ,'입장대기')`
);

await queryRunner.query(
`ALTER TABLE "ticket" ALTER COLUMN "status" DROP DEFAULT`
);

await queryRunner.query(
`ALTER TABLE "ticket" ALTER COLUMN "status" TYPE "public"."ticket_status_enum_migration" USING "status"::"text"::"public"."ticket_status_enum_migration"`
);
await queryRunner.query(
`UPDATE "ticket"
SET status = '입장대기'
WHERE status IN('확인대기', '기한만료' ,'입장대기') ;`
);
await queryRunner.query(
`ALTER TABLE "ticket" ALTER COLUMN "status" TYPE "public"."ticket_status_enum_old" USING "status"::"text"::"public"."ticket_status_enum_old"`
);

await queryRunner.query(
`ALTER TABLE "ticket" ALTER COLUMN "status" SET DEFAULT '입장대기'`
);
await queryRunner.query(`DROP TYPE "public"."ticket_status_enum"`);
await queryRunner.query(
`DROP TYPE "public"."ticket_status_enum_migration"`
);
await queryRunner.query(
`ALTER TYPE "public"."ticket_status_enum_old" RENAME TO "ticket_status_enum"`
);
}
}
19 changes: 19 additions & 0 deletions src/database/migrations/1658841312873-TicketUuidToVARCHAR.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class TicketUuidToVARCHAR1658841312873 implements MigrationInterface {
name = 'migrations1658841312873';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "ticket" DROP COLUMN "uuid"`);
await queryRunner.query(
`ALTER TABLE "ticket" ADD "uuid" character varying(14) NOT NULL`
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "ticket" DROP COLUMN "uuid"`);
await queryRunner.query(
`ALTER TABLE "ticket" ADD "uuid" uuid NOT NULL DEFAULT uuid_generate_v4()`
);
}
}
23 changes: 23 additions & 0 deletions src/database/migrations/typeOrm.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'reflect-metadata';
import { DataSource } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { config } from 'dotenv';
import { Ticket } from '../entities/ticket.entity';
import { Order } from '../entities/order.entity';
import { User } from '../entities/user.entity';
import { Comment } from '../entities/comment.entity';
import { TicketStatusAddEnum1658837628780 } from './1658837628780-TicketStatusAddEnum';

config();

const configService = new ConfigService();
console.log(configService.get('POSTGRES_HOST'));
export default new DataSource({
type: 'postgres',
host: configService.get('POSTGRES_HOST'),
port: configService.get('POSTGRES_PORT'),
username: configService.get('POSTGRES_USER'),
password: configService.get('POSTGRES_PASSWORD'),
entities: [Ticket, Order, User, Comment],
migrations: [TicketStatusAddEnum1658837628780]
});
50 changes: 50 additions & 0 deletions src/database/repositories/order.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { RequestOrderDto } from 'src/orders/dtos/request-order.dto';
import { Repository } from 'typeorm';
import { Order } from '../entities/order.entity';
import { User } from '../entities/user.entity';

@Injectable()
export class OrderRepository {
constructor(
@InjectRepository(Order)
private orderRepository: Repository<Order>
) {}

/**
* 주문을 생성한다
* @param requestOrderDto {selection, ticketCount}
* @param user Request User
* @param totalPrice 총 입금할 금액
* @returns 생성된 주문
*/
async createOrder(
requestOrderDto: RequestOrderDto,
user: User,
totalPrice: number
): Promise<Order> {
const { selection, ticketCount } = requestOrderDto;
const order = this.orderRepository.create({
selection,
ticketCount,
price: totalPrice,
user: user,
isFree: false
});
await this.orderRepository.save(order);
return order;
}

/**
*
* @param userId 해당 유저의 주문 목록을 가져온다
* @returns Order배열
*/
async findAllByUserId(userId: number): Promise<Order[]> {
return await this.orderRepository
.createQueryBuilder('order')
.where({ user: userId })
.getMany();
}
}
17 changes: 14 additions & 3 deletions src/database/repositories/ticket.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export class TicketRepository {
const ticket = await this.ticketRepository.findOne({
where: {
id: ticketId
}
},
relations: ['user']
});

if (!ticket) {
Expand Down Expand Up @@ -132,6 +133,18 @@ export class TicketRepository {
.getMany();
}

/**
*
* @param orderId 조회할 주문id
* @returns 해당 주문에 속한 Ticket 배열
*/
async findAllByOrderId(orderId: number): Promise<Ticket[]> {
return await this.ticketRepository
.createQueryBuilder('ticket')
.where({ order: orderId })
.getMany();
}

/**
* 해당 티켓을 저장한다
* @param ticket 저장할 티켓
Expand All @@ -150,8 +163,6 @@ export class TicketRepository {
async createTicket(createTicketDto: CreateTicketDto): Promise<Ticket> {
const { user, order, date } = createTicketDto;

//order = orderRepository.findOne(order)

const ticket = this.ticketRepository.create({
date: date,
user: user,
Expand Down
18 changes: 18 additions & 0 deletions src/orders/dtos/request-order.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ApiProperty } from "@nestjs/swagger";
import { Expose } from "class-transformer";
import { IsEnum, IsIn, IsNotEmpty, isNotEmpty, IsNumber } from "class-validator";
import { Order } from "src/database/entities/order.entity";
import { OrderDate } from "../../common/consts/enum";

export class RequestOrderDto {
@ApiProperty({ description: '공연일자', enum: OrderDate })
@IsEnum(OrderDate)
@Expose()
selection: OrderDate;

@ApiProperty({ description: '티켓수량', type: Number })
@IsNumber()
@IsIn([1,2,3])
@Expose()
ticketCount: number;
}
Loading

0 comments on commit 7a12b6e

Please sign in to comment.