Skip to content

Commit

Permalink
PIMS-2137 Export Additions (#2729)
Browse files Browse the repository at this point in the history
Co-authored-by: LawrenceLau2020 <[email protected]>
  • Loading branch information
dbarkowsky and LawrenceLau2020 authored Oct 21, 2024
1 parent a27b02a commit b3f0c8a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
19 changes: 19 additions & 0 deletions express-api/src/constants/projectStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
19 changes: 18 additions & 1 deletion express-api/src/services/properties/propertiesServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -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) => {
Expand All @@ -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[])
Expand All @@ -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,
};
});

Expand Down
5 changes: 4 additions & 1 deletion react-app/src/components/property/PropertyTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
};
});
};
Expand Down

0 comments on commit b3f0c8a

Please sign in to comment.