Skip to content

Commit

Permalink
FES-56-get-payment-method (#67)
Browse files Browse the repository at this point in the history
* add logic
Co-authored-by: NHT <[email protected]>
  • Loading branch information
nfesta2023 authored Mar 10, 2024
1 parent 37d3c30 commit 774ef81
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
27 changes: 27 additions & 0 deletions src/entity/payment-option.entity.ts
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 7 additions & 0 deletions src/feature/order/dto/get-payment-method-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class GetPaymentMethodResponse {
data: Payment[];
}
interface Payment {
payment_id: number;
name: string;
}
18 changes: 18 additions & 0 deletions src/feature/order/order.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -38,4 +39,21 @@ export class OrderController {
exchange_rate,
);
}

@MessagePattern({ cmd: 'get_payment_method' })
@UseFilters(new CustomRpcExceptionFilter())
async getPaymentMethod(): Promise<GetPaymentMethodResponse> {
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;
}
}
17 changes: 14 additions & 3 deletions src/feature/order/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Order>) {}
constructor(
@InjectRepository(Order) private orderRepo: Repository<Order>,
@InjectEntityManager() private entityManager: EntityManager,
) {}

async updateOrderStatusFromAhamoveWebhook(
orderId,
Expand Down Expand Up @@ -190,4 +194,11 @@ export class OrderService {
application_fee: applicationFee,
};
}

async getPaymentOptions(): Promise<PaymentOption[]> {
return await this.entityManager
.createQueryBuilder(PaymentOption, 'payment')
.where('payment.is_active = 1')
.getMany();
}
}
2 changes: 2 additions & 0 deletions src/type/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,5 @@ export interface PackagingInfo {
currency: string;
is_default: boolean;
}

export type NumbericBoolean = 0 | 1;

0 comments on commit 774ef81

Please sign in to comment.