From 19d628fda2d45a82bc7658524a0889490c33f74b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=B5=A9=E6=9E=97?= Date: Sun, 28 Apr 2024 10:51:47 +0800 Subject: [PATCH] =?UTF-8?q?[Bug]:=20=E4=BD=BF=E7=94=A8$inc=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E8=AE=B0=E5=BD=95=E6=97=B6=E7=B4=AF=E8=AE=A1=E6=B1=87?= =?UTF-8?q?=E6=80=BB=E5=A4=B1=E6=95=88=20#6791?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/objectql/src/util/field.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/objectql/src/util/field.ts b/packages/objectql/src/util/field.ts index e2479b10b5..3ac1f47c73 100644 --- a/packages/objectql/src/util/field.ts +++ b/packages/objectql/src/util/field.ts @@ -1,8 +1,8 @@ /* * @Author: 殷亮辉 yinlianghui@hotoa.com * @Date: 2023-01-06 22:43:24 - * @LastEditors: 殷亮辉 yinlianghui@hotoa.com - * @LastEditTime: 2024-04-16 11:47:59 + * @LastEditors: 孙浩林 sunhaolin@steedos.com + * @LastEditTime: 2024-04-28 10:38:18 */ const baseFieldsName = [{ "name": "object", "required": true }, { "name": "label", "required": true }, { name: '_name', required: true }, { "name": "type", "required": false }, { "name": "defaultValue" }, @@ -101,13 +101,24 @@ export const getFieldsByType = (doc, type: string, dataType?: string) => { export const getFieldNamesFromDoc = (doc: any, fields?: any): string[] => { const docFieldNames: string[] = _.keys(doc) || []; + + let reFieldNames: string[] = []; + for (const fieldName of docFieldNames) { + if(_.includes(['$inc','$min','$max','$mul'], fieldName)){ + const keys = getFieldNamesFromDoc(doc[fieldName], fields); + reFieldNames = reFieldNames.concat(keys); + } + } + + reFieldNames = _.union(reFieldNames, docFieldNames) + if(fields){ // 如果提供了fields,则进一步筛选,只返回fields中存在的字段我 - return docFieldNames.filter((docFieldName)=>{ + return reFieldNames.filter((docFieldName)=>{ return !!fields[docFieldName]; }); } else{ - return docFieldNames; + return reFieldNames; } } \ No newline at end of file