- Updated privilege key structure to use a 3- or 4-part dotted hierarchy (e.g., `GROUP.PARENT.MODULE`). - Modified the `RequirePrivilege` decorator to accept multiple keys, allowing for OR logic in privilege checks. - Enhanced `PrivilegesGuard` to validate against multiple privilege keys, improving access control logic. - Created migration scripts to update existing privilege keys in the database to the new format. - Updated related services, controllers, and tests to accommodate the new privilege key structure and validation logic.
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import { Controller, Get, Param, ParseUUIDPipe, Query } from '@nestjs/common';
|
|
import {
|
|
ApiBearerAuth,
|
|
ApiForbiddenResponse,
|
|
ApiNotFoundResponse,
|
|
ApiOkResponse,
|
|
ApiOperation,
|
|
ApiTags,
|
|
ApiUnauthorizedResponse,
|
|
} from '@nestjs/swagger';
|
|
import { RequirePrivilege } from '../../../common/decorators/require-privilege.decorator';
|
|
import {
|
|
Pagination,
|
|
type PaginationResponse,
|
|
PaginationMetaDto,
|
|
} from '../../../common/http/response';
|
|
import { BEARER_AUTH_NAME } from '../../../common/swagger/setup-swagger';
|
|
import { SalesOrderDto, ListSalesOrdersQueryDto } from './dto/sales-order.dto';
|
|
import { SalesOrdersService } from './sales-orders.service';
|
|
|
|
export const SALES_ORDER_PRIVILEGE_KEYS = [
|
|
'ADMIN.SALES.ACTIVITIES.ORDER',
|
|
'MOBILE.SALES.ORDER',
|
|
] as const;
|
|
|
|
@ApiTags('sales-orders')
|
|
@ApiBearerAuth(BEARER_AUTH_NAME)
|
|
@Controller('sales-orders')
|
|
export class SalesOrdersReadController {
|
|
constructor(private readonly salesOrdersService: SalesOrdersService) {}
|
|
|
|
@Get()
|
|
@Pagination()
|
|
@RequirePrivilege(SALES_ORDER_PRIVILEGE_KEYS, 'view')
|
|
@ApiOperation({ summary: 'List sales orders' })
|
|
@ApiOkResponse({
|
|
schema: {
|
|
properties: {
|
|
data: {
|
|
type: 'array',
|
|
items: { $ref: '#/components/schemas/SalesOrderDto' },
|
|
},
|
|
meta: { $ref: '#/components/schemas/PaginationMetaDto' },
|
|
},
|
|
},
|
|
})
|
|
@ApiUnauthorizedResponse()
|
|
@ApiForbiddenResponse()
|
|
list(
|
|
@Query() query: ListSalesOrdersQueryDto,
|
|
): Promise<PaginationResponse<SalesOrderDto>> {
|
|
return this.salesOrdersService.list(query);
|
|
}
|
|
|
|
@Get(':id')
|
|
@RequirePrivilege(SALES_ORDER_PRIVILEGE_KEYS, 'view')
|
|
@ApiOperation({ summary: 'Get sales order detail' })
|
|
@ApiOkResponse({ type: SalesOrderDto })
|
|
@ApiNotFoundResponse()
|
|
@ApiUnauthorizedResponse()
|
|
@ApiForbiddenResponse()
|
|
findOne(@Param('id', ParseUUIDPipe) id: string): Promise<SalesOrderDto> {
|
|
return this.salesOrdersService.findById(id);
|
|
}
|
|
}
|
|
|
|
void PaginationMetaDto;
|