feat(phase2): implement database optimization and RBAC enforcement
Deploy Canina / deploy (push) Failing after 28s

- TASK-FIN-001: Eliminate N+1 query loop in OrdersService.create with batched findMany query.
- Perform monetary calculations strictly using Prisma.Decimal methods (.add(), .mul(), .sub()).
- Add validation for duplicate product IDs and invalid quantities in order items.
- Implement global DecimalInterceptor registered in main.ts to serialize Prisma.Decimal values into exact string representations in API responses.
- TASK-SEC-003: Create roles.decorator.ts and roles.guard.ts in common directory with backward-compatible re-exports in auth directory.
- Enforce RBAC on SettingsController with @UseGuards(JwtAuthGuard, RolesGuard) and @Roles('Admin').
- Add unit specs for DecimalInterceptor, RolesGuard, SettingsController, and OrdersService Decimal batch operations.
This commit is contained in:
parsa committed 2026-08-06 21:29:20 +03:30
1 parent a64291a19a
commit 809c69f923
13 files changed
+403 -128

No files matched your search

@@ -0,0 +1,65 @@
import { DecimalInterceptor } from './decimal.interceptor';
import { Prisma } from '@prisma/client';
import { of } from 'rxjs';
describe('DecimalInterceptor', () => {
let interceptor: DecimalInterceptor;
beforeEach(() => {
interceptor = new DecimalInterceptor();
});
it('should be defined', () => {
expect(interceptor).toBeDefined();
});
it('should transform Prisma.Decimal instances to exact string representations', (done) => {
const mockData = {
id: 'order-1',
totalAmount: new Prisma.Decimal('64.98'),
items: [
{
id: 'item-1',
unitPrice: new Prisma.Decimal('32.49'),
},
],
};
const executionContext: any = {};
const callHandler: any = {
handle: () => of(mockData),
};
interceptor.intercept(executionContext, callHandler).subscribe((result) => {
expect(result).toEqual({
id: 'order-1',
totalAmount: '64.98',
items: [
{
id: 'item-1',
unitPrice: '32.49',
},
],
});
done();
});
});
it('should leave non-decimal values unchanged', (done) => {
const mockData = {
name: 'Test',
age: 5,
isActive: true,
createdAt: new Date('2026-01-01T00:00:00.000Z'),
};
const callHandler: any = {
handle: () => of(mockData),
};
interceptor.intercept({} as any, callHandler).subscribe((result) => {
expect(result).toEqual(mockData);
done();
});
});
});