Skip to content

Commit

Permalink
getinfoforuser handles non-leader users
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwofford committed Sep 18, 2019
1 parent c693ad7 commit 7dd40bd
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,28 +104,38 @@ export const getInfoForUser = user =>
airFind('Leaders', 'Slack ID', user)
.then(leader => (results.leader = leader))
// Then club from leader
.then(() =>
airFind('Clubs', `FIND("${results.leader.fields['ID']}", Leaders)`)
)
.then(() => {
if (!results.leader) return null

return airFind(
'Clubs',
`FIND("${results.leader.fields.ID}", Leaders)`
)
})
.then(club => (results.club = club))
// Then club's history from club
.then(() => airGet('History', 'Club', results.club.fields['ID']))
.then(history => {
.then(() => {
if (!results.club) return null

return airGet('History', 'Club', results.club.fields.ID)
})
.then(history => (results.rawHistory = history))
.then(() => {
if (!results.rawHistory) return null

results.history = {
lastMeetingDay: 'monday',
records: history,
meetings: history
.filter(h => h.fields['Attendance'])
records: results.rawHistory,
meetings: results.rawHistory
.filter(h => h.fields.Attendance)
.sort(
(a, b) =>
Date.parse(a.fields['Date']) - Date.parse(b.fields['Date'])
(a, b) => Date.parse(a.fields.Date) - Date.parse(b.fields.Date)
),
}
})
.then(() => {

if (results.history.meetings.length > 0) {
const lastMeetingDay = new Date(
results.history.meetings[0].fields['Date']
results.history.meetings[0].fields.Date
).toLocaleDateString('en-us', {
weekday: 'long',
timeZone: results.slackUser.tz,
Expand Down

0 comments on commit 7dd40bd

Please sign in to comment.