update role
This commit is contained in:
@@ -7,11 +7,6 @@ export class CreateRoleDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
name!: string;
|
name!: string;
|
||||||
|
|
||||||
@ApiProperty({ description: 'Role title' })
|
|
||||||
@IsNotEmpty()
|
|
||||||
@IsString()
|
|
||||||
title!: string;
|
|
||||||
|
|
||||||
|
|
||||||
@ApiProperty({ description: 'List of permission IDs', isArray: true, required: false })
|
@ApiProperty({ description: 'List of permission IDs', isArray: true, required: false })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
|||||||
@@ -7,11 +7,6 @@ export class UpdateRoleDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
name?: string;
|
name?: string;
|
||||||
|
|
||||||
@ApiProperty({ description: 'Role title', required: false })
|
|
||||||
@IsOptional()
|
|
||||||
@IsString()
|
|
||||||
title?: string;
|
|
||||||
|
|
||||||
@ApiProperty({ description: 'List of permission IDs', isArray: true, required: false })
|
@ApiProperty({ description: 'List of permission IDs', isArray: true, required: false })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsArray()
|
@IsArray()
|
||||||
|
|||||||
@@ -11,9 +11,6 @@ export class Role extends BaseEntity {
|
|||||||
@Property()
|
@Property()
|
||||||
name!: string;
|
name!: string;
|
||||||
|
|
||||||
@Property()
|
|
||||||
title!: string;
|
|
||||||
|
|
||||||
@ManyToMany({ entity: () => Permission, pivotEntity: () => RolePermission, inversedBy: p => p.roles })
|
@ManyToMany({ entity: () => Permission, pivotEntity: () => RolePermission, inversedBy: p => p.roles })
|
||||||
permissions = new Collection<Permission>(this);
|
permissions = new Collection<Permission>(this);
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export class RolesService {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async create(restId: string, dto: CreateRoleDto) {
|
async create(restId: string, dto: CreateRoleDto) {
|
||||||
const { name, title, permissionIds } = dto;
|
const { name, permissionIds } = dto;
|
||||||
|
|
||||||
// Check if role already exists
|
// Check if role already exists
|
||||||
const existing = await this.roleRepository.findOne({ name, restaurant: restId ? { id: restId } : null });
|
const existing = await this.roleRepository.findOne({ name, restaurant: restId ? { id: restId } : null });
|
||||||
@@ -39,7 +39,6 @@ export class RolesService {
|
|||||||
|
|
||||||
const role = this.roleRepository.create({
|
const role = this.roleRepository.create({
|
||||||
name,
|
name,
|
||||||
title,
|
|
||||||
restaurant,
|
restaurant,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -75,11 +74,11 @@ export class RolesService {
|
|||||||
populate: ['permissions', 'restaurant'],
|
populate: ['permissions', 'restaurant'],
|
||||||
});
|
});
|
||||||
|
|
||||||
// Filter by name or title in memory if provided
|
// Filter by name in memory if provided
|
||||||
let filtered = roles;
|
let filtered = roles;
|
||||||
if (name) {
|
if (name) {
|
||||||
filtered = roles.filter(
|
filtered = roles.filter(
|
||||||
r => r.name.toLowerCase().includes(name.toLowerCase()) || r.title.toLowerCase().includes(name.toLowerCase()),
|
r => r.name.toLowerCase().includes(name.toLowerCase()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,10 +115,6 @@ export class RolesService {
|
|||||||
role.name = dto.name;
|
role.name = dto.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dto.title) {
|
|
||||||
role.title = dto.title;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dto.permissionIds && dto.permissionIds.length >= 0) {
|
if (dto.permissionIds && dto.permissionIds.length >= 0) {
|
||||||
// Clear existing permissions and add new ones
|
// Clear existing permissions and add new ones
|
||||||
role.permissions.removeAll();
|
role.permissions.removeAll();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { Role } from '../modules/roles/entities/role.entity';
|
|||||||
import { Restaurant } from '../modules/restaurants/entities/restaurant.entity';
|
import { Restaurant } from '../modules/restaurants/entities/restaurant.entity';
|
||||||
import { User } from '../modules/users/entities/user.entity';
|
import { User } from '../modules/users/entities/user.entity';
|
||||||
import { Permission, PermissionTitles } from '../common/enums/permission.enum';
|
import { Permission, PermissionTitles } from '../common/enums/permission.enum';
|
||||||
|
import { PaymentMethod } from '../modules/payments/entities/payment-method.entity';
|
||||||
|
|
||||||
export class DatabaseSeeder extends Seeder {
|
export class DatabaseSeeder extends Seeder {
|
||||||
async run(em: EntityManager) {
|
async run(em: EntityManager) {
|
||||||
@@ -44,7 +45,7 @@ export class DatabaseSeeder extends Seeder {
|
|||||||
// 2. Create Roles (English)
|
// 2. Create Roles (English)
|
||||||
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' });
|
||||||
// Add all general permissions to restaurant role (excluding special permissions)
|
// Add all general permissions to restaurant role (excluding special permissions)
|
||||||
const generalPermissions = createdPermissions.filter(p => p.group === 'general');
|
const generalPermissions = createdPermissions.filter(p => p.group === 'general');
|
||||||
generalPermissions.forEach(p => role.permissions.add(p));
|
generalPermissions.forEach(p => role.permissions.add(p));
|
||||||
@@ -54,7 +55,7 @@ export class DatabaseSeeder extends Seeder {
|
|||||||
|
|
||||||
const accountantRole = await em.findOne(Role, { name: 'accountant' });
|
const accountantRole = await em.findOne(Role, { name: 'accountant' });
|
||||||
if (!accountantRole) {
|
if (!accountantRole) {
|
||||||
const role = em.create(Role, { name: 'accountant', title: 'حسابدار' });
|
const role = em.create(Role, { name: 'accountant' });
|
||||||
// Add financial permissions to accountant
|
// Add financial permissions to accountant
|
||||||
const financialPerms = createdPermissions.filter(
|
const financialPerms = createdPermissions.filter(
|
||||||
p =>
|
p =>
|
||||||
@@ -68,7 +69,7 @@ export class DatabaseSeeder extends Seeder {
|
|||||||
|
|
||||||
const superAdminRole = await em.findOne(Role, { name: 'superAdmin' });
|
const superAdminRole = await em.findOne(Role, { name: 'superAdmin' });
|
||||||
if (!superAdminRole) {
|
if (!superAdminRole) {
|
||||||
const role = em.create(Role, { name: 'superAdmin', title: 'مدیر کل' });
|
const role = em.create(Role, { name: 'superAdmin' });
|
||||||
// Add restaurant management permissions to superAdmin
|
// Add restaurant management permissions to superAdmin
|
||||||
const restaurantPerms = createdPermissions.filter(
|
const restaurantPerms = createdPermissions.filter(
|
||||||
p =>
|
p =>
|
||||||
@@ -89,7 +90,22 @@ export class DatabaseSeeder extends Seeder {
|
|||||||
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 Payment Methods
|
||||||
|
const zarinpalPaymentMethod = await em.findOne(PaymentMethod, { keyName: 'zarinpal' });
|
||||||
|
if (!zarinpalPaymentMethod) {
|
||||||
|
const paymentMethod = em.create(PaymentMethod, {
|
||||||
|
name: 'زرینپال',
|
||||||
|
keyName: 'zarinpal',
|
||||||
|
description: 'درگاه پرداخت زرینپال',
|
||||||
|
isActive: true,
|
||||||
|
order: 1,
|
||||||
|
});
|
||||||
|
em.persist(paymentMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
await em.flush();
|
||||||
|
|
||||||
|
// 4. Create Restaurants (Farsi)
|
||||||
const zhivanRestaurant = await em.findOne(Restaurant, { slug: 'zhivan' });
|
const zhivanRestaurant = await em.findOne(Restaurant, { slug: 'zhivan' });
|
||||||
if (!zhivanRestaurant) {
|
if (!zhivanRestaurant) {
|
||||||
const restaurant = em.create(Restaurant, {
|
const restaurant = em.create(Restaurant, {
|
||||||
@@ -116,7 +132,7 @@ export class DatabaseSeeder extends Seeder {
|
|||||||
const zhivan = await em.findOne(Restaurant, { slug: 'zhivan' });
|
const zhivan = await em.findOne(Restaurant, { slug: 'zhivan' });
|
||||||
const boote = await em.findOne(Restaurant, { slug: 'boote' });
|
const boote = await em.findOne(Restaurant, { slug: 'boote' });
|
||||||
|
|
||||||
// 4. Create Categories (Farsi)
|
// 5. Create Categories (Farsi)
|
||||||
const categories = [
|
const categories = [
|
||||||
{ title: 'غذای اصلی', restId: zhivan?.id },
|
{ title: 'غذای اصلی', restId: zhivan?.id },
|
||||||
{ title: 'پیش غذا', restId: zhivan?.id },
|
{ title: 'پیش غذا', restId: zhivan?.id },
|
||||||
@@ -146,7 +162,7 @@ export class DatabaseSeeder extends Seeder {
|
|||||||
|
|
||||||
await em.flush();
|
await em.flush();
|
||||||
|
|
||||||
// 5. Create Foods (Farsi)
|
// 6. Create Foods (Farsi)
|
||||||
const foods = [
|
const foods = [
|
||||||
// Zhivan Restaurant Foods
|
// Zhivan Restaurant Foods
|
||||||
{
|
{
|
||||||
@@ -429,7 +445,7 @@ export class DatabaseSeeder extends Seeder {
|
|||||||
|
|
||||||
await em.flush();
|
await em.flush();
|
||||||
|
|
||||||
// 6. Create Admins (Farsi)
|
// 7. Create Admins (Farsi)
|
||||||
const adminMorteza = await em.findOne(Admin, { phone: '09362532122' });
|
const adminMorteza = await em.findOne(Admin, { phone: '09362532122' });
|
||||||
if (!adminMorteza && restaurantRole && zhivan) {
|
if (!adminMorteza && restaurantRole && zhivan) {
|
||||||
const admin = em.create(Admin, {
|
const admin = em.create(Admin, {
|
||||||
@@ -489,7 +505,7 @@ export class DatabaseSeeder extends Seeder {
|
|||||||
|
|
||||||
await em.flush();
|
await em.flush();
|
||||||
|
|
||||||
// 7. Create Users (Farsi)
|
// 8. Create Users (Farsi)
|
||||||
const userMorteza = await em.findOne(User, { phone: '09362532122' });
|
const userMorteza = await em.findOne(User, { phone: '09362532122' });
|
||||||
if (!userMorteza && zhivan) {
|
if (!userMorteza && zhivan) {
|
||||||
const user = em.create(User, {
|
const user = em.create(User, {
|
||||||
|
|||||||
Reference in New Issue
Block a user