Remove image from album upon deletion
This commit is contained in:
parent
e06617f395
commit
4b2eab3e51
@ -68,10 +68,16 @@ class AlbumSpec extends TypeSpec {
|
||||
|
||||
export const AlbumType = PouchDB.registerType('Album', AlbumSpec);
|
||||
|
||||
// ImageType.watch({_deleted: true}, true)
|
||||
// .then(la => {
|
||||
// la.subscribe() );
|
||||
//
|
||||
// image.removed.subscribe(image => {
|
||||
// Object.keys(image.tags).forEach(t => index.removeMember(t, image._id));
|
||||
// })
|
||||
ImageType.subscribe((id, deleted, doc) => {
|
||||
if (!deleted) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object.keys(doc.$links)
|
||||
.filter(k => k.startsWith(AlbumType.prefix))
|
||||
.forEach(async albumId => {
|
||||
const album = await AlbumType.find(albumId);
|
||||
album.count -= 1;
|
||||
album.save();
|
||||
});
|
||||
});
|
||||
|
||||
@ -7,6 +7,7 @@ import find from 'pouchdb-find';
|
||||
import { log, warn } from './console.js';
|
||||
import { isObject } from '../utils/comparators.js';
|
||||
import { LiveArray } from '../utils/livearray.js';
|
||||
import { Watcher } from '../utils/watcher.js';
|
||||
import { deepAssign, pouchDocHash } from '../utils/conversion.js';
|
||||
|
||||
export const PouchDB = core
|
||||
@ -95,6 +96,7 @@ export function PouchORM(PouchDB) {
|
||||
const _baseSelector = Object.freeze({
|
||||
_id: { $gt: `${prefix}_0`, $lt: `${prefix}_\ufff0` }
|
||||
});
|
||||
const watch = Watcher(_db, _baseSelector, true);
|
||||
|
||||
if (!cls.hasOwnProperty('validate')) {
|
||||
warn(`${cls.name} has no validation.`);
|
||||
@ -156,8 +158,10 @@ export function PouchORM(PouchDB) {
|
||||
getOrCreate: { value: getOrCreate },
|
||||
find: { value: find },
|
||||
delete: { value: _delete },
|
||||
subscribe: { value: watch },
|
||||
db: { value: _db },
|
||||
name: { value: name },
|
||||
prefix: { value: prefix },
|
||||
selector: { value: _baseSelector }
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user