11import { yearsPassed } from '@douglasneuroinformatics/libjs' ;
22import { linearRegression } from '@douglasneuroinformatics/libstats' ;
33import { Injectable , NotFoundException , UnprocessableEntityException } from '@nestjs/common' ;
4- import type { ScalarInstrument } from '@opendatacapture/runtime-core' ;
4+ import type { Json , ScalarInstrument } from '@opendatacapture/runtime-core' ;
55import type {
66 CreateInstrumentRecordData ,
77 InstrumentRecord ,
@@ -25,6 +25,7 @@ import { SubjectsService } from '@/subjects/subjects.service';
2525import { VirtualizationService } from '@/virtualization/virtualization.service' ;
2626
2727import { InstrumentMeasuresService } from './instrument-measures.service' ;
28+ import { reviver } from '@douglasneuroinformatics/libjs' ;
2829
2930@Injectable ( )
3031export class InstrumentRecordsService {
@@ -286,7 +287,9 @@ export class InstrumentRecordsService {
286287
287288 const sessionId = session . id ;
288289
289- if ( ! instrument . validationSchema . safeParse ( data ) . success ) {
290+ const revivedData : Json = JSON . parse ( JSON . stringify ( data ) , reviver ) ;
291+
292+ if ( ! instrument . validationSchema . safeParse ( revivedData ) . success ) {
290293 throw new UnprocessableEntityException (
291294 `Data received for record at index '${ i } ' does not pass validation schema of instrument '${ instrument . id } '`
292295 ) ;
@@ -295,7 +298,7 @@ export class InstrumentRecordsService {
295298 const createdRecord = await this . instrumentRecordModel . create ( {
296299 data : {
297300 computedMeasures : instrument . measures
298- ? this . instrumentMeasuresService . computeMeasures ( instrument . measures , data )
301+ ? this . instrumentMeasuresService . computeMeasures ( instrument . measures , revivedData )
299302 : null ,
300303 data,
301304 date,
0 commit comments