Fetch previous term execs on error
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Amy 2022-09-02 00:33:01 -04:00
parent 5bd1890429
commit 35dc436533
3 changed files with 28 additions and 11 deletions

View File

@ -84,7 +84,7 @@ async function getExecNamePosPairs({
return [["codey", "mascot"]];
}
console.log(`Fetching Exec Name-Position pairs for ${term} ${year}`);
console.log(`Fetching exec name-position pairs for ${term} ${year}`);
const url = "ldap://ldap1.csclub.uwaterloo.ca";
const searchDN = "ou=People,dc=csclub,dc=uwaterloo,dc=ca";
@ -104,6 +104,10 @@ async function getExecNamePosPairs({
)}${year}))`,
});
if (searchEntries.length === 0) {
throw new Error(`No execs found for ${term} ${year}`);
}
// item.position might be an array if the member has more than one position
searchEntries.forEach((item) => {
if (typeof item.position === "string" && item.position in execPositions) {
@ -118,14 +122,10 @@ async function getExecNamePosPairs({
});
formattedExec = orderedExecPositions.map((position) => {
return [
`${execMembers[position].split(" ")[0].toLowerCase()}-${execMembers[
position
]
.split(" ")[1]
.toLowerCase()}`,
position,
];
const fullName = execMembers[position];
const firstName = fullName.split(" ")[0].toLowerCase();
const lastName = fullName.split(" ")[1].toLowerCase();
return [`${firstName}-${lastName}`, position];
});
formattedExec = [...formattedExec, ["codey", "mascot"]];

View File

@ -14,7 +14,7 @@ import {
Metadata as TeamMemberData,
getMemberImagePath,
} from "@/lib/team";
import { getCurrentTermYear } from "@/utils";
import { getCurrentTermYear, getPreviousTermYear } from "@/utils";
import designData from "../../content/team/design-team.json";
import discordData from "../../content/team/discord-team.json";
@ -155,7 +155,14 @@ function sortTeamMembers(team: Team): Team {
}
export const getStaticProps: GetStaticProps<Props> = async () => {
const execs = await getExecs(getCurrentTermYear());
let execs: SerializedExec[] = [];
try {
execs = await getExecs(getCurrentTermYear());
} catch (e: unknown) {
console.error(e instanceof Error ? e.message : e);
execs = await getExecs(getPreviousTermYear());
}
// Note that rawTeams do not contain image paths of members, even though
// TypeScript thinks that it does. It's just to simplify some code.

View File

@ -86,3 +86,13 @@ export function getCurrentTermYear() {
return result.value;
}
export function getPreviousTermYear() {
const result = getTermYear({ goBackwards: true, skipCurrent: true }).next();
if (result.done === true) {
throw new Error("Cannot get previous term. Iterator is done.");
}
return result.value;
}