Skip to content

Commit 30c1fbd

Browse files
committed
fix: enhance float value handling in setFieldValue method and simplify column type check in MongoConnector
1 parent 651159c commit 30c1fbd

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

adminforth/dataConnectors/baseConnector.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,14 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
233233
// Float
234234
if (field.type === AdminForthDataTypes.FLOAT) {
235235
if (value === "" || value === null) return this.setFieldValue(field, null);
236-
const number =
237-
typeof value === "number"
238-
? value
239-
: (typeof value === "object" && value !== null ? (value as any).valueOf() : NaN);
236+
let number: any;
237+
if (typeof value === "number") {
238+
number = value;
239+
} else if (typeof value === "object" && value !== null) {
240+
number = (value as any).valueOf();
241+
} else {
242+
number = NaN;
243+
}
240244

241245
if (typeof number !== "number" || !Number.isFinite(number)) {
242246
throw new Error(

adminforth/dataConnectors/mongo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class MongoConnector extends AdminForthBaseConnector implements IAdminForthDataS
266266
return { $expr: { [mongoExprOp]: [left, right] } };
267267
}
268268
const column = resource.dataSourceColumns.find((col) => col.name === (filter as IAdminForthSingleFilter).field);
269-
if (column && [AdminForthDataTypes.INTEGER, AdminForthDataTypes.DECIMAL, AdminForthDataTypes.FLOAT].includes(column.type)) {
269+
if ([AdminForthDataTypes.INTEGER, AdminForthDataTypes.DECIMAL, AdminForthDataTypes.FLOAT].includes(column.type)) {
270270
return { [(filter as IAdminForthSingleFilter).field]: this.OperatorsMap[filter.operator](+(filter as IAdminForthSingleFilter).value) };
271271
}
272272
return { [(filter as IAdminForthSingleFilter).field]: this.OperatorsMap[filter.operator]((filter as IAdminForthSingleFilter).value) };

0 commit comments

Comments
 (0)