Skip to content

Commit

Permalink
369 Sort Capital Commitments by Managing Code Capital Project Id by Date
Browse files Browse the repository at this point in the history
 - 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`
  • Loading branch information
horatiorosa committed Sep 4, 2024
1 parent 7aec4c9 commit a68b315
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
1 change: 1 addition & 0 deletions src/capital-project/capital-project.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export class CapitalProjectRepository {
totalValue: sql`${capitalCommitmentFund.value}`.mapWith(Number),
})
.from(capitalCommitment)
.orderBy(sql`${capitalCommitment.plannedDate} ASC`)
.leftJoin(
budgetLine,
and(
Expand Down
2 changes: 2 additions & 0 deletions src/capital-project/capital-project.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
1 change: 1 addition & 0 deletions src/capital-project/capital-project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class CapitalProjectService {

return {
capitalCommitments,
order: "plannedDate",
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"),
});

0 comments on commit a68b315

Please sign in to comment.