Accept orderby: as alternative for sort:

This commit is contained in:
Bobby Wibowo 2020-05-16 22:07:15 +07:00
parent 0fad346df6
commit 93c6031bb1
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF

View File

@ -849,7 +849,8 @@ self.list = async (req, res) => {
filterObj.queries = searchQuery.parse(filters, {
keywords: keywords.concat([
'is',
'sort'
'sort',
'orderby'
]),
ranges,
tokenize: true,
@ -857,6 +858,13 @@ self.list = async (req, res) => {
offsets: false
})
// Accept orderby as alternative for sort
if (filterObj.queries.orderby) {
if (!filterObj.queries.sort) filterObj.queries.sort = []
filterObj.queries.sort = filterObj.queries.sort.concat(filterObj.queries.orderby)
delete filterObj.queries.orderby
}
// For some reason, single value won't be in Array even with 'alwaysArray' option
if (typeof filterObj.queries.exclude.text === 'string')
filterObj.queries.exclude.text = [filterObj.queries.exclude.text]