update menu children

This commit is contained in:
2024-11-30 23:35:22 +07:00
parent 96e781e86b
commit 25a6187485

View File

@ -85,6 +85,7 @@ export class MenuController {
.where(whereAttr, whereVal);
const res_list = repo.createQueryBuilder()
.where(whereAttr, whereVal)
.andWhere('id_parent is null')
.orderBy(param.order_field, param.order_direction)
.offset(offset)
.limit(param.limit);
@ -94,9 +95,57 @@ export class MenuController {
res_list.withDeleted();
}
const res_list_all = await repo.createQueryBuilder().andWhere('id_parent is not null').getMany();
let list_data_final = await res_list.getMany();
let list_child: any = {};
for (let p of res_list_all) {
if (!list_child[p.id_parent]) {
list_child[p.id_parent] = [];
}
list_child[p.id_parent].push(p);
}
for (let f of list_data_final) {
if (list_child[f.id]) {
f.children = list_child[f.id];
for (let g of f.children) {
if (list_child[g.id]) {
g.children = list_child[g.id];
for (let h of g.children) {
if (list_child[h.id]) {
h.children = list_child[h.id];
for (let i of h.children) {
if (list_child[i.id]) {
i.children = list_child[i.id];
for (let j of i.children) {
if (list_child[j.id]) {
j.children = list_child[j.id];
for (let k of j.children) {
if (list_child[k.id]) {
k.children = list_child[k.id];
}
}
}
}
}
}
}
}
}
}
}
}
const current_page = param.page;
const total_count_data = await res_count.getCount();
const list_data = await res_list.getMany();
const list_data = list_data_final;
const count_data = CommonHelper.countObject(list_data);
return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, current_page, total_count_data, list_data);