Skip to content

Commit

Permalink
368 Sort City Council District Find Many by Id
Browse files Browse the repository at this point in the history
 - updated OpenAPI properties for CCD to include order variable
 - updated findMany to sort the CCDs by id as integers
 - updated CCD service spec to test `cityCouncilDistricts.order` value is `id`
  • Loading branch information
horatiorosa committed Sep 3, 2024
1 parent 63b6444 commit b486818
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 4 deletions.
9 changes: 7 additions & 2 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,13 @@ paths:
type: array
items:
$ref: '#/components/schemas/CityCouncilDistrict'
order:
type: string
description: City council districts ids are sorted as if numbers in ascending order
example: 'id'
required:
- cityCouncilDistricts
- order
'400':
$ref: '#/components/responses/BadRequest'
'500':
Expand Down Expand Up @@ -1067,8 +1072,8 @@ components:
id:
type: string
description: One or two character code to represent city council districts.
pattern: '^([0-9]{1,2})$'
example: 25
pattern: '^([0-9]{1,2})$'
example: '25'
required:
- id
CityCouncilDistrictGeoJson:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class CityCouncilDistrictRepository {
columns: {
id: true,
},
orderBy: sql`${cityCouncilDistrict.id}::integer ASC`,
});
} catch {
throw new DataRetrievalException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ describe("City Council District service unit", () => {
expect(() =>
findCityCouncilDistrictsQueryResponseSchema.parse(cityCouncilDistricts),
).not.toThrow();

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

Expand Down
1 change: 1 addition & 0 deletions src/city-council-district/city-council-district.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class CityCouncilDistrictService {

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

Expand Down
2 changes: 1 addition & 1 deletion src/gen/schemas/CityCouncilDistrict.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": {
"description": "One or two character code to represent city council districts.",
"type": "string",
"example": 25,
"example": "25",
"pattern": "^([0-9]{1,2})$"
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/gen/schemas/CityCouncilDistrictGeoJson.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"id": {
"description": "One or two character code to represent city council districts.",
"type": "string",
"example": 25,
"example": "25",
"pattern": "^([0-9]{1,2})$"
}
},
Expand Down
10 changes: 10 additions & 0 deletions src/gen/types/FindCityCouncilDistricts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export type FindCityCouncilDistricts200 = {
* @type array
*/
cityCouncilDistricts: CityCouncilDistrict[];
/**
* @description City council districts ids are sorted as if numbers in ascending order
* @type string
*/
order: string;
};
/**
* @description Invalid client request
Expand All @@ -26,6 +31,11 @@ export type FindCityCouncilDistrictsQueryResponse = {
* @type array
*/
cityCouncilDistricts: CityCouncilDistrict[];
/**
* @description City council districts ids are sorted as if numbers in ascending order
* @type string
*/
order: string;
};
export type FindCityCouncilDistrictsQuery = {
Response: FindCityCouncilDistrictsQueryResponse;
Expand Down
10 changes: 10 additions & 0 deletions src/gen/zod/findCityCouncilDistrictsSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { errorSchema } from "./errorSchema";
*/
export const findCityCouncilDistricts200Schema = z.object({
cityCouncilDistricts: z.array(z.lazy(() => cityCouncilDistrictSchema)),
order: z.coerce
.string()
.describe(
"City council districts ids are sorted as if numbers in ascending order",
),
});
/**
* @description Invalid client request
Expand All @@ -21,4 +26,9 @@ export const findCityCouncilDistricts500Schema = z.lazy(() => errorSchema);
*/
export const findCityCouncilDistrictsQueryResponseSchema = z.object({
cityCouncilDistricts: z.array(z.lazy(() => cityCouncilDistrictSchema)),
order: z.coerce
.string()
.describe(
"City council districts ids are sorted as if numbers in ascending order",
),
});

0 comments on commit b486818

Please sign in to comment.