mirror of
https://github.com/strapi/strapi.git
synced 2025-09-20 22:10:06 +00:00
It handles the scenarios where body.data is not correctly defined (as an object)
This commit is contained in:
parent
70da516801
commit
880c3c53a8
@ -1,11 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { propOr } = require('lodash/fp');
|
const { propOr, isObject } = require('lodash/fp');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
hasDraftAndPublish,
|
hasDraftAndPublish,
|
||||||
constants: { PUBLISHED_AT_ATTRIBUTE },
|
constants: { PUBLISHED_AT_ATTRIBUTE },
|
||||||
} = require('@strapi/utils').contentTypes;
|
} = require('@strapi/utils').contentTypes;
|
||||||
|
const { ValidationError } = require('@strapi/utils').errors;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
getPaginationInfo,
|
getPaginationInfo,
|
||||||
@ -60,6 +61,10 @@ const createCollectionTypeService = ({ model, strapi, utils }) => {
|
|||||||
create(params = {}) {
|
create(params = {}) {
|
||||||
const { data } = params;
|
const { data } = params;
|
||||||
|
|
||||||
|
if (!isObject(data)) {
|
||||||
|
throw new ValidationError(`Expecting body.data to be an object but found '${typeof data}'`);
|
||||||
|
}
|
||||||
|
|
||||||
if (hasDraftAndPublish(model)) {
|
if (hasDraftAndPublish(model)) {
|
||||||
setPublishedAt(data);
|
setPublishedAt(data);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const { isObject } = require('lodash/fp');
|
||||||
const { ValidationError } = require('@strapi/utils').errors;
|
const { ValidationError } = require('@strapi/utils').errors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,6 +28,10 @@ const createSingleTypeService = ({ model, strapi, utils }) => {
|
|||||||
async createOrUpdate({ data, ...params } = {}) {
|
async createOrUpdate({ data, ...params } = {}) {
|
||||||
const entity = await this.find(params);
|
const entity = await this.find(params);
|
||||||
|
|
||||||
|
if (!isObject(data)) {
|
||||||
|
throw new ValidationError(`Expecting body.data to be an object but found '${typeof data}'`);
|
||||||
|
}
|
||||||
|
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
const count = await strapi.query(uid).count();
|
const count = await strapi.query(uid).count();
|
||||||
if (count >= 1) {
|
if (count >= 1) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user