mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
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
3 changed files with 24 additions and 2 deletions
|
@ -10,7 +10,8 @@ module.exports = {
|
||||||
options: [
|
options: [
|
||||||
'limit',
|
'limit',
|
||||||
'page',
|
'page',
|
||||||
'include'
|
'include',
|
||||||
|
'filter'
|
||||||
],
|
],
|
||||||
permissions: true,
|
permissions: true,
|
||||||
validation: {},
|
validation: {},
|
||||||
|
|
|
@ -260,6 +260,26 @@ describe('Recommendations Admin API', function () {
|
||||||
|
|
||||||
assert.equal(page1.recommendations.length, 0);
|
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 () {
|
describe('read', function () {
|
||||||
|
|
|
@ -82,6 +82,7 @@ export class RecommendationController {
|
||||||
const page = options.optionalKey('page')?.integer ?? 1;
|
const page = options.optionalKey('page')?.integer ?? 1;
|
||||||
const limit = options.optionalKey('limit')?.integer ?? 5;
|
const limit = options.optionalKey('limit')?.integer ?? 5;
|
||||||
const include = options.optionalKey('withRelated')?.array.map(item => item.enum<RecommendationIncludeFields>(['count.clicks', 'count.subscribers'])) ?? [];
|
const include = options.optionalKey('withRelated')?.array.map(item => item.enum<RecommendationIncludeFields>(['count.clicks', 'count.subscribers'])) ?? [];
|
||||||
|
const filter = options.optionalKey('filter')?.string;
|
||||||
|
|
||||||
const order = [
|
const order = [
|
||||||
{
|
{
|
||||||
|
@ -91,7 +92,7 @@ export class RecommendationController {
|
||||||
];
|
];
|
||||||
|
|
||||||
const count = await this.service.countRecommendations({});
|
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(
|
return this.#serialize(
|
||||||
recommendations,
|
recommendations,
|
||||||
|
|
Loading…
Add table
Reference in a new issue