Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added number of tickets. Fixes #623 #647

Merged
merged 1 commit into from
Feb 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions libs/drupal_access.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const NodeCache = require("node-cache");
const drupalCache = new NodeCache({ stdTTL: drupalConfig.cacheTTL, checkperiod: 600 });

function parseFromAnchorTag(uid_string) {
var re = /<a.*>(.+)<\/a>/g;
m = re.exec(uid_string);
let re = /<a.*>(.+)<\/a>/g;
let m = re.exec(uid_string);
re.lastIndex = 0;
if (m.length === 2) {
return m[1];
Expand All @@ -17,18 +17,30 @@ function parseFromAnchorTag(uid_string) {
}
}

function parseTicketsCount(tickets_str) {
let re = /tickets string:(.*)/g;
let m = re.exec(tickets_str);
re.lastIndex = 0;
if (m.length === 2) {
let ticketsArr = JSON.parse(m[1]);
return ticketsArr.length;
}
else return 0;

}

function parseUser(res_body) {
if (res_body.length === 0 || !res_body[0]) {
return undefined
}

return {
last_name: res_body[0]['Last name'],
first_name: res_body[0]['First name'],
uid: res_body[0]['uid'],
email: parseFromAnchorTag(res_body[0]['E-mail']),
phone: res_body[0]['Phone number'],
has_ticket: res_body[0]['PHP'] !== "tickets string:[]"
has_ticket: res_body[0]['PHP'] !== "tickets string:[]",
num_of_tickets: parseTicketsCount(res_body[0]['PHP'])
};
}

Expand Down