Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/wincloud_gateway/node_modules/strapi/lib/core-api/service/ drwxr-xr-x | |
| Viewing file: Select action/file-type: 'use strict';
const _ = require('lodash');
const {
isSingleType,
getNonWritableAttributes,
constants: { DP_PUB_STATE_LIVE },
} = require('strapi-utils').contentTypes;
const createSingleTypeService = require('./single-type');
const createCollectionTypeService = require('./collection-type');
/**
* Returns a core api for the provided model
* @param {{ model: object, strapi: object }} context
* @returns {object}
*/
const createService = ({ model, strapi }) => {
const utils = createUtils({ model });
if (isSingleType(model)) {
return createSingleTypeService({ model, strapi, utils });
}
return createCollectionTypeService({ model, strapi, utils });
};
/**
* Default limit values from config
* @return {{maxLimit: number, defaultLimit: number}}
*/
const getLimitConfigDefaults = () => ({
defaultLimit: _.toNumber(strapi.config.get('api.rest.defaultLimit', 100)),
maxLimit: _.toNumber(strapi.config.get('api.rest.maxLimit')) || null,
});
const getLimitParam = params => {
const { defaultLimit, maxLimit } = getLimitConfigDefaults();
if (params._limit === undefined) {
return defaultLimit;
}
const limit = _.toNumber(params._limit);
// if there is max limit set and params._limit exceeds this number, return configured max limit
if (maxLimit && (limit === -1 || limit > maxLimit)) {
return maxLimit;
}
return limit;
};
/**
* Create default fetch params
* @param {*} params
* @returns
*/
const getFetchParams = (params = {}) => {
return {
_publicationState: DP_PUB_STATE_LIVE,
...params,
_limit: getLimitParam(params),
};
};
/**
* Mixins
*/
const createUtils = ({ model }) => {
return {
// make sure to keep the call to getNonWritableAttributes dynamic
sanitizeInput: data => _.omit(data, getNonWritableAttributes(model)),
getFetchParams,
};
};
module.exports = {
createService,
getFetchParams,
};
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.027 ]-- |