diff --git a/src/entity/payment-option.entity.ts b/src/entity/payment-option.entity.ts new file mode 100644 index 0000000..b4efa3b --- /dev/null +++ b/src/entity/payment-option.entity.ts @@ -0,0 +1,27 @@ +import { NumbericBoolean } from 'src/type'; +import { + Column, + Entity, + PrimaryGeneratedColumn, + CreateDateColumn, +} from 'typeorm'; + +@Entity('Payment_Option') +export class PaymentOption { + @PrimaryGeneratedColumn() + option_id: number; + + @Column({ type: 'varchar', length: 64, nullable: false, unique: false }) + name: string; + + @Column({ type: 'tinyint', nullable: false, unique: false }) + is_active: NumbericBoolean; + + @CreateDateColumn({ + type: 'datetime', + nullable: false, + unique: false, + default: () => 'CURRENT_TIMESTAMP', + }) + public created_at: Date; +} diff --git a/src/feature/order/dto/get-payment-method-response.dto.ts b/src/feature/order/dto/get-payment-method-response.dto.ts new file mode 100644 index 0000000..29361b9 --- /dev/null +++ b/src/feature/order/dto/get-payment-method-response.dto.ts @@ -0,0 +1,7 @@ +export class GetPaymentMethodResponse { + data: Payment[]; +} +interface Payment { + payment_id: number; + name: string; +} diff --git a/src/feature/order/order.controller.ts b/src/feature/order/order.controller.ts index 86ddd6b..ff87409 100644 --- a/src/feature/order/order.controller.ts +++ b/src/feature/order/order.controller.ts @@ -7,6 +7,7 @@ import { OrderService } from './order.service'; import { GetApplicationFeeRequest } from './dto/get-application-fee-request.dto'; import { CustomRpcExceptionFilter } from 'src/filters/custom-rpc-exception.filter'; import { GetApplicationFeeResponse } from './dto/get-application-fee-response.dto'; +import { GetPaymentMethodResponse } from './dto/get-payment-method-response.dto'; @Controller('order') export class OrderController { @@ -38,4 +39,21 @@ export class OrderController { exchange_rate, ); } + + @MessagePattern({ cmd: 'get_payment_method' }) + @UseFilters(new CustomRpcExceptionFilter()) + async getPaymentMethod(): Promise { + const result: GetPaymentMethodResponse = { + data: [], + }; + + const paymentOption = await this.orderService.getPaymentOptions(); + paymentOption.forEach((item) => { + result.data.push({ + payment_id: item.option_id, + name: item.name, + }); + }); + return result; + } } diff --git a/src/feature/order/order.service.ts b/src/feature/order/order.service.ts index 3af454f..ad8bdab 100644 --- a/src/feature/order/order.service.ts +++ b/src/feature/order/order.service.ts @@ -3,16 +3,20 @@ import { InternalServerErrorException, Logger, } from '@nestjs/common'; -import { InjectRepository } from '@nestjs/typeorm'; +import { InjectEntityManager, InjectRepository } from '@nestjs/typeorm'; import { Order } from 'src/entity/order.entity'; import { OrderStatus } from 'src/enum'; -import { Repository } from 'typeorm'; +import { EntityManager, Repository } from 'typeorm'; import { GetApplicationFeeResponse } from './dto/get-application-fee-response.dto'; +import { PaymentOption } from 'src/entity/payment-option.entity'; @Injectable() export class OrderService { private readonly logger = new Logger(OrderService.name); - constructor(@InjectRepository(Order) private orderRepo: Repository) {} + constructor( + @InjectRepository(Order) private orderRepo: Repository, + @InjectEntityManager() private entityManager: EntityManager, + ) {} async updateOrderStatusFromAhamoveWebhook( orderId, @@ -190,4 +194,11 @@ export class OrderService { application_fee: applicationFee, }; } + + async getPaymentOptions(): Promise { + return await this.entityManager + .createQueryBuilder(PaymentOption, 'payment') + .where('payment.is_active = 1') + .getMany(); + } } diff --git a/src/type/index.ts b/src/type/index.ts index a8e5944..dcde28a 100644 --- a/src/type/index.ts +++ b/src/type/index.ts @@ -190,3 +190,5 @@ export interface PackagingInfo { currency: string; is_default: boolean; } + +export type NumbericBoolean = 0 | 1;