From 8f43907091df3c2fbb969bb4e285833bbaa948f8 Mon Sep 17 00:00:00 2001 From: shancheas Date: Wed, 16 Oct 2024 17:01:47 +0700 Subject: [PATCH] feat: add vip pass and video url to item --- .../1729072422409-item-video-and-vip-pass.ts | 21 +++++++++++++++++++ .../item/data/models/item.model.ts | 3 +++ .../item/domain/entities/item.entity.ts | 1 + .../item/infrastructure/dto/item.dto.ts | 9 ++++++++ .../data/models/vip-category.model.ts | 3 +++ .../domain/entities/vip-category.entity.ts | 1 + .../infrastructure/dto/vip-category.dto.ts | 9 ++++++++ 7 files changed, 47 insertions(+) create mode 100644 src/database/migrations/1729072422409-item-video-and-vip-pass.ts diff --git a/src/database/migrations/1729072422409-item-video-and-vip-pass.ts b/src/database/migrations/1729072422409-item-video-and-vip-pass.ts new file mode 100644 index 0000000..b3d345b --- /dev/null +++ b/src/database/migrations/1729072422409-item-video-and-vip-pass.ts @@ -0,0 +1,21 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class ItemVideoAndVipPass1729072422409 implements MigrationInterface { + name = 'ItemVideoAndVipPass1729072422409'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "items" ADD "video_url" character varying`, + ); + await queryRunner.query( + `ALTER TABLE "vip_categories" ADD "has_vip_pass" boolean NOT NULL DEFAULT false`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "vip_categories" DROP COLUMN "has_vip_pass"`, + ); + await queryRunner.query(`ALTER TABLE "items" DROP COLUMN "video_url"`); + } +} diff --git a/src/modules/item-related/item/data/models/item.model.ts b/src/modules/item-related/item/data/models/item.model.ts index 90f8ecf..7506733 100644 --- a/src/modules/item-related/item/data/models/item.model.ts +++ b/src/modules/item-related/item/data/models/item.model.ts @@ -28,6 +28,9 @@ export class ItemModel @Column('varchar', { name: 'image_url', nullable: true }) image_url: string; + @Column('varchar', { nullable: true }) + video_url: string; + @Column('enum', { name: 'item_type', enum: ItemType, diff --git a/src/modules/item-related/item/domain/entities/item.entity.ts b/src/modules/item-related/item/domain/entities/item.entity.ts index 90fa227..7ade51e 100644 --- a/src/modules/item-related/item/domain/entities/item.entity.ts +++ b/src/modules/item-related/item/domain/entities/item.entity.ts @@ -6,6 +6,7 @@ export interface ItemEntity extends BaseStatusEntity { name: string; item_type: ItemType; image_url: string; + video_url?: string; hpp: number; sales_margin: number; diff --git a/src/modules/item-related/item/infrastructure/dto/item.dto.ts b/src/modules/item-related/item/infrastructure/dto/item.dto.ts index 8ca6b9b..c6f739e 100644 --- a/src/modules/item-related/item/infrastructure/dto/item.dto.ts +++ b/src/modules/item-related/item/infrastructure/dto/item.dto.ts @@ -31,6 +31,15 @@ export class ItemDto extends BaseStatusDto implements ItemEntity { @ValidateIf((body) => body.image) image_url: string; + @ApiProperty({ + type: String, + required: false, + example: '...', + }) + @IsString() + @ValidateIf((body) => body.video_url) + video_url: string; + @ApiProperty({ type: 'string', required: true, diff --git a/src/modules/transaction/vip-category/data/models/vip-category.model.ts b/src/modules/transaction/vip-category/data/models/vip-category.model.ts index 2d9e5f5..d1feab0 100644 --- a/src/modules/transaction/vip-category/data/models/vip-category.model.ts +++ b/src/modules/transaction/vip-category/data/models/vip-category.model.ts @@ -12,6 +12,9 @@ export class VipCategoryModel @Column('varchar', { name: 'name' }) name: string; + @Column('boolean', { default: false }) + has_vip_pass: boolean; + @OneToMany(() => VipCodeModel, (model) => model.vip_category, { cascade: true, onDelete: 'CASCADE', diff --git a/src/modules/transaction/vip-category/domain/entities/vip-category.entity.ts b/src/modules/transaction/vip-category/domain/entities/vip-category.entity.ts index 49af3a2..d6667b7 100644 --- a/src/modules/transaction/vip-category/domain/entities/vip-category.entity.ts +++ b/src/modules/transaction/vip-category/domain/entities/vip-category.entity.ts @@ -2,4 +2,5 @@ import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.e export interface VipCategoryEntity extends BaseStatusEntity { name: string; + has_vip_pass?: boolean; } diff --git a/src/modules/transaction/vip-category/infrastructure/dto/vip-category.dto.ts b/src/modules/transaction/vip-category/infrastructure/dto/vip-category.dto.ts index 5173949..eb46457 100644 --- a/src/modules/transaction/vip-category/infrastructure/dto/vip-category.dto.ts +++ b/src/modules/transaction/vip-category/infrastructure/dto/vip-category.dto.ts @@ -2,6 +2,7 @@ import { BaseStatusDto } from 'src/core/modules/infrastructure/dto/base-status.d import { VipCategoryEntity } from '../../domain/entities/vip-category.entity'; import { ApiProperty } from '@nestjs/swagger'; import { IsString } from 'class-validator'; +import { boolean } from 'mathjs'; export class VipCategoryDto extends BaseStatusDto implements VipCategoryEntity { @ApiProperty({ @@ -12,4 +13,12 @@ export class VipCategoryDto extends BaseStatusDto implements VipCategoryEntity { }) @IsString() name: string; + + @ApiProperty({ + name: 'has_vip_pass', + type: boolean, + required: false, + example: false, + }) + has_vip_pass: boolean; }