Ghost/core/server/models/plugins/custom-query.js
Kevin Ansfield f4d9a41d3b
Added ?paid query parameter to Admin API members browse endpoint (#11892)
no issue

- NQL does not support the relationship setup that members->stripe customer<->stripe subscriptions uses so it wasn't possible to use the `filter` param to query against having an active subscription
- adds `customQuery` bookshelf plugin that allows customisation of SQL query used in `findPage` method by individual models
- use `customQuery` in Member model to set up joins and conditionals to select free/paid members when `options.paid` is present
- allow `?paid` param through API and permitted options for member model
2020-06-12 12:12:10 +01:00

17 lines
422 B
JavaScript

const customQueryPlug = function customQueryPlug(Bookshelf) {
const Model = Bookshelf.Model.extend({
// override this on the model itself
customQuery() {},
applyCustomQuery: function applyCustomQuery(options) {
this.query((qb) => {
this.customQuery(qb, options);
});
}
});
Bookshelf.Model = Model;
};
module.exports = customQueryPlug;