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:
parent
2661ddcde2
commit
3ad8d9ab8b
1 changed files with 18 additions and 4 deletions
|
@ -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 {
|
module.exports = class EventRepository {
|
||||||
constructor({
|
constructor({
|
||||||
EmailRecipient,
|
EmailRecipient,
|
||||||
|
@ -93,8 +107,8 @@ module.exports = class EventRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSignupEvents(options = {}) {
|
async getSignupEvents(options = {}) {
|
||||||
|
options = addFilter(options, 'from_status:null');
|
||||||
options.withRelated = ['member'];
|
options.withRelated = ['member'];
|
||||||
options.filter = 'from_status:null';
|
|
||||||
const {data: models, meta} = await this._MemberStatusEvent.findPage(options);
|
const {data: models, meta} = await this._MemberStatusEvent.findPage(options);
|
||||||
|
|
||||||
const data = models.map((data) => {
|
const data = models.map((data) => {
|
||||||
|
@ -111,8 +125,8 @@ module.exports = class EventRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getEmailDelieveredEvents(options = {}) {
|
async getEmailDelieveredEvents(options = {}) {
|
||||||
|
options = addFilter(options, 'delivered_at:-null');
|
||||||
options.withRelated = ['member', 'email'];
|
options.withRelated = ['member', 'email'];
|
||||||
options.filter = 'delivered_at:-null';
|
|
||||||
const {data: models, meta} = await this._EmailRecipient.findPage(
|
const {data: models, meta} = await this._EmailRecipient.findPage(
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
|
@ -136,8 +150,8 @@ module.exports = class EventRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getEmailOpenedEvents(options = {}) {
|
async getEmailOpenedEvents(options = {}) {
|
||||||
|
options = addFilter(options, 'opened_at:-null');
|
||||||
options.withRelated = ['member', 'email'];
|
options.withRelated = ['member', 'email'];
|
||||||
options.filter = 'opened_at:-null';
|
|
||||||
const {data: models, meta} = await this._EmailRecipient.findPage(
|
const {data: models, meta} = await this._EmailRecipient.findPage(
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
|
@ -161,8 +175,8 @@ module.exports = class EventRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getEmailFailedEvents(options = {}) {
|
async getEmailFailedEvents(options = {}) {
|
||||||
|
options = addFilter(options, 'failed_at:-null');
|
||||||
options.withRelated = ['member', 'email'];
|
options.withRelated = ['member', 'email'];
|
||||||
options.filter = 'failed_at:-null';
|
|
||||||
const {data: models, meta} = await this._EmailRecipient.findPage(
|
const {data: models, meta} = await this._EmailRecipient.findPage(
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue