updated events

This commit is contained in:
2025-08-02 20:08:43 +03:00
parent b54bbe2db2
commit 1b87dee60d
9 changed files with 202 additions and 56 deletions

View File

@@ -8,35 +8,44 @@ import {
Body,
HttpCode,
UseGuards,
ForbiddenException,
Req,
Query,
} 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) {}
constructor(private accountsService: AccountsService) { }
@Get('events')
@HttpCode(200)
@UseGuards(AuthControlGuard, EndpointControlGuard)
async getEvents(@Query() query: any) {
const { url, func } = query;
const events = await this.accountsService.infoEvents(url, func);
return {
events,
message: "Events fetched successfully",
}
}
@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: [] };
async filterAccounts(@Body() query: any, @Req() req: any) {
const driveToken = req.driveToken
const redirectToService = await this.accountsService.getEvents();
console.log('redirectToService', redirectToService);
try {
const functionToCall = redirectToService[driveToken];
return await functionToCall(query);
} catch (error) {
console.error('Error redirecting to service:', error);
throw new ForbiddenException(`This user is not allowed to access this endpoint. Please contact your system administrator.`);
}
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 };
}
}