Files
production-evyos-systems-an…/ServicesApi/src/accounts/superusers/superusers.service.ts

55 lines
2.2 KiB
TypeScript

import { PaginationHelper } from '@/src/utils/pagination-helper';
import { Injectable } from '@nestjs/common';
import { PaginationInfo } from '@/src/utils/pagination-helper';
import { PrismaService } from '@/src/prisma.service';
import { UrlHandler } from '@/src/utils/navigator/urlHandler';
@Injectable()
export class SuperUsersService {
userToken: string = "j0adQOsJBR0xq24dxLKdDU9EQRmt4gzE05CmhA"
constructor(
private paginationHelper: PaginationHelper,
private prisma: PrismaService,
private urlHandler: UrlHandler,
) { }
events = {
"e6hewIe7YqbQZHO3:j0adQOsJBR0xq24dxLKdDU9EQRmt4gzE05CmhA": [
{
"key": "qt5P0xoeThjNT9EuWfwBgxsntHY5ydRtKFr1pgKGcgxx",
"endpoint": "/accounts/filter:POST",
"eToken": "e6hewIe7YqbQZHO3",
"token": "j0adQOsJBR0xq24dxLKdDU9EQRmt4gzE05CmhA",
"description": "Super Users Account Filter",
"isDefault": true,
"query": { "query": true, "page": false, "pageSize": false },
"pages": []
}
]
};
mapper = {
"e6hewIe7YqbQZHO3:j0adQOsJBR0xq24dxLKdDU9EQRmt4gzE05CmhA:qt5P0xoeThjNT9EuWfwBgxsntHY5ydRtKFr1pgKGcgxx": (query: any) => this.filter(query),
}
async getEvents() { return this.urlHandler.getEvents(this.events, this.mapper) }
async infoEvents(userToken: string) { return Object.entries(this.events).filter(([key]) => key.endsWith(userToken)) }
async filter(query: any & { page?: number; pageSize?: number }): Promise<{ pagination: PaginationInfo; data: any[] }> {
const result = await this.paginationHelper.findWithPagination(query, this.prisma.account_records);
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 };
}
}