feat(phase2): implement database optimization and RBAC enforcement
Deploy Canina / deploy (push) Failing after 28s
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:
1 parent
a64291a19a
commit
809c69f923
13 files changed
+403
-128
No files matched your search
@@ -1,6 +1,11 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { SettingsController } from './settings.controller';
|
||||
import { SettingsService } from './settings.service';
|
||||
import { GUARDS_METADATA } from '@nestjs/common/constants';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { RolesGuard } from '../common/guards/roles.guard';
|
||||
import { ROLES_KEY } from '../common/decorators/roles.decorator';
|
||||
import { Reflector } from '@nestjs/core';
|
||||
|
||||
describe('SettingsController', () => {
|
||||
let controller: SettingsController;
|
||||
@@ -32,6 +37,16 @@ describe('SettingsController', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
|
||||
it('should have JwtAuthGuard, RolesGuard and Admin role applied at controller level', () => {
|
||||
const guards = Reflect.getMetadata(GUARDS_METADATA, SettingsController);
|
||||
expect(guards).toBeDefined();
|
||||
expect(guards).toContain(JwtAuthGuard);
|
||||
expect(guards).toContain(RolesGuard);
|
||||
|
||||
const roles = Reflect.getMetadata(ROLES_KEY, SettingsController);
|
||||
expect(roles).toEqual(['Admin']);
|
||||
});
|
||||
|
||||
it('should getUiTexts', async () => {
|
||||
const result = await controller.getUiTexts();
|
||||
expect(service.getUiTexts).toHaveBeenCalled();
|
||||
@@ -63,3 +78,4 @@ describe('SettingsController', () => {
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,6 +11,8 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { SettingsService } from './settings.service';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { RolesGuard } from '../common/guards/roles.guard';
|
||||
import { Roles } from '../common/decorators/roles.decorator';
|
||||
import {
|
||||
ApiTags,
|
||||
ApiOperation,
|
||||
@@ -21,6 +23,8 @@ import {
|
||||
} from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Settings - تنظیمات متون پویا و واژهنامه علمی')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@Controller('settings')
|
||||
export class SettingsController {
|
||||
constructor(private readonly settingsService: SettingsService) {}
|
||||
|
||||
Reference in new issue
Block a user