mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 05:14:23 +00:00
db + saving of reserved tickets
This commit is contained in:
@@ -14,22 +14,46 @@ class POSTHandler {
|
||||
|
||||
}
|
||||
|
||||
handleCall ( call, data, lang ) {
|
||||
handleCall ( call, data, lang, session ) {
|
||||
return new Promise( ( resolve, reject ) => {
|
||||
console.log( lang );
|
||||
if ( call === 'saveSeatplanDraft' ) {
|
||||
db.getJSONDataSimple( 'seatplan', data.location ).then( res => {
|
||||
let dat = res;
|
||||
dat[ 'draft' ] = data.data;
|
||||
db.writeJSONDataSimple( 'seatplan', data.location, dat ).then( resp => {
|
||||
resolve( resp );
|
||||
if ( call === 'reserveTicket' ) {
|
||||
db.getDataSimple( 'temp', 'user_id', session.id ).then( dat => {
|
||||
let transmit = {};
|
||||
if ( dat.length > 0 ) {
|
||||
transmit = JSON.parse( dat[ 0 ].data );
|
||||
} else {
|
||||
transmit[ data.eventID ] = {};
|
||||
}
|
||||
transmit[ data.eventID ][ data.id ] = data;
|
||||
db.writeDataSimple( 'temp', 'user_id', session.id, { 'user_id': session.id, 'data': JSON.stringify( transmit ), 'timestamp': new Date().toString() } ).then( ret => {
|
||||
resolve( ret );
|
||||
} ).catch( error => {
|
||||
reject( error );
|
||||
} );
|
||||
} ).catch( error => {
|
||||
reject( error );
|
||||
} );
|
||||
} else if ( call === 'deselectTicket' ) {
|
||||
db.getDataSimple( 'temp', 'user_id', session.id ).then( dat => {
|
||||
let transmit = JSON.parse( dat[ 0 ].data );
|
||||
if ( transmit[ data.eventID ] ) {
|
||||
if ( transmit[ data.eventID ][ data.id ] ) {
|
||||
delete transmit[ data.eventID ][ data.id ];
|
||||
} else {
|
||||
reject( 'ERR_DATA_NONE_EXISTENT' );
|
||||
}
|
||||
if ( Object.keys( transmit[ data.eventID ] ).length < 1 ) {
|
||||
delete transmit[ data.eventID ];
|
||||
}
|
||||
} else {
|
||||
reject( 'ERR_DATA_NONE_EXISTENT' );
|
||||
}
|
||||
db.writeDataSimple( 'temp', 'user_id', session.id, { 'user_id': session.id, 'data': JSON.stringify( transmit ) } ).then( ret => {
|
||||
resolve( ret );
|
||||
} ).catch( error => {
|
||||
reject( error );
|
||||
} );
|
||||
} else if ( call === 'saveSeatplan' ) {
|
||||
db.writeJSONDataSimple( 'seatplan', data.location, { 'draft': {}, 'save': data.data } ).then( resp => {
|
||||
resolve( resp );
|
||||
} ).catch( error => {
|
||||
reject( error );
|
||||
} );
|
||||
|
||||
@@ -12,7 +12,7 @@ const fs = require( 'fs' );
|
||||
|
||||
const settings = JSON.parse( fs.readFileSync( path.join( __dirname + '/../../config/settings.config.json' ) ) );
|
||||
|
||||
const dbRef = { 'user': 'libreevent_users', 'admin': 'libreevent_admin', 'order': 'libreevent_orders' };
|
||||
const dbRef = { 'user': 'libreevent_users', 'admin': 'libreevent_admin', 'order': 'libreevent_orders', 'users': 'libreevent_users', 'orders': 'libreevent_orders', 'temp': 'libreevent_temp' };
|
||||
|
||||
let dbh;
|
||||
|
||||
@@ -27,19 +27,35 @@ if ( settings.db === 'mysql' ) {
|
||||
}
|
||||
|
||||
module.exports.getDataSimple = ( db, column, searchQuery ) => {
|
||||
return new Promise( resolve => {
|
||||
return new Promise( ( resolve, reject ) => {
|
||||
dbh.query( { 'command': 'getFilteredData', 'property': column, 'searchQuery': searchQuery }, dbRef[ db ] ).then( data => {
|
||||
console.log( data );
|
||||
resolve( data );
|
||||
} ).catch( error => {
|
||||
console.error( error );
|
||||
reject( error );
|
||||
} );
|
||||
resolve( '$2b$05$ElMYWoMjk7567lXkIkee.e.6cxCrWU4gkfuNLB8gmGYLQQPm7gT3O' );
|
||||
// resolve( '$2b$05$ElMYWoMjk7567lXkIkee.e.6cxCrWU4gkfuNLB8gmGYLQQPm7gT3O' );
|
||||
} );
|
||||
};
|
||||
|
||||
module.exports.writeDataSimple = ( db, column, searchQuery ) => {
|
||||
module.exports.writeDataSimple = ( db, column, searchQuery, data ) => {
|
||||
return new Promise( ( resolve, reject ) => {
|
||||
|
||||
dbh.query( { 'command': 'checkDataAvailability', 'property': column, 'searchQuery': searchQuery }, dbRef[ db ] ).then( res => {
|
||||
if ( res.length > 0 ) {
|
||||
dbh.query( { 'command': 'updateData', 'property': column, 'searchQuery': searchQuery, 'newValues': data }, dbRef[ db ] ).then( dat => {
|
||||
resolve( dat );
|
||||
} ).catch( error => {
|
||||
reject( error );
|
||||
} );
|
||||
} else {
|
||||
dbh.query( { 'command': 'addData', 'data': data }, dbRef[ db ] ).then( dat => {
|
||||
resolve( dat );
|
||||
} ).catch( error => {
|
||||
reject( error );
|
||||
} );
|
||||
}
|
||||
} ).catch( error => {
|
||||
reject( error );
|
||||
} );
|
||||
} );
|
||||
};
|
||||
|
||||
|
||||
@@ -61,8 +61,9 @@ class SQLDB {
|
||||
if ( error ) if ( error.code !== 'ER_TABLE_EXISTS_ERROR' ) throw error;
|
||||
this.sqlConnection.query( 'CREATE TABLE libreevent_admin ( account_id INT NOT NULL AUTO_INCREMENT, email TINYTEXT, pass TEXT, permissions VARCHAR( 1000 ), PRIMARY KEY ( account_id ) );', ( error ) => {
|
||||
if ( error ) if ( error.code !== 'ER_TABLE_EXISTS_ERROR' ) throw error;
|
||||
this.sqlConnection.query( 'CREATE TABLE libreevent_temp ( entry_id INT NOT NULL AUTO_INCREMENT, user_id TINYTEXT, pass TEXT, data VARCHAR( 60000 ), PRIMARY KEY ( entry_id ) );', ( error ) => {
|
||||
this.sqlConnection.query( 'CREATE TABLE libreevent_temp ( entry_id INT NOT NULL AUTO_INCREMENT, user_id TINYTEXT, data VARCHAR( 60000 ), timestamp TINYTEXT, PRIMARY KEY ( entry_id ) );', ( error ) => {
|
||||
if ( error ) if ( error.code !== 'ER_TABLE_EXISTS_ERROR' ) throw error;
|
||||
return 'DONE';
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
@@ -101,8 +102,7 @@ class SQLDB {
|
||||
- operation.matchingParam (Which properties should be matched to get the data, e.g. order.user_id=users.id)
|
||||
|
||||
- addData:
|
||||
- operation.columns (the columns into which the data should be inserted (as a space separated string))
|
||||
- operation.values (the data to be inserted into the columns selected before (as a space separated string))
|
||||
- operation.data (key-value pair with all data as values and column to insert into as key)
|
||||
|
||||
- updateData:
|
||||
- operation.newValues (a object with keys being the column and value being the value to be inserted into that column, values are being
|
||||
@@ -125,14 +125,22 @@ class SQLDB {
|
||||
} else if ( operation.command === 'fullCustomCommand' ) {
|
||||
command = operation.query;
|
||||
} else if ( operation.command === 'addData' ) {
|
||||
command = 'INSERT INTO ' + table + ' (' + operation.columns + ') VALUES (' + this.sqlConnection.escape( operation.values ) + ');';
|
||||
let keys = '';
|
||||
let values = '';
|
||||
for ( let key in operation.data ) {
|
||||
keys += String( key ) + ', ';
|
||||
values += this.sqlConnection.escape( String( operation.data[ key ] ) ) + ', ' ;
|
||||
}
|
||||
command = 'INSERT INTO ' + table + ' (' + keys.slice( 0, keys.length - 2 ) + ') VALUES (' + values.slice( 0, values.length - 2 ) + ');';
|
||||
} else if ( operation.command === 'updateData' ) {
|
||||
if ( !operation.property || !operation.searchQuery ) reject( 'Refusing to run destructive command: Missing Constraints' );
|
||||
else {
|
||||
command = 'UPDATE ' + table + ' SET ';
|
||||
let updatedValues = '';
|
||||
for ( let value in operation.newValues ) {
|
||||
command += value + ' = ' + this.sqlConnection.escape( operation.newValues[ value ] );
|
||||
updatedValues += value + ' = ' + this.sqlConnection.escape( operation.newValues[ value ] ) + ', ';
|
||||
}
|
||||
command += updatedValues.slice( 0, updatedValues.length - 2 );
|
||||
command += ' WHERE ' + operation.property + ' = ' + this.sqlConnection.escape( operation.searchQuery );
|
||||
}
|
||||
} else if ( operation.command === 'deleteData' ) {
|
||||
|
||||
@@ -26,7 +26,7 @@ module.exports = ( app ) => {
|
||||
} );
|
||||
|
||||
app.post( '/API/:call', ( req, res ) => {
|
||||
postHandler.handleCall( req.params.call, req.body, req.query.lang ).then( data => {
|
||||
postHandler.handleCall( req.params.call, req.body, req.query.lang, req.session ).then( data => {
|
||||
res.send( data );
|
||||
} ).catch( error => {
|
||||
res.status( 500 ).send( error );
|
||||
|
||||
6
src/server/prepareDB.js
Normal file
6
src/server/prepareDB.js
Normal file
@@ -0,0 +1,6 @@
|
||||
const sql = require( './backend/db/mysqldb.js' );
|
||||
const sqlDB = new sql();
|
||||
|
||||
sqlDB.connect();
|
||||
// sqlDB.resetDB();
|
||||
sqlDB.setupDB();
|
||||
@@ -317,13 +317,41 @@
|
||||
if ( option.status == 'ok' ) {
|
||||
this.$refs[ 'component' + this.selectedSeat.componentID ][ 0 ].validateSeatSelection( this.selectedSeat, option.data );
|
||||
this.cartHandling( 'select', option.data );
|
||||
|
||||
// Make call to server to reserve ticket to have server also keep track of reserved tickets
|
||||
const options = {
|
||||
method: 'post',
|
||||
body: JSON.stringify( { 'id': this.selectedSeat[ 'id' ], 'component': this.selectedSeat[ 'componentID' ], 'ticketOption': option.data, 'eventID': this.event.name } ),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'charset': 'utf-8'
|
||||
}
|
||||
};
|
||||
fetch( localStorage.getItem( 'url' ) + '/API/reserveTicket', options ).then( res => {
|
||||
res.text().then( text => {
|
||||
console.log( text );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
// TODO: Make call to server to reserve ticket when data is returned
|
||||
},
|
||||
seatDeselected ( seat ) {
|
||||
this.selectedSeat = seat;
|
||||
this.cartHandling( 'deselect' );
|
||||
// TODO: Make call to server to deselect ticket
|
||||
|
||||
// Make call to server to deselect ticket
|
||||
const options = {
|
||||
method: 'post',
|
||||
body: JSON.stringify( { 'id': seat[ 'id' ], 'eventID': this.event.name } ),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'charset': 'utf-8'
|
||||
}
|
||||
};
|
||||
fetch( localStorage.getItem( 'url' ) + '/API/deselectTicket', options ).then( res => {
|
||||
res.text().then( text => {
|
||||
console.log( text );
|
||||
} );
|
||||
} );
|
||||
},
|
||||
standing ( id ) {
|
||||
const d = this.draggables[ id ];
|
||||
|
||||
Reference in New Issue
Block a user