mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Refactored post removal from all collections
refs https://github.com/TryGhost/Team/issues/3169 - It's easier to read this way and possibly reusable in the future
This commit is contained in:
parent
e7a0462877
commit
ebd58515bd
1 changed files with 11 additions and 7 deletions
|
@ -198,16 +198,20 @@ export class CollectionsService {
|
|||
}
|
||||
}
|
||||
|
||||
private async removePostFromAllCollections(postId: string) {
|
||||
const collections = await this.collectionsRepository.getAll();
|
||||
|
||||
for (const collection of collections) {
|
||||
if (collection.includesPost(postId)) {
|
||||
await collection.removePost(postId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async updateCollections(event: CollectionResourceChangeEvent) {
|
||||
if (event.name === 'post.deleted') {
|
||||
// NOTE: 'delete' works the same for both manual and automatic collections
|
||||
const collections = await this.collectionsRepository.getAll();
|
||||
|
||||
for (const collection of collections) {
|
||||
if (collection.includesPost(event.data.id)) {
|
||||
await collection.removePost(event.data.id);
|
||||
}
|
||||
}
|
||||
await this.removePostFromAllCollections(event.data.id);
|
||||
} else {
|
||||
const collections = await this.collectionsRepository.getAll({
|
||||
filter: 'type:automatic'
|
||||
|
|
Loading…
Reference in a new issue