Skip to content

Commit ef7d9ce

Browse files
committed
fix: improve object type handling in normalizeMongoValue and setFieldValue methods
1 parent 30c1fbd commit ef7d9ce

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

adminforth/dataConnectors/baseConnector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
236236
let number: any;
237237
if (typeof value === "number") {
238238
number = value;
239-
} else if (typeof value === "object" && value !== null) {
239+
} else if (typeof value === "object") {
240240
number = (value as any).valueOf();
241241
} else {
242242
number = NaN;
@@ -269,7 +269,7 @@ export default class AdminForthBaseConnector implements IAdminForthDataSourceCon
269269
throw new Error(`Value is not a decimal. Field ${field.name} got: ${value} (string)`);
270270
}
271271

272-
if (typeof value === "object" && value) {
272+
if (typeof value === "object") {
273273
if (typeof value.toString !== "function") {
274274
throw new Error(`Decimal object has no toString(). Field ${field.name} got: ${String(value)}`);
275275
}

adminforth/dataConnectors/mongo.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ const escapeRegex = (value) => {
1212
function normalizeMongoValue(v: any) {
1313
if (v == null) return v;
1414
if (v instanceof Decimal128) return v.toString();
15+
if (v instanceof Double) return v.valueOf();
1516
if (typeof v === "object" && v.$numberDecimal) return String(v.$numberDecimal);
17+
if (typeof v === "object" && v.$numberDouble) return Number(v.$numberDouble);
1618
return v;
1719
}
1820

0 commit comments

Comments
 (0)