diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 9b24595..5d52a90 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 827a808..64c94ef 100644 --- a/src/capital-project/capital-project.repository.ts +++ b/src/capital-project/capital-project.repository.ts @@ -232,6 +232,7 @@ export class CapitalProjectRepository { totalValue: sql`${capitalCommitmentFund.value}`.mapWith(Number), }) .from(capitalCommitment) + .orderBy(sql`${capitalCommitment.plannedDate} ASC`) .leftJoin( budgetLine, and( diff --git a/src/capital-project/capital-project.service.spec.ts b/src/capital-project/capital-project.service.spec.ts index e06e8d3..3fa63b1 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 22f4333..e568418 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 0001bcb..cf6f35c 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 096c6da..2ba5281 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"), });