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';
|
||||
|
||||
const { propOr } = require('lodash/fp');
|
||||
const { propOr, isObject } = require('lodash/fp');
|
||||
|
||||
const {
|
||||
hasDraftAndPublish,
|
||||
constants: { PUBLISHED_AT_ATTRIBUTE },
|
||||
} = require('@strapi/utils').contentTypes;
|
||||
const { ValidationError } = require('@strapi/utils').errors;
|
||||
|
||||
const {
|
||||
getPaginationInfo,
|
||||
@ -60,6 +61,10 @@ const createCollectionTypeService = ({ model, strapi, utils }) => {
|
||||
create(params = {}) {
|
||||
const { data } = params;
|
||||
|
||||
if (!isObject(data)) {
|
||||
throw new ValidationError(`Expecting body.data to be an object but found '${typeof data}'`);
|
||||
}
|
||||
|
||||
if (hasDraftAndPublish(model)) {
|
||||
setPublishedAt(data);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { isObject } = require('lodash/fp');
|
||||
const { ValidationError } = require('@strapi/utils').errors;
|
||||
|
||||
/**
|
||||
@ -27,6 +28,10 @@ const createSingleTypeService = ({ model, strapi, utils }) => {
|
||||
async createOrUpdate({ data, ...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) {
|
||||
const count = await strapi.query(uid).count();
|
||||
if (count >= 1) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user