Sort children by birth day
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pierre HUBERT 2023-08-25 19:20:55 +02:00
parent 26df996f8a
commit d07bc200c4

View File

@ -1,5 +1,5 @@
import { Couple, CouplesList } from "../api/CoupleApi";
import { Member, MembersList } from "../api/MemberApi";
import { Member, MembersList, dateTimestamp } from "../api/MemberApi";
export interface CoupleInformation {
couple: Couple;
@ -67,13 +67,25 @@ export function buildDescendingTree(
member_couples.push({
couple: c,
member: pair!,
down: c_children.map((c) => buildDescendingTree(c.id, members, couples)),
down: sortChildren(
c_children.map((c) => buildDescendingTree(c.id, members, couples))
),
});
}
return {
member: member,
down: children.map((c) => buildDescendingTree(c.id, members, couples)),
down: sortChildren(
children.map((c) => buildDescendingTree(c.id, members, couples))
),
couples: member_couples,
};
}
function sortChildren(n: FamilyTreeNode[]): FamilyTreeNode[] {
n.sort(
(a, b) =>
dateTimestamp(a.member.dateOfBirth) - dateTimestamp(b.member.dateOfBirth)
);
return n;
}