Supported using NQL filter to get Offers

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

This adds initial support for pass through a filter to the Model layer,
so that we can fetch Offers based on an NQL filter.
This commit is contained in:
Fabien O'Carroll 2021-10-12 17:53:08 +02:00
parent 8b271835d2
commit 1e4b5c792a
2 changed files with 17 additions and 9 deletions

View File

@ -4,10 +4,16 @@ const Offer = require('../domain/models/Offer');
const OfferStatus = require('../domain/models/OfferStatus');
/**
* @typedef {object} OfferRepositoryOptions
* @typedef {object} BaseOptions
* @prop {import('knex').Transaction} transacting
*/
/**
* @extends BaseOptions
* @typedef {object} ListOptions
* @prop {string} filter
*/
/**
* @param {any} json
* @returns {Offer.OfferCreateProps}
@ -57,7 +63,7 @@ class OfferRepository {
/**
* @param {string} name
* @param {OfferRepositoryOptions} [options]
* @param {BaseOptions} [options]
* @returns {Promise<boolean>}
*/
async existsByName(name, options) {
@ -70,7 +76,7 @@ class OfferRepository {
/**
* @param {string} code
* @param {OfferRepositoryOptions} [options]
* @param {BaseOptions} [options]
* @returns {Promise<boolean>}
*/
async existsByCode(code, options) {
@ -83,7 +89,7 @@ class OfferRepository {
/**
* @param {string} id
* @param {OfferRepositoryOptions} [options]
* @param {BaseOptions} [options]
* @returns {Promise<Offer>}
*/
async getById(id, options) {
@ -98,7 +104,7 @@ class OfferRepository {
}
/**
* @param {OfferRepositoryOptions} [options]
* @param {ListOptions} options
* @returns {Promise<Offer[]>}
*/
async getAll(options) {
@ -111,7 +117,7 @@ class OfferRepository {
/**
* @param {Offer} offer
* @param {OfferRepositoryOptions} [options]
* @param {BaseOptions} [options]
* @returns {Promise<void>}
*/
async save(offer, options) {

View File

@ -99,13 +99,15 @@ class OffersAPI {
}
/**
* @param {object} options
* @param {string} options.filter
* @returns {Promise<OfferMapper.OfferDTO[]>}
*/
async listOffers() {
async listOffers(options) {
return await this.repository.createTransaction(async (transaction) => {
const options = {transacting: transaction};
const opts = {transacting: transaction, filter: options.filter};
const offers = await this.repository.getAll(options);
const offers = await this.repository.getAll(opts);
return offers.map(OfferMapper.toDTO);
});