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

Loading…
Cancel
Save