import fs from 'fs-extra'; import _ from 'lodash'; import * as DataEvent from '../../src/com/events/DataEvent'; const settings = require('../../site/settings.json'); export default class Navigation { //-------------------------- // constructor //-------------------------- constructor() {} //-------------------------- // methods //-------------------------- sync(req) { return new Promise((resolve, reject) => { let payload = req.body; settings.menu = payload; let response = []; fs.writeJson('site/settings.json', settings) .then(() => { response = { type: DataEvent.SETTINGS_UPDATED, message: 'Menu order saved, champ' }; resolve(response); }) .catch(err => { response = { type: DataEvent.REQUEST_LAME, message: err }; reject(response); }); }); } editMenu(task, item) { switch (task) { case DataEvent.MENU_ADD_ITEM: break; case DataEvent.MENU_DELETE_ITEM: fs.readJSON('site/settings.json').then(settings => { settings.menu = _.remove(settings.menu, m => { return m.uuid != item.uuid; }); fs.writeJSON('site/settings.json', settings); }); break; } } //-------------------------- // event handlers //-------------------------- }