Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

369 Sort Capital Commitments by Managing Code Capital Project Id by Date #372

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion src/capital-project/capital-project.repository.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -232,6 +232,7 @@ export class CapitalProjectRepository {
totalValue: sql`${capitalCommitmentFund.value}`.mapWith(Number),
})
.from(capitalCommitment)
.orderBy(asc(capitalCommitment.plannedDate))
.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"),
});