Created
December 13, 2019 02:57
-
-
Save package71/f4bcdba20e006abfb12cda7d91b9a4e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @name API.plugin.sortAPI */ | |
module.exports = { | |
/** | |
* @param {object} initialSort - start sort | |
* @param {object} params - client params | |
* */ | |
get: function (initialSort, params) { | |
let sort = {}; | |
if (params.sortKey && params.sortType) | |
sort[params.sortKey] = (params.sortType === 'DESC') ? -1 : 1; | |
if (initialSort && typeof initialSort === 'object' && !Array.isArray(initialSort)) | |
sort = {...sort, ...initialSort}; | |
return sort; | |
}, | |
docsParams: (API, avalibleKey) => { | |
return { | |
sortKey: { | |
type: (avalibleKey && Array.isArray(avalibleKey)) ? API.types.ENUM(...avalibleKey) : API.types.STRING(100), | |
// type: API.types.ENUM("createdAt", "method", "user.name", "user.email", "network.ip", "network.counterName"), | |
title: 'sort by field', | |
error_code: 1181529524750553 | |
}, | |
sortType: { | |
type: API.types.ENUM("ASC", "DESC"), | |
title: 'sort type (default:ASC)', | |
error_code: 2461538399520777 | |
}, | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment