Skip to content

Commit e7c13ce

Browse files
committed
feat: add safeparse check for dataValue elements
1 parent 6a55f16 commit e7c13ce

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { linearRegression } from '@douglasneuroinformatics/libstats';
55
import { BadRequestException, Injectable, NotFoundException, UnprocessableEntityException } from '@nestjs/common';
66
import type { Json, ScalarInstrument } from '@opendatacapture/runtime-core';
77
import { DEFAULT_GROUP_NAME } from '@opendatacapture/schemas/core';
8+
import { $RecordArrayFieldValue } from '@opendatacapture/schemas/instrument';
89
import type {
910
CreateInstrumentRecordData,
1011
InstrumentRecord,
@@ -413,6 +414,8 @@ export class InstrumentRecordsService {
413414
if (listEntry.length > 0) {
414415
for (const objectEntry of listEntry) {
415416
for (const [dataKey, dataValue] of Object.entries(objectEntry as { [key: string]: any })) {
417+
const parseResult = $RecordArrayFieldValue.safeParse(dataValue);
418+
if (!parseResult.success) return err('Invalid data value');
416419
data.push({
417420
groupId: record.groupId ?? DEFAULT_GROUP_NAME,
418421
instrumentEdition: instrument.internal.edition,

0 commit comments

Comments
 (0)