feat: implement dynamic create DTO for Menu

This commit is contained in:
yassinedorbozgithub 2025-01-10 17:24:48 +01:00
parent 635687536b
commit 43c56ab2dd
3 changed files with 15 additions and 3 deletions

View File

@ -16,6 +16,7 @@ import {
ValidateIf,
} from 'class-validator';
import { DtoConfig } from '@/utils/types/dto.types';
import { IsObjectId } from '@/utils/validation-rules/is-object-id';
import { MenuType } from '../schemas/types/menu';
@ -53,3 +54,7 @@ export class MenuCreateDto {
}
export class MenuQueryDto extends PartialType(MenuCreateDto) {}
export type MenuDTOMapActions = DtoConfig<{
create: MenuCreateDto;
}>;

View File

@ -13,6 +13,7 @@ import { Model } from 'mongoose';
import { BaseRepository } from '@/utils/generics/base-repository';
import { MenuDTOMapActions } from '../dto/menu.dto';
import {
Menu,
MENU_POPULATE,
@ -26,7 +27,8 @@ import { MenuType } from '../schemas/types/menu';
export class MenuRepository extends BaseRepository<
Menu,
MenuPopulate,
MenuFull
MenuFull,
MenuDTOMapActions
> {
constructor(
readonly eventEmitter: EventEmitter2,

View File

@ -20,13 +20,18 @@ import { MENU_CACHE_KEY } from '@/utils/constants/cache';
import { Cacheable } from '@/utils/decorators/cacheable.decorator';
import { BaseService } from '@/utils/generics/base-service';
import { MenuCreateDto } from '../dto/menu.dto';
import { MenuCreateDto, MenuDTOMapActions } from '../dto/menu.dto';
import { MenuRepository } from '../repositories/menu.repository';
import { Menu, MenuFull, MenuPopulate } from '../schemas/menu.schema';
import { AnyMenu, MenuTree, MenuType } from '../schemas/types/menu';
@Injectable()
export class MenuService extends BaseService<Menu, MenuPopulate, MenuFull> {
export class MenuService extends BaseService<
Menu,
MenuPopulate,
MenuFull,
MenuDTOMapActions
> {
private RootSymbol: symbol = Symbol('RootMenu');
constructor(