refactor: better types

pull/8/head
Inga 🏳‍🌈 10 months ago
parent ac7aabb7c4
commit dcf34b6791
  1. 18
      src/transaction/transaction.controller.ts

@ -14,6 +14,8 @@ import {
} from './transaction.dto'; } from './transaction.dto';
import { Transaction } from './transaction.entity'; import { Transaction } from './transaction.entity';
type TransactionRuleData = Pick<Transaction, 'amount' | 'client_id'>;
@Controller('transaction') @Controller('transaction')
export class TransactionController { export class TransactionController {
constructor( constructor(
@ -39,9 +41,7 @@ export class TransactionController {
}); });
} }
getClientDeposit = async ( getClientDeposit = async (transactionInput: TransactionRuleData) => {
transactionInput: Pick<Transaction, 'client_id'>,
) => {
try { try {
const deposit = const deposit =
await this.transactionService.findByClientIdWithinActualMonth( await this.transactionService.findByClientIdWithinActualMonth(
@ -64,7 +64,7 @@ export class TransactionController {
return 0; return 0;
}; };
turnoverRule = async (transactionInput: Pick<Transaction, 'client_id'>) => { turnoverRule = async (transactionInput: TransactionRuleData) => {
try { try {
const clientDeposit = await this.getClientDeposit(transactionInput); const clientDeposit = await this.getClientDeposit(transactionInput);
if (clientDeposit) { if (clientDeposit) {
@ -75,13 +75,13 @@ export class TransactionController {
} }
}; };
discountRule(transactionInput: Pick<Transaction, 'client_id'>) { discountRule(transactionInput: TransactionRuleData) {
return transactionInput.client_id === 42 return transactionInput.client_id === 42
? DiscountRuleForClientById.client_42 ? DiscountRuleForClientById.client_42
: false; : false;
} }
defaultRule(transactionInput: Pick<Transaction, 'amount'>) { defaultRule(transactionInput: TransactionRuleData) {
const commissionAmount = const commissionAmount =
(transactionInput.amount * DefaultCommissionPercentage.percentage) / 100; (transactionInput.amount * DefaultCommissionPercentage.percentage) / 100;
return commissionAmount < DefaultCommissionAmount.amount return commissionAmount < DefaultCommissionAmount.amount
@ -91,9 +91,9 @@ export class TransactionController {
async applyRules( async applyRules(
rules: (( rules: ((
transactionInput: Pick<Transaction, 'client_id' | 'amount'>, transactionInput: TransactionRuleData,
) => any)[], ) => number | false | undefined | Promise<number | false | undefined>)[],
transactionInput: Pick<Transaction, 'client_id' | 'amount'>, transactionInput: TransactionRuleData,
) { ) {
let commissionAmount; let commissionAmount;
for (let i = 0; i < rules.length; i++) { for (let i = 0; i < rules.length; i++) {

Loading…
Cancel
Save