2016-10-02 20:57:00 +00:00
|
|
|
import * as db from '../index';
|
2016-09-21 20:32:45 +00:00
|
|
|
|
2016-10-02 20:57:00 +00:00
|
|
|
export const type = 'CookieJar';
|
|
|
|
export const prefix = 'jar';
|
|
|
|
export function init () {
|
|
|
|
return db.initModel({
|
|
|
|
name: 'Default Jar',
|
|
|
|
cookies: []
|
|
|
|
})
|
|
|
|
}
|
2016-09-21 20:32:45 +00:00
|
|
|
|
2016-10-02 20:57:00 +00:00
|
|
|
export function create (patch = {}) {
|
|
|
|
return db.docCreate(type, patch);
|
|
|
|
}
|
2016-09-21 20:32:45 +00:00
|
|
|
|
2016-10-02 20:57:00 +00:00
|
|
|
export async function getOrCreateForWorkspace (workspace) {
|
2016-09-21 20:32:45 +00:00
|
|
|
const parentId = workspace._id;
|
2016-10-02 20:57:00 +00:00
|
|
|
const cookieJars = await db.find(type, {parentId});
|
|
|
|
if (cookieJars.length === 0) {
|
|
|
|
return await create({parentId})
|
|
|
|
} else {
|
|
|
|
return cookieJars[0];
|
|
|
|
}
|
|
|
|
}
|
2016-09-21 20:32:45 +00:00
|
|
|
|
2016-10-02 20:57:00 +00:00
|
|
|
export function all () {
|
|
|
|
return db.all(type);
|
|
|
|
}
|
2016-09-21 20:32:45 +00:00
|
|
|
|
2016-10-02 20:57:00 +00:00
|
|
|
export function getById (id) {
|
|
|
|
return db.get(type, id);
|
|
|
|
}
|
2016-09-21 20:32:45 +00:00
|
|
|
|
2016-10-02 20:57:00 +00:00
|
|
|
export function update (cookieJar, patch) {
|
2016-09-21 20:32:45 +00:00
|
|
|
return db.docUpdate(cookieJar, patch);
|
|
|
|
};
|