insomnia/app/backend/database/settings.js

38 lines
865 B
JavaScript
Raw Normal View History

2016-09-21 20:32:45 +00:00
'use strict';
const db = require('./');
module.exports.type = 'Settings';
module.exports.prefix = 'set';
2016-09-21 21:46:42 +00:00
module.exports.slug = 'settings';
module.exports.init = () => db.initModel({
2016-09-21 20:32:45 +00:00
showPasswords: true,
useBulkHeaderEditor: false,
followRedirects: false,
editorFontSize: 12,
editorLineWrapping: true,
httpProxy: '',
httpsProxy: '',
timeout: 0,
validateSSL: true
});
module.exports.create = (patch = {}) => {
return db.docCreate(module.exports.type, patch);
};
module.exports.update = (settings, patch) => {
return db.docUpdate(settings, patch);
};
module.exports.getOrCreate = () => {
return db.all(module.exports.type).then(results => {
if (results.length === 0) {
return module.exports.create()
.then(module.exports.getOrCreate);
} else {
return new Promise(resolve => resolve(results[0]));
}
});
};