mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 05:14:23 +00:00
prepare for rewrite of ticket counting
This commit is contained in:
@@ -16,6 +16,8 @@ class POSTHandler {
|
|||||||
constructor () {
|
constructor () {
|
||||||
this.loadData();
|
this.loadData();
|
||||||
|
|
||||||
|
this.temporarilySelected = {};
|
||||||
|
this.temporarilySelectedTotals = {};
|
||||||
this.settings = JSON.parse( fs.readFileSync( path.join( __dirname + '/../../config/settings.config.json' ) ) );
|
this.settings = JSON.parse( fs.readFileSync( path.join( __dirname + '/../../config/settings.config.json' ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +53,7 @@ class POSTHandler {
|
|||||||
handleCall ( call, data, session ) {
|
handleCall ( call, data, session ) {
|
||||||
return new Promise( ( resolve, reject ) => {
|
return new Promise( ( resolve, reject ) => {
|
||||||
if ( call === 'reserveTicket' ) {
|
if ( call === 'reserveTicket' ) {
|
||||||
|
// TODO: probably rewrite from scratch
|
||||||
if ( data.count || data.count === 0 ) {
|
if ( data.count || data.count === 0 ) {
|
||||||
db.getDataSimple( 'temp', 'user_id', session.id ).then( dat => {
|
db.getDataSimple( 'temp', 'user_id', session.id ).then( dat => {
|
||||||
if ( dat[ 0 ] ) {
|
if ( dat[ 0 ] ) {
|
||||||
@@ -101,6 +104,11 @@ class POSTHandler {
|
|||||||
}
|
}
|
||||||
if ( maxTickets > 0 ) {
|
if ( maxTickets > 0 ) {
|
||||||
db.writeDataSimple( 'temp', 'user_id', session.id, { 'user_id': session.id, 'timestamp': new Date().toString(), 'data': JSON.stringify( info ) } );
|
db.writeDataSimple( 'temp', 'user_id', session.id, { 'user_id': session.id, 'timestamp': new Date().toString(), 'data': JSON.stringify( info ) } );
|
||||||
|
this.temporarilySelected[ id ] = info;
|
||||||
|
if ( !this.temporarilySelectedTotals[ data.eventID ] ) {
|
||||||
|
this.ticketTotals[ data.eventID ] = 0;
|
||||||
|
}
|
||||||
|
this.ticketTotals[ data.eventID ] -= ticketCount;
|
||||||
resolve( { 'status': 'ok', 'ticketCount': ticketCount } );
|
resolve( { 'status': 'ok', 'ticketCount': ticketCount } );
|
||||||
} else {
|
} else {
|
||||||
reject( { 'code': 409, 'message': 'ERR_ALL_OCCUPIED' } );
|
reject( { 'code': 409, 'message': 'ERR_ALL_OCCUPIED' } );
|
||||||
@@ -117,6 +125,8 @@ class POSTHandler {
|
|||||||
}
|
}
|
||||||
if ( maxTickets > 0 ) {
|
if ( maxTickets > 0 ) {
|
||||||
db.writeDataSimple( 'temp', 'user_id', session.id, { 'user_id': session.id, 'timestamp': new Date().toString(), 'data': JSON.stringify( info ) } );
|
db.writeDataSimple( 'temp', 'user_id', session.id, { 'user_id': session.id, 'timestamp': new Date().toString(), 'data': JSON.stringify( info ) } );
|
||||||
|
this.allSelectedSeats[ data.id ] = info;
|
||||||
|
this.ticketTotals[ data.eventID ] -= ticketCount;
|
||||||
resolve( { 'status': 'ok', 'ticketCount': ticketCount } );
|
resolve( { 'status': 'ok', 'ticketCount': ticketCount } );
|
||||||
} else {
|
} else {
|
||||||
reject( { 'code': 409, 'message': 'ERR_ALL_OCCUPIED' } );
|
reject( { 'code': 409, 'message': 'ERR_ALL_OCCUPIED' } );
|
||||||
@@ -140,6 +150,7 @@ class POSTHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ( call === 'deselectTicket' ) {
|
} else if ( call === 'deselectTicket' ) {
|
||||||
|
// TODO: probably rewrite from scratch
|
||||||
db.getDataSimple( 'temp', 'user_id', session.id ).then( dat => {
|
db.getDataSimple( 'temp', 'user_id', session.id ).then( dat => {
|
||||||
let transmit = {};
|
let transmit = {};
|
||||||
if ( dat[ 0 ] ) {
|
if ( dat[ 0 ] ) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ module.exports = ( app, settings ) => {
|
|||||||
}
|
}
|
||||||
res.send( dat );
|
res.send( dat );
|
||||||
} else if ( req.params.call === 'reloadData' ) {
|
} else if ( req.params.call === 'reloadData' ) {
|
||||||
if ( req.session.loggedInAdmin ) {
|
if ( req.session.loggedInAdmin || req.session.loggedInUser ) {
|
||||||
postHandler.loadData();
|
postHandler.loadData();
|
||||||
res.send( 'ok' );
|
res.send( 'ok' );
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user