diff --git a/schemas/app.json b/schemas/app.json index 51902063..e436a7ef 100644 --- a/schemas/app.json +++ b/schemas/app.json @@ -13,6 +13,19 @@ } ], "definitions": { + "ApplicationDataBase": { + "additionalProperties": false, + "description": "Base type for ApplicationData. Contains all shared properties across all application types", + "properties": { + "somethingShared": { + "type": "string" + } + }, + "required": [ + "somethingShared" + ], + "type": "object" + }, "BaseWTT": { "additionalProperties": false, "properties": { @@ -24,25 +37,7 @@ "additionalProperties": false, "properties": { "application": { - "additionalProperties": false, - "properties": { - "applicationType": { - "const": "wtt", - "type": "string" - }, - "somethingShared": { - "type": "string" - }, - "wttSpecificProperty": { - "type": "number" - } - }, - "required": [ - "applicationType", - "somethingShared", - "wttSpecificProperty" - ], - "type": "object" + "$ref": "#/definitions/WTTApplicationData" }, "user": { "$ref": "#/definitions/WTTUser" @@ -72,25 +67,7 @@ "additionalProperties": false, "properties": { "application": { - "additionalProperties": false, - "properties": { - "applicationType": { - "const": "wtt.consent", - "type": "string" - }, - "somethingShared": { - "type": "string" - }, - "wttSpecificProperty": { - "type": "number" - } - }, - "required": [ - "applicationType", - "somethingShared", - "wttSpecificProperty" - ], - "type": "object" + "$ref": "#/definitions/WTTApplicationData" }, "user": { "$ref": "#/definitions/WTTUser" @@ -120,25 +97,7 @@ "additionalProperties": false, "properties": { "application": { - "additionalProperties": false, - "properties": { - "applicationType": { - "const": "wtt.notice", - "type": "string" - }, - "somethingShared": { - "type": "string" - }, - "wttSpecificProperty": { - "type": "number" - } - }, - "required": [ - "applicationType", - "somethingShared", - "wttSpecificProperty" - ], - "type": "object" + "$ref": "#/definitions/WTTApplicationData" }, "user": { "$ref": "#/definitions/WTTUser" @@ -157,6 +116,23 @@ ], "type": "object" }, + "PPApplicationData": { + "additionalProperties": false, + "description": "Specific ApplicationData required for \"Planning Permission\" applications", + "properties": { + "ppSpecificProperty": { + "type": "number" + }, + "somethingShared": { + "type": "string" + } + }, + "required": [ + "ppSpecificProperty", + "somethingShared" + ], + "type": "object" + }, "PPUser": { "additionalProperties": false, "properties": { @@ -189,25 +165,7 @@ "additionalProperties": false, "properties": { "application": { - "additionalProperties": false, - "properties": { - "applicationType": { - "const": "pp", - "type": "string" - }, - "ppSpecificProperty": { - "type": "number" - }, - "somethingShared": { - "type": "string" - } - }, - "required": [ - "applicationType", - "ppSpecificProperty", - "somethingShared" - ], - "type": "object" + "$ref": "#/definitions/PPApplicationData" }, "user": { "$ref": "#/definitions/PPUser" @@ -237,21 +195,7 @@ "additionalProperties": false, "properties": { "application": { - "additionalProperties": false, - "properties": { - "applicationType": { - "const": "pa", - "type": "string" - }, - "somethingShared": { - "type": "string" - } - }, - "required": [ - "applicationType", - "somethingShared" - ], - "type": "object" + "$ref": "#/definitions/ApplicationDataBase" }, "user": { "$ref": "#/definitions/UserBase" @@ -287,6 +231,23 @@ ], "type": "object" }, + "WTTApplicationData": { + "additionalProperties": false, + "description": "Specific ApplicationData required for \"Works to trees\" applications", + "properties": { + "somethingShared": { + "type": "string" + }, + "wttSpecificProperty": { + "type": "number" + } + }, + "required": [ + "somethingShared", + "wttSpecificProperty" + ], + "type": "object" + }, "WTTUser": { "additionalProperties": false, "properties": { diff --git a/types/schemas/app/ApplicationData.ts b/types/schemas/app/ApplicationData.ts index 229a1a0a..fb95ca79 100644 --- a/types/schemas/app/ApplicationData.ts +++ b/types/schemas/app/ApplicationData.ts @@ -1,28 +1,23 @@ -import { - ApplicationTypeKeys, - PrimaryApplicationType, -} from '../digitalPlanningApplication/enums/ApplicationTypes'; +import {PrimaryApplicationType} from '../digitalPlanningApplication/enums/ApplicationTypes'; /** - * @internal * Base type for ApplicationData. Contains all shared properties across all application types */ -export interface ApplicationDataBase { - applicationType: TGranular; +export interface ApplicationDataBase { somethingShared: string; } /** * @description Specific ApplicationData required for "Works to trees" applications */ -export interface WTTApplicationData { +export interface WTTApplicationData extends ApplicationDataBase { wttSpecificProperty: number; } /** * @description Specific ApplicationData required for "Planning Permission" applications */ -export interface PPApplicationData { +export interface PPApplicationData extends ApplicationDataBase { ppSpecificProperty: number; } @@ -37,11 +32,8 @@ export interface ApplicationDataVariants { /** * @internal * Conditional type to return a specific or generic ApplicationData model, based on PrimaryApplicationType - * TPrimary and TGranular are both required as the granular variable is exposed, and must match the value in the Application root */ -export type ApplicationData< - TPrimary extends PrimaryApplicationType, - TGranular extends ApplicationTypeKeys, -> = TPrimary extends keyof ApplicationDataVariants - ? ApplicationDataVariants[TPrimary] & ApplicationDataBase - : ApplicationDataBase; +export type ApplicationData = + TPrimary extends keyof ApplicationDataVariants + ? ApplicationDataVariants[TPrimary] + : ApplicationDataBase; diff --git a/types/schemas/app/index.ts b/types/schemas/app/index.ts index ce35cfbb..8cd96be2 100644 --- a/types/schemas/app/index.ts +++ b/types/schemas/app/index.ts @@ -18,7 +18,7 @@ interface ApplicationSpecification< applicationType: TGranular; data: { user: User; - application: ApplicationData; + application: ApplicationData; }; } @@ -56,7 +56,6 @@ export type App = // wttSpecificProperty: true, // }, // application: { -// applicationType: 'wtt.consent', // wttSpecificProperty: 123, // somethingShared: 'abc', // },