isSystem: false
This commit is contained in:
@@ -51,7 +51,7 @@ export class AdminService {
|
||||
});
|
||||
await this.em.persistAndFlush(admin);
|
||||
}
|
||||
const role = await this.em.findOne(Role, { id: roleId });
|
||||
const role = await this.em.findOne(Role, { id: roleId, isSystem: false });
|
||||
if (!role) throw new NotFoundException('Role not found');
|
||||
|
||||
const restaurant = await this.em.findOne(Restaurant, { id: restId });
|
||||
@@ -131,8 +131,8 @@ export class AdminService {
|
||||
}
|
||||
|
||||
// Update role if roleId is provided
|
||||
if (roleId ) {
|
||||
const role = await this.em.findOne(Role, { id: roleId });
|
||||
if (roleId) {
|
||||
const role = await this.em.findOne(Role, { id: roleId, isSystem: false });
|
||||
if (!role) {
|
||||
throw new NotFoundException('Role not found');
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// role.entity.ts
|
||||
import { Collection, Entity, ManyToMany, OneToMany, ManyToOne, Property } from '@mikro-orm/core';
|
||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { Permission } from './permission.entity';
|
||||
@@ -11,6 +10,9 @@ export class Role extends BaseEntity {
|
||||
@Property()
|
||||
name!: string;
|
||||
|
||||
@Property({ default: false })
|
||||
isSystem: boolean = false;
|
||||
|
||||
@ManyToMany({ entity: () => Permission, pivotEntity: () => RolePermission, inversedBy: p => p.roles })
|
||||
permissions = new Collection<Permission>(this);
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ export class RolesService {
|
||||
const role = this.roleRepository.create({
|
||||
name,
|
||||
restaurant,
|
||||
isSystem: false,
|
||||
});
|
||||
|
||||
// Add permissions if provided
|
||||
@@ -60,7 +61,7 @@ export class RolesService {
|
||||
}
|
||||
|
||||
async findAllGeneralAndRestaurantRoles(restId: string) {
|
||||
const where: FilterQuery<Role> = { $or: [{ restaurant: restId }, { restaurant: null }] };
|
||||
const where: FilterQuery<Role> = { $or: [{ restaurant: restId }, { restaurant: null }], isSystem: false };
|
||||
|
||||
const roles = await this.roleRepository.find(where, {
|
||||
orderBy: { createdAt: 'desc' },
|
||||
|
||||
@@ -47,7 +47,7 @@ export class DatabaseSeeder extends Seeder {
|
||||
// 2. Create Roles (English)
|
||||
let restaurantRole = await em.findOne(Role, { name: 'restaurant' });
|
||||
if (!restaurantRole) {
|
||||
const role = em.create(Role, { name: 'restaurant' });
|
||||
const role = em.create(Role, { name: 'restaurant', isSystem: false });
|
||||
// Add all general permissions to restaurant role (excluding special permissions)
|
||||
const generalPermissions = createdPermissions.filter(p => p.group === 'general');
|
||||
generalPermissions.forEach(p => role.permissions.add(p));
|
||||
@@ -57,7 +57,7 @@ export class DatabaseSeeder extends Seeder {
|
||||
|
||||
const accountantRole = await em.findOne(Role, { name: 'accountant' });
|
||||
if (!accountantRole) {
|
||||
const role = em.create(Role, { name: 'accountant' });
|
||||
const role = em.create(Role, { name: 'accountant', isSystem: false });
|
||||
// Add financial permissions to accountant
|
||||
const financialPerms = createdPermissions.filter(
|
||||
p =>
|
||||
@@ -71,7 +71,7 @@ export class DatabaseSeeder extends Seeder {
|
||||
|
||||
const superAdminRole = await em.findOne(Role, { name: 'superAdmin' });
|
||||
if (!superAdminRole) {
|
||||
const role = em.create(Role, { name: 'superAdmin' });
|
||||
const role = em.create(Role, { name: 'superAdmin', isSystem: true });
|
||||
// Add restaurant management permissions to superAdmin
|
||||
const restaurantPerms = createdPermissions.filter(
|
||||
p =>
|
||||
|
||||
Reference in New Issue
Block a user