insomnia/app/backend/models/response.js
2016-11-09 17:15:27 -08:00

33 lines
684 B
JavaScript

import * as db from '../database';
export const type = 'Response';
export const prefix = 'res';
export function init () {
return {
statusCode: 0,
statusMessage: '',
contentType: '',
url: '',
bytesRead: 0,
elapsedTime: 0,
headers: [],
cookies: [],
body: '',
encoding: 'utf8', // Legacy format
error: ''
}
}
export function create (patch = {}) {
if (!patch.parentId) {
throw new Error('New Response missing `parentId`');
}
db.removeBulkSilently(type, {parentId: patch.parentId});
return db.docCreate(type, patch);
}
export function getLatestByParentId (parentId) {
return db.getMostRecentlyModified(type, {parentId});
}