mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 14:49:53 +00:00
38 lines
853 B
JavaScript
38 lines
853 B
JavaScript
'use strict';
|
|
|
|
const db = require('./');
|
|
|
|
module.exports.type = 'CookieJar';
|
|
module.exports.prefix = 'jar';
|
|
module.exports.init = () => ({
|
|
name: 'Default Jar',
|
|
cookies: []
|
|
});
|
|
|
|
module.exports.create = (patch = {}) => {
|
|
return db.docCreate(module.exports.type, patch);
|
|
};
|
|
|
|
module.exports.getOrCreateForWorkspace = workspace => {
|
|
const parentId = workspace._id;
|
|
return db.find(module.exports.type, {parentId}).then(cookieJars => {
|
|
if (cookieJars.length === 0) {
|
|
return module.exports.create({parentId})
|
|
} else {
|
|
return new Promise(resolve => resolve(cookieJars[0]));
|
|
}
|
|
});
|
|
};
|
|
|
|
module.exports.all = () => {
|
|
return db.all(module.exports.type);
|
|
};
|
|
|
|
module.exports.getById = id => {
|
|
return db.get(module.exports.type, id);
|
|
};
|
|
|
|
module.exports.update = (cookieJar, patch) => {
|
|
return db.docUpdate(cookieJar, patch);
|
|
};
|