cleaning package and replace jsonfile by fs-extra

This commit is contained in:
2023-02-22 08:00:08 +01:00
parent 559ead2f11
commit a03e35c9e2
11 changed files with 67 additions and 213 deletions

View File

@@ -1,13 +1,9 @@
const fs = require( 'fs-extra' );
const jsonfile = require( 'jsonfile' );
const glob = require( 'glob' );
const path = require( 'path' );
const moment = require( 'moment' );
const axios = require( 'axios' );
const scrapeit = require( 'scrape-it' );
const cheerio = require( 'cheerio' );
const Mustache = require( 'mustache' );
const qrcode = require( 'qrcode' );
// Check if package is installed or not to pickup the right config file
@@ -62,14 +58,14 @@ Contracts.initActiontodo = async ( envoie ) => {
nbactionerr: 0,
actionlist: ""
};
const listclient = jsonfile.readFileSync( `${config.tribes}/tribeids.json` );
const listclient = fs.readJsonSync( `${config.tribes}/tribeids.json` );
for( let clid in listclient ) {
console.log( listclient[ clid ] );
let listaction = glob.sync( `${config.tribes}/${listclient[clid]}/actions/todo/*.json` );
for( let action in listaction ) {
console.log( listaction[ action ] )
log.nbaction++;
todo = jsonfile.readFileSync( listaction[ action ] );
todo = fs.readJsonSync( listaction[ action ] );
let passdate = true;
// currentdate doit etre après la startDate si existe et avant valideuntilDate si existe
// console.log('test now est avant date start ', moment() < moment(todo.startDate, 'YYYYMMDD HH:mm:ss').toDate());
@@ -99,12 +95,12 @@ Contracts.initActiontodo = async ( envoie ) => {
};
if( parseInt( todo.maxnumberoftime ) && todo.maxnumberoftime != "999" && ( todo.datesRun.length >= parseInt( todo.maxnumberoftime ) ) ) {
//archive en done this triggeraction
jsonfile.writeFileSync( listaction[ action ].replace( '/todo/', '/done/' ), todo, {
fs.outputJsonSync( listaction[ action ].replace( '/todo/', '/done/' ), todo, {
spaces: 2
} );
fs.unlinkSync( listaction[ action ] );
} else {
jsonfile.writeFileSync( listaction[ action ], todo, {
fs.outputJsonSync( listaction[ action ], todo, {
spaces: 2
} );
}

View File

@@ -324,7 +324,7 @@ Messages.request = ( tribeid, uuid, ACCESSRIGHTS, apprequest ) => {
Messages.aggregate();
//for test purpose
//const notif = jsonfile.readFileSync( `${config.tribes}/ndda/spacedev/mesa/src/static/components/notification/data_notiflist_fr.json` );
//const notif = fs.readJsonSync( `${config.tribes}/ndda/spacedev/mesa/src/static/components/notification/data_notiflist_fr.json` );
let notif;
if( !fs.existsSync( `${config.tribes}/${apprequest.tribeid}/spacedev/${apprequest.website}/src/static/components/notification/data_notiflist_${apprequest.lang}.json` ) ) {
// by default we send back this but this highlght an issue
@@ -345,7 +345,7 @@ Messages.request = ( tribeid, uuid, ACCESSRIGHTS, apprequest ) => {
} ]
};
} else {
notif = jsonfile.readFileSync( `${config.tribes}/${apprequest.tribeid}/spacedev/${apprequest.website}/src/static/components/notification/data_notiflist_${apprequest.lang}.json` );
notif = fs.readJsonSync( `${config.tribes}/${apprequest.tribeid}/spacedev/${apprequest.website}/src/static/components/notification/data_notiflist_${apprequest.lang}.json` );
//clean up example notif
notif.notifs = [];
}

View File

@@ -178,10 +178,10 @@ Outputs.generemsg = async ( msg, header ) => {
// Recupere les parametre smtp du domainName à utiliser
console.log( 'pass Outputs.generemsg' )
try {
const confclientexpediteur = jsonfile.readFileSync( `${config.tribes}/${msg.tribeidperso.tribeidexpediteur}/clientconf.json` );
const confclientexpediteur = fs.readJsonSync( `${config.tribes}/${msg.tribeidperso.tribeidexpediteur}/clientconf.json` );
//console.log('expediteur', confclientexpediteur);
msg.smtp = confclientexpediteur.smtp;
/* const confclient = jsonfile.readFileSync(
/* const confclient = fs.readJsonSync(
`${config.tribes}/${msg.tribeidperso.tribeid}/clientconf.json`
);*/
} catch ( err ) {
@@ -433,7 +433,7 @@ Outputs.addjson = function ( data, header ) {
*/
// console.log(req.body.jsonp);
try {
jsonfile.writeFileSync( header.destinationfile + '/' + header.filename, data.jsonp );
fs.outputJsonSync( header.destinationfile + '/' + header.filename, data.jsonp );
if( data.callback ) {
const execCB = require( `${config.mainDir}/models/tribeid/${header.xworkon
}` );

View File

@@ -147,7 +147,7 @@ Outputs.generemsg = async ( msg, header ) => {
// Recupere les parametre smtp du domainName à utiliser
console.log( 'pass Outputs.generemsg' )
try {
const confclientexpediteur = jsonfile.readFileSync( `${config.tribes}/${msg.tribeidperso.tribeidexpediteur}/clientconf.json` );
const confclientexpediteur = fs.readJsonSync( `${config.tribes}/${msg.tribeidperso.tribeidexpediteur}/clientconf.json` );
msg.smtp = confclientexpediteur.smtp;
} catch ( err ) {
console.log( 'la conf smtp du client n\'est pas definie' );
@@ -348,7 +348,7 @@ Outputs.addjson = function ( data, header ) {
*/
// console.log(req.body.jsonp);
try {
jsonfile.writeFileSync( header.destinationfile + '/' + header.filename, data.jsonp );
fs.outputJsonSync( header.destinationfile + '/' + header.filename, data.jsonp );
if( data.callback ) {
const execCB = require( `${config.mainDir}/models/tribeid/${header.xworkon
}` );

View File

@@ -141,7 +141,7 @@ Pagans.updateDatabase = ( user, tribeid, rm = false ) => {
console.group( `Pagans.updateDatabase for ${tribeid} with user ${user.LOGIN}` )
console.assert( config.loglevel == "quiet", 'user', user );
const loginsIndex = `${config.tribes}/${tribeid}/users/searchindex/logins.json`;
jsonfile.readFile( loginsIndex, function ( err, logins ) {
fs.readJson( loginsIndex, function ( err, logins ) {
console.assert( config.loglevel == "quiet", 'logins', logins );
try {
if( rm ) {
@@ -149,7 +149,7 @@ Pagans.updateDatabase = ( user, tribeid, rm = false ) => {
} else {
logins[ user.LOGIN ] = user.UUID;
}
jsonfile.writeFile( loginsIndex, logins, {
fs.outputJson( loginsIndex, logins, {
spaces: 2
}, err => {
if( err ) console.log( err );
@@ -159,7 +159,7 @@ Pagans.updateDatabase = ( user, tribeid, rm = false ) => {
}
} );
const uidsIndex = `${config.tribes}/${tribeid}/users/searchindex/uids.json`;
jsonfile.readFile( uidsIndex, function ( err, uids ) {
fs.readJson( uidsIndex, function ( err, uids ) {
try {
if( rm ) {
delete uids[ user.UUID ];
@@ -172,7 +172,7 @@ Pagans.updateDatabase = ( user, tribeid, rm = false ) => {
user.TOKEN
];
}
jsonfile.writeFile( uidsIndex, uids, {
fs.outputJson( uidsIndex, uids, {
spaces: 2
}, err => {
if( err ) console.log( err );
@@ -182,7 +182,7 @@ Pagans.updateDatabase = ( user, tribeid, rm = false ) => {
}
} );
const emailsIndex = `${config.tribes}/${tribeid}/users/searchindex/emails.json`;
jsonfile.readFile( emailsIndex, function ( err, emails ) {
fs.readJson( emailsIndex, function ( err, emails ) {
console.assert( config.loglevel == "quiet", 'emailss', emails );
try {
if( rm ) {
@@ -190,7 +190,7 @@ Pagans.updateDatabase = ( user, tribeid, rm = false ) => {
} else {
emails[ user.EMAIL ] = user.UUID;
}
jsonfile.writeFile( emailsIndex, emails, {
fs.outputJson( emailsIndex, emails, {
spaces: 2
}, err => {
if( err ) console.log( err );
@@ -202,19 +202,19 @@ Pagans.updateDatabase = ( user, tribeid, rm = false ) => {
const tokensIndex = `${config.tmp}/tokens.json`;
let tokens = {};
try {
tokens = jsonfile.readFileSync( tokensIndex );
tokens = fs.readJsonSync( tokensIndex );
} catch ( err ) {
console.log( 'tokens.json not available' )
}
// tokens[user.UUID] = user.TOKEN;
tokens[ user.UUID ] = { TOKEN: user.TOKEN, ACCESSRIGHTS: user.ACCESSRIGHTS };
jsonfile.writeFileSync( tokensIndex, tokens, {
fs.outputJsonSync( tokensIndex, tokens, {
spaces: 2
} );
/*
jsonfile.readFile(tokensIndex, function(err, tokens) {
fs.readJson(tokensIndex, function(err, tokens) {
tokens[user.UUID] = user.TOKEN;
jsonfile.writeFile(tokensIndex, tokens, { spaces: 2 }, err => {
fs.outputJson(tokensIndex, tokens, { spaces: 2 }, err => {
if (err) console.log(err);
});
});*/
@@ -254,7 +254,7 @@ Pagans.getUserlist = ( header, filter, field ) => {
const Userlist = [];
glob.sync( `${config.tribes}/${header.xworkon}/users/*/profil.json` )
.forEach( f => {
const infouser = jsonfile.readFileSync( f );
const infouser = fs.readJsonSync( f );
// Ajouter filter et liste de field
if( filter != 'all' ) {
// decode filter et test
@@ -283,7 +283,7 @@ Pagans.getinfoPagans = ( tribeid, accessrights, listindex ) => {
indexs.forEach( index => {
access = !( [ 'emails', 'logins', 'uids' ].includes( index ) && !( accessrights.data[ object ] && accessrights.data[ object ].includes( 'R' ) ) );
if( access && fs.existsSync( `${config.tribes}/${tribeid}/${object}/searchindex/${index}.json` ) ) {
info[ index ] = jsonfile.readFileSync( `${config.tribes}/${tribeid}/${object}/searchindex/${index}.json` )
info[ index ] = fs.readJsonSync( `${config.tribes}/${tribeid}/${object}/searchindex/${index}.json` )
}
} )
console.log( info )
@@ -304,7 +304,7 @@ Pagans.getUser = ( UUID, tribeid, accessrights ) => {
}
}
}
const user = jsonfile.readFileSync( `${config.tribes}/${tribeid}/users/${UUID}.json` );
const user = fs.readJsonSync( `${config.tribes}/${tribeid}/users/${UUID}.json` );
let access = true;
//console.log("test accessrights.data['users'].includes('R')", accessrights.data['users'].includes('R'))
console.assert( config.loglevel == "quiet", 'accessrights', accessrights )
@@ -341,7 +341,7 @@ Pagans.getUserIdFromEMAIL = ( tribeid, EMAIL ) => {
}
};
}
const emailsIndex = jsonfile.readFileSync( `${config.tribes}/${tribeid}/users/searchindex/emails.json` );
const emailsIndex = fs.readJsonSync( `${config.tribes}/${tribeid}/users/searchindex/emails.json` );
if( !emailsIndex.hasOwnProperty( EMAIL ) ) {
return {
status: 404,
@@ -371,7 +371,7 @@ Pagans.updateUserpassword = ( UUID, header, data ) => {
// console.log('Credentials are matching!');
if( checkdata.test.password( {}, data.pswnew ) ) {
user.PASSWORD = bcrypt.hashSync( data.pswnew, config.saltRounds );
jsonfile.writeFileSync( `${config.tribes}/${header.xworkon}/users/${UUID}.json`, user, {
fs.outputJsonSync( `${config.tribes}/${header.xworkon}/users/${UUID}.json`, user, {
spaces: 2
} );
Pagans.updateDatabase( user, header.xworkon, false );
@@ -399,11 +399,11 @@ Pagans.createUser = ( header, data ) => {
*/
console.log( 'createUser on header.xworkon:' + header.xworkon + ' by user:' + header.xpaganid );
console.assert( config.loglevel == "quiet", 'with data:', data );
const ref = jsonfile.readFileSync( `${config.tribes}/${header.xworkon}/referentials/${header.xlang}/object/users.json` );
const logins = jsonfile.readFileSync( `${config.tribes}/${header.xworkon}/users/searchindex/logins.json` );
const ref = fs.readJsonSync( `${config.tribes}/${header.xworkon}/referentials/${header.xlang}/object/users.json` );
const logins = fs.readJsonSync( `${config.tribes}/${header.xworkon}/users/searchindex/logins.json` );
const LOGIN = Object.keys( logins );
console.assert( config.loglevel == "quiet", 'LOGIN list', LOGIN );
const emails = jsonfile.readFileSync( `${config.tribes}/${header.xworkon}/users/searchindex/emails.json` );
const emails = fs.readJsonSync( `${config.tribes}/${header.xworkon}/users/searchindex/emails.json` );
console.assert( config.loglevel == "quiet", 'emails', emails );
const EMAIL = Object.keys( emails );
console.assert( config.loglevel == "quiet", 'EMAIL list', EMAIL );
@@ -427,7 +427,7 @@ Pagans.createUser = ( header, data ) => {
}
};
}
const clientConfig = jsonfile.readFileSync( `${config.tribes}/${header.xworkon}/clientconf.json` );
const clientConfig = fs.readJsonSync( `${config.tribes}/${header.xworkon}/clientconf.json` );
const user = check.data;
user.DATE_CREATE = new Date()
.toISOString();
@@ -441,7 +441,7 @@ Pagans.createUser = ( header, data ) => {
user.ACCESSRIGHTS = { app: {}, data: {} };
}
user.ACCESSRIGHTS.data[ header.xworkon ] = { users: "O" };
jsonfile.writeFileSync( `${config.tribes}/${header.xworkon}/users/${user.UUID}.json`, user, {
fs.outputJsonSync( `${config.tribes}/${header.xworkon}/users/${user.UUID}.json`, user, {
spaces: 2
} );
Pagans.updateDatabase( user, header.xworkon, false );
@@ -490,14 +490,14 @@ Pagans.updateUser = ( UUID, header, data ) => {
};
}
*/
const ref = jsonfile.readFileSync( `${config.tribes}/${header.xworkon}/referentials/object/users_${
const ref = fs.readJsonSync( `${config.tribes}/${header.xworkon}/referentials/object/users_${
header.xlang
}.json` );
const logins = jsonfile.readFileSync( `${config.tribes}/${header.xworkon}/users/searchindex/logins.json` );
const logins = fs.readJsonSync( `${config.tribes}/${header.xworkon}/users/searchindex/logins.json` );
const LOGIN = Object.keys( logins )
.filter( l => logins[ l ] != user.UUID );
// console.log( 'LOGIN list', LOGIN );
const emails = jsonfile.readFileSync( `${config.tribes}/${header.xworkon}/users/searchindex/emails.json` );
const emails = fs.readJsonSync( `${config.tribes}/${header.xworkon}/users/searchindex/emails.json` );
// console.log( 'emails', emails );
const EMAIL = Object.keys( emails )
.filter( e => emails[ e ] != user.UUID );
@@ -546,7 +546,7 @@ Pagans.updateUser = ( UUID, header, data ) => {
.toISOString();
}
try {
jsonfile.writeFileSync( `${config.tribes}/${header.xworkon}/users/${UUID}.json`, user, {
fs.outputJsonSync( `${config.tribes}/${header.xworkon}/users/${UUID}.json`, user, {
spaces: 2
} );
//console.log( 'declenche updatabase', updateDatabase )
@@ -579,7 +579,7 @@ Pagans.deleteUser = ( UUID, header ) => {
// Delete remove from users object UUID and update index
// Activity is not deleted => means some activity can concern an UUID that does not exist anymore.
// update index
const infouser = jsonfile.readFileSync( `${config.tribes}/${header.xworkon}/users/${UUID}.json` );
const infouser = fs.readJsonSync( `${config.tribes}/${header.xworkon}/users/${UUID}.json` );
Pagans.updateDatabase( infouser, header.xworkon, true );
fs.removeSync( `${config.tribes}/${header.xworkon}/users/${UUID}.json` );
return {
@@ -612,7 +612,7 @@ Pagans.loginUser = ( header, body, checkpsw ) => {
// il faut donc modifier le header au moment du LOGIN
// pour que l'update du user au moment du LOGIN concerne bien le bon domain
header.xworkon = header.xtribe
const LOGINdom = jsonfile.readFileSync( `${config.tmp}/loginsglob.json` );
const LOGINdom = fs.readJsonSync( `${config.tmp}/loginsglob.json` );
console.assert( config.loglevel == "quiet", LOGINdom )
console.assert( config.loglevel == "quiet", body )
if( !LOGINdom[ body.LOGIN ] ) {
@@ -621,7 +621,7 @@ Pagans.loginUser = ( header, body, checkpsw ) => {
data: { info: [ 'LoginDoesNotExist' ], model: 'Pagans' }
};
}
const logins = jsonfile.readFileSync( `${config.tribes}/${LOGINdom[body.LOGIN]}/users/searchindex/logins.json` );
const logins = fs.readJsonSync( `${config.tribes}/${LOGINdom[body.LOGIN]}/users/searchindex/logins.json` );
if( !Object.keys( logins )
.includes( body.LOGIN ) ) {
return {
@@ -678,7 +678,7 @@ Pagans.loginUser = ( header, body, checkpsw ) => {
if( user.ACCESSRIGHTS.data[ "Alltribeid" ] ) {
//cas admin on transforme les droits sur tous les tribeid existant
const newaccessrightsdata = {}
jsonfile.readFileSync( `${config.tribes}/tribeids.json` )
fs.readJsonSync( `${config.tribes}/tribeids.json` )
.forEach( cid => {
newaccessrightsdata[ cid ] = user.ACCESSRIGHTS.data[ "Alltribeid" ]
} )
@@ -701,7 +701,7 @@ Pagans.loginUser = ( header, body, checkpsw ) => {
Pagans.getlinkwithoutpsw = async ( EMAIL, header ) => {
// check le domain d'appartenance de l'eamail dans /tribes/emailsglob.json={email:cleintId}
// on remplace le header.xtribeid
const domforemail = jsonfile.readFileSync( `${config.tribes}/emailsglob.json`, 'utf-8' );
const domforemail = fs.readJsonSync( `${config.tribes}/emailsglob.json`, 'utf-8' );
if( domforemail[ EMAIL ] ) {
header.xtribe = domforemail[ EMAIL ]
} else {
@@ -710,10 +710,10 @@ Pagans.getlinkwithoutpsw = async ( EMAIL, header ) => {
// recupere le uuid du user dans /tribes/tribeid/users/searchindex/emails.json
// puis l'ensemble des info des user du domain /uuids.json
// infoforuuid[uuidforemail[EMAIL]] permet de récupérer toutes info du user, droit, etc...
const uuidforemail = jsonfile.readFileSync( `${config.tribes}/${header.xtribe}/users/searchindex/emails.json`, 'utf8' );
const infoforuuid = jsonfile.readFileSync( `${config.tribes}/${header.xtribe}/users/searchindex/uids.json`, 'utf8' );
const uuidforemail = fs.readJsonSync( `${config.tribes}/${header.xtribe}/users/searchindex/emails.json`, 'utf8' );
const infoforuuid = fs.readJsonSync( `${config.tribes}/${header.xtribe}/users/searchindex/uids.json`, 'utf8' );
// On recupere le modele d'email appemailinfo qui doit être présent dans clientconf.json
let confdom = jsonfile.readFileSync( `${config.tribes}/${header.xtribe}/clientconf.json`, 'utf8' );
let confdom = fs.readJsonSync( `${config.tribes}/${header.xtribe}/clientconf.json`, 'utf8' );
let checkinfomail = "";
if( !confdom.appemailinfo ) {
checkinfomail += ' Erreur de clientconfig il manque un objet appemailinfo pour poursuivre';

View File

@@ -57,7 +57,7 @@ Tags.getfile = ( filename, req ) => {
}
}
if( infotg[ 0 ] == "imgtg" ) {
jsonfile.writeFile( `${config.tribes}/${infotg[1]}/tags/imgtg/${Date.now()}.json`, Tags.info( { filename: filename, messageId: infotg[ 2 ], operationId: infotg[ 3 ], identifiant: infotg[ 4 ] }, req ), function ( err ) {
fs.outputJson( `${config.tribes}/${infotg[1]}/tags/imgtg/${Date.now()}.json`, Tags.info( { filename: filename, messageId: infotg[ 2 ], operationId: infotg[ 3 ], identifiant: infotg[ 4 ] }, req ), function ( err ) {
if( err ) {
console.log( `Erreur de sauvegarde de tag:${filename}` )
}
@@ -75,7 +75,7 @@ Tags.savehits = ( req ) => {
return false;
} else {
const info = JSON.parse( JSON.stringify( req.body ) );
jsonfile.writeFile( `${config.tribes}/${req.params.tribeid}/tags/hits/${Date.now()}.json`, Tags.info( info, req ), function ( err ) {
fs.outputJson( `${config.tribes}/${req.params.tribeid}/tags/hits/${Date.now()}.json`, Tags.info( info, req ), function ( err ) {
if( err ) {
console.log( `Erreur de sauvegarde de tag pour ${req.params.tribeid} check si /tags/hits et /tags/imgtg exist bien ` )
}
@@ -131,15 +131,15 @@ Tags.dataloadstat = ( tribeid ) => {
}
};
try {
agrege.data = jsonfile.readfileSync( `${config.tribes}/${tribeid}/tags/stats/data.json`, "utf-8" );
agrege.graph = jsonfile.readfileSync( `${config.tribes}/${tribeid}/tags/stats/graph.json`, "utf-8" );
agrege.data = fs.readJsonSync( `${config.tribes}/${tribeid}/tags/stats/data.json`, "utf-8" );
agrege.graph = fs.readJsonSync( `${config.tribes}/${tribeid}/tags/stats/graph.json`, "utf-8" );
} catch ( err ) {
console.log( "ATTENTION tag reinitialisé en data.json et graph.json, s'il s'agit de 1ere connexion pas de pb. Le risque est de perdre les tag historiques" )
//return { status: 503, payload: { info: ['Errconfig'], model: 'Tags', moreinfo: `Il manque un ${config.tribes}/${tribeid}/tags/stats/data.json ou stats/graph.json` } }
}
glob.sync( `${config.tribes}/${tribeid}/tags/hits/*` )
.forEach( f => {
const hit = jsonfile.readFileSync( f );
const hit = fs.readJsonSync( f );
const ts = parseInt( path.basename( f )
.split( ".json" )[ 0 ] );
//console.log(moment(ts).format('DD-MM-YYYY h:mm:ss'));
@@ -214,8 +214,8 @@ Tags.dataloadstat = ( tribeid ) => {
}
}
} )
jsonfile.writeFileSync( `${config.tribes}/${tribeid}/tags/stats/data.json`, agrege.data, 'utf-8' );
jsonfile.writeFileSync( `${config.tribes}/${tribeid}/tags/stats/graph.json`, agrege.graph, 'utf-8' );
fs.outputJsonSync( `${config.tribes}/${tribeid}/tags/stats/data.json`, agrege.data, 'utf-8' );
fs.outputJsonSync( `${config.tribes}/${tribeid}/tags/stats/graph.json`, agrege.graph, 'utf-8' );
return { status: 200, payload: { info: [ 'Statsupdated' ], model: 'Tags' } }
}
//console.log(Tags.dataloadstat('yes'));

View File

@@ -36,7 +36,7 @@ UploadFiles.addjson = function ( data, header ) {
*/
// console.log(req.body.jsonp);
try {
jsonfile.writeFileSync( header.destinationfile + '/' + header.filename, data.jsonp );
fs.outputJsonSync( header.destinationfile + '/' + header.filename, data.jsonp );
if( data.callback ) {
const execCB = require( `${config.mainDir}/models/tribeid/${
header.xworkon
@@ -106,10 +106,10 @@ UploadFiles.updateEvent = function ( domainId, eventId, event ) {
// checkAndCreateNeededDirectories(domainId);
const eventsFile = `${config.tribes}/${domainId}/actions/events/events.json`;
if( !fs.existsSync( eventsFile ) ) {
jsonfile.writeFileSync( eventsFile, {} );
fs.outputJsonSync( eventsFile, {} );
return { status: 404, payload: 'You have not any events.' };
}
const events = jsonfile.readFileSync( eventsFile );
const events = fs.readJsonSync( eventsFile );
if( !events.hasOwnProperty( eventId ) ) {
return {
status: 404,
@@ -121,7 +121,7 @@ UploadFiles.updateEvent = function ( domainId, eventId, event ) {
eventDate: event.eventDate,
eventDescription: event.eventDescription
};
jsonfile.writeFileSync( eventsFile, events, { spaces: 2 } );
fs.outputJsonSync( eventsFile, events, { spaces: 2 } );
return {
status: 200,
payload: events
@@ -131,13 +131,13 @@ UploadFiles.deleteEvent = function ( domainId, eventId ) {
// checkAndCreateNeededDirectories(domainId);
const eventsFile = `${config.tribes}/${domainId}/actions/events/events.json`;
if( !fs.existsSync( eventsFile ) ) {
jsonfile.writeFileSync( eventsFile, {} );
fs.outputJsonSync( eventsFile, {} );
return { status: 404, payload: 'You have not any events.' };
}
const events = jsonfile.readFileSync( eventsFile );
const events = fs.readJsonSync( eventsFile );
if( events.hasOwnProperty( eventId ) ) {
delete events[ eventId ];
jsonfile.writeFileSync( eventsFile, events, { spaces: 2 } );
fs.outputJsonSync( eventsFile, events, { spaces: 2 } );
return {
status: 200,
payload: events