insomnia/app/models/settings.js
Gregory Schier 1d45367aa1 Added eslint and fixed all problems (#101)
* Fixed duplication kve bug

* Added semistandard and updated code

* Actually got it working

* Even better

* I think it should work on Windows now
2017-03-03 12:09:08 -08:00

53 lines
1.0 KiB
JavaScript

import * as db from '../common/database';
export const name = 'Settings';
export const type = 'Settings';
export const prefix = 'set';
export function init () {
return {
showPasswords: false,
useBulkHeaderEditor: false,
followRedirects: true,
editorFontSize: 12,
editorLineWrapping: true,
editorKeyMap: 'default',
httpProxy: '',
httpsProxy: '',
timeout: 0,
validateSSL: true,
forceVerticalLayout: false,
theme: 'default'
};
}
export function migrate (doc) {
return doc;
}
export async function all () {
const settings = await db.all(type);
if (settings.length === 0) {
return [await getOrCreate()];
} else {
return settings;
}
}
export async function create (patch = {}) {
return db.docCreate(type, patch);
}
export async function update (settings, patch) {
return db.docUpdate(settings, patch);
}
export async function getOrCreate () {
const results = await db.all(type);
if (results.length === 0) {
return await create();
} else {
return results[0];
}
}