From f9d388f4739d3fe3f615aa3c19b14cced3f3feec Mon Sep 17 00:00:00 2001 From: horatio Date: Wed, 4 Sep 2024 11:50:09 -0400 Subject: [PATCH] 369 Sort Capital Commitments by Managing Code Capital Project Id by Date - updated OpenAPI properties for CCMCCP id to include order variable - updated `findCapitalCommitmentsByManagingCodeCapitalProjectId` to sort the capital commitments by `plannedDate` - updated CCMCCP service spec to test `results.order` (results=Capital Commitments) value is `plannedDate` --- openapi/openapi.yaml | 5 +++++ src/capital-project/capital-project.repository.ts | 3 ++- src/capital-project/capital-project.service.spec.ts | 2 ++ src/capital-project/capital-project.service.ts | 1 + ...CapitalCommitmentsByManagingCodeCapitalProjectId.ts | 10 ++++++++++ ...lCommitmentsByManagingCodeCapitalProjectIdSchema.ts | 6 ++++++ 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 9b245955..5d52a90f 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -222,8 +222,13 @@ paths: type: array items: $ref: '#/components/schemas/CapitalCommitment' + order: + type: string + description: Capital commitment dates are sorted in ascending order + example: 'plannedDate' required: - capitalCommitments + - order '400': $ref: "#/components/responses/BadRequest" '404': diff --git a/src/capital-project/capital-project.repository.ts b/src/capital-project/capital-project.repository.ts index 827a8081..743e1d27 100644 --- a/src/capital-project/capital-project.repository.ts +++ b/src/capital-project/capital-project.repository.ts @@ -1,5 +1,5 @@ import { Inject } from "@nestjs/common"; -import { isNotNull, sql, and, eq, sum } from "drizzle-orm"; +import { isNotNull, sql, and, eq, sum, asc } from "drizzle-orm"; import { DataRetrievalException } from "src/exception"; import { FindCapitalCommitmentsByManagingCodeCapitalProjectIdPathParams, @@ -232,6 +232,7 @@ export class CapitalProjectRepository { totalValue: sql`${capitalCommitmentFund.value}`.mapWith(Number), }) .from(capitalCommitment) + .orderBy(asc(capitalCommitment.plannedDate)) .leftJoin( budgetLine, and( diff --git a/src/capital-project/capital-project.service.spec.ts b/src/capital-project/capital-project.service.spec.ts index e06e8d37..3fa63b18 100644 --- a/src/capital-project/capital-project.service.spec.ts +++ b/src/capital-project/capital-project.service.spec.ts @@ -118,6 +118,8 @@ describe("CapitalProjectService", () => { result, ), ).not.toThrow(); + + expect(result.order).toBe("plannedDate"); }); it("should throw a resource error when requesting a missing project", async () => { diff --git a/src/capital-project/capital-project.service.ts b/src/capital-project/capital-project.service.ts index 22f4333b..e5684180 100644 --- a/src/capital-project/capital-project.service.ts +++ b/src/capital-project/capital-project.service.ts @@ -85,6 +85,7 @@ export class CapitalProjectService { return { capitalCommitments, + order: "plannedDate", }; } } diff --git a/src/gen/types/FindCapitalCommitmentsByManagingCodeCapitalProjectId.ts b/src/gen/types/FindCapitalCommitmentsByManagingCodeCapitalProjectId.ts index 0001bcb0..cf6f35c9 100644 --- a/src/gen/types/FindCapitalCommitmentsByManagingCodeCapitalProjectId.ts +++ b/src/gen/types/FindCapitalCommitmentsByManagingCodeCapitalProjectId.ts @@ -21,6 +21,11 @@ export type FindCapitalCommitmentsByManagingCodeCapitalProjectId200 = { * @type array */ capitalCommitments: CapitalCommitment[]; + /** + * @description Capital commitment dates are sorted in ascending order + * @type string + */ + order: string; }; /** * @description Invalid client request @@ -43,6 +48,11 @@ export type FindCapitalCommitmentsByManagingCodeCapitalProjectIdQueryResponse = * @type array */ capitalCommitments: CapitalCommitment[]; + /** + * @description Capital commitment dates are sorted in ascending order + * @type string + */ + order: string; }; export type FindCapitalCommitmentsByManagingCodeCapitalProjectIdQuery = { Response: FindCapitalCommitmentsByManagingCodeCapitalProjectIdQueryResponse; diff --git a/src/gen/zod/findCapitalCommitmentsByManagingCodeCapitalProjectIdSchema.ts b/src/gen/zod/findCapitalCommitmentsByManagingCodeCapitalProjectIdSchema.ts index 096c6da8..2ba52817 100644 --- a/src/gen/zod/findCapitalCommitmentsByManagingCodeCapitalProjectIdSchema.ts +++ b/src/gen/zod/findCapitalCommitmentsByManagingCodeCapitalProjectIdSchema.ts @@ -22,6 +22,9 @@ export const findCapitalCommitmentsByManagingCodeCapitalProjectIdPathParamsSchem export const findCapitalCommitmentsByManagingCodeCapitalProjectId200Schema = z.object({ capitalCommitments: z.array(z.lazy(() => capitalCommitmentSchema)), + order: z.coerce + .string() + .describe("Capital commitment dates are sorted in ascending order"), }); /** * @description Invalid client request @@ -44,4 +47,7 @@ export const findCapitalCommitmentsByManagingCodeCapitalProjectId500Schema = export const findCapitalCommitmentsByManagingCodeCapitalProjectIdQueryResponseSchema = z.object({ capitalCommitments: z.array(z.lazy(() => capitalCommitmentSchema)), + order: z.coerce + .string() + .describe("Capital commitment dates are sorted in ascending order"), });