Skip to content

Commit

Permalink
Link counter table to ticketing (#956)
Browse files Browse the repository at this point in the history
* Fix volunteers api lib
Add to counter on gate enter + exit

* Uncomment stuff
  • Loading branch information
NitayRabi authored and amotenko committed May 6, 2018
1 parent 27f4ff4 commit b9add4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
6 changes: 3 additions & 3 deletions libs/volunteers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module.exports = function(config_ = undefined) {
const config = config_ || default_config;
let VOLUNTEERS_API_URL = config.api_url;
const EARLY_ENTRY_URL = new URL('/api/v1/public/volunteers/getEarlyEntrance', VOLUNTEERS_API_URL);
return {
return {

hasEarlyEntry: async userEmail => {
try {
let response = await request
Expand All @@ -20,7 +20,7 @@ module.exports = function(config_ = undefined) {
return (!isNaN(early_arrival_time)) && early_arrival_time < Date.now();
}
catch (err) {
log.error(`Volunteers API hasEarlyEntry for ${email} failed. ${err}`)
log.error(`Volunteers API hasEarlyEntry for ${userEmail} failed. ${err}`)
return false;
}
},
Expand Down
24 changes: 17 additions & 7 deletions routes/api/api_gate_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ router.post('/get-ticket/', async function (req, res) {
let production_early_arrival = false;
if (gate_status === 'early_arrival') {
production_early_arrival = await volunteersAPI.hasEarlyEntry(holder.attributes.email);
log.debug(`get-ticket - user {holder.attributes.email} is a production volunteer`);
log.debug(`get-ticket - user ${holder.attributes.email} is a production volunteer`);
}
// Preparing result.
let result = {
Expand Down Expand Up @@ -165,7 +165,7 @@ router.post('/gate-enter', async function (req, res) {

// Loading ticket data from the DB.
let [ticket, gate_status] = await getTicketBySearchTerms(req, res);

const isEarlyArrival = gate_status === "early_arrival";
if (!ticket) {
return sendError(res, 500, "TICKET_NOT_FOUND");
}
Expand All @@ -189,7 +189,7 @@ router.post('/gate-enter', async function (req, res) {
}

let holder = ticket.relations.holder;
if (gate_status === "early_arrival")
if (isEarlyArrival)
// Finding the right users group and updating it.
{
let production_early_arrival = false;
Expand Down Expand Up @@ -228,7 +228,12 @@ router.post('/gate-enter', async function (req, res) {
ticket.attributes.first_entrance_timestamp = new Date();
}
await ticket.save();

// We want to add to the counter based on entry type (we don't use await to not break ticketing due to counter errors...)
const entryType = isEarlyArrival ? 'early_arrival' : 'regular';
knex(constants.ENTRIES_TABLE_NAME).insert({timestamp: new Date(), direction: 'arrival', event_id: req.body.event_id, type: entryType})
.catch(err => {
log.warn('A ticket entry count failed', err);
});
// TODO PATCH - Notifying Drupal that this ticket is now non-transferable. Remove with Drupal.
drupalSync.passTicket(ticket.attributes.barcode);

Expand All @@ -240,8 +245,8 @@ router.post('/gate-enter', async function (req, res) {
router.post('/gate-exit', async function (req, res) {

try {
let [ticket] = await getTicketBySearchTerms(req, res);

let [ticket, gate_status] = await getTicketBySearchTerms(req, res);
const isEarlyArrival = gate_status === "early_arrival";
if (!ticket) {
return sendError(res, 500, "TICKET_NOT_FOUND");
}
Expand All @@ -260,7 +265,12 @@ router.post('/gate-exit', async function (req, res) {
ticket.attributes.entrance_timestamp = null;
ticket.attributes.last_exit_timestamp = new Date();
await ticket.save();

// We want to add to the counter based on entry type (we don't use await to not break ticketing due to counter errors...)
const entryType = isEarlyArrival ? 'early_arrival' : 'regular';
knex(constants.ENTRIES_TABLE_NAME).insert({timestamp: new Date(), direction: 'departure', event_id: req.body.event_id, type: entryType})
.catch(err => {
log.warn('A ticket entry count failed', err);
});
return res.status(200).json({
message: "Ticket exit completed"
});
Expand Down

0 comments on commit b9add4e

Please sign in to comment.