insomnia/app/backend/database/response.js
2016-09-21 13:32:45 -07:00

32 lines
690 B
JavaScript

'use strict';
const db = require('./');
module.exports.type = 'Response';
module.exports.prefix = 'res';
module.exports.init = () => ({
statusCode: 0,
statusMessage: '',
contentType: 'text/plain',
url: '',
bytesRead: 0,
elapsedTime: 0,
headers: [],
cookies: [],
body: '',
error: ''
});
module.exports.create = (patch = {}) => {
if (!patch.parentId) {
throw new Error('New Response missing `parentId`');
}
db.removeBulkSilently(module.exports.type, {parentId: patch.parentId});
return db.docCreate(module.exports.type, patch);
};
module.exports.getLatestByParentId = parentId => {
return db.getMostRecentlyModified(module.exports.type, {parentId});
};