feat: sort stats
This commit is contained in:
parent
3b8e156e47
commit
21aeacfaf3
1 changed files with 15 additions and 2 deletions
|
|
@ -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,
|
||||
}),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue