Fetch previous term execs on error
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
5bd1890429
commit
35dc436533
18
lib/team.ts
18
lib/team.ts
|
@ -84,7 +84,7 @@ async function getExecNamePosPairs({
|
||||||
return [["codey", "mascot"]];
|
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 url = "ldap://ldap1.csclub.uwaterloo.ca";
|
||||||
const searchDN = "ou=People,dc=csclub,dc=uwaterloo,dc=ca";
|
const searchDN = "ou=People,dc=csclub,dc=uwaterloo,dc=ca";
|
||||||
|
@ -104,6 +104,10 @@ async function getExecNamePosPairs({
|
||||||
)}${year}))`,
|
)}${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
|
// item.position might be an array if the member has more than one position
|
||||||
searchEntries.forEach((item) => {
|
searchEntries.forEach((item) => {
|
||||||
if (typeof item.position === "string" && item.position in execPositions) {
|
if (typeof item.position === "string" && item.position in execPositions) {
|
||||||
|
@ -118,14 +122,10 @@ async function getExecNamePosPairs({
|
||||||
});
|
});
|
||||||
|
|
||||||
formattedExec = orderedExecPositions.map((position) => {
|
formattedExec = orderedExecPositions.map((position) => {
|
||||||
return [
|
const fullName = execMembers[position];
|
||||||
`${execMembers[position].split(" ")[0].toLowerCase()}-${execMembers[
|
const firstName = fullName.split(" ")[0].toLowerCase();
|
||||||
position
|
const lastName = fullName.split(" ")[1].toLowerCase();
|
||||||
]
|
return [`${firstName}-${lastName}`, position];
|
||||||
.split(" ")[1]
|
|
||||||
.toLowerCase()}`,
|
|
||||||
position,
|
|
||||||
];
|
|
||||||
});
|
});
|
||||||
|
|
||||||
formattedExec = [...formattedExec, ["codey", "mascot"]];
|
formattedExec = [...formattedExec, ["codey", "mascot"]];
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {
|
||||||
Metadata as TeamMemberData,
|
Metadata as TeamMemberData,
|
||||||
getMemberImagePath,
|
getMemberImagePath,
|
||||||
} from "@/lib/team";
|
} from "@/lib/team";
|
||||||
import { getCurrentTermYear } from "@/utils";
|
import { getCurrentTermYear, getPreviousTermYear } from "@/utils";
|
||||||
|
|
||||||
import designData from "../../content/team/design-team.json";
|
import designData from "../../content/team/design-team.json";
|
||||||
import discordData from "../../content/team/discord-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 () => {
|
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
|
// Note that rawTeams do not contain image paths of members, even though
|
||||||
// TypeScript thinks that it does. It's just to simplify some code.
|
// TypeScript thinks that it does. It's just to simplify some code.
|
||||||
|
|
10
utils.ts
10
utils.ts
|
@ -86,3 +86,13 @@ export function getCurrentTermYear() {
|
||||||
|
|
||||||
return result.value;
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue