-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
주문 중간 배포 , 레디스 큐 관련 배포 v0.0.9
- Loading branch information
Showing
33 changed files
with
1,052 additions
and
175 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,10 @@ | ||
import { PipeTransform } from '@nestjs/common'; | ||
|
||
export class OrderIdValidationPipe implements PipeTransform { | ||
|
||
transform(value: any) { | ||
value = value - 10000; | ||
return value; | ||
} | ||
|
||
} |
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
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
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
78 changes: 78 additions & 0 deletions
78
src/database/migrations/1658837628780-TicketStatusAddEnum.ts
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,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
19
src/database/migrations/1658841312873-TicketUuidToVARCHAR.ts
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 { 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()` | ||
); | ||
} | ||
} |
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,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] | ||
}); |
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,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(); | ||
} | ||
} |
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,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; | ||
} |
Oops, something went wrong.