insomnia/app/backend/models/response.js

33 lines
698 B
JavaScript
Raw Normal View History

2016-11-09 04:26:49 +00:00
import * as db from '../database';
2016-09-21 20:32:45 +00:00
export const type = 'Response';
export const prefix = 'res';
export function init () {
return db.initModel({
statusCode: 0,
statusMessage: '',
2016-10-27 16:45:44 +00:00
contentType: '',
url: '',
bytesRead: 0,
elapsedTime: 0,
headers: [],
cookies: [],
body: '',
2016-10-26 23:22:15 +00:00
encoding: 'utf8', // Legacy format
error: ''
})
}
2016-09-21 20:32:45 +00:00
export function create (patch = {}) {
2016-09-21 20:32:45 +00:00
if (!patch.parentId) {
throw new Error('New Response missing `parentId`');
}
db.removeBulkSilently(type, {parentId: patch.parentId});
return db.docCreate(type, patch);
}
2016-09-21 20:32:45 +00:00
export function getLatestByParentId (parentId) {
return db.getMostRecentlyModified(type, {parentId});
}