Computer Science Club of the University of Waterloo's website. https://csclub.uwaterloo.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
www-new/lib/members.ts

61 lines
1.4 KiB

import { Client } from "ldapts";
export interface Member {
name: string;
id: string;
program: string;
}
export async function getMembers(
year: string,
term: string
): Promise<Member[]> {
if (term !== "winter" && term !== "spring" && term !== "fall") {
throw new Error(`[getMembers] Not a valid term: "${term}"`);
}
if (process.env.USE_LDAP?.toLowerCase() !== "true") {
return dummyMembers;
}
let members: Member[] = [];
const url = "ldap://ldap1.csclub.uwaterloo.ca";
const searchDN = "ou=People,dc=csclub,dc=uwaterloo,dc=ca";
const client = new Client({ url });
try {
await client.bind("", "");
const { searchEntries } = await client.search(searchDN, {
scope: "sub",
filter: `(&(objectClass=member)(term=${term.slice(0, 1)}${year}))`,
});
members = searchEntries
.map((item) => {
return {
name: item.cn as string,
id: item.uid as string,
program: item.program === undefined ? "" : (item.program as string),
};
})
.sort((item1: Member, item2: Member) => item1.id.localeCompare(item2.id));
} finally {
await client.unbind();
}
return members;
}
const dummyMembers: Member[] = [
{
name: "John Smith",
id: "j12smith",
program: "MAT/Mathematics Computer Science",
},
{
name: "Jane Smith",
id: "j34smith",
program: "MAT/Mathematics Computer Science",
},
];