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

46 lines
931 B
JavaScript
Raw Normal View History

import * as db from '../index';
export const type = 'RequestGroup';
export const prefix = 'fld';
export function init () {
return db.initModel({
name: 'New Folder',
environment: {},
metaCollapsed: false,
metaSortKey: -1 * Date.now()
})
}
export function create (patch = {}) {
2016-09-21 20:32:45 +00:00
if (!patch.parentId) {
throw new Error('New Requests missing `parentId`', patch);
}
return db.docCreate(type, patch);
}
2016-09-21 20:32:45 +00:00
export function update (requestGroup, patch) {
2016-09-21 20:32:45 +00:00
return db.docUpdate(requestGroup, patch);
}
2016-09-21 20:32:45 +00:00
export function getById (id) {
return db.get(type, id);
}
2016-09-21 20:32:45 +00:00
export function findByParentId (parentId) {
return db.find(type, {parentId})
}
2016-09-21 20:32:45 +00:00
export function remove (requestGroup) {
2016-09-21 20:32:45 +00:00
return db.remove(requestGroup);
}
2016-09-21 20:32:45 +00:00
export function all () {
return db.all(type);
}
2016-09-21 20:32:45 +00:00
export function duplicate (requestGroup) {
2016-09-21 20:32:45 +00:00
const name = `${requestGroup.name} (Copy)`;
return db.duplicate(requestGroup, {name});
}