70 lines
2.0 KiB
JavaScript
70 lines
2.0 KiB
JavaScript
tsUtils = require("../lib/utils");
|
|
const path = require('path');
|
|
const { teamsnapFailure, tsPromise, teamsnapCallback } = require("../lib/utils");
|
|
const {promisify} = require('util')
|
|
|
|
|
|
exports.helpers = {
|
|
availability_percentage: (availabilitySummary, status) => {
|
|
attribute = {
|
|
going: "playerGoingCount",
|
|
notgoing: "playerNotGoingCount",
|
|
maybe: "playerMaybeCount",
|
|
unknown: "playerUnknownCount"
|
|
}[status.toLowerCase()]
|
|
return (availabilitySummary[attribute]/availabilitySummary.team.playerMemberCount)*100.0
|
|
},
|
|
isAway: (event) => {
|
|
return event.gameType == "Away";
|
|
}
|
|
}
|
|
|
|
exports.partials = path.join(__dirname, "../views/event/partials")
|
|
|
|
exports.getEvents = async (req, res, next) => {
|
|
const {user, team, layout} = req
|
|
const bulkLoadTypes = ["event", "availabilitySummary"]
|
|
// const tsPromiseBulkload = promisify(teamsnap.bulkLoad)
|
|
const promise = teamsnap.bulkLoad(
|
|
{teamId: team.id, types: bulkLoadTypes},
|
|
undefined,
|
|
(err,items) => {teamsnapCallback(err, items, {req, source: 'getEvents', method: 'bulkLoad'})}
|
|
)
|
|
.then(items=>tsUtils.groupTeamsnapItems(items))
|
|
.then(items=>{
|
|
items.events.forEach((event) => {
|
|
event.link('availabilitySummary', items.availabilitySummaries.find(a=>a.eventId==event.id))
|
|
}
|
|
)
|
|
req.events = items.events;
|
|
}
|
|
)
|
|
|
|
req.promises.push(promise)
|
|
all = await Promise.all(req.promises)
|
|
|
|
try {
|
|
const context = {
|
|
title: "Events",
|
|
user, team, layout,
|
|
events: req.events,
|
|
};
|
|
res.render("event/list", context);
|
|
} catch(e) {
|
|
next(e)
|
|
}
|
|
};
|
|
|
|
exports.getEvent = async (req, res, next) => {
|
|
await Promise.all(req.promises)
|
|
const {user, team, event, layout} = req
|
|
lineups = await req.event.loadItem('eventLineups')
|
|
event.link('availabilitySummary', req.availabilitySummary)
|
|
context = {
|
|
title: "Event",
|
|
user, team, event, layout,
|
|
availabilitySummary: req.availabilitySummary,
|
|
};
|
|
res.render("event/show", context);
|
|
};
|