Skip to content

Commit e399b53

Browse files
committed
fixed diagnostic bugs
1 parent ad3d065 commit e399b53

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

server/src/preFlight/validateBatchConfig.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,7 @@ class ValidationError extends Error {
250250
}
251251
}
252252

253-
<<<<<<< HEAD
254-
=======
255253
//changed line 260 errors type so it would throw no errors in deliberation-lab-tools, if it breaks something then revert this change
256-
>>>>>>> config-validators
257254
export function validateBatchConfig(config: unknown) {
258255
const result = batchConfigSchema.safeParse(config);
259256
if (!result.success) {

server/src/preFlight/validateTreatmentFile.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ export const introSequencesSchema = altTemplateContext(
685685
}).nonempty()
686686
);
687687

688-
export const treatmentSchema = altTemplateContext(
688+
export const baseTreatmentSchema =
689689
z.object({
690690
name: nameSchema,
691691
desc: descriptionSchema.optional(),
@@ -697,10 +697,18 @@ export const treatmentSchema = altTemplateContext(
697697
exitSequence: introExitStepsSchema.optional(),
698698
})
699699
.strict()
700+
701+
702+
export const treatmentSchema = altTemplateContext(
703+
baseTreatmentSchema
704+
//works currently for the case where playerSchema always occurs within a treatmentSchema
705+
//However if a playerSchema is used outside of a treatmentSchema, this will not work, as playerCount will not be defined in its scope
706+
//With the current structure of templateSchema, this is hypothetically possible, but unlikely
700707
.superRefine((treatment, ctx) => {
701-
//works currently for the case where playerSchema always occurs within a treatmentSchema
702-
//However if a playerSchema is used outside of a treatmentSchema, this will not work, as playerCount will not be defined in its scope
703-
//With the current structure of templateSchema, this is hypothetically possible, but unlikely
708+
const baseResult = baseTreatmentSchema.safeParse(treatment);
709+
if (!baseResult.success) {
710+
return;
711+
}
704712
const { playerCount, groupComposition, gameStages } = treatment;
705713
groupComposition?.forEach((player, index) => {
706714
if (typeof player.position === "number" && player.position >= playerCount) {
@@ -711,12 +719,12 @@ export const treatmentSchema = altTemplateContext(
711719
});
712720
}
713721
});
714-
gameStages.forEach((stage: { elements: any[]; name: any; }, stageIndex: string | number) => {
715-
stage.elements.forEach((element: any, elementIndex: string | number) => {
722+
gameStages?.forEach((stage: { elements: any[]; name: any; }, stageIndex: string | number) => {
723+
stage?.elements?.forEach((element: any, elementIndex: string | number) => {
716724
["showToPositions", "hideFromPositions"].forEach((key) => {
717725
const positions = (element as any)[key];
718726
if (Array.isArray(positions)) {
719-
positions.forEach((pos, posIndex) => {
727+
positions?.forEach((pos, posIndex) => {
720728
if (typeof pos === "number" && pos >= playerCount) {
721729
ctx.addIssue({
722730
code: z.ZodIssueCode.custom,

0 commit comments

Comments
 (0)