From 724d0d4e3f75dfd7c1db3bb4baf41dda0695597d Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Mon, 18 Sep 2023 12:03:01 +0100 Subject: [PATCH] feat: `Responses` type (#29) --- examples/data/Responses.ts | 32 ++ examples/index.ts | 20 +- examples/validExampleAgent.json | 46 +- examples/validExampleApplicant.json | 46 +- schema/schema.json | 633 +++++++++++++++++++++++++++- types/enums/Flags.ts | 67 +-- types/schema/Responses.ts | 30 +- types/schema/Result.ts | 2 +- 8 files changed, 814 insertions(+), 62 deletions(-) create mode 100644 examples/data/Responses.ts diff --git a/examples/data/Responses.ts b/examples/data/Responses.ts new file mode 100644 index 00000000..8dcddd6e --- /dev/null +++ b/examples/data/Responses.ts @@ -0,0 +1,32 @@ +import {Schema} from '../../types/Schema'; + +export const validResponses: Schema['responses'] = [ + { + metadata: { + sectionName: 'The property', + autoAnswered: true, + }, + question: 'Is the property in London Borough of Southwark?', + responses: [ + { + value: 'Yes', + }, + ], + }, + { + metadata: { + policyRefs: [ + { + text: 'Town and Country Planning Act 1990, Part 7, Section 191 & Section 192', + }, + ], + sectionName: 'About the project', + }, + question: 'What are you applying about?', + responses: [ + { + value: 'Proposed changes I want to make in the future', + }, + ], + }, +]; diff --git a/examples/index.ts b/examples/index.ts index cedc08b6..65226c54 100644 --- a/examples/index.ts +++ b/examples/index.ts @@ -3,6 +3,7 @@ import {validAgent, validApplicant} from './data/Applicant'; import {validApplication} from './data/Application'; import {validProperty} from './data/Property'; import {validProposal} from './data/Proposal'; +import {validResponses} from './data/Responses'; const validMetadata: Schema['metadata'] = { service: { @@ -45,14 +46,15 @@ const validFiles: Schema['files'] = [ }, ]; -const validResult = [ +const validResult: Schema['result'] = [ { - value: "Planning permission / Permitted development", - description: "It looks like the proposed changes may fall within the rules for Permitted Development and therefore would not need planning permission." + value: 'Planning permission / Permitted development', + description: + 'It looks like the proposed changes may fall within the rules for Permitted Development and therefore would not need planning permission.', }, { - value: "Listed building consent / Not required", - description: "", + value: 'Listed building consent / Not required', + description: '', }, ]; @@ -68,9 +70,7 @@ export const validExampleApplicant: Schema = { }, result: validResult, metadata: validMetadata, - responses: { - name: 'Test', - }, + responses: validResponses, files: validFiles, }; @@ -86,8 +86,6 @@ export const validExampleAgent: Schema = { }, result: validResult, metadata: validMetadata, - responses: { - name: 'Test', - }, + responses: validResponses, files: validFiles, }; diff --git a/examples/validExampleAgent.json b/examples/validExampleAgent.json index 58c63314..3ee9ce33 100644 --- a/examples/validExampleAgent.json +++ b/examples/validExampleAgent.json @@ -134,9 +134,16 @@ "description": "This is a test application" } }, - "result": { - "name": "Test" - }, + "result": [ + { + "value": "Planning permission / Permitted development", + "description": "It looks like the proposed changes may fall within the rules for Permitted Development and therefore would not need planning permission." + }, + { + "value": "Listed building consent / Not required", + "description": "" + } + ], "metadata": { "service": { "publishedFlowId": "b3320abe-f5bc-4185-b61f-40e9e65f07ad", @@ -151,9 +158,36 @@ "submittedAt": "2018-11-13T20:20:39+00:00" } }, - "responses": { - "name": "Test" - }, + "responses": [ + { + "metadata": { + "sectionName": "The property", + "autoAnswered": true + }, + "question": "Is the property in London Borough of Southwark?", + "responses": [ + { + "value": "Yes" + } + ] + }, + { + "metadata": { + "policyRefs": [ + { + "text": "Town and Country Planning Act 1990, Part 7, Section 191 & Section 192" + } + ], + "sectionName": "About the project" + }, + "question": "What are you applying about?", + "responses": [ + { + "value": "Proposed changes I want to make in the future" + } + ] + } + ], "files": [ { "name": "https://api.editor.planx.uk/file/private/folderId/file1.pdf", diff --git a/examples/validExampleApplicant.json b/examples/validExampleApplicant.json index 67bcb74f..f903106f 100644 --- a/examples/validExampleApplicant.json +++ b/examples/validExampleApplicant.json @@ -107,9 +107,16 @@ "description": "This is a test application" } }, - "result": { - "name": "Test" - }, + "result": [ + { + "value": "Planning permission / Permitted development", + "description": "It looks like the proposed changes may fall within the rules for Permitted Development and therefore would not need planning permission." + }, + { + "value": "Listed building consent / Not required", + "description": "" + } + ], "metadata": { "service": { "publishedFlowId": "b3320abe-f5bc-4185-b61f-40e9e65f07ad", @@ -124,9 +131,36 @@ "submittedAt": "2018-11-13T20:20:39+00:00" } }, - "responses": { - "name": "Test" - }, + "responses": [ + { + "metadata": { + "sectionName": "The property", + "autoAnswered": true + }, + "question": "Is the property in London Borough of Southwark?", + "responses": [ + { + "value": "Yes" + } + ] + }, + { + "metadata": { + "policyRefs": [ + { + "text": "Town and Country Planning Act 1990, Part 7, Section 191 & Section 192" + } + ], + "sectionName": "About the project" + }, + "question": "What are you applying about?", + "responses": [ + { + "value": "Proposed changes I want to make in the future" + } + ] + } + ], "files": [ { "name": "https://api.editor.planx.uk/file/private/folderId/file1.pdf", diff --git a/schema/schema.json b/schema/schema.json index 3e0907a6..9a009f7b 100644 --- a/schema/schema.json +++ b/schema/schema.json @@ -11668,30 +11668,651 @@ ], "type": "object" }, - "Responses": { + "QuestionAndResponses": { "additionalProperties": false, "properties": { - "name": { + "metadata": { + "$ref": "#/definitions/QuestionMetaData" + }, + "question": { "type": "string" + }, + "responses": { + "anyOf": [ + { + "items": { + "$ref": "#/definitions/Response" + }, + "type": "array" + }, + { + "type": "string" + } + ] } }, "required": [ - "name" + "question", + "responses" ], "type": "object" }, - "Result": { + "QuestionMetaData": { "additionalProperties": false, "properties": { - "name": { + "autoAnswered": { + "type": "boolean" + }, + "policyRefs": { + "items": { + "additionalProperties": false, + "properties": { + "text": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "type": "object" + }, + "type": "array" + }, + "sectionName": { + "type": "string" + } + }, + "type": "object" + }, + "Response": { + "additionalProperties": false, + "properties": { + "metadata": { + "$ref": "#/definitions/ResponseMetaData" + }, + "value": { "type": "string" } }, "required": [ - "name" + "value" ], "type": "object" }, + "ResponseMetaData": { + "additionalProperties": false, + "properties": { + "flags": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "type": "object" + }, + "Responses": { + "$id": "#Responses", + "description": "The ordered list of questions, answers, and their metadata for this application", + "items": { + "$ref": "#/definitions/QuestionAndResponses" + }, + "type": "array" + }, + "Result": { + "$id": "#Result", + "description": "The result of this application. Results are determined by flags corresponding to responses; each application can have up to one result per flagset", + "items": { + "$ref": "#/definitions/ResultFlag" + }, + "type": "array" + }, + "ResultFlag": { + "$id": "#ResultFlag", + "anyOf": [ + { + "additionalProperties": false, + "properties": { + "description": { + "const": "It looks like the changes may now be beyond the time limit for enforcement action. This does not apply if the changes have been deliberately concealed.", + "type": "string" + }, + "value": { + "const": "Planning permission / Immune", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "There is some key information missing that will be needed to assess this application.", + "type": "string" + }, + "value": { + "const": "Planning permission / Missing information", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "It looks like the proposed changes may require planning permission.", + "type": "string" + }, + "value": { + "const": "Planning permission / Permission needed", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "It looks like the proposed changes do not require planning permission, however the applicant must apply for Prior Approval before proceeding.", + "type": "string" + }, + "value": { + "const": "Planning permission / Prior approval", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "It looks like the proposed changes may not require planning permission, however the applicant must provide notice to the planning authority before proceeding.", + "type": "string" + }, + "value": { + "const": "Planning permission / Notice", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "It looks like the proposed changes may fall within the rules for Permitted Development and therefore would not need planning permission.", + "type": "string" + }, + "value": { + "const": "Planning permission / Permitted development", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "It looks like the proposed changes may not fall within the legal definition of 'development', and therefore would not require planning permission.", + "type": "string" + }, + "value": { + "const": "Planning permission / Not development", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Listed building consent / Missing information", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Listed building consent / Required", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Listed building consent / De minimis", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Listed building consent / Not required", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Works to trees & hedges / Missing information", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Works to trees & hedges / Required", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Works to trees & hedges / De minimis", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Works to trees & hedges / Not required", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Demolition in a conservation area / Missing information", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Demolition in a conservation area / Required", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Demolition in a conservation area / De minimis", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Demolition in a conservation area / Not required", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Planning policy / Missing information", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Planning policy / Fails to meet policy", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Planning policy / Edge case", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Planning policy / Meets policy", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Community infrastructure levy / Missing information", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Community infrastructure levy / Exemption void", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Community infrastructure levy / Exempt", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Community infrastructure levy / Relief void", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Community infrastructure levy / Relief", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Community infrastructure levy / Liable", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "description": { + "const": "", + "type": "string" + }, + "value": { + "const": "Community infrastructure levy / Not liable", + "type": "string" + } + }, + "required": [ + "value", + "description" + ], + "type": "object" + } + ], + "description": "An individual result of this application" + }, "SiteContact": { "$id": "#SiteContact", "anyOf": [ diff --git a/types/enums/Flags.ts b/types/enums/Flags.ts index 55b5c65a..506da97c 100644 --- a/types/enums/Flags.ts +++ b/types/enums/Flags.ts @@ -2,34 +2,41 @@ * Flags */ export const Flags = { - "Planning permission / Immune": "It looks like the changes may now be beyond the time limit for enforcement action. This does not apply if the changes have been deliberately concealed.", - "Planning permission / Missing information": "There is some key information missing that will be needed to assess this application.", - "Planning permission / Permission needed": "It looks like the proposed changes may require planning permission.", - "Planning permission / Prior approval": "It looks like the proposed changes do not require planning permission, however the applicant must apply for Prior Approval before proceeding.", - "Planning permission / Notice": "It looks like the proposed changes may not require planning permission, however the applicant must provide notice to the planning authority before proceeding.", - "Planning permission / Permitted development": "It looks like the proposed changes may fall within the rules for Permitted Development and therefore would not need planning permission.", - "Planning permission / Not development": "It looks like the proposed changes may not fall within the legal definition of 'development', and therefore would not require planning permission.", - "Listed building consent / Missing information": "", - "Listed building consent / Required": "", - "Listed building consent / De minimis": "", - "Listed building consent / Not required": "", - "Works to trees & hedges / Missing information": "", - "Works to trees & hedges / Required": "", - "Works to trees & hedges / De minimis": "", - "Works to trees & hedges / Not required": "", - "Demolition in a conservation area / Missing information": "", - "Demolition in a conservation area / Required": "", - "Demolition in a conservation area / De minimis": "", - "Demolition in a conservation area / Not required": "", - "Planning policy / Missing information": "", - "Planning policy / Fails to meet policy": "", - "Planning policy / Edge case": "", - "Planning policy / Meets policy": "", - "Community infrastructure levy / Missing information": "", - "Community infrastructure levy / Exemption void": "", - "Community infrastructure levy / Exempt": "", - "Community infrastructure levy / Relief void": "", - "Community infrastructure levy / Relief": "", - "Community infrastructure levy / Liable": "", - "Community infrastructure levy / Not liable": "", + 'Planning permission / Immune': + 'It looks like the changes may now be beyond the time limit for enforcement action. This does not apply if the changes have been deliberately concealed.', + 'Planning permission / Missing information': + 'There is some key information missing that will be needed to assess this application.', + 'Planning permission / Permission needed': + 'It looks like the proposed changes may require planning permission.', + 'Planning permission / Prior approval': + 'It looks like the proposed changes do not require planning permission, however the applicant must apply for Prior Approval before proceeding.', + 'Planning permission / Notice': + 'It looks like the proposed changes may not require planning permission, however the applicant must provide notice to the planning authority before proceeding.', + 'Planning permission / Permitted development': + 'It looks like the proposed changes may fall within the rules for Permitted Development and therefore would not need planning permission.', + 'Planning permission / Not development': + "It looks like the proposed changes may not fall within the legal definition of 'development', and therefore would not require planning permission.", + 'Listed building consent / Missing information': '', + 'Listed building consent / Required': '', + 'Listed building consent / De minimis': '', + 'Listed building consent / Not required': '', + 'Works to trees & hedges / Missing information': '', + 'Works to trees & hedges / Required': '', + 'Works to trees & hedges / De minimis': '', + 'Works to trees & hedges / Not required': '', + 'Demolition in a conservation area / Missing information': '', + 'Demolition in a conservation area / Required': '', + 'Demolition in a conservation area / De minimis': '', + 'Demolition in a conservation area / Not required': '', + 'Planning policy / Missing information': '', + 'Planning policy / Fails to meet policy': '', + 'Planning policy / Edge case': '', + 'Planning policy / Meets policy': '', + 'Community infrastructure levy / Missing information': '', + 'Community infrastructure levy / Exemption void': '', + 'Community infrastructure levy / Exempt': '', + 'Community infrastructure levy / Relief void': '', + 'Community infrastructure levy / Relief': '', + 'Community infrastructure levy / Liable': '', + 'Community infrastructure levy / Not liable': '', }; diff --git a/types/schema/Responses.ts b/types/schema/Responses.ts index acf9e663..5c2d1a45 100644 --- a/types/schema/Responses.ts +++ b/types/schema/Responses.ts @@ -1,3 +1,29 @@ -export interface Responses { - name: string; +/** + * @id #Responses + * @description The ordered list of questions, answers, and their metadata for this application + */ +export type Responses = QuestionAndResponses[]; + +export interface QuestionMetaData { + autoAnswered?: boolean; + policyRefs?: Array<{ + url?: string; + text?: string; + }>; + sectionName?: string; +} + +export interface ResponseMetaData { + flags?: Array; // @todo connect to result/flags enum +} + +export interface Response { + value: string; + metadata?: ResponseMetaData; +} + +export interface QuestionAndResponses { + question: string; + responses: Array | string; + metadata?: QuestionMetaData; } diff --git a/types/schema/Result.ts b/types/schema/Result.ts index 4b8dadaa..ffd4c46b 100644 --- a/types/schema/Result.ts +++ b/types/schema/Result.ts @@ -1,4 +1,4 @@ -import {Flags} from "../enums/Flags"; +import {Flags} from '../enums/Flags'; /** * @id #Result