Skip to content

Commit

Permalink
Fix cancelled tickets issue Fixes #976 (#977)
Browse files Browse the repository at this point in the history
* Prevent fetching of tickets with status different then complete
Prevent ticketing a ticket with status different then complete

* updated ticket bundle ids (#975)

* added new migration

* Handle ticket statuses other than completed
  • Loading branch information
ArtyomKa authored and NitayRabi committed Sep 21, 2018
1 parent e731dab commit 3048697
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
13 changes: 13 additions & 0 deletions migrations/20180921143257_add_ticket_status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const constants = require('../models/constants');

exports.up = function(knex, Promise) {
return Promise.all([
knex.schema.table(constants.TICKETS_TABLE_NAME, function (table) {
table.string("ticket_status", 128).nullable();
})
]);
};

exports.down = function(knex, Promise) {

};
4 changes: 4 additions & 0 deletions models/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ module.exports = {
USER_GENDERS: get_enum(user_genders),
USER_GENDERS_DEFAULT: get_default_enum(user_genders),

TICKET_STATUSES: {
COMPLETED: 'Completed',
ENTERED: 'Entered'
},
/**
* User Current Status:
* define the position of the profile. in which event user is,
Expand Down
8 changes: 7 additions & 1 deletion routes/api/api_gate_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const ERRORS = {
INVALID_VEHICLE_DIRECTION: 'Please enter only in or out as the direction',
EVENT_CLOSED: "Event is currently closed",
INVALID_ENTRY_TYPE: 'Please enter only correct entry type (regular, early_arrival)',
INCORRECT_FORCE_ENTRY_PASSWORD: 'Incorrect Force Entry password'
INCORRECT_FORCE_ENTRY_PASSWORD: 'Incorrect Force Entry password',
TICKET_INCOMPLETE: 'Ticket is either canceled or in processing'
};

function _incorrect_force_entry_password(password) {
Expand Down Expand Up @@ -178,6 +179,11 @@ router.post('/gate-enter', async function (req, res) {
return sendError(res, 500, "ALREADY_INSIDE");
}

if (ticket.attributes.ticket_status !== constants.TICKET_STATUSES.COMPLETED &&
ticket.attributes.ticket_status !== constants.TICKET_STATUSES.ENTERED) {
return sendError(res, 500, "TICKET_INCOMPLETE");
}

if (req.body.force === "true") {
let force_pwd = req.body.force_pwd;
if (_incorrect_force_entry_password(force_pwd)) {
Expand Down
4 changes: 4 additions & 0 deletions routes/pages/gate_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const router = express.Router({
const knex = require('../../libs/db').knex;
const userRole = require('../../libs/user_role');
const Event = require('../../models/event').Event;
const constants = require('../../models/constants');

router.get('/', userRole.isGateManager(), function (req, res) {
Event.forge({event_id: req.user.currentEventId}).fetch().then(event => {
Expand Down Expand Up @@ -45,6 +46,9 @@ router.get('/ajax/tickets',

knex.select('*').from('tickets').leftJoin('users', 'tickets.holder_id', 'users.user_id')
.where('event_id', req.user.currentEventId)
.andWhere(function() {
this.where('ticket_status', 'IN', [constants.TICKET_STATUSES.COMPLETED, constants.TICKET_STATUSES.ENTERED])
})
.andWhere(function () {
this.where('ticket_number', isNaN(parseInt(req.query.search))? req.query.search: parseInt(req.query.search))
.orWhere('first_name', 'LIKE', '%' + req.query.search + '%')
Expand Down
16 changes: 9 additions & 7 deletions scripts/drupal_ticket_sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const constants = require('../models/constants')

var User = require('../models/user.js').User;
var Ticket = require('../models/ticket.js').Ticket;
const STATUS_COMPLETED = 'Completed';

const EVENT_ID = constants.DEFAULT_EVENT_ID
const TICKETS_TYPE_IDS = [...constants.events[constants.DEFAULT_EVENT_ID].bundles]
Expand Down Expand Up @@ -75,7 +74,7 @@ async function dumpDrupalTickets(session, date, page) {
headers: headers,
qs: {
changed: dateFormat(date, "yyyy-mm-dd hh:MM:ss"),
ticket_state_target_id: 3,
//ticket_state_target_id: 3,
page: page
}
};
Expand All @@ -94,9 +93,10 @@ async function dumpDrupalTickets(session, date, page) {

for (var ticket of tickets) {
var status = ticket['Ticket State'];

var type_id = parseInt(ticket['ticket_registration_bundle']);
//log.debug("type", type_id, ticket['user_ticket_type_name'][[0]], status);
if (status === STATUS_COMPLETED && TICKETS_TYPE_IDS.includes(type_id)) {
if (TICKETS_TYPE_IDS.includes(type_id)) {
utickets.push({
'id' : ticket['Docment id'],
'passport_id' : ticket['passport_id'],
Expand All @@ -109,7 +109,8 @@ async function dumpDrupalTickets(session, date, page) {
'ticket_id' : ticket['Ticket number'],
'ticket_number' : ticket['Ticket number'],
'barcode' : ticket['ticket barcode']['value'],
'ticket_type' : ticket['user_ticket_type_name']
'ticket_type' : ticket['user_ticket_type_name'],
'ticket_status' : status
});
}
}
Expand Down Expand Up @@ -144,7 +145,8 @@ async function updateTicket(ticket) {
order_id,
ticket_id,
barcode,
ticket_type
ticket_type,
ticket_status
} = ticket;

log.info('Updating ticket', ticket_id, 'user ', holder_email);
Expand Down Expand Up @@ -194,9 +196,9 @@ async function updateTicket(ticket) {
ticket_id: ticket_id,
type: ticket_type,
disabled_parking: parseInt(ticket.disabled_parking, 10) === 1,
ticket_number: ticket_id // In Drupal, they are the same
ticket_number: ticket_id, // In Drupal, they are the same
ticket_status: ticket_status
});

await sparkTicket.save(null, saveOptions);
log.info('Ticket update success for ticket', ticket_id);
}
Expand Down

0 comments on commit 3048697

Please sign in to comment.