Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streaks #2

Merged
merged 8 commits into from Mar 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 31 additions & 7 deletions airtable.js
Expand Up @@ -34,16 +34,40 @@ module.exports = () => {
)`,
})
.all()

const findAll = clubName =>
base('History')
.select({
filterByFormula: `FIND('${clubName}', {Club})`
})
.all()

const calculateStreak = clubName => (
findAll(clubName).then(clubRecords => {
index = 0
clubRecords.forEach(record => {
awaitingResponse = record.get('Type').indexOf('Awaiting response') !== -1
checkIn = record.get('Type').indexOf('Check-in') !== -1
meeting = record.get('Type').indexOf('Meeting') !== -1
if (checkIn && !awaitingResponse) {
index++
} else if (awaitingResponse) {
return index
}
})
return index
})
)

fetchClubs.then(clubs => {
clubs.forEach(clubRecord => {
const club = {}
club.name = clubRecord.get('Name')
club.email = clubRecord.get('Contact Email')[0]

fetchEventsFrom(club.name).then(events => {
club.streak = events.length
sendCheckInTo(club)
let clubName = clubRecord.get('Name')
calculateStreak(clubName).then(streak => {
sendCheckInTo({
name: clubName,
email: clubRecord.get('Contact Email')[0],
streak
})
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion secrets.js
Expand Up @@ -8,4 +8,4 @@ if (env == 'development') {
config = Object.assign(config, require('./env.json'))
}

module.exports = config
module.exports = config