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