updates to teamsnapCallback

This commit is contained in:
2024-03-10 14:01:09 -05:00
parent 7efb083e1d
commit a9fa89107e
9 changed files with 77 additions and 63 deletions

View File

@@ -2,16 +2,20 @@ const express = require("express");
const eventsController = require("../controllers/event");
const router = express.Router();
const tsUtils = require("../lib/utils")
const {teamsnapCallback} = require("../lib/utils")
// Middleware
const loadEvent = (req,res,next) => {
const {team_id, event_id} = req.params;
const bulkLoadTypes = ["event", "availabilitySummary"]
tsUtils.teamsnapLog('bulkLoad', types=bulkLoadTypes, team_id, req);
req.promises.push(teamsnap.bulkLoad({teamId: team_id, types: bulkLoadTypes, scopeTo:'event', event__id:event_id}, null, tsUtils.teamsnapCallback)
req.promises.push(
teamsnap.bulkLoad(
{teamId: team_id, types: bulkLoadTypes, scopeTo:'event', event__id:event_id},
null,
(err, items) => {teamsnapCallback(err, items, {req, source:"loadEvent", method:'bulkLoad'})}
)
.then(bulkLoadItems=>{
const items = tsUtils.groupTeamsnapItems(bulkLoadItems, bulkLoadTypes);
tsUtils.teamsnapLog('bulkLoad', types=bulkLoadTypes, team_id, req);
req.availabilitySummary = items.availabilitySummaries.find(e=>e.eventId==event_id);
req.event = items.events.find(e=>e.id==event_id);
}