fix major bug in json db

This commit is contained in:
2023-08-26 09:58:19 +02:00
parent 97183cb304
commit c128b18418
3 changed files with 7 additions and 8 deletions

View File

@@ -1 +1 @@
{} {"db":{"libreevent_temp":{},"libreevent_admin":{},"libreevent_orders":{},"libreevent_users":{"1":{"email":"info@janishutz.com","pass":"$2b$10$HeW7Z2q9kAKkzIsdsiIQ3ea9bUPiloENZXblBJQUJCE697iG/2n2e","first_name":"t","name":"t","two_fa":"","user_data":"{\"country\":\"t\"}","marketing":null,"mail_confirmed":"true"}}},"index":{"libreevent_temp":0,"libreevent_admin":0,"libreevent_orders":0,"libreevent_users":1}}

View File

@@ -24,7 +24,6 @@ class JSONDB {
this.dbIndex = data[ 'index' ] ?? { 'libreevent_temp': 0, 'libreevent_admin': 0, 'libreevent_orders': 0, 'libreevent_users': 0 }; this.dbIndex = data[ 'index' ] ?? { 'libreevent_temp': 0, 'libreevent_admin': 0, 'libreevent_orders': 0, 'libreevent_users': 0 };
this.db[ 'libreevent_temp' ] = {}; this.db[ 'libreevent_temp' ] = {};
this.saveToDisk(); this.saveToDisk();
console.log( this.db );
console.log( '[ JSON-DB ] Database initialized successfully' ); console.log( '[ JSON-DB ] Database initialized successfully' );
return 'connection'; return 'connection';
} }
@@ -42,8 +41,6 @@ class JSONDB {
fs.writeFile( path.join( __dirname + '/data/db.json' ), JSON.stringify( { 'db': this.db, 'index': this.dbIndex } ), ( err ) => { fs.writeFile( path.join( __dirname + '/data/db.json' ), JSON.stringify( { 'db': this.db, 'index': this.dbIndex } ), ( err ) => {
if ( err ) console.error( '[ JSON-DB ] An error occurred during saving: ' + err ); if ( err ) console.error( '[ JSON-DB ] An error occurred during saving: ' + err );
this.isSaving = false; this.isSaving = false;
console.log( 'afterSaving' );
console.log( this.db );
if ( this.awaitingSaving ) { if ( this.awaitingSaving ) {
this.saveToDisk(); this.saveToDisk();
} }
@@ -129,11 +126,9 @@ class JSONDB {
} else if ( operation.command === 'updateData' ) { } else if ( operation.command === 'updateData' ) {
if ( !operation.property || !operation.searchQuery ) reject( 'Refusing to run destructive command: Missing Constraints' ); if ( !operation.property || !operation.searchQuery ) reject( 'Refusing to run destructive command: Missing Constraints' );
else { else {
console.log( operation );
for ( let entry in this.db[ table ] ) { for ( let entry in this.db[ table ] ) {
if ( this.db[ table ][ entry ][ operation.property ] == operation.searchQuery ) { if ( this.db[ table ][ entry ][ operation.property ] == operation.searchQuery ) {
for ( let changed in operation.newValues ) { for ( let changed in operation.newValues ) {
console.log( this.db[ table ][ entry ] );
this.db[ table ][ entry ][ changed ] = operation.newValues[ changed ]; this.db[ table ][ entry ][ changed ] = operation.newValues[ changed ];
} }
} }

View File

@@ -26,8 +26,12 @@ module.exports = ( app, settings ) => {
if ( request.session.loggedInUser ) { if ( request.session.loggedInUser ) {
db.getDataSimple( 'users', 'email', request.session.username ).then( data => { db.getDataSimple( 'users', 'email', request.session.username ).then( data => {
if ( data[ 0 ] ) { if ( data[ 0 ] ) {
let dat = data[ 0 ]; let dat = {};
delete dat[ 'pass' ]; for ( let element in data[ 0 ] ) {
if ( element === 'pass' ) {
dat[ element ] = data[ 0 ][ element ];
}
}
response.send( { 'data': dat, 'status': true } ); response.send( { 'data': dat, 'status': true } );
} else { } else {
response.status( 404 ).send( { 'data': 'This user does not exist', 'status': false } ); response.status( 404 ).send( { 'data': 'This user does not exist', 'status': false } );