|
|
@ -14,7 +14,7 @@ import { |
|
|
|
} from './transaction.dto'; |
|
|
|
} from './transaction.dto'; |
|
|
|
import { Transaction } from './transaction.entity'; |
|
|
|
import { Transaction } from './transaction.entity'; |
|
|
|
|
|
|
|
|
|
|
|
type TransactionRuleData = Pick<Transaction, 'amount' | 'client_id'>; |
|
|
|
type TransactionRuleData = Pick<Transaction, 'base_amount' | 'client_id'>; |
|
|
|
|
|
|
|
|
|
|
|
@Controller('transaction') |
|
|
|
@Controller('transaction') |
|
|
|
export class TransactionController { |
|
|
|
export class TransactionController { |
|
|
@ -83,7 +83,8 @@ export class TransactionController { |
|
|
|
|
|
|
|
|
|
|
|
defaultRule(transactionInput: TransactionRuleData) { |
|
|
|
defaultRule(transactionInput: TransactionRuleData) { |
|
|
|
const commissionAmount = |
|
|
|
const commissionAmount = |
|
|
|
(transactionInput.amount * DefaultCommissionPercentage.percentage) / 100; |
|
|
|
(transactionInput.base_amount * DefaultCommissionPercentage.percentage) / |
|
|
|
|
|
|
|
100; |
|
|
|
return commissionAmount < DefaultCommissionAmount.amount |
|
|
|
return commissionAmount < DefaultCommissionAmount.amount |
|
|
|
? DefaultCommissionAmount.amount |
|
|
|
? DefaultCommissionAmount.amount |
|
|
|
: commissionAmount; |
|
|
|
: commissionAmount; |
|
|
@ -123,12 +124,20 @@ export class TransactionController { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getAmountWithExchange(transactionInput: TransactionInput) { |
|
|
|
async getAmountWithExchange(transactionInput: TransactionInput) { |
|
|
|
|
|
|
|
const exchangeRateResponse = await this.getExchangeRate({ |
|
|
|
|
|
|
|
date: transactionInput.date, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const transactionAmount = parseInt(transactionInput.amount); |
|
|
|
const transactionData = { |
|
|
|
const transactionData = { |
|
|
|
date: transactionInput.date, |
|
|
|
date: transactionInput.date, |
|
|
|
amount: parseInt(transactionInput.amount), |
|
|
|
amount: transactionAmount, |
|
|
|
currency: transactionInput.currency, |
|
|
|
currency: transactionInput.currency, |
|
|
|
client_id: transactionInput.client_id, |
|
|
|
client_id: transactionInput.client_id, |
|
|
|
|
|
|
|
base_currency: Currency.EUR, |
|
|
|
|
|
|
|
base_amount: |
|
|
|
|
|
|
|
transactionAmount * exchangeRateResponse[transactionInput.currency], |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const commissionAmount = this.applyRules( |
|
|
|
const commissionAmount = this.applyRules( |
|
|
@ -136,22 +145,12 @@ export class TransactionController { |
|
|
|
transactionData, |
|
|
|
transactionData, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const exhangeRateInput = { |
|
|
|
commissionAmount |
|
|
|
date: transactionInput.date, |
|
|
|
.then((commission) => |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.getExchangeRate(exhangeRateInput) |
|
|
|
|
|
|
|
.then((exchangeRateResponse) => |
|
|
|
|
|
|
|
commissionAmount.then((commission) => |
|
|
|
|
|
|
|
this.transactionService.insertOne({ |
|
|
|
this.transactionService.insertOne({ |
|
|
|
...transactionData, |
|
|
|
...transactionData, |
|
|
|
commission, |
|
|
|
commission, |
|
|
|
base_currency: Currency.EUR, |
|
|
|
|
|
|
|
base_amount: |
|
|
|
|
|
|
|
parseInt(transactionInput.amount) * |
|
|
|
|
|
|
|
exchangeRateResponse[transactionInput.currency], |
|
|
|
|
|
|
|
}), |
|
|
|
}), |
|
|
|
), |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
.catch((error) => console.log(error)); |
|
|
|
.catch((error) => console.log(error)); |
|
|
|
|
|
|
|
|
|
|
@ -164,6 +163,8 @@ export class TransactionController { |
|
|
|
amount: parseInt(transactionInput.amount), |
|
|
|
amount: parseInt(transactionInput.amount), |
|
|
|
currency: transactionInput.currency, |
|
|
|
currency: transactionInput.currency, |
|
|
|
client_id: transactionInput.client_id, |
|
|
|
client_id: transactionInput.client_id, |
|
|
|
|
|
|
|
base_currency: Currency.EUR, |
|
|
|
|
|
|
|
base_amount: parseInt(transactionInput.amount), |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const commissionAmount = await this.applyRules( |
|
|
|
const commissionAmount = await this.applyRules( |
|
|
@ -173,13 +174,8 @@ export class TransactionController { |
|
|
|
try { |
|
|
|
try { |
|
|
|
this.transactionService |
|
|
|
this.transactionService |
|
|
|
.insertOne({ |
|
|
|
.insertOne({ |
|
|
|
date: transactionInput.date, |
|
|
|
...transactionData, |
|
|
|
amount: parseInt(transactionInput.amount), |
|
|
|
|
|
|
|
currency: transactionInput.currency, |
|
|
|
|
|
|
|
client_id: transactionInput.client_id, |
|
|
|
|
|
|
|
commission: commissionAmount, |
|
|
|
commission: commissionAmount, |
|
|
|
base_currency: Currency.EUR, |
|
|
|
|
|
|
|
base_amount: parseInt(transactionInput.amount), |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((error) => console.log(error)); |
|
|
|
.catch((error) => console.log(error)); |
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
|