From 926a7858d570430511aeeab13426510509ff86ea Mon Sep 17 00:00:00 2001 From: spectralo Date: Sat, 11 Jan 2025 18:56:31 +0100 Subject: [PATCH] Moved departments to Array and fixed the await in a forEach --- package.json | 3 +- pages/api/team.js | 78 ++++++++--------- pages/team.js | 2 +- public/team.json | 212 ++++++++++++++++++++++++++-------------------- 4 files changed, 161 insertions(+), 134 deletions(-) diff --git a/package.json b/package.json index 7fce95615..144ff1d86 100644 --- a/package.json +++ b/package.json @@ -107,5 +107,6 @@ "eslint": "8.57.0", "eslint-config-next": "14.1.0", "prettier": "^3.2.5" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/pages/api/team.js b/pages/api/team.js index 6bb905d69..b1bd0d29f 100644 --- a/pages/api/team.js +++ b/pages/api/team.js @@ -4,50 +4,52 @@ export async function fetchTeam() { const current = [] const acknowledged = [] - teamMembers.forEach(async member => { - const currentmember = { - name: member.Name, - bio: member.Bio || null, - department: member.Department, - role: member.Role, - bio_hackfoundation: null, - pronouns: null, - slack_id: member['Slack ID'] || null, - slack_display_name: '', - avatar: member['Override Avatar'] || null, - avatar_id: '', - email: member.Email || null, - website: member.Website || null - } + for (const member of teamMembers) { + for (const department of member.Department) { + const currentmember = { + name: member.Name, + bio: member.Bio || null, + department: department, + role: member.Role, + bio_hackfoundation: null, + pronouns: null, + slack_id: member['Slack ID'] || null, + slack_display_name: '', + avatar: member['Override Avatar'] || null, + avatar_id: '', + email: member.Email || null, + website: member.Website || null + } - if (process.env.SLACK_API_TOKEN) { - const slackData = await fetch( - 'https://hackclub.slack.com/api/users.profile.get?user=' + - record.fields['Slack ID'], - { - method: 'POST', - headers: { - 'content-type': 'multipart/form-data; boundary=----orpheus', - cookie: process.env.SLACK_API_COOKIE - }, - body: `------orpheus\r\nContent-Disposition: form-data; name=\"token\"\r\n\r\n${process.env.SLACK_API_TOKEN}\r\n------orpheus\r\nContent-Disposition: form-data; name=\"user\"\r\n\r\n${record.fields['Slack ID']}\r\n------orpheus\r\n` - } - ).then(r => r.json()) + if (process.env.SLACK_API_TOKEN) { + const slackData = await fetch( + 'https://hackclub.slack.com/api/users.profile.get?user=' + + member['Slack ID'], + { + method: 'POST', + headers: { + 'content-type': 'multipart/form-data; boundary=----orpheus', + cookie: process.env.SLACK_API_COOKIE + }, + body: `------orpheus\r\nContent-Disposition: form-data; name=\"token\"\r\n\r\n${process.env.SLACK_API_TOKEN}\r\n------orpheus\r\nContent-Disposition: form-data; name=\"user\"\r\n\r\n${member['Slack ID']}\r\n------orpheus\r\n` + } + ).then(r => r.json()) - if (slackData.ok) { - if (!currentmember.avatar == null) { - member.avatar = `https://ca.slack-edge.com/T0266FRGM-${record.fields['Slack ID']}-${slackData.profile.avatar_hash}-128` + if (slackData.ok) { + if (!currentmember.avatar == null) { + currentmember.avatar = `https://ca.slack-edge.com/T0266FRGM-${member['Slack ID']}-${slackData.profile.avatar_hash}-128` + } + currentmember.pronouns = slackData.profile.pronouns } - member.pronouns = slackData.profile.pronouns } - } - if (member['Acknowledged']) { - acknowledged.push(currentmember) - } else { - current.push(currentmember) + if (member['Acknowledged']) { + acknowledged.push(currentmember) + } else { + current.push(currentmember) + } } - }) + } return { current, acknowledged } } diff --git a/pages/team.js b/pages/team.js index 16a0b2083..ee12b34c8 100644 --- a/pages/team.js +++ b/pages/team.js @@ -280,7 +280,7 @@ export default function Team({ team }) { > {team.current - ?.filter(member => member.department === 'Welcomers') + ?.filter(member => member.department === 'Welcoming') .map(member => (