import { PARAMTYPES_METADATA } from "@nestjs/common/constants"; import { get } from "lodash"; import { PlaceholderDto } from "../dtos/placeholder.dto"; export function Crud(Dto) { return target => { const controller = target.prototype; const METHODS = ["create", "update"]; for (let method of METHODS) { const types: [] = Reflect.getMetadata( PARAMTYPES_METADATA, controller, method ); Reflect.decorate( [ Reflect.metadata( PARAMTYPES_METADATA, types.map((v: any) => { if (get(v, "name") === PlaceholderDto.name) { return Dto; } return v; }) ) ], controller, method, Object.getOwnPropertyDescriptor(controller, method) ); } }; }