make payment processing more robust

This commit is contained in:
2023-10-15 08:02:02 +02:00
parent 9b6fd1355e
commit a679c5915e
7 changed files with 64 additions and 23 deletions

View File

@@ -12,7 +12,15 @@ 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', 'users': 'libreevent_users', 'orders': 'libreevent_orders', 'temp': 'libreevent_temp' };
const dbRef = {
'user': 'libreevent_users',
'admin': 'libreevent_admin',
'order': 'libreevent_orders',
'users': 'libreevent_users',
'orders': 'libreevent_orders',
'temp': 'libreevent_temp',
'processingOrders': 'libreevent_processing_orders'
};
const letters = [ ',', '{' ];

View File

@@ -13,7 +13,7 @@ const path = require( 'path' );
class JSONDB {
constructor () {
this.db = {};
this.dbIndex = { 'libreevent_temp': 0, 'libreevent_admin': 0, 'libreevent_orders': 0, 'libreevent_users': 0 };
this.dbIndex = { 'libreevent_temp': 0, 'libreevent_admin': 0, 'libreevent_orders': 0, 'libreevent_users': 0, 'libreevent_processing_orders': 0 };
this.isSaving = false;
this.awaitingSaving = true;
}
@@ -26,8 +26,8 @@ class JSONDB {
console.error( '[ JSON-DB ] CRITICAL INITIALIZATION FAILURE!' + err );
throw ( 'JSONDB failed to start!' );
}
this.db = data[ 'db' ] ?? { 'libreevent_temp': {}, 'libreevent_admin': {}, 'libreevent_orders': {}, 'libreevent_users': {} };
this.dbIndex = data[ 'index' ] ?? { 'libreevent_temp': 0, 'libreevent_admin': 0, 'libreevent_orders': 0, 'libreevent_users': 0 };
this.db = data[ 'db' ] ?? { 'libreevent_temp': {}, 'libreevent_admin': {}, 'libreevent_orders': {}, 'libreevent_users': {}, 'libreevent_processing_orders': {} };
this.dbIndex = data[ 'index' ] ?? { 'libreevent_temp': 0, 'libreevent_admin': 0, 'libreevent_orders': 0, 'libreevent_users': 0, 'libreevent_processing_orders': 0 };
this.db[ 'libreevent_temp' ] = {};
this.saveToDisk();
console.log( '[ JSON-DB ] Database initialized successfully' );
@@ -54,14 +54,14 @@ class JSONDB {
}
async resetDB () {
this.db = { 'libreevent_temp': {}, 'libreevent_admin': {}, 'libreevent_orders': {}, 'libreevent_users': {} };
this.dbIndex = { 'libreevent_temp': 0, 'libreevent_admin': 0, 'libreevent_orders': 0, 'libreevent_users': 0 };
this.db = { 'libreevent_temp': {}, 'libreevent_admin': {}, 'libreevent_orders': {}, 'libreevent_users': {}, 'libreevent_processing_orders': {} };
this.dbIndex = { 'libreevent_temp': 0, 'libreevent_admin': 0, 'libreevent_orders': 0, 'libreevent_users': 0, 'libreevent_processing_orders': 0 };
fs.writeFile( path.join( __dirname + '/../../data/db.json' ), JSON.stringify( { 'db': this.db, 'index': this.dbIndex } ) );
}
async setupDB () {
this.db = { 'libreevent_temp': {}, 'libreevent_admin': {}, 'libreevent_orders': {}, 'libreevent_users': {} };
this.dbIndex = { 'libreevent_temp': 0, 'libreevent_admin': 0, 'libreevent_orders': 0, 'libreevent_users': 0 };
this.db = { 'libreevent_temp': {}, 'libreevent_admin': {}, 'libreevent_orders': {}, 'libreevent_users': {}, 'libreevent_processing_orders': {} };
this.dbIndex = { 'libreevent_temp': 0, 'libreevent_admin': 0, 'libreevent_orders': 0, 'libreevent_users': 0, 'libreevent_processing_orders': 0 };
fs.writeFile( path.join( __dirname + '/../../data/db.json' ), JSON.stringify( { 'db': this.db, 'index': this.dbIndex } ) );
}

View File

@@ -51,7 +51,10 @@ class SQLDB {
if ( error ) if ( error.code !== 'ER_BAD_TABLE_ERROR' ) throw error;
this.sqlConnection.query( 'DROP TABLE libreevent_temp;', ( error ) => {
if ( error ) if ( error.code !== 'ER_BAD_TABLE_ERROR' ) throw error;
return 'done';
this.sqlConnection.query( 'DROP TABLE libreevent_processing_orders;', ( error ) => {
if ( error ) if ( error.code !== 'ER_BAD_TABLE_ERROR' ) throw error;
return 'done';
} );
} );
} );
} );
@@ -71,7 +74,10 @@ class SQLDB {
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, data VARCHAR( 60000 ), timestamp TINYTEXT, PRIMARY KEY ( entry_id ) );', ( error ) => {
if ( error ) if ( error.code !== 'ER_TABLE_EXISTS_ERROR' ) throw error;
return 'DONE';
this.sqlConnection.query( 'CREATE TABLE libreevent_processing_orders ( 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';
} );
} );
} );
} );