auth services implmented
This commit is contained in:
18
ServicesApi/src/accounts/accounts.controller.spec.ts
Normal file
18
ServicesApi/src/accounts/accounts.controller.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AccountsController } from './accounts.controller';
|
||||
|
||||
describe('AccountsController', () => {
|
||||
let controller: AccountsController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AccountsController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<AccountsController>(AccountsController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
39
ServicesApi/src/accounts/accounts.controller.ts
Normal file
39
ServicesApi/src/accounts/accounts.controller.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Param,
|
||||
Body,
|
||||
HttpCode,
|
||||
} from '@nestjs/common';
|
||||
import { AccountsService } from './accounts.service';
|
||||
|
||||
@Controller('accounts')
|
||||
export class AccountsController {
|
||||
constructor(private accountsService: AccountsService) {}
|
||||
|
||||
@Post('filter')
|
||||
@HttpCode(200)
|
||||
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 };
|
||||
}
|
||||
}
|
||||
13
ServicesApi/src/accounts/accounts.module.ts
Normal file
13
ServicesApi/src/accounts/accounts.module.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AccountsService } from './accounts.service';
|
||||
import { AccountsController } from './accounts.controller';
|
||||
import { PrismaModule } from '@/prisma/prisma.module';
|
||||
import { CacheService } from '../cache.service';
|
||||
import { UtilsModule } from '../utils/utils.module';
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule, UtilsModule],
|
||||
providers: [AccountsService, CacheService],
|
||||
controllers: [AccountsController],
|
||||
})
|
||||
export class AccountsModule {}
|
||||
18
ServicesApi/src/accounts/accounts.service.spec.ts
Normal file
18
ServicesApi/src/accounts/accounts.service.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AccountsService } from './accounts.service';
|
||||
|
||||
describe('AccountsService', () => {
|
||||
let service: AccountsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [AccountsService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<AccountsService>(AccountsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
42
ServicesApi/src/accounts/accounts.service.ts
Normal file
42
ServicesApi/src/accounts/accounts.service.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '@/src/prisma.service';
|
||||
import { Prisma, account_records } from '@prisma/client';
|
||||
import { CacheService } from '../cache.service';
|
||||
import { PaginationHelper, PaginationInfo } from '../utils/pagination-helper';
|
||||
|
||||
@Injectable()
|
||||
export class AccountsService {
|
||||
constructor(
|
||||
private prisma: PrismaService,
|
||||
private cacheService: CacheService,
|
||||
private paginationHelper: PaginationHelper,
|
||||
) {}
|
||||
|
||||
async findAll(filter: any): Promise<Partial<account_records>[]> {
|
||||
return this.prisma.account_records.findMany({
|
||||
where: { ...filter },
|
||||
});
|
||||
}
|
||||
|
||||
async findDynamic(
|
||||
query: Prisma.account_recordsFindManyArgs,
|
||||
): Promise<{ totalCount: number; result: Partial<account_records>[] }> {
|
||||
const totalCount = await this.prisma.account_records.count({
|
||||
where: query.where,
|
||||
});
|
||||
const result = await this.prisma.account_records.findMany(query);
|
||||
return { totalCount, result };
|
||||
}
|
||||
|
||||
async findWithPagination(
|
||||
query: any & { page?: number; pageSize?: number },
|
||||
): Promise<{ data: any[]; pagination: PaginationInfo }> {
|
||||
return this.paginationHelper.paginate(this.prisma.account_records, query);
|
||||
}
|
||||
|
||||
async findOne(uuid: string): Promise<Partial<account_records> | null> {
|
||||
return this.prisma.account_records.findUnique({
|
||||
where: { uu_id: uuid },
|
||||
});
|
||||
}
|
||||
}
|
||||
36
ServicesApi/src/accounts/text_example.txt
Normal file
36
ServicesApi/src/accounts/text_example.txt
Normal file
@@ -0,0 +1,36 @@
|
||||
http://localhost:3000/accounts/filter
|
||||
|
||||
{
|
||||
"where": {
|
||||
"build_parts": {
|
||||
"part_code": {
|
||||
"contains": "10",
|
||||
"mode": "insensitive"
|
||||
}
|
||||
}
|
||||
},
|
||||
"select": {
|
||||
"process_comment": true,
|
||||
"bank_date": true,
|
||||
"currency_value": true,
|
||||
"build_parts": {
|
||||
"select": {
|
||||
"part_code": true
|
||||
}
|
||||
},
|
||||
"build_decision_book_payments": {
|
||||
"select": {
|
||||
"payment_amount": true,
|
||||
"process_date": true,
|
||||
"build_decision_book_items": {
|
||||
"select": {
|
||||
"item_order": true,
|
||||
"item_comment": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"page": 2,
|
||||
"pageSize": 5
|
||||
}
|
||||
Reference in New Issue
Block a user