This commit is contained in:
2025-11-22 12:28:26 +03:30
parent aa13cdcbba
commit 0da07417c4
3 changed files with 11 additions and 6 deletions
+4
View File
@@ -24,6 +24,9 @@ export enum Permission {
CREATE_RESTAURANT = 'create_restaurant', CREATE_RESTAURANT = 'create_restaurant',
DELETE_RESTAURANT = 'delete_restaurant', DELETE_RESTAURANT = 'delete_restaurant',
UPDATE_RESTAURANT = 'update_restaurant', UPDATE_RESTAURANT = 'update_restaurant',
// Role Management
CREATE_ROLE = 'create_role',
} }
/** /**
@@ -43,4 +46,5 @@ export const PermissionTitles: Record<Permission, string> = {
[Permission.CREATE_RESTAURANT]: 'ایجاد رستوران', [Permission.CREATE_RESTAURANT]: 'ایجاد رستوران',
[Permission.DELETE_RESTAURANT]: 'حذف رستوران', [Permission.DELETE_RESTAURANT]: 'حذف رستوران',
[Permission.UPDATE_RESTAURANT]: 'ویرایش رستوران', [Permission.UPDATE_RESTAURANT]: 'ویرایش رستوران',
[Permission.CREATE_ROLE]: 'ایجاد نقش',
}; };
@@ -36,7 +36,7 @@ export class RolesController {
return adminPermissionNames; return adminPermissionNames;
} }
@Permissions('create-role') @Permissions('create_role')
@Post() @Post()
@ApiOperation({ summary: 'Create a new role' }) @ApiOperation({ summary: 'Create a new role' })
@ApiBody({ type: CreateRoleDto }) @ApiBody({ type: CreateRoleDto })
+6 -5
View File
@@ -45,8 +45,9 @@ export class DatabaseSeeder extends Seeder {
let restaurantRole = await em.findOne(Role, { name: 'restaurant' }); let restaurantRole = await em.findOne(Role, { name: 'restaurant' });
if (!restaurantRole) { if (!restaurantRole) {
const role = em.create(Role, { name: 'restaurant', title: 'رستوران' }); const role = em.create(Role, { name: 'restaurant', title: 'رستوران' });
// Add all permissions to restaurant role (including update_restaurant) // Add all general permissions to restaurant role (excluding special permissions)
createdPermissions.forEach(p => role.permissions.add(p)); const generalPermissions = createdPermissions.filter(p => p.group === 'general');
generalPermissions.forEach(p => role.permissions.add(p));
em.persist(role); em.persist(role);
restaurantRole = role; restaurantRole = role;
} }
@@ -85,7 +86,7 @@ export class DatabaseSeeder extends Seeder {
if (!restaurantRole) { if (!restaurantRole) {
restaurantRole = await em.findOne(Role, { name: 'restaurant' }); restaurantRole = await em.findOne(Role, { name: 'restaurant' });
} }
const accountant = await em.findOne(Role, { name: 'accountant' }); await em.findOne(Role, { name: 'accountant' });
const superAdmin = await em.findOne(Role, { name: 'superAdmin' }); const superAdmin = await em.findOne(Role, { name: 'superAdmin' });
// 3. Create Restaurants (Farsi) // 3. Create Restaurants (Farsi)
@@ -449,7 +450,7 @@ export class DatabaseSeeder extends Seeder {
} }
const adminHamid = await em.findOne(Admin, { phone: '09185290775' }); const adminHamid = await em.findOne(Admin, { phone: '09185290775' });
if (!adminHamid && accountant && boote) { if (!adminHamid && restaurantRole && boote) {
const admin = em.create(Admin, { const admin = em.create(Admin, {
phone: '09185290775', phone: '09185290775',
firstName: 'حمید', firstName: 'حمید',
@@ -460,7 +461,7 @@ export class DatabaseSeeder extends Seeder {
// Create AdminRole linking admin to role and restaurant // Create AdminRole linking admin to role and restaurant
const adminRole = em.create(AdminRole, { const adminRole = em.create(AdminRole, {
admin, admin,
role: accountant, role: restaurantRole,
restaurant: boote, restaurant: boote,
}); });
em.persist(adminRole); em.persist(adminRole);