From 3506b6d00c00ab8efa9033cc241a1b79ed9a9e19 Mon Sep 17 00:00:00 2001 From: Rebecca-Chou Date: Wed, 16 Feb 2022 21:07:19 +0800 Subject: [PATCH] test sort function --- lib/members.ts | 13 ++++++++++++- lib/team.ts | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/members.ts b/lib/members.ts index 812bc55c..71b6242b 100644 --- a/lib/members.ts +++ b/lib/members.ts @@ -8,6 +8,14 @@ export interface Member { program: string; } +const execPositions: { [name: string]: number } = { + presidentcro: 1, + "vice-president": 2, + secretary: 3, + treasurer: 4, + sysadmin: 5, +}; + export async function getMembers(year: string, term: Term): Promise { if (process.env.USE_LDAP?.toLowerCase() !== "true") { return dummyMembers; @@ -36,7 +44,10 @@ export async function getMembers(year: string, term: Term): Promise { program: item.position === undefined ? "" : (item.position as string), }; }) - .filter((item: Member) => item.program !== ""); + .filter((item: Member) => item.program !== "") + .sort((item1: Member, item2: Member) => { + return execPositions[item1.program] - execPositions[item2.program]; + }); // .sort((item1: Member, item2: Member) => // item1.name.localeCompare(item2.name) // ); diff --git a/lib/team.ts b/lib/team.ts index 2adda714..8bf35269 100644 --- a/lib/team.ts +++ b/lib/team.ts @@ -68,10 +68,10 @@ export async function getExecNames() { return { name: item.cn as string, position: - item.position === undefined ? "none" : (item.position as string), + item.position === undefined ? "" : (item.position as string), }; }) - .filter((item: execMembers) => item.position in execPositions) + .filter((item: execMembers) => item.position !== "") .sort((item1: execMembers, item2: execMembers) => { return execPositions[item1.position] - execPositions[item2.position]; });