2023-03-04
This commit is contained in:
49
src/middlewares/bulkload.js
Normal file
49
src/middlewares/bulkload.js
Normal file
@@ -0,0 +1,49 @@
|
||||
exports.loadRecentAndUpcomingEvents = async (req, res, next) => {
|
||||
const {team_id, event_id} = req.params
|
||||
var subject_date = ""
|
||||
if (event_id) {
|
||||
const event = await teamsnap.loadEvents({id: event_id}).pop()
|
||||
subject_date = event.startDate.toISOString().slice(0,10)
|
||||
}
|
||||
else {
|
||||
subject_date = new Date().toISOString().slice(0,10)
|
||||
}
|
||||
req.promises.push(
|
||||
teamsnap.bulkLoad({
|
||||
teamId: team_id,
|
||||
types: ["event", "availabilitySummary"],
|
||||
scopeTo: "event",
|
||||
event__startedAfter: subject_date,
|
||||
event__pageSize: 4
|
||||
})
|
||||
.then(items => tsUtils.groupTeamsnapItems(items))
|
||||
.then((items)=>{
|
||||
req.upcoming_events=items.events || [];
|
||||
const availabilitySummaries=items.availabilitySummaries;
|
||||
req.upcoming_events.forEach((event) => {
|
||||
event.link('availabilitySummary', availabilitySummaries.find(a=>a.eventId==event.id))
|
||||
})
|
||||
}
|
||||
).fail(utils.teamsnapFailure)
|
||||
)
|
||||
req.promises.push(
|
||||
teamsnap.bulkLoad({
|
||||
teamId: team_id,
|
||||
types: ["event", "availabilitySummary"],
|
||||
scopeTo: "event",
|
||||
event__startedBefore: subject_date,
|
||||
event__pageSize: 4,
|
||||
event__sortStartDate: "desc"
|
||||
})
|
||||
.then(items => tsUtils.groupTeamsnapItems(items))
|
||||
.then((items)=>{
|
||||
req.recent_events=items.events || [];
|
||||
const availabilitySummaries=items.availabilitySummaries;
|
||||
req.recent_events.forEach((event) => {
|
||||
event.link('availabilitySummary', availabilitySummaries.find(a=>a.eventId==event.id))
|
||||
})
|
||||
}
|
||||
).fail(utils.teamsnapFailure)
|
||||
)
|
||||
next();
|
||||
}
|
||||
18
src/middlewares/csrf.js
Normal file
18
src/middlewares/csrf.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const { doubleCsrf } = require('csrf-csrf');
|
||||
|
||||
const csrf = doubleCsrf({
|
||||
getSecret: () => process.env.CSRF_SECRET,
|
||||
getTokenFromRequest: req => {
|
||||
return req.body.csrfToken
|
||||
},
|
||||
cookieName: process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'development' ? '__benchcoach.x-csrf-token' : '_csrf',
|
||||
cookieOptions: {
|
||||
secure: process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'development' // Enable for HTTPS in production
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
module.exports = {
|
||||
doubleCsrfProtection: csrf.doubleCsrfProtection,
|
||||
generateToken: csrf.generateToken
|
||||
};
|
||||
Reference in New Issue
Block a user