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

Added the option to filter events from getEventTimeline

refs https://github.com/TryGhost/Team/issues/1277

- Added the pre-existing framework filters to each event query.
- Made sure we aren't modifying the original `options.filter` to avoid side-effects between event queries.
This commit is contained in:
Thibaut Patel 2022-01-21 11:16:24 +01:00
parent 2661ddcde2
commit 3ad8d9ab8b

View file

@ -1,3 +1,17 @@
/**
* Adds a filter to `options`. Returns a copy of options to avoid this
* action to affect other event getters.
* @param {Object} options The framework `options` object.
* @param {string} filter The NQL filter to add to the `options` filter.
* @returns {Object} A copy of options with the filter
*/
function addFilter(options, filter) {
return {
...options,
filter: `(${options.filter})+(${filter})`
};
}
module.exports = class EventRepository {
constructor({
EmailRecipient,
@ -93,8 +107,8 @@ module.exports = class EventRepository {
}
async getSignupEvents(options = {}) {
options = addFilter(options, 'from_status:null');
options.withRelated = ['member'];
options.filter = 'from_status:null';
const {data: models, meta} = await this._MemberStatusEvent.findPage(options);
const data = models.map((data) => {
@ -111,8 +125,8 @@ module.exports = class EventRepository {
}
async getEmailDelieveredEvents(options = {}) {
options = addFilter(options, 'delivered_at:-null');
options.withRelated = ['member', 'email'];
options.filter = 'delivered_at:-null';
const {data: models, meta} = await this._EmailRecipient.findPage(
options
);
@ -136,8 +150,8 @@ module.exports = class EventRepository {
}
async getEmailOpenedEvents(options = {}) {
options = addFilter(options, 'opened_at:-null');
options.withRelated = ['member', 'email'];
options.filter = 'opened_at:-null';
const {data: models, meta} = await this._EmailRecipient.findPage(
options
);
@ -161,8 +175,8 @@ module.exports = class EventRepository {
}
async getEmailFailedEvents(options = {}) {
options = addFilter(options, 'failed_at:-null');
options.withRelated = ['member', 'email'];
options.filter = 'failed_at:-null';
const {data: models, meta} = await this._EmailRecipient.findPage(
options
);