43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Param,
|
|
Body,
|
|
HttpCode,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { AccountsService } from './accounts.service';
|
|
import { AuthControlGuard, EndpointControlGuard } from '../middleware/access-control.guard';
|
|
|
|
@Controller('accounts')
|
|
export class AccountsController {
|
|
constructor(private accountsService: AccountsService) {}
|
|
|
|
@Post('filter')
|
|
@HttpCode(200)
|
|
@UseGuards(AuthControlGuard, EndpointControlGuard)
|
|
async filterAccounts(@Body() query: any) {
|
|
const result = await this.accountsService.findWithPagination(query);
|
|
const { pagination, data } = result;
|
|
|
|
if (data.length === 0) {
|
|
return { pagination, data: [] };
|
|
}
|
|
|
|
const resultRefined = data.map((rec: any) => ({
|
|
...rec,
|
|
build_decision_book_payments: rec.build_decision_book_payments?.map(
|
|
(pmt: any) => ({
|
|
...pmt,
|
|
ratePercent:
|
|
((pmt.payment_amount / rec.currency_value) * 100).toFixed(2) + '%',
|
|
}),
|
|
),
|
|
}));
|
|
return { pagination, data: resultRefined };
|
|
}
|
|
}
|