Add simple dynamics API support
This commit is contained in:
parent
b93d016a77
commit
28bad44220
@ -239,4 +239,10 @@ export const dataFieldsConfig = valueType<DataFieldConfig>()({ /* eslint-disable
|
|||||||
verify: false,
|
verify: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
demolished_buildings: {
|
||||||
|
edit: true,
|
||||||
|
verify: false,
|
||||||
|
asJson: true,
|
||||||
|
sqlCast: 'jsonb',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
@ -3,5 +3,64 @@ import { SomeJSONSchema } from 'ajv/dist/types/json-schema';
|
|||||||
import { dataFieldsConfig } from './dataFields';
|
import { dataFieldsConfig } from './dataFields';
|
||||||
|
|
||||||
export const fieldSchemaConfig: { [key in keyof typeof dataFieldsConfig]?: SomeJSONSchema} = { /*eslint-disable @typescript-eslint/camelcase */
|
export const fieldSchemaConfig: { [key in keyof typeof dataFieldsConfig]?: SomeJSONSchema} = { /*eslint-disable @typescript-eslint/camelcase */
|
||||||
|
|
||||||
|
demolished_buildings: {
|
||||||
|
type: 'array',
|
||||||
|
items: {
|
||||||
|
type: 'object',
|
||||||
|
required: ['year_constructed', 'year_demolished', 'overlap_present', 'links'],
|
||||||
|
properties: {
|
||||||
|
year_constructed: {
|
||||||
|
type: 'object',
|
||||||
|
required: ['min', 'max'],
|
||||||
|
additionalProperties: false,
|
||||||
|
properties: {
|
||||||
|
min: {
|
||||||
|
type: 'integer'
|
||||||
|
},
|
||||||
|
max: {
|
||||||
|
type: 'integer'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
year_demolished: {
|
||||||
|
type: 'object',
|
||||||
|
required: ['min', 'max'],
|
||||||
|
additionalProperties: false,
|
||||||
|
properties: {
|
||||||
|
min: {
|
||||||
|
type: 'integer'
|
||||||
|
},
|
||||||
|
max: {
|
||||||
|
type: 'integer'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
overlap_present: {
|
||||||
|
type: 'string',
|
||||||
|
enum: ['1%', '25%', '50%', '75%', '100%']
|
||||||
|
},
|
||||||
|
links: {
|
||||||
|
type: 'array',
|
||||||
|
items: {
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
minItems: 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
additionalProperties: false,
|
||||||
|
}
|
||||||
|
} as JSONSchemaType<{
|
||||||
|
year_constructed: {
|
||||||
|
min: number;
|
||||||
|
max: number;
|
||||||
|
};
|
||||||
|
year_demolished: {
|
||||||
|
min: number;
|
||||||
|
max: number;
|
||||||
|
}
|
||||||
|
overlap_present: string;
|
||||||
|
links: string[];
|
||||||
|
}[]>,
|
||||||
|
|
||||||
} as const;
|
} as const;
|
||||||
|
@ -6,6 +6,9 @@ import { ArgumentError } from '../../errors/general';
|
|||||||
|
|
||||||
import { updateLandUse } from './landUse';
|
import { updateLandUse } from './landUse';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process land use classifications - derive land use order from land use groups
|
||||||
|
*/
|
||||||
async function processCurrentLandUseClassifications(buildingId: number, buildingUpdate: any): Promise<any> {
|
async function processCurrentLandUseClassifications(buildingId: number, buildingUpdate: any): Promise<any> {
|
||||||
const currentBuildingData = await getBuildingData(buildingId);
|
const currentBuildingData = await getBuildingData(buildingId);
|
||||||
|
|
||||||
@ -31,10 +34,26 @@ async function processCurrentLandUseClassifications(buildingId: number, building
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process Dynamics data - sort past buildings by construction date
|
||||||
|
*/
|
||||||
|
async function processDynamicsPastBuildings(buildingId: number, buildingUpdate: any): Promise<any> {
|
||||||
|
buildingUpdate.demolished_buildings = buildingUpdate.demolished_buildings.sort((a, b) => b.year_constructed.min - a.year_constructed.min);
|
||||||
|
return buildingUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define any custom processing logic for specific building attributes
|
||||||
|
*/
|
||||||
export async function processBuildingUpdate(buildingId: number, buildingUpdate: any): Promise<any> {
|
export async function processBuildingUpdate(buildingId: number, buildingUpdate: any): Promise<any> {
|
||||||
if(hasAnyOwnProperty(buildingUpdate, ['current_landuse_group'])) {
|
if(hasAnyOwnProperty(buildingUpdate, ['current_landuse_group'])) {
|
||||||
buildingUpdate = await processCurrentLandUseClassifications(buildingId, buildingUpdate);
|
buildingUpdate = await processCurrentLandUseClassifications(buildingId, buildingUpdate);
|
||||||
}
|
}
|
||||||
|
if('demolished_buildings' in buildingUpdate) {
|
||||||
|
buildingUpdate = await processDynamicsPastBuildings(buildingId, buildingUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
return buildingUpdate;
|
return buildingUpdate;
|
||||||
}
|
}
|
||||||
|
2
migrations/019.simple-dynamics.down.sql
Normal file
2
migrations/019.simple-dynamics.down.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE buildings
|
||||||
|
DROP demolished_buildings;
|
2
migrations/019.simple-dynamics.up.sql
Normal file
2
migrations/019.simple-dynamics.up.sql
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE buildings
|
||||||
|
ADD column demolished_buildings JSONB DEFAULT '[]'::JSONB;
|
Loading…
Reference in New Issue
Block a user