Notes/src/services/options.js

38 lines
809 B
JavaScript
Raw Normal View History

2018-01-28 19:30:14 -05:00
async function getOption(name) {
const option = await require('./repository').getOption(name);
2017-11-02 20:48:02 -04:00
if (!option) {
2018-01-28 19:30:14 -05:00
throw new Error("Option " + name + " doesn't exist");
2017-11-02 20:48:02 -04:00
}
return option.value;
2017-11-02 20:48:02 -04:00
}
async function setOption(name, value) {
const option = await require('./repository').getOption(name);
if (!option) {
2018-01-28 19:30:14 -05:00
throw new Error(`Option ${name} doesn't exist`);
}
option.value = value;
await option.save();
}
async function createOption(name, value, isSynced) {
// to avoid circular dependency, need to find better solution
const Option = require('../entities/option');
await new Option({
2018-01-28 19:30:14 -05:00
name: name,
value: value,
isSynced: isSynced
}).save();
2017-11-02 20:48:02 -04:00
}
module.exports = {
getOption,
setOption,
createOption
2017-11-02 20:48:02 -04:00
};