Skip to content

Commit

Permalink
Implemented an endpoint for classifications and predominate uses
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamS-Quartech committed Mar 18, 2024
1 parent 37766f7 commit b8f3ae3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
28 changes: 26 additions & 2 deletions express-api/src/controllers/lookup/lookupController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { AppDataSource } from '@/appDataSource';
import { PropertyClassification } from '@/typeorm/Entities/PropertyClassification';
import { stubResponse } from '@/utilities/stubResponse';
import { Request, Response } from 'express';
import {
ClassificationPublicResponseSchema,
PredominateUsePublicResponseSchema,
} from './lookupSchema';
import { BuildingPredominateUse } from '@/typeorm/Entities/BuildingPredominateUse';

// TODO: What controllers here could just be replaced by existing GET requests?

Expand Down Expand Up @@ -56,8 +63,25 @@ export const lookupPropertyClassifications = async (req: Request, res: Response)
}]
*/

// TODO: Replace stub response with controller logic
return stubResponse(res);
const classifications = await AppDataSource.getRepository(PropertyClassification).find();
const filtered = classifications.filter((c) => !c.IsDisabled);
const parsed = ClassificationPublicResponseSchema.array().safeParse(filtered);
if (parsed.success) {
return res.status(200).send(parsed.data);
} else {
return res.status(400).send('Something went wrong.');
}
};

export const lookupBuildingPredominateUse = async (req: Request, res: Response) => {
const uses = await AppDataSource.getRepository(BuildingPredominateUse).find();
const filtered = uses.filter((u) => !u.IsDisabled);
const parsed = PredominateUsePublicResponseSchema.array().safeParse(filtered);
if (parsed.success) {
return res.status(200).send(parsed.data);
} else {
return res.status(400).send('Something went wrong.');
}
};

/**
Expand Down
14 changes: 14 additions & 0 deletions express-api/src/controllers/lookup/lookupSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { z } from 'zod';

export const ClassificationPublicResponseSchema = z.object({
Name: z.string(),
Id: z.number(),
SortOrder: z.number(),
IsVisible: z.boolean(),
});

export const PredominateUsePublicResponseSchema = z.object({
Name: z.string(),
Id: z.number(),
SortOrder: z.number(),
});
2 changes: 2 additions & 0 deletions express-api/src/routes/lookupRouter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import controllers from '@/controllers';
import { lookupBuildingPredominateUse } from '@/controllers/lookup/lookupController';
import express from 'express';

const router = express.Router();
Expand All @@ -15,6 +16,7 @@ const {
router.route('/agencies').get(lookupAgencies);
router.route('/roles').get(lookupRoles);
router.route('/property/classifications').get(lookupPropertyClassifications);
router.route('/property/predominateUses').get(lookupBuildingPredominateUse);
router.route('/project/tier/levels').get(lookupProjectTierLevels);
router.route('/project/risks').get(lookupProjectRisks);
router.route('/all').get(lookupAll);
Expand Down

0 comments on commit b8f3ae3

Please sign in to comment.