From b9e1c4ada8bb27db60a07d35b1d72b2cc981c669 Mon Sep 17 00:00:00 2001 From: horatio Date: Tue, 3 Sep 2024 11:23:34 -0400 Subject: [PATCH] 368 Sort City Council District Find Many by Id - 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` --- openapi/openapi.yaml | 8 ++++++-- .../city-council-district.repository.ts | 1 + .../city-council-district.service.spec.ts | 2 ++ .../city-council-district.service.ts | 1 + src/gen/schemas/CityCouncilDistrict.json | 2 +- src/gen/schemas/CityCouncilDistrictGeoJson.json | 2 +- src/gen/types/FindCityCouncilDistricts.ts | 10 ++++++++++ src/gen/zod/findCityCouncilDistrictsSchema.ts | 12 ++++++++++++ 8 files changed, 34 insertions(+), 4 deletions(-) diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 9fb5ab49..09237e80 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -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': @@ -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: diff --git a/src/city-council-district/city-council-district.repository.ts b/src/city-council-district/city-council-district.repository.ts index 9618aaf3..8a429649 100644 --- a/src/city-council-district/city-council-district.repository.ts +++ b/src/city-council-district/city-council-district.repository.ts @@ -50,6 +50,7 @@ export class CityCouncilDistrictRepository { columns: { id: true, }, + orderBy: sql`${cityCouncilDistrict.id}::integer ASC`, }); } catch { throw new DataRetrievalException(); diff --git a/src/city-council-district/city-council-district.service.spec.ts b/src/city-council-district/city-council-district.service.spec.ts index 5e016a3a..92e172bd 100644 --- a/src/city-council-district/city-council-district.service.spec.ts +++ b/src/city-council-district/city-council-district.service.spec.ts @@ -37,6 +37,8 @@ describe("City Council District service unit", () => { expect(() => findCityCouncilDistrictsQueryResponseSchema.parse(cityCouncilDistricts), ).not.toThrow(); + + expect(cityCouncilDistricts.order).toBe("id"); }); }); diff --git a/src/city-council-district/city-council-district.service.ts b/src/city-council-district/city-council-district.service.ts index 060d5715..7aacbb3e 100644 --- a/src/city-council-district/city-council-district.service.ts +++ b/src/city-council-district/city-council-district.service.ts @@ -27,6 +27,7 @@ export class CityCouncilDistrictService { return { cityCouncilDistricts, + order: "id", }; } diff --git a/src/gen/schemas/CityCouncilDistrict.json b/src/gen/schemas/CityCouncilDistrict.json index 0cec1d15..5a63b580 100644 --- a/src/gen/schemas/CityCouncilDistrict.json +++ b/src/gen/schemas/CityCouncilDistrict.json @@ -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})$" } }, diff --git a/src/gen/schemas/CityCouncilDistrictGeoJson.json b/src/gen/schemas/CityCouncilDistrictGeoJson.json index d92cacc5..7aad020b 100644 --- a/src/gen/schemas/CityCouncilDistrictGeoJson.json +++ b/src/gen/schemas/CityCouncilDistrictGeoJson.json @@ -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})$" } }, diff --git a/src/gen/types/FindCityCouncilDistricts.ts b/src/gen/types/FindCityCouncilDistricts.ts index 564cd44f..77e1f739 100644 --- a/src/gen/types/FindCityCouncilDistricts.ts +++ b/src/gen/types/FindCityCouncilDistricts.ts @@ -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 @@ -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; diff --git a/src/gen/zod/findCityCouncilDistrictsSchema.ts b/src/gen/zod/findCityCouncilDistrictsSchema.ts index feb03337..1fde82bf 100644 --- a/src/gen/zod/findCityCouncilDistrictsSchema.ts +++ b/src/gen/zod/findCityCouncilDistrictsSchema.ts @@ -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 @@ -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(), });