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 PermissionFull
> { > {
constructor( constructor(
private readonly permissionService: PermissionService, protected readonly permissionService: PermissionService,
private readonly logger: LoggerService, protected readonly logger: LoggerService,
private readonly roleService: RoleService, protected readonly roleService: RoleService,
private readonly modelService: ModelService, protected readonly modelService: ModelService,
) { ) {
super(permissionService); super(permissionService);
} }

View File

@ -7,8 +7,9 @@
*/ */
import { ApiProperty } from '@nestjs/swagger'; 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 { IsObjectId } from '@/utils/validation-rules/is-object-id';
import { Action } from '../types/action.type'; import { Action } from '../types/action.type';
@ -40,3 +41,7 @@ export class PermissionCreateDto {
@IsOptional() @IsOptional()
relation?: TRelation; 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 { BaseRepository } from '@/utils/generics/base-repository';
import { PermissionDTOMapActions } from '../dto/permission.dto';
import { import {
Permission, Permission,
PERMISSION_POPULATE, PERMISSION_POPULATE,
@ -24,7 +25,8 @@ import {
export class PermissionRepository extends BaseRepository< export class PermissionRepository extends BaseRepository<
Permission, Permission,
PermissionPopulate, PermissionPopulate,
PermissionFull PermissionFull,
PermissionDTOMapActions
> { > {
constructor( constructor(
readonly eventEmitter: EventEmitter2, readonly eventEmitter: EventEmitter2,

View File

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

View File

@ -10,6 +10,7 @@ import { Injectable } from '@nestjs/common';
import { BaseSeeder } from '@/utils/generics/base-seeder'; import { BaseSeeder } from '@/utils/generics/base-seeder';
import { PermissionDTOMapActions } from '../dto/permission.dto';
import { PermissionRepository } from '../repositories/permission.repository'; import { PermissionRepository } from '../repositories/permission.repository';
import { import {
Permission, Permission,
@ -21,7 +22,8 @@ import {
export class PermissionSeeder extends BaseSeeder< export class PermissionSeeder extends BaseSeeder<
Permission, Permission,
PermissionPopulate, PermissionPopulate,
PermissionFull PermissionFull,
PermissionDTOMapActions
> { > {
constructor(private readonly permissionRepository: PermissionRepository) { constructor(private readonly permissionRepository: PermissionRepository) {
super(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 { Cacheable } from '@/utils/decorators/cacheable.decorator';
import { BaseService } from '@/utils/generics/base-service'; import { BaseService } from '@/utils/generics/base-service';
import { PermissionDTOMapActions } from '../dto/permission.dto';
import { PermissionRepository } from '../repositories/permission.repository'; import { PermissionRepository } from '../repositories/permission.repository';
import { import {
Permission, Permission,
@ -27,7 +28,8 @@ import { PermissionsTree } from '../types/permission.type';
export class PermissionService extends BaseService< export class PermissionService extends BaseService<
Permission, Permission,
PermissionPopulate, PermissionPopulate,
PermissionFull PermissionFull,
PermissionDTOMapActions
> { > {
constructor( constructor(
readonly repository: PermissionRepository, readonly repository: PermissionRepository,