Skip to content

Commit c3f924a

Browse files
committed
fix: replace numeric coercion with toNumericSafe method in query functions
1 parent e3b2048 commit c3f924a

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

‎apps/nestjs-backend/src/db-provider/generated-column-query/postgres/generated-column-query.postgres.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('GeneratedColumnQueryPostgres unit-aware helpers', () => {
1313
};
1414

1515
beforeEach(() => {
16-
query.setContext(stubContext);
16+
query.setContext(stubContext);
1717
});
1818

1919
it('left casts expressions to text for generated columns', () => {

‎apps/nestjs-backend/src/db-provider/generated-column-query/postgres/generated-column-query.postgres.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class GeneratedColumnQueryPostgres extends GeneratedColumnQueryAbstract {
191191
}
192192

193193
value(text: string): string {
194-
return `${text}::numeric`;
194+
return this.toNumericSafe(text);
195195
}
196196

197197
// Text Functions

‎apps/nestjs-backend/src/db-provider/select-query/postgres/select-query.postgres.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export class SelectQueryPostgres extends SelectQueryAbstract {
332332
}
333333

334334
value(text: string): string {
335-
return `${text}::numeric`;
335+
return this.toNumericSafe(text);
336336
}
337337

338338
// Text Functions

‎apps/nestjs-backend/test/formula-field.e2e-spec.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,4 +867,55 @@ describe('OpenAPI Formula Field (e2e)', () => {
867867
expect(records[1].fields[formulaField.id]).toBe(1999);
868868
});
869869
});
870+
871+
describe('localized single select numeric coercion', () => {
872+
let table: ITableFullVo;
873+
874+
beforeEach(async () => {
875+
table = await createTable(baseId, {
876+
name: 'Localized Duration Formula',
877+
fields: [
878+
{
879+
name: '定型时长',
880+
type: FieldType.SingleSelect,
881+
options: {
882+
preventAutoNewOptions: true,
883+
choices: [
884+
{ name: '0分钟', color: Colors.GrayDark1 },
885+
{ name: '20分钟', color: Colors.BlueLight1 },
886+
{ name: '30分钟', color: Colors.BlueBright },
887+
],
888+
},
889+
},
890+
],
891+
records: [
892+
{ fields: { 定型时长: '0分钟' } },
893+
{ fields: { 定型时长: '20分钟' } },
894+
{ fields: { 定型时长: '30分钟' } },
895+
],
896+
});
897+
});
898+
899+
afterEach(async () => {
900+
if (table?.id) {
901+
await deleteTable(baseId, table.id);
902+
}
903+
});
904+
905+
it('parses localized option labels through VALUE()', async () => {
906+
const durationFieldId = table.fields.find((f) => f.name === '定型时长')!.id;
907+
908+
const numericField = await createField(table.id, {
909+
type: FieldType.Formula,
910+
name: '定型时长(数值)',
911+
options: {
912+
expression: `VALUE({${durationFieldId}})`,
913+
},
914+
});
915+
916+
const { records } = await getRecords(table.id, { fieldKeyType: FieldKeyType.Id });
917+
const parsedValues = records.map((record) => record.fields[numericField.id]);
918+
expect(parsedValues).toEqual([0, 20, 30]);
919+
});
920+
});
870921
});

‎apps/nestjs-backend/test/lookup.e2e-spec.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,13 @@ describe('OpenAPI Lookup field (e2e)', () => {
15251525
const formulaValue = projectRecord!.fields[formulaField.id];
15261526
expect(typeof formulaValue).toBe('string');
15271527
expect(formulaValue as string).toContain('prefix-');
1528+
1529+
await updateRecordByApi(
1530+
projectTable.id,
1531+
projectRecordId,
1532+
projectNameField.id,
1533+
'Project Beta'
1534+
);
15281535
});
15291536
});
15301537
});

0 commit comments

Comments
 (0)