From 3e85d40885dffb89587e27fc642035420d11e5b5 Mon Sep 17 00:00:00 2001 From: Aswin Ashar Abdullah Date: Tue, 30 Jul 2024 13:00:49 +0700 Subject: [PATCH] feat(SPG-651) BE Reason Refund Request --- ...722318939681-add-column-to-refund-table.ts | 27 +++++++++++++++++++ .../infrastructure/constant.controller.ts | 10 ++++++- src/modules/transaction/refund/constants.ts | 6 +++++ .../refund/data/models/refund.model.ts | 12 ++++++++- .../refund/domain/entities/refund.entity.ts | 4 ++- .../managers/detail-refund.manager.ts | 2 ++ .../usecases/managers/index-refund.manager.ts | 2 ++ .../refund/infrastructure/dto/refund.dto.ts | 18 ++++++++++++- 8 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 src/database/migrations/1722318939681-add-column-to-refund-table.ts diff --git a/src/database/migrations/1722318939681-add-column-to-refund-table.ts b/src/database/migrations/1722318939681-add-column-to-refund-table.ts new file mode 100644 index 0000000..c731b00 --- /dev/null +++ b/src/database/migrations/1722318939681-add-column-to-refund-table.ts @@ -0,0 +1,27 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class AddColumnToRefundTable1722318939681 implements MigrationInterface { + name = 'AddColumnToRefundTable1722318939681'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE TYPE "public"."refunds_refund_reason_type_enum" AS ENUM('weather', 'ride malfunction', 'other')`, + ); + await queryRunner.query( + `ALTER TABLE "refunds" ADD "refund_reason_type" "public"."refunds_refund_reason_type_enum" NOT NULL DEFAULT 'ride malfunction'`, + ); + await queryRunner.query(`ALTER TABLE "refunds" ADD "refund_reason" text`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "refunds" DROP COLUMN "refund_reason"`, + ); + await queryRunner.query( + `ALTER TABLE "refunds" DROP COLUMN "refund_reason_type"`, + ); + await queryRunner.query( + `DROP TYPE "public"."refunds_refund_reason_type_enum"`, + ); + } +} diff --git a/src/modules/configuration/constant/infrastructure/constant.controller.ts b/src/modules/configuration/constant/infrastructure/constant.controller.ts index a388236..fd0e04b 100644 --- a/src/modules/configuration/constant/infrastructure/constant.controller.ts +++ b/src/modules/configuration/constant/infrastructure/constant.controller.ts @@ -5,7 +5,10 @@ import { STATUS } from 'src/core/strings/constants/base.constants'; import { ItemType } from 'src/modules/item-related/item-category/constants'; import { LimitType } from 'src/modules/item-related/item/constants'; import { PaymentMethodType } from 'src/modules/transaction/payment-method/constants'; -import { RefundType } from 'src/modules/transaction/refund/constants'; +import { + RefundReasonType, + RefundType, +} from 'src/modules/transaction/refund/constants'; import { GateType } from 'src/modules/web-information/gate/constants'; @ApiTags('configuration - constant') @@ -52,6 +55,11 @@ export class ConstantController { return Object.values(RefundType); } + @Get('refund-reason-type') + async refundReasonType(): Promise { + return Object.values(RefundReasonType); + } + @Get('gate-type') async gateType(): Promise { return Object.values(GateType); diff --git a/src/modules/transaction/refund/constants.ts b/src/modules/transaction/refund/constants.ts index 0c9b67b..886b781 100644 --- a/src/modules/transaction/refund/constants.ts +++ b/src/modules/transaction/refund/constants.ts @@ -2,3 +2,9 @@ export enum RefundType { BOOKING = 'pengembalian booking', WAHANA = 'pengembalian wahana', } + +export enum RefundReasonType { + WEATHER = 'weather', + RIDE_MALFUNCTION = 'ride malfunction', + OTHER = 'other', +} diff --git a/src/modules/transaction/refund/data/models/refund.model.ts b/src/modules/transaction/refund/data/models/refund.model.ts index 4740870..e50043a 100644 --- a/src/modules/transaction/refund/data/models/refund.model.ts +++ b/src/modules/transaction/refund/data/models/refund.model.ts @@ -4,7 +4,7 @@ import { Column, Entity, JoinColumn, OneToMany, OneToOne } from 'typeorm'; import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model'; import { TransactionModel } from 'src/modules/transaction/transaction/data/models/transaction.model'; import { RefundItemModel } from './refund-item.model'; -import { RefundType } from '../../constants'; +import { RefundReasonType, RefundType } from '../../constants'; @Entity(TABLE_NAME.REFUND) export class RefundModel @@ -33,6 +33,16 @@ export class RefundModel @Column('decimal', { name: 'refund_total', nullable: true }) refund_total: number; + @Column('enum', { + name: 'refund_reason_type', + enum: RefundReasonType, + default: RefundReasonType.RIDE_MALFUNCTION, + }) + refund_reason_type: RefundReasonType; + + @Column('text', { name: 'refund_reason', nullable: true }) + refund_reason: string; + // bank info @Column('varchar', { name: 'bank_name', nullable: true }) bank_name: string; diff --git a/src/modules/transaction/refund/domain/entities/refund.entity.ts b/src/modules/transaction/refund/domain/entities/refund.entity.ts index c9bf720..5d9ae53 100644 --- a/src/modules/transaction/refund/domain/entities/refund.entity.ts +++ b/src/modules/transaction/refund/domain/entities/refund.entity.ts @@ -1,5 +1,5 @@ import { BaseStatusEntity } from 'src/core/modules/domain/entities/base-status.entity'; -import { RefundType } from '../../constants'; +import { RefundReasonType, RefundType } from '../../constants'; export interface RefundEntity extends BaseStatusEntity { type: RefundType; @@ -8,6 +8,8 @@ export interface RefundEntity extends BaseStatusEntity { refund_date: Date; refund_sub_total: number; refund_total: number; + refund_reason_type: RefundReasonType; + refund_reason: string; bank_name: string; bank_account_name: string; diff --git a/src/modules/transaction/refund/domain/usecases/managers/detail-refund.manager.ts b/src/modules/transaction/refund/domain/usecases/managers/detail-refund.manager.ts index 88c3e89..486e581 100644 --- a/src/modules/transaction/refund/domain/usecases/managers/detail-refund.manager.ts +++ b/src/modules/transaction/refund/domain/usecases/managers/detail-refund.manager.ts @@ -39,6 +39,8 @@ export class DetailRefundManager extends BaseDetailManager { `${this.tableName}.status`, `${this.tableName}.type`, + `${this.tableName}.refund_reason`, + `${this.tableName}.refund_reason_type`, `${this.tableName}.request_date`, `${this.tableName}.refund_date`, `${this.tableName}.created_at`, diff --git a/src/modules/transaction/refund/domain/usecases/managers/index-refund.manager.ts b/src/modules/transaction/refund/domain/usecases/managers/index-refund.manager.ts index 2fd80a0..1be1328 100644 --- a/src/modules/transaction/refund/domain/usecases/managers/index-refund.manager.ts +++ b/src/modules/transaction/refund/domain/usecases/managers/index-refund.manager.ts @@ -50,6 +50,8 @@ export class IndexRefundManager extends BaseIndexManager { `${this.tableName}.status`, `${this.tableName}.type`, + `${this.tableName}.refund_reason`, + `${this.tableName}.refund_reason_type`, `${this.tableName}.request_date`, `${this.tableName}.refund_date`, `${this.tableName}.created_at`, diff --git a/src/modules/transaction/refund/infrastructure/dto/refund.dto.ts b/src/modules/transaction/refund/infrastructure/dto/refund.dto.ts index 86a3b70..8e89845 100644 --- a/src/modules/transaction/refund/infrastructure/dto/refund.dto.ts +++ b/src/modules/transaction/refund/infrastructure/dto/refund.dto.ts @@ -4,9 +4,25 @@ import { ApiProperty } from '@nestjs/swagger'; import { IsNumber, IsString, ValidateIf } from 'class-validator'; import { Exclude } from 'class-transformer'; import { TransactionEntity } from 'src/modules/transaction/transaction/domain/entities/transaction.entity'; -import { RefundType } from '../../constants'; +import { RefundReasonType, RefundType } from '../../constants'; export class RefundDto extends BaseStatusDto implements RefundEntity { + @ApiProperty({ + type: String, + required: true, + example: RefundReasonType.RIDE_MALFUNCTION, + }) + @IsString() + refund_reason_type: RefundReasonType; + + @ApiProperty({ + type: String, + required: false, + example: '', + }) + @ValidateIf((object) => object.refund_reason_type == RefundReasonType.OTHER) + refund_reason: string; + @ApiProperty({ type: String, required: true,