From b3f0c8aac35fba6c37efc023b04d4bcad97491cd Mon Sep 17 00:00:00 2001 From: Dylan Barkowsky <37922247+dbarkowsky@users.noreply.github.com> Date: Mon, 21 Oct 2024 09:45:06 -0700 Subject: [PATCH] PIMS-2137 Export Additions (#2729) Co-authored-by: LawrenceLau2020 <68400651+LawrenceLau2020@users.noreply.github.com> --- express-api/src/constants/projectStatus.ts | 19 +++++++++++++++++++ .../services/properties/propertiesServices.ts | 19 ++++++++++++++++++- .../src/components/property/PropertyTable.tsx | 5 ++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/express-api/src/constants/projectStatus.ts b/express-api/src/constants/projectStatus.ts index 788c4447b..8d03a8814 100644 --- a/express-api/src/constants/projectStatus.ts +++ b/express-api/src/constants/projectStatus.ts @@ -37,3 +37,22 @@ export enum ProjectStatus { * Adding new statuses to this list will reveal them to outside agencies. */ export const exposedProjectStatuses = [ProjectStatus.APPROVED_FOR_ERP]; + +/** + * A list of statuses that are active/non-final projects. + * For example, a project in pre-marketing is ongoing, + * but a project with status Cancelled would not be. + */ +export const activeProjectStatuses = [ + ProjectStatus.SUBMITTED, + ProjectStatus.SUBMITTED_EXEMPTION, + ProjectStatus.APPROVED_FOR_ERP, + ProjectStatus.APPROVED_FOR_EXEMPTION, + ProjectStatus.APPROVED_FOR_SPL, + ProjectStatus.NOT_IN_SPL, + ProjectStatus.ON_HOLD, + ProjectStatus.PRE_MARKETING, + ProjectStatus.ON_MARKET, + ProjectStatus.CONTRACT_IN_PLACE, + ProjectStatus.CLOSE_OUT, +]; diff --git a/express-api/src/services/properties/propertiesServices.ts b/express-api/src/services/properties/propertiesServices.ts index 42d5c6d25..e38ee3bee 100644 --- a/express-api/src/services/properties/propertiesServices.ts +++ b/express-api/src/services/properties/propertiesServices.ts @@ -32,7 +32,11 @@ import { import userServices from '../users/usersServices'; import { Brackets, FindOptionsWhere, ILike, In, QueryRunner } from 'typeorm'; import { PropertyType } from '@/constants/propertyType'; -import { exposedProjectStatuses, ProjectStatus } from '@/constants/projectStatus'; +import { + activeProjectStatuses, + exposedProjectStatuses, + ProjectStatus, +} from '@/constants/projectStatus'; import { ProjectProperty } from '@/typeorm/Entities/ProjectProperty'; import { ProjectStatus as ProjectStatusEntity } from '@/typeorm/Entities/ProjectStatus'; import { parentPort } from 'worker_threads'; @@ -999,6 +1003,13 @@ const getPropertiesForExport = async (filter: PropertyUnionFilter) => { ongoingFinds.push( AppDataSource.getRepository(BuildingFiscal).find({ order: { FiscalYear: 'DESC' } }), ); + ongoingFinds.push( + AppDataSource.getRepository(ProjectProperty).find({ + order: { CreatedOn: 'DESC' }, + relations: { Project: true }, + where: { Project: { StatusId: In(activeProjectStatuses) } }, + }), + ); // Wait for all database requests to resolve, then build the parcels and buildings lists // Use IDs from filtered properties above to filter lists @@ -1007,6 +1018,7 @@ const getPropertiesForExport = async (filter: PropertyUnionFilter) => { const parcelFiscals = resolvedFinds.at(3) as ParcelFiscal[]; const buildingEvaluations = resolvedFinds.at(4) as BuildingEvaluation[]; const buildingFiscals = resolvedFinds.at(5) as BuildingFiscal[]; + const projectProperties = resolvedFinds.at(6) as ProjectProperty[]; const parcels: Parcel[] = (resolvedFinds.at(0) as Parcel[]) .filter((p: Parcel) => parcelIds.includes(p.Id)) .map((p: Parcel) => { @@ -1016,6 +1028,8 @@ const getPropertiesForExport = async (filter: PropertyUnionFilter) => { ...p, Evaluations: evaluation ? [evaluation] : undefined, Fiscals: fiscal ? [fiscal] : undefined, + ProjectNumber: + projectProperties.find((pp) => pp.ParcelId === p.Id)?.Project.ProjectNumber ?? undefined, }; }); const buildings: Building[] = (resolvedFinds.at(1) as Building[]) @@ -1027,6 +1041,9 @@ const getPropertiesForExport = async (filter: PropertyUnionFilter) => { ...b, Evaluations: evaluation ? [evaluation] : undefined, Fiscals: fiscal ? [fiscal] : undefined, + ProjectNumber: + projectProperties.find((pp) => pp.BuildingId === b.Id)?.Project.ProjectNumber ?? + undefined, }; }); diff --git a/react-app/src/components/property/PropertyTable.tsx b/react-app/src/components/property/PropertyTable.tsx index e90c75c0e..5fdbff45d 100644 --- a/react-app/src/components/property/PropertyTable.tsx +++ b/react-app/src/components/property/PropertyTable.tsx @@ -254,7 +254,7 @@ const PropertyTable = (props: IPropertyTable) => { } }; - const excelDataMap = (data: (Parcel | Building)[]) => { + const excelDataMap = (data: ((Parcel | Building) & { ProjectNumber: string })[]) => { return data.map((property) => { return { Type: propertyTypeMapper(property.PropertyTypeId), @@ -329,6 +329,9 @@ const PropertyTable = (props: IPropertyTable) => { property.PropertyTypeId === PropertyTypes.BUILDING ? (property as Building).BuildingTenancy : '', + Latitude: property.Location.y, // This seems backwards, but it's how the database stores it. + Longitude: property.Location.x, + 'Active Project Number': property.ProjectNumber, }; }); };