Skip to content

Instantly share code, notes, and snippets.

@package71
Created December 13, 2019 02:57
Show Gist options
  • Save package71/f4bcdba20e006abfb12cda7d91b9a4e5 to your computer and use it in GitHub Desktop.
Save package71/f4bcdba20e006abfb12cda7d91b9a4e5 to your computer and use it in GitHub Desktop.
/** @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