Skip to content

Commit

Permalink
Added post_id filter to activity feed API
Browse files Browse the repository at this point in the history
fixes https://github.com/TryGhost/Team/issues/2091

- Added new fixtures to make testing easier for the activity feed
- Improved E2E test coverage of activity feed with separate test file
- Added data.post_id filter to enable filtering by events related to a given post
  • Loading branch information
SimonBackx committed Oct 18, 2022
1 parent 95cfb48 commit 47f273f
Show file tree
Hide file tree
Showing 10 changed files with 717 additions and 71 deletions.
24 changes: 24 additions & 0 deletions ghost/core/core/server/models/member-click-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,31 @@ const MemberClickEvent = ghostBookshelf.Model.extend({

member() {
return this.belongsTo('Member', 'member_id', 'id');
},

filterExpansions: function filterExpansions() {
const expansions = [{
key: 'post_id',
replacement: 'link.post_id'
}];

return expansions;
},

filterRelations() {
return {
link: {
// Mongo-knex doesn't support belongsTo relations
tableName: 'redirects',
tableNameAs: 'link',
type: 'manyToMany',
joinTable: 'members_click_events',
joinFrom: 'id',
joinTo: 'redirect_id'
}
};
}

}, {
async edit() {
throw new errors.IncorrectUsageError({message: 'Cannot edit MemberClickEvent'});
Expand Down
15 changes: 15 additions & 0 deletions ghost/core/core/server/models/member-paid-subscription-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ const MemberPaidSubscriptionEvent = ghostBookshelf.Model.extend({
.groupByRaw('currency, DATE(created_at)')
.orderByRaw('DATE(created_at)');
}
},

filterRelations() {
return {
subscriptionCreatedEvent: {
// Mongo-knex doesn't support belongsTo relations
tableName: 'members_subscription_created_events',
tableNameAs: 'subscriptionCreatedEvent',
type: 'manyToMany',
joinTable: 'members_paid_subscription_events',
joinFrom: 'id',
joinToForeign: 'subscription_id',
joinTo: 'subscription_id'
}
};
}
}, {
permittedOptions(methodName) {
Expand Down
Loading

0 comments on commit 47f273f

Please sign in to comment.