Skip to content

Commit 9a8c146

Browse files
authored
Merge pull request #997 from david-roper/process-csv-fix
2 parents c81d923 + ca20f7c commit 9a8c146

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

apps/web/src/features/upload/utils.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,26 @@ export async function processInstrumentCSV(
398398
instrument: AnyUnilingualFormInstrument
399399
): Promise<UploadOperationResult<FormTypes.Data[]>> {
400400
const instrumentSchema = instrument.validationSchema as z.AnyZodObject;
401-
const instrumentSchemaWithInternal = instrumentSchema.extend({
402-
date: z.coerce.date(),
403-
subjectID: z.string()
404-
});
405-
const shape = instrumentSchemaWithInternal.shape as { [key: string]: z.ZodTypeAny };
401+
let shape: { [key: string]: z.ZodTypeAny } = {};
402+
let instrumentSchemaWithInternal: z.AnyZodObject;
403+
404+
if ((instrumentSchema._def.typeName as string) === 'ZodEffects') {
405+
// TODO - find a type safe way to call this
406+
407+
instrumentSchemaWithInternal = instrumentSchema._def.schema.extend({
408+
date: z.coerce.date(),
409+
subjectID: z.string()
410+
}) as z.AnyZodObject;
411+
412+
shape = instrumentSchemaWithInternal._def.shape() as { [key: string]: z.ZodTypeAny };
413+
} else {
414+
//const shape2 = instrumentSchema.shape as { [key: string]: z.ZodTypeAny };
415+
instrumentSchemaWithInternal = instrumentSchema.extend({
416+
date: z.coerce.date(),
417+
subjectID: z.string()
418+
});
419+
shape = instrumentSchemaWithInternal.shape as { [key: string]: z.ZodTypeAny };
420+
}
406421

407422
return new Promise<UploadOperationResult<FormTypes.Data[]>>((resolve) => {
408423
const reader = new FileReader();

0 commit comments

Comments
 (0)