mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
Added collection handling for post's tag attach events
refs https://github.com/TryGhost/Arch/issues/41 - When a tag is attached or detached to the post automatic collections matching the tag filter should be updated.
This commit is contained in:
parent
f4301b16e8
commit
eec610dc53
@ -3,14 +3,18 @@ type PostEditData = {
|
||||
current: {
|
||||
id: string;
|
||||
title: string;
|
||||
status: string;
|
||||
featured: boolean;
|
||||
published_at: Date;
|
||||
tags: string[];
|
||||
},
|
||||
previous: {
|
||||
id: string;
|
||||
title: string;
|
||||
status: string;
|
||||
featured: boolean;
|
||||
published_at: Date;
|
||||
tags: string[];
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -85,11 +85,18 @@ export class ModelToDomainEventInterceptor {
|
||||
title: data.attributes.title,
|
||||
status: data.attributes.status,
|
||||
featured: data.attributes.featured,
|
||||
published_at: data.attributes.published_at
|
||||
published_at: data.attributes.published_at,
|
||||
tags: data.relations?.tags?.models.map((tag: any) => (tag.get('slug')))
|
||||
},
|
||||
// @NOTE: this will need to represent the previous state of the post
|
||||
// will be needed to optimize the query for the collection
|
||||
previous: {
|
||||
id: data.id,
|
||||
title: data._previousAttributes?.title,
|
||||
status: data._previousAttributes?.status,
|
||||
featured: data._previousAttributes?.featured,
|
||||
published_at: data._previousAttributes?.published_at,
|
||||
tags: data._previousRelations?.tags?.models.map((tag: any) => (tag.get('slug')))
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
@ -82,7 +82,10 @@ describe('ModelToDomainEventInterceptor', function () {
|
||||
assert.ok(event.data);
|
||||
assert.ok(event.data.current);
|
||||
assert.equal(event.data.current.status, 'draft');
|
||||
assert.equal(event.data.previous.status, 'published');
|
||||
|
||||
assert.equal(event.data.current.tags[0], 'tag-current-slug');
|
||||
assert.equal(event.data.previous.tags[0], 'tag-previous-slug');
|
||||
interceptedEvent = event;
|
||||
});
|
||||
|
||||
@ -92,6 +95,28 @@ describe('ModelToDomainEventInterceptor', function () {
|
||||
status: 'draft',
|
||||
featured: false,
|
||||
published_at: new Date()
|
||||
},
|
||||
_previousAttributes: {
|
||||
status: 'published',
|
||||
featured: true
|
||||
},
|
||||
relations: {
|
||||
tags: {
|
||||
models: [{
|
||||
get: function (key: string) {
|
||||
return `tag-current-${key}`;
|
||||
}
|
||||
}]
|
||||
}
|
||||
},
|
||||
_previousRelations: {
|
||||
tags: {
|
||||
models: [{
|
||||
get: function (key: string) {
|
||||
return `tag-previous-${key}`;
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user