Skip to content

Commit e69c196

Browse files
committed
refactor: add recordArrayPair type to allow both exports to work
1 parent 6c9ef9e commit e69c196

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

apps/api/src/instrument-records/instrument-records.service.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -423,19 +423,17 @@ export class InstrumentRecordsService {
423423
throw new Error('Record Array is Empty');
424424
}
425425
for (const objectEntry of Object.values(listEntry)) {
426-
const parseResult = $RecordArrayFieldValue.safeParse(objectEntry);
427-
if (!parseResult.success) {
428-
validRecordArrayList.push({
429-
message: `Error interpreting value of record array entry ${objectEntry}`,
430-
success: false
431-
});
432-
}
433-
for (const [dataKey, dataValue] of Object.entries(
434-
objectEntry as { [key: string]: boolean | Date | number | string | undefined }
435-
)) {
426+
for (const [dataKey, dataValue] of Object.entries(objectEntry as { [key: string]: any })) {
427+
const parseResult = $RecordArrayFieldValue.safeParse(dataValue);
428+
if (!parseResult.success) {
429+
validRecordArrayList.push({
430+
message: `Error interpreting value ${dataValue} and record array key ${dataKey}`,
431+
success: false
432+
});
433+
}
436434
validRecordArrayList.push({
437435
measure: dataKey,
438-
measureValue: dataValue,
436+
measureValue: parseResult.data,
439437
success: true
440438
});
441439
}

packages/schemas/src/instrument/instrument.base.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,16 @@ const $UnilingualInstrumentDetails = $InstrumentDetails.extend({
9292

9393
const $InstrumentMeasureVisibility: z.ZodType<InstrumentMeasureVisibility> = z.enum(['hidden', 'visible']);
9494

95-
const $RecordArrayFieldValue = z.record(
96-
z.string(),
97-
z.union([z.string(), z.boolean(), z.number(), z.date(), z.undefined()])
98-
);
95+
const $RecordArrayFieldValue = z.union([z.string(), z.boolean(), z.number(), z.date(), z.undefined()]);
96+
97+
const $RecordArrayPair = z.record(z.string(), $RecordArrayFieldValue);
9998

10099
const $InstrumentMeasureValue: z.ZodType<InstrumentMeasureValue> = z.union([
101100
z.string(),
102101
z.boolean(),
103102
z.number(),
104103
z.date(),
105-
z.array($RecordArrayFieldValue),
104+
z.array($RecordArrayPair),
106105
z.undefined()
107106
]);
108107

0 commit comments

Comments
 (0)