Skip to content

Commit

Permalink
Merge pull request #397 from Midburn/gate
Browse files Browse the repository at this point in the history
fixing sync script
  • Loading branch information
LeonFedotov authored May 16, 2017
2 parents 5fd3348 + 8eb8523 commit 42d846c
Show file tree
Hide file tree
Showing 2 changed files with 821 additions and 223 deletions.
37 changes: 21 additions & 16 deletions scripts/drupal_ticket_sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var log = require('../libs/logger')(module);

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

const TICKETS_TYPE_IDS = [38, 39, 40];
const TICKETS_TYPE_IDS = [39, 40, 41, 43, 44, 45, 46]
// const TICKETS_TYPE_IDS = [38, 39, 40];
const STATUS_COMPLETED = 'Completed';

const EVENT_ID = "MIDBURN2017";
Expand Down Expand Up @@ -82,32 +82,36 @@ async function dumpDrupalTickets(session, date, page) {

var x = await r(options);
if (x.response) {

var tickets = JSON.parse(x.body);

if (!tickets) {
log.info("Didn't get ticket updates from Drupal");
return null;
}
log.info("got " + tickets.length + " tickets");

var utickets = [];

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)) {
var uticket = {};
uticket['holder_email'] = ticket['Email'];
uticket['buyer_email'] = ticket['Buyer E-mail'];
uticket['name'] = ticket['Name'];
uticket['id'] = ticket['Docment id'];
uticket['order_id'] = ticket['users_ticket_registration_uid'];
uticket['ticket_id'] = ticket['Ticket number'];
uticket['ticket_number'] = ticket['Ticket number'];
uticket['barcode'] = ticket['ticket barcode']['value'];
uticket['ticket_type'] = ticket['user_ticket_type_name'];
utickets.push(uticket);
utickets.push({
'id' : ticket['Docment id'],
'holder_email' : ticket['Email'],
'buyer_email' : ticket['Buyer E-mail'],
'name' : ticket['Name'],
'order_id' : ticket['users_ticket_registration_uid'],
'ticket_id' : ticket['Ticket number'],
'ticket_number' : ticket['Ticket number'],
'barcode' : ticket['ticket barcode']['value'],
'ticket_type' : ticket['user_ticket_type_name']
});
}
}
return utickets;
return [utickets, tickets.length];
}
else {
log.warn("Ticket dump failed");
Expand Down Expand Up @@ -241,12 +245,13 @@ async function syncTickets(fromDate, callback) {
var running = true;
while (running) {
log.info("Page:", page);
var tickets = await dumpDrupalTickets(session, fromDate, page);
if (tickets.length > 0) {
var [tickets, resultCount] = await dumpDrupalTickets(session, fromDate, page);
if (resultCount > 0) {
await updateAllTickets(tickets);
page++;
}
else {
log.info(`FINISH SYNC TICKETS page:${page}`);
running = false;
}
}
Expand Down
Loading

0 comments on commit 42d846c

Please sign in to comment.