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:
ChengLei Shao 2023-10-26 11:42:09 +08:00 committed by GitHub
parent e62d383bf1
commit a1c425f733
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -108,4 +108,13 @@ describe('create action', () => {
expect(await tag.hasPost(p1)).toBeTruthy();
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);
});
});

View File

@ -2,7 +2,6 @@ import lodash from 'lodash';
import { ModelStatic } from 'sequelize';
import { Model } from './model';
import { AssociationKeysToBeUpdate, BlackList, WhiteList } from './repository';
import { isPlainObject } from '@nocobase/utils/src';
type UpdateValueItem = string | number | UpdateValues;
@ -100,6 +99,10 @@ export class UpdateGuard {
* @param values
*/
sanitize(values: UpdateValues) {
if (values === null || values === undefined) {
return values;
}
values = lodash.clone(values);
if (!this.model) {