Skip to content

Commit

Permalink
CMDCT-4224: adding some comments and some code that doesn't work but …
Browse files Browse the repository at this point in the history
…that i want to work
  • Loading branch information
angelaco11 committed Jan 13, 2025
1 parent a03cb02 commit be4dc46
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions services/app-api/utils/reportValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,18 @@ const parentPageTemplateSchema = object().shape({
childPageIds: array().of(string()).required(),
});

const formPageTemplate = {
const formPageTemplateSchema = object().shape({
id: string().required(),
title: string().required(),
type: mixed<PageType>().oneOf(Object.values(PageType)).required(),
elements: pageElementSchema,
sidebar: boolean().notRequired(),
hideNavButtons: boolean().notRequired(),
childPageIds: array().of(string()).notRequired(),
};
const formPageTemplateSchema = object().shape({
...formPageTemplate,
});

const measurePageTemplateSchema = object().shape({
...formPageTemplate,
// MeasurePageTemplate extends FormPageTemplate
const measurePageTemplateSchema = formPageTemplateSchema.shape({
cmit: number().notRequired(),
required: boolean().notRequired(),
stratified: boolean().notRequired(),
Expand All @@ -158,6 +155,13 @@ const measureLookupSchema = object().shape({
),
});

/**
* This schema is meant to represent the pages field in the ReportTemplate type.
* The following yup `lazy` function is building up the union type:
* `(ParentPageTemplate | FormPageTemplate | MeasurePageTemplate)[]`
* and outputs the correct type in the union based on various fields
* on the page object that gets passed through.
*/
const pagesSchema = array()
.of(
lazy((pageObject) => {
Expand All @@ -172,6 +176,28 @@ const pagesSchema = array()
)
.required();

/**
* This schema represents a typescript type of Record<MeasureTemplateName, MeasurePageTemplate>
*
* The following code is looping through the MeasureTemplateName enum and building
* a yup validation object that looks like so:
* {
[MeasureTemplateName["LTSS-1"]]: measurePageTemplateSchema,
[MeasureTemplateName["LTSS-2"]]: measurePageTemplateSchema,
[MeasureTemplateName["LTSS-6"]]: measurePageTemplateSchema,
...
...
}
*/
// const measureTemplatesSchema = object().shape(
// Object.fromEntries(
// Object.keys(MeasureTemplateName).map((meas) => [
// meas,
// measurePageTemplateSchema,
// ])
// )
// );

const measureTemplatesSchema = object().shape({
[MeasureTemplateName["LTSS-1"]]: measurePageTemplateSchema,
[MeasureTemplateName["LTSS-2"]]: measurePageTemplateSchema,
Expand Down

0 comments on commit be4dc46

Please sign in to comment.