|
|
@@ -247,6 +247,12 @@ export class MenuService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ private normalizeParentOfDto(dto: MenuDto) {
|
|
|
+ if (dto.parentId == null) return;
|
|
|
+ const trimmedId = dto.parentId.trim();
|
|
|
+ dto.parentId = trimmedId === '' ? undefined : trimmedId;
|
|
|
+ }
|
|
|
+
|
|
|
private ensureValidHierarchy(id: string | null, dto: MenuDto) {
|
|
|
if (id !== null && id === dto.parentId) {
|
|
|
throw new BadRequestException('父级菜单不能是自己');
|
|
|
@@ -275,12 +281,14 @@ export class MenuService {
|
|
|
}
|
|
|
|
|
|
async create(menuDto: MenuDto) {
|
|
|
+ this.normalizeParentOfDto(menuDto);
|
|
|
await this.checkMenuDto(null, menuDto);
|
|
|
const data = this.toCreateData(menuDto);
|
|
|
await this.mongoPrismaService.sysMenu.create({ data });
|
|
|
}
|
|
|
|
|
|
async update(id: string, menuDto: MenuDto) {
|
|
|
+ this.normalizeParentOfDto(menuDto);
|
|
|
this.ensureValidHierarchy(id, menuDto);
|
|
|
|
|
|
if (menuDto.type !== MenuType.DIRECTORY) {
|