mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
Keep _ to make the client work until we remove them on the client
This commit is contained in:
parent
e20e7738b5
commit
50849e68c7
@ -57,6 +57,21 @@ module.exports = ctx => {
|
||||
return service;
|
||||
};
|
||||
|
||||
// TODO: remove once the front is migrated
|
||||
const convertOldQuery = params => {
|
||||
const obj = {};
|
||||
|
||||
Object.keys(params).forEach(key => {
|
||||
if (key.startsWith('_')) {
|
||||
obj[key.slice(1)] = params[key];
|
||||
} else {
|
||||
obj[key] = params[key];
|
||||
}
|
||||
});
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
// TODO: move to Controller ?
|
||||
const transformParamsToQuery = (uid, params = {}) => {
|
||||
const model = strapi.getModel(uid);
|
||||
@ -75,10 +90,13 @@ const transformParamsToQuery = (uid, params = {}) => {
|
||||
fields,
|
||||
populate,
|
||||
publicationState,
|
||||
_q,
|
||||
_where,
|
||||
...rest
|
||||
} = params;
|
||||
|
||||
if (params._q) {
|
||||
query._q = params._q;
|
||||
if (_q) {
|
||||
query._q = _q;
|
||||
}
|
||||
|
||||
if (page) {
|
||||
@ -105,6 +123,12 @@ const transformParamsToQuery = (uid, params = {}) => {
|
||||
query.where = filters;
|
||||
}
|
||||
|
||||
if (_where) {
|
||||
query.where = {
|
||||
$and: [_where].concat(query.where || []),
|
||||
};
|
||||
}
|
||||
|
||||
if (fields) {
|
||||
query.select = _.castArray(fields);
|
||||
}
|
||||
@ -133,7 +157,12 @@ const transformParamsToQuery = (uid, params = {}) => {
|
||||
}
|
||||
}
|
||||
|
||||
return query;
|
||||
const finalQuery = {
|
||||
...convertOldQuery(rest),
|
||||
...query,
|
||||
};
|
||||
|
||||
return finalQuery;
|
||||
};
|
||||
|
||||
const pickSelectionParams = pick(['fields', 'populate']);
|
||||
|
||||
@ -37,6 +37,20 @@ const wrapParams = async (params = {}, ctx = {}) => {
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: remove when the _locale is renamed to locale
|
||||
if (has('_locale', params)) {
|
||||
if (params['_locale'] === 'all') {
|
||||
return omit('_locale', params);
|
||||
}
|
||||
|
||||
return {
|
||||
...omit('_locale', params),
|
||||
filters: {
|
||||
$and: [{ locale: params['_locale'] }].concat(params.filters || []),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const entityDefinedById = paramsContain('id', params) && SINGLE_ENTRY_ACTIONS.includes(action);
|
||||
const entitiesDefinedByIds = paramsContain('id.$in', params) && BULK_ACTIONS.includes(action);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user