Added filter option to the Recommendations Admin API's browse endpoint (#18233)
closes https://github.com/TryGhost/Product/issues/3907
This commit is contained in:
parent
3928b628ca
commit
e1c966b6d7
@ -10,7 +10,8 @@ module.exports = {
|
||||
options: [
|
||||
'limit',
|
||||
'page',
|
||||
'include'
|
||||
'include',
|
||||
'filter'
|
||||
],
|
||||
permissions: true,
|
||||
validation: {},
|
||||
|
@ -260,6 +260,26 @@ describe('Recommendations Admin API', function () {
|
||||
|
||||
assert.equal(page1.recommendations.length, 0);
|
||||
});
|
||||
|
||||
it('can fetch recommendations filtered by an exact title', async function () {
|
||||
await addDummyRecommendations(5);
|
||||
|
||||
const {body} = await agent.get(`recommendations/?filter=title:'Recommendation 1'`)
|
||||
.expectStatus(200);
|
||||
|
||||
assert.equal(body.recommendations.length, 1);
|
||||
assert.equal(body.recommendations[0].title, 'Recommendation 1');
|
||||
});
|
||||
|
||||
it('can fetch recommendations filtered by a partial URL', async function () {
|
||||
await addDummyRecommendations(5);
|
||||
|
||||
const {body} = await agent.get(`recommendations/?filter=url:~'recommendation1.com'`)
|
||||
.expectStatus(200);
|
||||
|
||||
assert.equal(body.recommendations.length, 1);
|
||||
assert.equal(body.recommendations[0].url, 'https://recommendation1.com/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('read', function () {
|
||||
|
@ -82,6 +82,7 @@ export class RecommendationController {
|
||||
const page = options.optionalKey('page')?.integer ?? 1;
|
||||
const limit = options.optionalKey('limit')?.integer ?? 5;
|
||||
const include = options.optionalKey('withRelated')?.array.map(item => item.enum<RecommendationIncludeFields>(['count.clicks', 'count.subscribers'])) ?? [];
|
||||
const filter = options.optionalKey('filter')?.string;
|
||||
|
||||
const order = [
|
||||
{
|
||||
@ -91,7 +92,7 @@ export class RecommendationController {
|
||||
];
|
||||
|
||||
const count = await this.service.countRecommendations({});
|
||||
const recommendations = (await this.service.listRecommendations({page, limit, order, include}));
|
||||
const recommendations = (await this.service.listRecommendations({page, limit, filter, include, order}));
|
||||
|
||||
return this.#serialize(
|
||||
recommendations,
|
||||
|
Loading…
Reference in New Issue
Block a user