Skip to content

Commit

Permalink
It handles the scenarios where body.data is not correctly defined (as…
Browse files Browse the repository at this point in the history
… an object)
  • Loading branch information
Convly committed Nov 15, 2021
1 parent 70da516 commit 880c3c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/core/strapi/lib/core-api/service/collection-type.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/core/strapi/lib/core-api/service/single-type.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const { isObject } = require('lodash/fp');
const { ValidationError } = require('@strapi/utils').errors;

/**
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 880c3c5

Please sign in to comment.