2020-03-18 18:58:57 +00:00
|
|
|
// @flow
|
|
|
|
|
2016-12-01 01:50:59 +00:00
|
|
|
import * as db from '../common/database';
|
2020-03-18 18:58:57 +00:00
|
|
|
import type { BaseModel } from './index';
|
2016-12-01 01:50:59 +00:00
|
|
|
|
|
|
|
export const name = 'Folder Meta';
|
|
|
|
export const type = 'RequestGroupMeta';
|
|
|
|
export const prefix = 'fldm';
|
2017-06-15 17:08:24 +00:00
|
|
|
export const canDuplicate = false;
|
2019-04-18 00:50:03 +00:00
|
|
|
export const canSync = false;
|
2016-12-01 01:50:59 +00:00
|
|
|
|
2020-03-18 18:58:57 +00:00
|
|
|
type BaseRequestGroupMeta = {
|
|
|
|
collapsed: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
export type RequestGroupMeta = BaseModel & BaseRequestGroupMeta;
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function init() {
|
2016-12-01 01:50:59 +00:00
|
|
|
return {
|
|
|
|
parentId: null,
|
2018-12-12 17:36:11 +00:00
|
|
|
collapsed: false,
|
2017-03-03 20:09:08 +00:00
|
|
|
};
|
2016-12-01 01:50:59 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 18:58:57 +00:00
|
|
|
export function migrate(doc: RequestGroupMeta): RequestGroupMeta {
|
2016-12-01 01:50:59 +00:00
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2020-03-18 18:58:57 +00:00
|
|
|
export function create(patch: $Shape<RequestGroupMeta> = {}): Promise<RequestGroupMeta> {
|
2016-12-01 01:50:59 +00:00
|
|
|
if (!patch.parentId) {
|
2020-03-18 18:58:57 +00:00
|
|
|
throw new Error('New RequestGroupMeta missing `parentId`: ' + JSON.stringify(patch));
|
2016-12-01 01:50:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return db.docCreate(type, patch);
|
|
|
|
}
|
|
|
|
|
2020-03-18 18:58:57 +00:00
|
|
|
export function update(
|
|
|
|
requestGroupMeta: RequestGroupMeta,
|
|
|
|
patch: $Shape<RequestGroupMeta>,
|
|
|
|
): Promise<RequestGroupMeta> {
|
2016-12-01 01:50:59 +00:00
|
|
|
return db.docUpdate(requestGroupMeta, patch);
|
|
|
|
}
|
|
|
|
|
2020-03-18 18:58:57 +00:00
|
|
|
export function getByParentId(parentId: string): Promise<RequestGroupMeta | null> {
|
2018-06-25 17:42:50 +00:00
|
|
|
return db.getWhere(type, { parentId });
|
2016-12-01 01:50:59 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 18:58:57 +00:00
|
|
|
export function all(): Promise<Array<RequestGroupMeta>> {
|
2016-12-01 01:50:59 +00:00
|
|
|
return db.all(type);
|
|
|
|
}
|