feat: implement dynamic create DTO for Role

This commit is contained in:
yassinedorbozgithub 2025-01-10 18:42:11 +01:00
parent e0e773454d
commit 1936e6a0e7
3 changed files with 16 additions and 2 deletions

View File

@ -9,6 +9,8 @@
import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';
import { IsBoolean, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { DtoConfig } from '@/utils/types/dto.types';
export class RoleCreateDto {
@ApiProperty({ description: 'Name of the role', type: String })
@IsNotEmpty()
@ -26,3 +28,7 @@ export class RoleCreateDto {
}
export class RoleUpdateDto extends PartialType(RoleCreateDto) {}
export type RoleDTOMapActions = DtoConfig<{
create: RoleCreateDto;
}>;

View File

@ -13,6 +13,7 @@ import { Model } from 'mongoose';
import { BaseRepository, DeleteResult } from '@/utils/generics/base-repository';
import { RoleDTOMapActions } from '../dto/role.dto';
import { Permission } from '../schemas/permission.schema';
import {
Role,
@ -25,7 +26,8 @@ import {
export class RoleRepository extends BaseRepository<
Role,
RolePopulate,
RoleFull
RoleFull,
RoleDTOMapActions
> {
constructor(
readonly eventEmitter: EventEmitter2,

View File

@ -10,11 +10,17 @@ import { Injectable } from '@nestjs/common';
import { BaseService } from '@/utils/generics/base-service';
import { RoleDTOMapActions } from '../dto/role.dto';
import { RoleRepository } from '../repositories/role.repository';
import { Role, RoleFull, RolePopulate } from '../schemas/role.schema';
@Injectable()
export class RoleService extends BaseService<Role, RolePopulate, RoleFull> {
export class RoleService extends BaseService<
Role,
RolePopulate,
RoleFull,
RoleDTOMapActions
> {
constructor(readonly repository: RoleRepository) {
super(repository);
}