0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Refactored model interceptor to use switch syntax

refs https://github.com/TryGhost/Arch/issues/41

- Having switch statement instead of lots of if/else is slightly more readable. Before adding 5 more event mappings it makes sense to cleanup before things get too messy :)
This commit is contained in:
Naz 2023-07-18 13:39:10 +08:00 committed by naz
parent daa19e06b4
commit 9ce0c92597

View file

@ -64,16 +64,20 @@ export class ModelToDomainEventInterceptor {
}, data._changed);
let event;
if (modelEventName === 'post.deleted') {
switch (modelEventName) {
case 'post.deleted':
event = PostDeletedEvent.create({id: data.id});
} else if (modelEventName === 'post.added') {
break;
case 'post.added':
event = PostAddedEvent.create({
id: data.id,
featured: data.attributes.featured,
status: data.attributes.status,
published_at: data.attributes.published_at
});
} else if (modelEventName === 'post.edited') {
break;
case 'post.edited':
event = PostEditedEvent.create({
id: data.id,
current: {
@ -88,7 +92,8 @@ export class ModelToDomainEventInterceptor {
previous: {
}
});
} else {
break;
default:
event = CollectionResourceChangeEvent.create(modelEventName, change);
}