mirror of
https://github.com/strapi/strapi.git
synced 2025-07-18 06:24:58 +00:00
20 lines
445 B
JavaScript
20 lines
445 B
JavaScript
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
|
|
/**
|
|
* If exists, rename the key "id" by the primary key name of the model ("_id" by default for mongoose).
|
|
*/
|
|
const replaceIdByPrimaryKey = (params, model) => {
|
|
const newParams = { ...params };
|
|
if (_.has(params, 'id')) {
|
|
delete newParams.id;
|
|
newParams[model.primaryKey] = params[model.primaryKey] || params.id;
|
|
}
|
|
return newParams;
|
|
};
|
|
|
|
module.exports = {
|
|
replaceIdByPrimaryKey,
|
|
};
|