feat: implement dynamic create DTO for Permission

This commit is contained in:
yassinedorbozgithub 2025-01-10 18:38:17 +01:00
parent b6102b3843
commit e0e773454d
6 changed files with 21 additions and 9 deletions

View File

@ -47,10 +47,10 @@ export class PermissionController extends BaseController<
PermissionFull
> {
constructor(
private readonly permissionService: PermissionService,
private readonly logger: LoggerService,
private readonly roleService: RoleService,
private readonly modelService: ModelService,
protected readonly permissionService: PermissionService,
protected readonly logger: LoggerService,
protected readonly roleService: RoleService,
protected readonly modelService: ModelService,
) {
super(permissionService);
}

View File

@ -7,8 +7,9 @@
*/
import { ApiProperty } from '@nestjs/swagger';
import { IsEnum, IsNotEmpty, IsString, IsOptional } from 'class-validator';
import { IsEnum, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { DtoConfig } from '@/utils/types/dto.types';
import { IsObjectId } from '@/utils/validation-rules/is-object-id';
import { Action } from '../types/action.type';
@ -40,3 +41,7 @@ export class PermissionCreateDto {
@IsOptional()
relation?: TRelation;
}
export type PermissionDTOMapActions = DtoConfig<{
create: PermissionCreateDto;
}>;

View File

@ -13,6 +13,7 @@ import { Model } from 'mongoose';
import { BaseRepository } from '@/utils/generics/base-repository';
import { PermissionDTOMapActions } from '../dto/permission.dto';
import {
Permission,
PERMISSION_POPULATE,
@ -24,7 +25,8 @@ import {
export class PermissionRepository extends BaseRepository<
Permission,
PermissionPopulate,
PermissionFull
PermissionFull,
PermissionDTOMapActions
> {
constructor(
readonly eventEmitter: EventEmitter2,

View File

@ -18,6 +18,7 @@ import {
} from '@/utils/types/filter.types';
import { Action } from '../types/action.type';
import { TRelation } from '../types/index.type';
import { Model } from './model.schema';
import { Role } from './role.schema';
@ -41,7 +42,7 @@ export class PermissionStub extends BaseSchema {
type: String,
default: 'role',
})
relation?: string;
relation: TRelation;
}
@Schema({ timestamps: true })

View File

@ -10,6 +10,7 @@ import { Injectable } from '@nestjs/common';
import { BaseSeeder } from '@/utils/generics/base-seeder';
import { PermissionDTOMapActions } from '../dto/permission.dto';
import { PermissionRepository } from '../repositories/permission.repository';
import {
Permission,
@ -21,7 +22,8 @@ import {
export class PermissionSeeder extends BaseSeeder<
Permission,
PermissionPopulate,
PermissionFull
PermissionFull,
PermissionDTOMapActions
> {
constructor(private readonly permissionRepository: PermissionRepository) {
super(permissionRepository);

View File

@ -15,6 +15,7 @@ import { PERMISSION_CACHE_KEY } from '@/utils/constants/cache';
import { Cacheable } from '@/utils/decorators/cacheable.decorator';
import { BaseService } from '@/utils/generics/base-service';
import { PermissionDTOMapActions } from '../dto/permission.dto';
import { PermissionRepository } from '../repositories/permission.repository';
import {
Permission,
@ -27,7 +28,8 @@ import { PermissionsTree } from '../types/permission.type';
export class PermissionService extends BaseService<
Permission,
PermissionPopulate,
PermissionFull
PermissionFull,
PermissionDTOMapActions
> {
constructor(
readonly repository: PermissionRepository,