2016-12-01 01:50:59 +00:00
|
|
|
import * as db from '../common/database';
|
2018-06-25 17:42:50 +00:00
|
|
|
import { PREVIEW_MODE_FRIENDLY } from '../common/constants';
|
2016-12-01 01:50:59 +00:00
|
|
|
|
|
|
|
export const name = 'Request Meta';
|
|
|
|
export const type = 'RequestMeta';
|
|
|
|
export const prefix = 'reqm';
|
2017-06-15 17:08:24 +00:00
|
|
|
export const canDuplicate = false;
|
2016-12-01 01:50:59 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function init() {
|
2016-12-01 01:50:59 +00:00
|
|
|
return {
|
|
|
|
parentId: null,
|
2017-03-30 18:52:07 +00:00
|
|
|
previewMode: PREVIEW_MODE_FRIENDLY,
|
2016-12-01 01:50:59 +00:00
|
|
|
responseFilter: '',
|
2017-06-08 02:42:16 +00:00
|
|
|
responseFilterHistory: [],
|
2018-02-16 16:24:54 +00:00
|
|
|
activeResponseId: null,
|
|
|
|
savedRequestBody: {}
|
2017-03-03 20:09:08 +00:00
|
|
|
};
|
2016-12-01 01:50:59 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function migrate(doc) {
|
2016-12-01 01:50:59 +00:00
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function create(patch = {}) {
|
2016-12-01 01:50:59 +00:00
|
|
|
if (!patch.parentId) {
|
|
|
|
throw new Error('New RequestMeta missing `parentId`', patch);
|
|
|
|
}
|
|
|
|
|
|
|
|
return db.docCreate(type, patch);
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function update(requestMeta, patch) {
|
2016-12-01 01:50:59 +00:00
|
|
|
return db.docUpdate(requestMeta, patch);
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function getByParentId(parentId) {
|
|
|
|
return db.getWhere(type, { parentId });
|
2016-12-01 01:50:59 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export async function getOrCreateByParentId(parentId) {
|
2018-03-02 09:49:10 +00:00
|
|
|
const requestMeta = await getByParentId(parentId);
|
|
|
|
|
|
|
|
if (requestMeta) {
|
|
|
|
return requestMeta;
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
return create({ parentId });
|
2018-03-02 09:49:10 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function all() {
|
2016-12-01 01:50:59 +00:00
|
|
|
return db.all(type);
|
|
|
|
}
|