From 50cbaa38c16ce96446cae82a610e9a66037bd530 Mon Sep 17 00:00:00 2001 From: ashar Date: Tue, 11 Jun 2024 16:25:23 +0700 Subject: [PATCH] fix(item) perbaikan module item --- src/database/migrations/1718085330130-item.ts | 15 -------- src/database/migrations/1718097870787-item.ts | 34 +++++++++++++++++++ .../item/data/models/item.model.ts | 3 ++ .../item/domain/entities/item.entity.ts | 1 + .../usecases/managers/detail-item.manager.ts | 1 + .../item/infrastructure/dto/item.dto.ts | 9 +++++ 6 files changed, 48 insertions(+), 15 deletions(-) delete mode 100644 src/database/migrations/1718085330130-item.ts create mode 100644 src/database/migrations/1718097870787-item.ts diff --git a/src/database/migrations/1718085330130-item.ts b/src/database/migrations/1718085330130-item.ts deleted file mode 100644 index 2815d54..0000000 --- a/src/database/migrations/1718085330130-item.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; - -export class Item1718085330130 implements MigrationInterface { - name = 'Item1718085330130'; - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query( - `ALTER TABLE "items" ADD "image" character varying`, - ); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "items" DROP COLUMN "image"`); - } -} diff --git a/src/database/migrations/1718097870787-item.ts b/src/database/migrations/1718097870787-item.ts new file mode 100644 index 0000000..5059c0e --- /dev/null +++ b/src/database/migrations/1718097870787-item.ts @@ -0,0 +1,34 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Item1718097870787 implements MigrationInterface { + name = 'Item1718097870787' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TYPE "public"."items_status_enum" AS ENUM('active', 'cancel', 'confirmed', 'draft', 'expired', 'inactive', 'pending', 'refunded', 'rejected', 'settled', 'waiting')`); + await queryRunner.query(`CREATE TYPE "public"."items_item_type_enum" AS ENUM('tiket masuk', 'wahana', 'bundling', 'free gift')`); + await queryRunner.query(`CREATE TYPE "public"."items_limit_type_enum" AS ENUM('no limit', 'time limit', 'qty limit')`); + await queryRunner.query(`CREATE TABLE "items" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "creator_id" character varying(36), "creator_name" character varying(125), "editor_id" character varying(36), "editor_name" character varying(125), "created_at" bigint NOT NULL, "updated_at" bigint NOT NULL, "status" "public"."items_status_enum" NOT NULL DEFAULT 'draft', "name" character varying NOT NULL, "image" character varying, "item_type" "public"."items_item_type_enum" NOT NULL DEFAULT 'tiket masuk', "hpp" bigint, "sales_margin" integer, "total_price" bigint, "base_price" bigint, "use_queue" boolean NOT NULL DEFAULT false, "show_to_booking" boolean NOT NULL DEFAULT false, "limit_type" "public"."items_limit_type_enum" NOT NULL DEFAULT 'no limit', "limit_value" integer, "item_category_id" uuid, "tenant_id" uuid, CONSTRAINT "PK_ba5885359424c15ca6b9e79bcf6" PRIMARY KEY ("id"))`); + await queryRunner.query(`CREATE TABLE "item_bundlings" ("item_bundling_id" uuid NOT NULL, "item_id" uuid NOT NULL, CONSTRAINT "PK_da8e062f97fe862c3e60ed929b5" PRIMARY KEY ("item_bundling_id", "item_id"))`); + await queryRunner.query(`CREATE INDEX "IDX_a50e7abf2caba4d0394f3726b8" ON "item_bundlings" ("item_bundling_id") `); + await queryRunner.query(`CREATE INDEX "IDX_edb9c8d945303a725f6b8648a0" ON "item_bundlings" ("item_id") `); + await queryRunner.query(`ALTER TABLE "items" ADD CONSTRAINT "FK_205e327d4c1bf3cdc00852845e6" FOREIGN KEY ("item_category_id") REFERENCES "item_categories"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "items" ADD CONSTRAINT "FK_d7d027b642add7f0e77c36b874f" FOREIGN KEY ("tenant_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "item_bundlings" ADD CONSTRAINT "FK_a50e7abf2caba4d0394f3726b86" FOREIGN KEY ("item_bundling_id") REFERENCES "items"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE "item_bundlings" ADD CONSTRAINT "FK_edb9c8d945303a725f6b8648a00" FOREIGN KEY ("item_id") REFERENCES "items"("id") ON DELETE CASCADE ON UPDATE CASCADE`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "item_bundlings" DROP CONSTRAINT "FK_edb9c8d945303a725f6b8648a00"`); + await queryRunner.query(`ALTER TABLE "item_bundlings" DROP CONSTRAINT "FK_a50e7abf2caba4d0394f3726b86"`); + await queryRunner.query(`ALTER TABLE "items" DROP CONSTRAINT "FK_d7d027b642add7f0e77c36b874f"`); + await queryRunner.query(`ALTER TABLE "items" DROP CONSTRAINT "FK_205e327d4c1bf3cdc00852845e6"`); + await queryRunner.query(`DROP INDEX "public"."IDX_edb9c8d945303a725f6b8648a0"`); + await queryRunner.query(`DROP INDEX "public"."IDX_a50e7abf2caba4d0394f3726b8"`); + await queryRunner.query(`DROP TABLE "item_bundlings"`); + await queryRunner.query(`DROP TABLE "items"`); + await queryRunner.query(`DROP TYPE "public"."items_limit_type_enum"`); + await queryRunner.query(`DROP TYPE "public"."items_item_type_enum"`); + await queryRunner.query(`DROP TYPE "public"."items_status_enum"`); + } + +} 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 da5cc93..e1cd7ec 100644 --- a/src/modules/item-related/item/data/models/item.model.ts +++ b/src/modules/item-related/item/data/models/item.model.ts @@ -38,6 +38,9 @@ export class ItemModel @Column('int', { name: 'sales_margin', nullable: true }) sales_margin: number; + @Column('bigint', { name: 'total_price', nullable: true }) + total_price: number; + @Column('bigint', { name: 'base_price', nullable: true }) base_price: number; 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 e98885c..b0ab24b 100644 --- a/src/modules/item-related/item/domain/entities/item.entity.ts +++ b/src/modules/item-related/item/domain/entities/item.entity.ts @@ -9,6 +9,7 @@ export interface ItemEntity extends BaseStatusEntity { hpp: number; sales_margin: number; + total_price: number; base_price: number; limit_type: LimitType; limit_value: number; diff --git a/src/modules/item-related/item/domain/usecases/managers/detail-item.manager.ts b/src/modules/item-related/item/domain/usecases/managers/detail-item.manager.ts index 058c1e0..e85f231 100644 --- a/src/modules/item-related/item/domain/usecases/managers/detail-item.manager.ts +++ b/src/modules/item-related/item/domain/usecases/managers/detail-item.manager.ts @@ -41,6 +41,7 @@ export class DetailItemManager extends BaseDetailManager { `${this.tableName}.limit_value`, `${this.tableName}.hpp`, `${this.tableName}.sales_margin`, + `${this.tableName}.total_price`, `${this.tableName}.base_price`, `${this.tableName}.use_queue`, `${this.tableName}.show_to_booking`, 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 c818e68..0ac5660 100644 --- a/src/modules/item-related/item/infrastructure/dto/item.dto.ts +++ b/src/modules/item-related/item/infrastructure/dto/item.dto.ts @@ -69,6 +69,15 @@ export class ItemDto extends BaseStatusDto implements ItemEntity { @ValidateIf((body) => body.item_type.toLowerCase() != ItemType.FREE_GIFT) sales_margin: number; + @ApiProperty({ + type: Number, + required: false, + example: 100000, + }) + @IsNumber() + @ValidateIf((body) => body.item_type.toLowerCase() == ItemType.BUNDLING) + total_price: number; + @ApiProperty({ type: Number, required: false,