feat: sort stats

This commit is contained in:
Methapon2001 2024-04-23 13:48:08 +07:00
parent 3b8e156e47
commit 21aeacfaf3

View file

@ -109,13 +109,26 @@ export class BranchController extends Controller {
const record = await prisma.branch.findMany({
select: {
id: true,
headOfficeId: true,
isHeadOffice: true,
nameEN: true,
name: true,
isHeadOffice: true,
},
orderBy: [{ isHeadOffice: "desc" }, { createdAt: "asc" }],
});
return record.map((a) =>
const sort = record.reduce<(typeof record)[]>((acc, curr) => {
for (const i of acc) {
if (i[0].id === curr.headOfficeId) {
i.push(curr);
return acc;
}
}
acc.push([curr]);
return acc;
}, []);
return sort.flat().map((a) =>
Object.assign(a, {
count: list.find((b) => b.branchId === a.id)?._count ?? 0,
}),