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

373 Sort Community Districts by Id #374

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 @@ -101,8 +101,13 @@ paths:
type: array
items:
$ref: '#/components/schemas/CommunityDistrict'
order:
type: string
description: Community district numbers are sorted in ascending order
example: 'id'
required:
- communityDistricts
- order
'400':
$ref: "#/components/responses/BadRequest"
'404':
Expand Down
3 changes: 2 additions & 1 deletion src/borough/borough.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
FindCapitalProjectTilesByBoroughIdCommunityDistrictIdRepo,
} from "./borough.repository.schema";
import { capitalProject, communityDistrict } from "src/schema";
import { eq, sql, and, isNotNull } from "drizzle-orm";
import { eq, sql, and, isNotNull, asc } from "drizzle-orm";
import {
FindCapitalProjectTilesByBoroughIdCommunityDistrictIdPathParams,
FindCommunityDistrictGeoJsonByBoroughIdCommunityDistrictIdPathParams,
Expand Down Expand Up @@ -59,6 +59,7 @@ export class BoroughRepository {
boroughId: true,
},
where: eq(communityDistrict.boroughId, id),
orderBy: asc(communityDistrict.id),
});
} catch {
throw new DataRetrievalException();
Expand Down
2 changes: 2 additions & 0 deletions src/borough/borough.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ describe("Borough service unit", () => {
communityDistricts,
),
).not.toThrow();

expect(communityDistricts.order).toBe("id");
});

it("service should throw a resource error when requesting with a missing id", async () => {
Expand Down
1 change: 1 addition & 0 deletions src/borough/borough.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class BoroughService {

return {
communityDistricts,
order: "id",
};
}

Expand Down
10 changes: 10 additions & 0 deletions src/gen/types/FindCommunityDistrictsByBoroughId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export type FindCommunityDistrictsByBoroughId200 = {
* @type array
*/
communityDistricts: CommunityDistrict[];
/**
* @description Community district numbers are sorted in ascending order
* @type string
*/
order: string;
};
/**
* @description Invalid client request
Expand All @@ -37,6 +42,11 @@ export type FindCommunityDistrictsByBoroughIdQueryResponse = {
* @type array
*/
communityDistricts: CommunityDistrict[];
/**
* @description Community district numbers are sorted in ascending order
* @type string
*/
order: string;
};
export type FindCommunityDistrictsByBoroughIdQuery = {
Response: FindCommunityDistrictsByBoroughIdQueryResponse;
Expand Down
6 changes: 6 additions & 0 deletions src/gen/zod/findCommunityDistrictsByBoroughIdSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export const findCommunityDistrictsByBoroughIdPathParamsSchema = z.object({
*/
export const findCommunityDistrictsByBoroughId200Schema = z.object({
communityDistricts: z.array(z.lazy(() => communityDistrictSchema)),
order: z.coerce
.string()
.describe("Community district numbers are sorted in ascending order"),
});
/**
* @description Invalid client request
Expand All @@ -39,4 +42,7 @@ export const findCommunityDistrictsByBoroughId500Schema = z.lazy(
*/
export const findCommunityDistrictsByBoroughIdQueryResponseSchema = z.object({
communityDistricts: z.array(z.lazy(() => communityDistrictSchema)),
order: z.coerce
.string()
.describe("Community district numbers are sorted in ascending order"),
});