-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenAPI Implementation findCityCouncilDistricts endpoint
implement city council district (ccd) endpoint: - ccd controller, module, repository, service - cd unit and e2e tests - indentation fixes on openapi yaml - tweaks to README - regenerate ts and zod schemas Closes #250
- Loading branch information
1 parent
9b50671
commit 67eb14f
Showing
24 changed files
with
279 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/city-council-district/city-council-district.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Controller, Get, UseFilters } from "@nestjs/common"; | ||
import { CityCouncilDistrictService } from "./city-council-district.service"; | ||
import { InternalServerErrorExceptionFilter } from "src/filter"; | ||
|
||
@UseFilters(InternalServerErrorExceptionFilter) | ||
@Controller("city-council-districts") | ||
export class CityCouncilDistrictController { | ||
constructor( | ||
private readonly cityCouncilDistrictService: CityCouncilDistrictService, | ||
) {} | ||
|
||
@Get() | ||
async findMany() { | ||
return this.cityCouncilDistrictService.findMany(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { CityCouncilDistrictService } from "./city-council-district.service"; | ||
import { CityCouncilDistrictController } from "./city-council-district.controller"; | ||
import { CityCouncilDistrictRepository } from "./city-council-district.repository"; | ||
|
||
@Module({ | ||
exports: [CityCouncilDistrictService], | ||
providers: [CityCouncilDistrictService, CityCouncilDistrictRepository], | ||
controllers: [CityCouncilDistrictController], | ||
}) | ||
export class CityCouncilDistrictModule {} |
6 changes: 6 additions & 0 deletions
6
src/city-council-district/city-council-district.repository.schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { cityCouncilDistrictEntitySchema } from "src/schema"; | ||
import { z } from "zod"; | ||
|
||
export const findManyRepoSchema = z.array(cityCouncilDistrictEntitySchema); | ||
|
||
export type FindManyRepo = z.infer<typeof findManyRepoSchema>; |
23 changes: 23 additions & 0 deletions
23
src/city-council-district/city-council-district.repository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Inject } from "@nestjs/common"; | ||
import { DB, DbType } from "src/global/providers/db.provider"; | ||
import { DataRetrievalException } from "src/exception"; | ||
import { FindManyRepo } from "./city-council-district.repository.schema"; | ||
|
||
export class CityCouncilDistrictRepository { | ||
constructor( | ||
@Inject(DB) | ||
private readonly db: DbType, | ||
) {} | ||
|
||
async findMany(): Promise<FindManyRepo> { | ||
try { | ||
return await this.db.query.cityCouncilDistrict.findMany({ | ||
columns: { | ||
id: true, | ||
}, | ||
}); | ||
} catch { | ||
throw new DataRetrievalException(); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/city-council-district/city-council-district.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { CityCouncilDistrictRepositoryMock } from "test/city-council-district/city-council-district.repository.mock"; | ||
import { Test } from "@nestjs/testing"; | ||
import { CityCouncilDistrictRepository } from "./city-council-district.repository"; | ||
import { findCityCouncilDistrictsQueryResponseSchema } from "src/gen"; | ||
import { CityCouncilDistrictService } from "./city-council-district.service"; | ||
|
||
describe("City Council District service unit", () => { | ||
let cityCouncilDistrictService: CityCouncilDistrictService; | ||
|
||
beforeEach(async () => { | ||
const cityCouncilDistrictRepositoryMock = | ||
new CityCouncilDistrictRepositoryMock(); | ||
|
||
const moduleRef = await Test.createTestingModule({ | ||
providers: [CityCouncilDistrictService, CityCouncilDistrictRepository], | ||
}) | ||
.overrideProvider(CityCouncilDistrictRepository) | ||
.useValue(cityCouncilDistrictRepositoryMock) | ||
.compile(); | ||
|
||
cityCouncilDistrictService = moduleRef.get<CityCouncilDistrictService>( | ||
CityCouncilDistrictService, | ||
); | ||
}); | ||
|
||
it("service should return a findCityCouncilDistrictsQueryResponseSchema compliant object", async () => { | ||
const cityCouncilDistricts = await cityCouncilDistrictService.findMany(); | ||
expect(() => | ||
findCityCouncilDistrictsQueryResponseSchema.parse(cityCouncilDistricts), | ||
).not.toThrow(); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
src/city-council-district/city-council-district.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Inject, Injectable } from "@nestjs/common"; | ||
import { CityCouncilDistrictRepository } from "./city-council-district.repository"; | ||
|
||
@Injectable() | ||
export class CityCouncilDistrictService { | ||
constructor( | ||
@Inject(CityCouncilDistrictRepository) | ||
private readonly cityCouncilDistrictRepository: CityCouncilDistrictRepository, | ||
) {} | ||
|
||
async findMany() { | ||
const cityCouncilDistricts = | ||
await this.cityCouncilDistrictRepository.findMany(); | ||
|
||
return { | ||
cityCouncilDistricts, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,49 @@ | ||
export type CapitalCommitment = { | ||
/** | ||
* @description A uuid used to refer to the capital commitment. | ||
* @type string | undefined uuid | ||
* @type string uuid | ||
*/ | ||
id?: string; | ||
id: string; | ||
/** | ||
* @description A four character string used to refer to the commitment type. | ||
* @type string | undefined | ||
* @type string | ||
* @example DSGN | ||
*/ | ||
type?: string; | ||
type: string; | ||
/** | ||
* @description A string used to refer to the date when the commitment is projected to be committed. | ||
* @type string | undefined date | ||
* @type string date | ||
* @example 2012-04-23 | ||
*/ | ||
plannedDate?: string; | ||
plannedDate: string; | ||
/** | ||
* @description A string used to refer to the budget line. | ||
* @type string | undefined | ||
* @type string | ||
* @example HW | ||
*/ | ||
budgetLineCode?: string; | ||
budgetLineCode: string; | ||
/** | ||
* @description A string used to refer to the budget line. | ||
* @type string | undefined | ||
* @type string | ||
* @example 0002Q | ||
*/ | ||
budgetLineId?: string; | ||
budgetLineId: string; | ||
/** | ||
* @description A string of variable length containing the initials of the sponsoring agency. | ||
* @type string | undefined | ||
* @type string | ||
* @example DOT | ||
*/ | ||
sponsoringAgencyInitials?: string; | ||
sponsoringAgencyInitials: string; | ||
/** | ||
* @description A string of variable length denoting the type of budget. | ||
* @type string | undefined | ||
* @type string | ||
* @example Highways | ||
*/ | ||
budgetType?: string; | ||
budgetType: string; | ||
/** | ||
* @description A numeric string used to refer to the amount of total planned commitments. | ||
* @type number | undefined | ||
* @type number | ||
* @example 1600000 | ||
*/ | ||
totalValue?: number; | ||
required?: any; | ||
totalValue: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { Page } from "./Page"; | ||
import type { CapitalProject } from "./CapitalProject"; | ||
|
||
export type CapitalProjectPage = Page & { | ||
/** | ||
* @type array | ||
*/ | ||
capitalProjects: CapitalProject[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
export type CommunityDistrict = { | ||
/** | ||
* @description The two character numeric string containing the number used to refer to the community district. | ||
* @type string | undefined | ||
* @type string | ||
* @example 1 | ||
*/ | ||
id?: string; | ||
id: string; | ||
/** | ||
* @description A single character numeric string containing the common number used to refer to the borough. Possible values are 1-5. | ||
* @type string | undefined | ||
* @type string | ||
* @example 1 | ||
*/ | ||
boroughId?: string; | ||
required?: any; | ||
boroughId: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { Error } from "./Error"; | ||
import type { CityCouncilDistrict } from "./CityCouncilDistrict"; | ||
|
||
export type FindCityCouncilDistricts400 = Error; | ||
|
||
export type FindCityCouncilDistricts500 = Error; | ||
|
||
/** | ||
* @description an object of city council districts | ||
*/ | ||
export type FindCityCouncilDistrictsQueryResponse = { | ||
/** | ||
* @type array | ||
*/ | ||
cityCouncilDistricts: CityCouncilDistrict[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { z } from "zod"; | ||
|
||
import { pageSchema } from "./pageSchema"; | ||
import { capitalProjectSchema } from "./capitalProjectSchema"; | ||
|
||
export const capitalProjectPageSchema = z | ||
.lazy(() => pageSchema) | ||
.schema.and( | ||
z.object({ | ||
capitalProjects: z.array(z.lazy(() => capitalProjectSchema).schema), | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.