fix: error when post create action with emtpy value (#2916)
* fix: error when post create action with emtpy value * chore: sanitize
This commit is contained in:
parent
e62d383bf1
commit
a1c425f733
@ -108,4 +108,13 @@ describe('create action', () => {
|
|||||||
expect(await tag.hasPost(p1)).toBeTruthy();
|
expect(await tag.hasPost(p1)).toBeTruthy();
|
||||||
expect(tag.get('name')).toEqual('hello');
|
expect(tag.get('name')).toEqual('hello');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('create with empty values', async () => {
|
||||||
|
const response = await app.agent().resource('posts').create({});
|
||||||
|
expect(response.statusCode).toEqual(200);
|
||||||
|
const p1 = await Post.repository.findOne();
|
||||||
|
|
||||||
|
const response2 = await app.agent().resource('posts.comments', p1.get('id')).create({});
|
||||||
|
expect(response2.statusCode).toEqual(200);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,6 @@ import lodash from 'lodash';
|
|||||||
import { ModelStatic } from 'sequelize';
|
import { ModelStatic } from 'sequelize';
|
||||||
import { Model } from './model';
|
import { Model } from './model';
|
||||||
import { AssociationKeysToBeUpdate, BlackList, WhiteList } from './repository';
|
import { AssociationKeysToBeUpdate, BlackList, WhiteList } from './repository';
|
||||||
import { isPlainObject } from '@nocobase/utils/src';
|
|
||||||
|
|
||||||
type UpdateValueItem = string | number | UpdateValues;
|
type UpdateValueItem = string | number | UpdateValues;
|
||||||
|
|
||||||
@ -100,6 +99,10 @@ export class UpdateGuard {
|
|||||||
* @param values
|
* @param values
|
||||||
*/
|
*/
|
||||||
sanitize(values: UpdateValues) {
|
sanitize(values: UpdateValues) {
|
||||||
|
if (values === null || values === undefined) {
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
values = lodash.clone(values);
|
values = lodash.clone(values);
|
||||||
|
|
||||||
if (!this.model) {
|
if (!this.model) {
|
||||||
|
Loading…
Reference in New Issue
Block a user