It handles the scenarios where body.data is not correctly defined (as an object)

This commit is contained in:
Convly 2021-11-15 15:34:23 +01:00
parent 70da516801
commit 880c3c53a8
2 changed files with 11 additions and 1 deletions

View File

@ -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);
}

View File

@ -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) {