up
This commit is contained in:
@@ -3,7 +3,7 @@ import { IsNotEmpty, IsString, IsArray, ValidateNested, IsNumber, Min } from 'cl
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
export class CartItemDto {
|
||||
@ApiProperty({ description: 'Food ID', example: '01KA9Q52JSWFY98TW3HZY6XEVZ' })
|
||||
@ApiProperty({ description: 'Food ID' })
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
foodId!: string;
|
||||
@@ -19,7 +19,6 @@ export class CreateCartDto {
|
||||
@ApiProperty({
|
||||
description: 'List of cart items',
|
||||
type: [CartItemDto],
|
||||
example: [{ foodId: '01KA9Q52JSWFY98TW3HZY6XEVZ', quantity: 2 }],
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@IsArray()
|
||||
|
||||
@@ -10,7 +10,10 @@ export class Permission extends BaseEntity {
|
||||
|
||||
@Property()
|
||||
title!: string;
|
||||
// اضافه شد
|
||||
@Property({ default: 'general' })
|
||||
group!: string;
|
||||
|
||||
@ManyToMany({ entity: () => Role, mappedBy: r => r.permissions })
|
||||
@ManyToMany({ entity: () => Role, mappedBy: 'permissions' })
|
||||
roles = new Collection<Role>(this);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,11 @@ export class RolesService {
|
||||
if (permissions.length !== permissionIds.length) {
|
||||
throw new BadRequestException('One or more permissions not found');
|
||||
}
|
||||
// Check if any permission is special
|
||||
const specialPermissions = permissions.filter(p => p.group === 'special');
|
||||
if (specialPermissions.length > 0) {
|
||||
throw new BadRequestException('Special permissions cannot be assigned to roles');
|
||||
}
|
||||
permissions.forEach(p => role.permissions.add(p));
|
||||
}
|
||||
|
||||
@@ -122,6 +127,11 @@ export class RolesService {
|
||||
if (permissions.length !== dto.permissionIds.length) {
|
||||
throw new BadRequestException('One or more permissions not found');
|
||||
}
|
||||
// Check if any permission is special
|
||||
const specialPermissions = permissions.filter(p => p.group === 'special');
|
||||
if (specialPermissions.length > 0) {
|
||||
throw new BadRequestException('Special permissions cannot be assigned to roles');
|
||||
}
|
||||
permissions.forEach(p => role.permissions.add(p));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import { FindRolesDto } from './dto/find-roles.dto';
|
||||
import { AdminAuthGuard } from '../auth/guards/adminAuth.guard';
|
||||
import { Permissions } from '../auth/decorators/permissions.decorator';
|
||||
import { RestId } from 'src/common/decorators';
|
||||
import { AdminId } from 'src/common/decorators/admin-id.decorator';
|
||||
|
||||
@UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@@ -27,10 +28,12 @@ export class RolesController {
|
||||
}
|
||||
|
||||
@Get('permissions')
|
||||
@ApiOperation({ summary: 'Get all permissions' })
|
||||
@ApiOperation({ summary: 'Get all permissions that the admin has' })
|
||||
@ApiResponse({ status: 200, description: 'Permissions retrieved successfully' })
|
||||
findAllPermissions() {
|
||||
return this.permissionService.findAll();
|
||||
async findAllPermissions(@AdminId() adminId: string, @RestId() restId: string) {
|
||||
const adminPermissionNames = await this.permissionService.getAdminPermissions(adminId, restId);
|
||||
|
||||
return adminPermissionNames;
|
||||
}
|
||||
|
||||
@Permissions('create-role')
|
||||
|
||||
Reference in New Issue
Block a user