From dcf34b6791cd2d82ed3abd1a1444d7beb24c07f7 Mon Sep 17 00:00:00 2001 From: Inga Date: Mon, 15 Jan 2024 20:45:26 +0000 Subject: [PATCH] refactor: better types --- src/transaction/transaction.controller.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/transaction/transaction.controller.ts b/src/transaction/transaction.controller.ts index 065ae35..3fd1bc1 100644 --- a/src/transaction/transaction.controller.ts +++ b/src/transaction/transaction.controller.ts @@ -14,6 +14,8 @@ import { } from './transaction.dto'; import { Transaction } from './transaction.entity'; +type TransactionRuleData = Pick; + @Controller('transaction') export class TransactionController { constructor( @@ -39,9 +41,7 @@ export class TransactionController { }); } - getClientDeposit = async ( - transactionInput: Pick, - ) => { + getClientDeposit = async (transactionInput: TransactionRuleData) => { try { const deposit = await this.transactionService.findByClientIdWithinActualMonth( @@ -64,7 +64,7 @@ export class TransactionController { return 0; }; - turnoverRule = async (transactionInput: Pick) => { + turnoverRule = async (transactionInput: TransactionRuleData) => { try { const clientDeposit = await this.getClientDeposit(transactionInput); if (clientDeposit) { @@ -75,13 +75,13 @@ export class TransactionController { } }; - discountRule(transactionInput: Pick) { + discountRule(transactionInput: TransactionRuleData) { return transactionInput.client_id === 42 ? DiscountRuleForClientById.client_42 : false; } - defaultRule(transactionInput: Pick) { + defaultRule(transactionInput: TransactionRuleData) { const commissionAmount = (transactionInput.amount * DefaultCommissionPercentage.percentage) / 100; return commissionAmount < DefaultCommissionAmount.amount @@ -91,9 +91,9 @@ export class TransactionController { async applyRules( rules: (( - transactionInput: Pick, - ) => any)[], - transactionInput: Pick, + transactionInput: TransactionRuleData, + ) => number | false | undefined | Promise)[], + transactionInput: TransactionRuleData, ) { let commissionAmount; for (let i = 0; i < rules.length; i++) {