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 b9e1c4a
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 4 deletions.
8 changes: 6 additions & 2 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ 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
'400':
Expand Down Expand Up @@ -1067,8 +1071,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 | undefined
*/
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 | undefined
*/
order?: string;
};
export type FindCityCouncilDistrictsQuery = {
Response: FindCityCouncilDistrictsQueryResponse;
Expand Down
12 changes: 12 additions & 0 deletions src/gen/zod/findCityCouncilDistrictsSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ 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",
)
.optional(),
});
/**
* @description Invalid client request
Expand All @@ -21,4 +27,10 @@ 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",
)
.optional(),
});

0 comments on commit b9e1c4a

Please sign in to comment.