Skip to content

Commit

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

- 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
- Fixed return types in JSDoc of test agents (TypeScript interprets these as `typeof Agent` if we don't add `InstanceType<Agent>`)
- Added total pagination metadata to activity feed API (to allow a basic type of pagination using filters)
  • Loading branch information
SimonBackx committed Oct 18, 2022
1 parent 95cfb48 commit 4c54ed8
Show file tree
Hide file tree
Showing 16 changed files with 1,051 additions and 89 deletions.
5 changes: 1 addition & 4 deletions ghost/core/core/server/api/endpoints/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,7 @@ module.exports = {
method: 'browse'
},
async query(frame) {
const events = await membersService.api.events.getEventTimeline(frame.options);
return {
events
};
return await membersService.api.events.getEventTimeline(frame.options);
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ function bulkAction(bulkActionResult, _apiConfig, frame) {

/**
*
* @returns {{events: any[]}}
* @returns {{events: any[], meta: any}}
*/
function activityFeed(data, _apiConfig, frame) {
return {
events: data.events.map(e => mappers.activityFeedEvents(e, frame))
events: data.events.map(e => mappers.activityFeedEvents(e, frame)),
meta: data.meta
};
}

Expand Down
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 4c54ed8

Please sign in to comment.