Skip to content

Commit

Permalink
fix: account for manually answered planning constraints in ODP Schema…
Browse files Browse the repository at this point in the history
… generation (#390)
  • Loading branch information
jessicamcinchak authored May 21, 2024
1 parent 3612b8a commit 1b95557
Showing 1 changed file with 78 additions and 48 deletions.
126 changes: 78 additions & 48 deletions src/export/digitalPlanning/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,58 +496,88 @@ export class DigitalPlanning {

private getPlanningConstraints(): Payload["data"]["property"]["planning"] {
const teamSlug: string = this.metadata.flow.team.slug;
const designations: PlanningDesignation[] = [];

// Passport will have `_constraints` if successfully fetched from Planning Data
const constraints = this.passport.data
?._constraints as unknown as EnhancedGISResponse[];
const designations: PlanningDesignation[] = [];

constraints?.forEach((response: EnhancedGISResponse) => {
response.constraints &&
Object.entries(response.constraints)
.filter(([key, _constraint]) => !key.split(".").includes(teamSlug))
.map(([key, constraint]) => {
if (constraint.value) {
// Intersecting constraints
designations.push({
value: key,
description: this.findDescriptionFromValueUnionType(
"PlanningDesignation",
key,
),
intersects: constraint.value,
entities:
constraint.data?.map(
(entity) =>
Boolean(entity) && {
name: entity.name,
description: entity.description,
source:
key === "road.classified"
? { text: "Ordnance Survey MasterMap Highways" }
: {
text: "Planning Data",
url: `https://www.planning.data.gov.uk/entity/${entity.entity}`,
},
},
) || [],
} as PlanningDesignation);
} else {
// Non-intersecting constraints
designations.push({
value: key,
description: this.findDescriptionFromValueUnionType(
"PlanningDesignation",
key,
),
intersects: constraint.value,
} as PlanningDesignation);
}
});
});
// Passport will not have `_constraints`, and only `property.constraints.planning` if manually answered
const manualConstraints = this.passport.data?.[
"property.constraints.planning"
] as string[];

if (constraints) {
constraints?.forEach((response: EnhancedGISResponse) => {
response.constraints &&
Object.entries(response.constraints)
.filter(([key, _constraint]) => !key.split(".").includes(teamSlug))
.map(([key, constraint]) => {
if (constraint.value) {
// Intersecting constraints
designations.push({
value: key,
description: this.findDescriptionFromValueUnionType(
"PlanningDesignation",
key,
),
intersects: constraint.value,
entities:
constraint.data?.map(
(entity) =>
Boolean(entity) && {
name: entity.name,
description: entity.description,
source:
key === "road.classified"
? { text: "Ordnance Survey MasterMap Highways" }
: {
text: "Planning Data",
url: `https://www.planning.data.gov.uk/entity/${entity.entity}`,
},
},
) || [],
} as PlanningDesignation);
} else {
// Non-intersecting constraints
designations.push({
value: key,
description: this.findDescriptionFromValueUnionType(
"PlanningDesignation",
key,
),
intersects: constraint.value,
} as PlanningDesignation);
}
});
});

return {
sources: constraints?.map((constraint) => constraint.planxRequest) || [],
designations: designations,
};
return {
sources:
constraints?.map((constraint) => constraint.planxRequest) || [],
designations: designations,
};
} else if (!constraints && manualConstraints) {
manualConstraints
.filter((key) => !key.split(".").includes(teamSlug))
.map((key) => {
designations.push({
value: key,
description: this.findDescriptionFromValueUnionType(
"PlanningDesignation",
key,
),
intersects: true,
} as PlanningDesignation);
});

return {
sources: ["Answered by user"],
designations: designations,
};
} else {
return undefined;
}
}

private getApplicationType(): Payload["data"]["application"]["type"] {
Expand Down

0 comments on commit 1b95557

Please sign in to comment.