Ensured page filter works in routes.yaml

refs #10922

The frontend UrlGenerator parses the filters itself rather than passing
to the api, so we need to replicate the conversion from page -> type
This commit is contained in:
Fabien O'Carroll 2019-08-12 18:18:32 +08:00
parent 8c5f1d0ef0
commit 9037c19e50

View File

@ -23,6 +23,8 @@ const _ = require('lodash'),
replacement: 'primary_author.slug'
}];
const mapNQLKeyValues = require('nql-map-key-values');
/**
* The UrlGenerator class is responsible to generate urls based on a router's conditions.
* It is the component which sits between routers and resources and connects them together.
@ -44,7 +46,22 @@ class UrlGenerator {
// CASE: routers can define custom filters, but not required.
if (this.router.getFilter()) {
this.filter = this.router.getFilter();
this.nql = nql(this.filter, {expansions: EXPANSIONS});
this.nql = nql(this.filter, {
expansions: EXPANSIONS,
transformer: mapNQLKeyValues({
key: {
from: 'page',
to: 'type'
},
values: [{
from: false,
to: 'post'
}, {
from: true,
to: 'page'
}]
})
});
debug('filter', this.filter);
}