mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +00:00
check both action & params.id
This commit is contained in:
parent
883c2a4955
commit
108409941b
@ -7,13 +7,16 @@ const { isLocalized } = require('./content-types');
|
||||
const { syncLocalizations, updateNonLocalizedFields } = require('./localizations');
|
||||
|
||||
const LOCALE_QUERY_FILTER = '_locale';
|
||||
const SINGLE_ENTRY_ACTIONS = ['findOne', 'update', 'delete'];
|
||||
|
||||
/**
|
||||
* Adds default locale or replaces _locale by locale in query params
|
||||
* @param {object} params - query params
|
||||
*/
|
||||
const wrapParams = async (params = {}) => {
|
||||
if (params.id) {
|
||||
const wrapParams = async (params = {}, ctx = {}) => {
|
||||
const { action } = ctx;
|
||||
|
||||
if (has('id', params) && SINGLE_ENTRY_ACTIONS.includes(action)) {
|
||||
return params;
|
||||
}
|
||||
|
||||
@ -47,14 +50,7 @@ const decorator = service => ({
|
||||
*/
|
||||
|
||||
async wrapOptions(opts = {}, ctx = {}) {
|
||||
const { action } = ctx;
|
||||
|
||||
const wrappedOptions = await service.wrapOptions.apply(this, [opts, ctx]);
|
||||
|
||||
// do not change if parameter contains an id ?
|
||||
if (action === 'findOne') {
|
||||
return wrappedOptions;
|
||||
}
|
||||
const wrappedOptions = await service.wrapOptions.call(this, opts, ctx);
|
||||
|
||||
const model = strapi.db.getModel(ctx.model);
|
||||
|
||||
@ -64,7 +60,7 @@ const decorator = service => ({
|
||||
|
||||
return {
|
||||
...wrappedOptions,
|
||||
params: await wrapParams(wrappedOptions.params),
|
||||
params: await wrapParams(wrappedOptions.params, ctx),
|
||||
};
|
||||
},
|
||||
|
||||
@ -76,7 +72,7 @@ const decorator = service => ({
|
||||
*/
|
||||
async create(opts, ctx) {
|
||||
const model = strapi.db.getModel(ctx.model);
|
||||
const entry = await service.create.apply(this, [opts, ctx]);
|
||||
const entry = await service.create.call(this, opts, ctx);
|
||||
|
||||
if (isLocalized(model)) {
|
||||
await syncLocalizations(entry, { model });
|
||||
@ -96,13 +92,14 @@ const decorator = service => ({
|
||||
|
||||
const { data, ...restOptions } = opts;
|
||||
|
||||
const entry = await service.update.apply(this, [
|
||||
const entry = await service.update.call(
|
||||
this,
|
||||
{
|
||||
data: omit(['locale', 'localizations'], data),
|
||||
...restOptions,
|
||||
},
|
||||
ctx,
|
||||
]);
|
||||
ctx
|
||||
);
|
||||
|
||||
if (isLocalized(model)) {
|
||||
await updateNonLocalizedFields(entry, { model });
|
||||
|
Loading…
x
Reference in New Issue
Block a user