insomnia/app/backend/database/models/workspace.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-09-21 20:32:45 +00:00
'use strict';
2016-09-22 01:26:40 +00:00
const db = require('../index');
const {DEFAULT_SIDEBAR_WIDTH} = require('../../constants');
2016-09-21 20:32:45 +00:00
module.exports.type = 'Workspace';
module.exports.prefix = 'wrk';
2016-09-21 21:46:42 +00:00
module.exports.slug = 'workspace';
module.exports.init = () => db.initModel({
2016-09-21 20:32:45 +00:00
name: 'New Workspace',
metaSidebarWidth: DEFAULT_SIDEBAR_WIDTH,
metaActiveEnvironmentId: null,
metaActiveRequestId: null,
metaFilter: '',
metaSidebarHidden: false
});
module.exports.getById = id => {
return db.get(module.exports.type, id);
};
module.exports.create = (patch = {}) => {
return db.docCreate(module.exports.type, patch);
};
module.exports.all = () => {
return db.all(module.exports.type).then(workspaces => {
if (workspaces.length === 0) {
return module.exports.create({name: 'Insomnia'})
.then(module.exports.all);
} else {
return new Promise(resolve => resolve(workspaces))
}
});
};
module.exports.count = () => {
return db.count(module.exports.type)
};
module.exports.update = (workspace, patch) => {
return db.docUpdate(workspace, patch);
};
module.exports.remove = workspace => {
return db.remove(workspace);
};