0
Fork 0
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:
Naz 2023-06-21 21:53:52 +07:00 committed by naz
parent e7a0462877
commit ebd58515bd

View file

@ -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'