diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index ba7d5d1c4..072936510 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -28,6 +28,7 @@ import { PersonComplaintXrefCodeModule } from "./v1/person_complaint_xref_code/p import { BcGeoCoderModule } from "./external_api/bc_geo_coder/bc_geo_coder.module"; import { ConfigurationModule } from './v1/configuration/configuration.module'; import { ComplaintTypeCodeModule } from "./v1/complaint_type_code/complaint_type_code.module"; +import { CodeTableModule } from './v1/code-table/code-table.module'; console.log("Var check - POSTGRESQL_HOST", process.env.POSTGRESQL_HOST); @@ -78,6 +79,7 @@ if (process.env.POSTGRESQL_PASSWORD != null ){ BcGeoCoderModule, ConfigurationModule, ComplaintTypeCodeModule, + CodeTableModule, ], controllers: [AppController], providers: [AppService], diff --git a/backend/src/types/models/code-tables/agency.ts b/backend/src/types/models/code-tables/agency.ts new file mode 100644 index 000000000..9e8f222b5 --- /dev/null +++ b/backend/src/types/models/code-tables/agency.ts @@ -0,0 +1,5 @@ +import { BaseCodeTable } from "../../models/code-tables/code-table"; + +export interface Agency extends BaseCodeTable { + agency: string +} \ No newline at end of file diff --git a/backend/src/types/models/code-tables/attractant.ts b/backend/src/types/models/code-tables/attractant.ts new file mode 100644 index 000000000..a433270e2 --- /dev/null +++ b/backend/src/types/models/code-tables/attractant.ts @@ -0,0 +1,5 @@ +import { BaseCodeTable } from "../../models/code-tables/code-table"; + +export interface Attractant extends BaseCodeTable { + attractant: string +} \ No newline at end of file diff --git a/backend/src/types/models/code-tables/code-table.ts b/backend/src/types/models/code-tables/code-table.ts new file mode 100644 index 000000000..689ee760c --- /dev/null +++ b/backend/src/types/models/code-tables/code-table.ts @@ -0,0 +1,6 @@ +export interface BaseCodeTable { + shortDescription: string; + longDescription: string; + displayOrder?: number; + isActive?: boolean; +} diff --git a/backend/src/types/models/code-tables/community.ts b/backend/src/types/models/code-tables/community.ts new file mode 100644 index 000000000..8180e50da --- /dev/null +++ b/backend/src/types/models/code-tables/community.ts @@ -0,0 +1,5 @@ +import { Zone } from "./zone"; + +export interface Community extends Zone { + zone: string +} \ No newline at end of file diff --git a/backend/src/types/models/code-tables/complaint-status.ts b/backend/src/types/models/code-tables/complaint-status.ts new file mode 100644 index 000000000..08c3951a4 --- /dev/null +++ b/backend/src/types/models/code-tables/complaint-status.ts @@ -0,0 +1,5 @@ +import { BaseCodeTable } from "../../models/code-tables/code-table"; + +export interface ComplaintStatus extends BaseCodeTable { + complaintStatus: string +} \ No newline at end of file diff --git a/backend/src/types/models/code-tables/complaint-type.ts b/backend/src/types/models/code-tables/complaint-type.ts new file mode 100644 index 000000000..5d09e416f --- /dev/null +++ b/backend/src/types/models/code-tables/complaint-type.ts @@ -0,0 +1,5 @@ +import { BaseCodeTable } from "./code-table"; + +export interface ComplaintType extends BaseCodeTable { + complaintType: string +} \ No newline at end of file diff --git a/backend/src/types/models/code-tables/index.ts b/backend/src/types/models/code-tables/index.ts new file mode 100644 index 000000000..2f1680b5e --- /dev/null +++ b/backend/src/types/models/code-tables/index.ts @@ -0,0 +1,52 @@ +import { BaseCodeTable } from "./code-table"; +import { Agency } from "./agency"; +import { Attractant } from "./attractant"; +import { ComplaintStatus } from "./complaint-status"; +import { NatureOfComplaint } from "./nature-of-complaint"; +import { OrganizationUnitType } from "./organization-unit-type"; +import { OrganizationUnit } from "./organization-unit"; +import { PersonComplaintType } from "./person-complaint-type"; +import { Species } from "./species"; +import { Violation } from "./violation"; +import { OrganizationCodeTable } from "./organization-code-table"; +import { ComplaintType } from "./complaint-type"; +import { Sector } from "./sector"; +import { Community } from "./community"; +import { Zone } from "./zone"; + +export const AvailableCodeTables = [ + "agency", + "attractant", + "complaint-status", + "complaint-type", + "nature-of-complaint", + "organization-unit-type", + "organization-unit", + "person-complaint", + "species", + "violation", + "cos-organization-unit", + "complaint-type", +]; + +export const AvailableAgencies = [ + "cos" +] + +export default BaseCodeTable; +export { + Agency, + Attractant, + ComplaintStatus, + NatureOfComplaint, + OrganizationUnitType, + OrganizationUnit, + PersonComplaintType, + Species, + Violation, + OrganizationCodeTable, + ComplaintType, + Sector, + Zone, + Community +}; diff --git a/backend/src/types/models/code-tables/nature-of-complaint.ts b/backend/src/types/models/code-tables/nature-of-complaint.ts new file mode 100644 index 000000000..fffd1776b --- /dev/null +++ b/backend/src/types/models/code-tables/nature-of-complaint.ts @@ -0,0 +1,5 @@ +import { BaseCodeTable } from "./code-table"; + +export interface NatureOfComplaint extends BaseCodeTable { + natureOfComplaint: string +} \ No newline at end of file diff --git a/backend/src/types/models/code-tables/organization-code-table.ts b/backend/src/types/models/code-tables/organization-code-table.ts new file mode 100644 index 000000000..b70d592cd --- /dev/null +++ b/backend/src/types/models/code-tables/organization-code-table.ts @@ -0,0 +1,10 @@ +export interface OrganizationCodeTable { + areaName: string; + officeLocationName: string; + regionName: string; + zoneName: string; + area: string; + officeLocation: string; + region: string; + zone: string; +} diff --git a/backend/src/types/models/code-tables/organization-unit-type.ts b/backend/src/types/models/code-tables/organization-unit-type.ts new file mode 100644 index 000000000..f6d3279d5 --- /dev/null +++ b/backend/src/types/models/code-tables/organization-unit-type.ts @@ -0,0 +1,5 @@ +import { BaseCodeTable } from "./code-table"; + +export interface OrganizationUnitType extends BaseCodeTable { + organizationUnitType: string +} \ No newline at end of file diff --git a/backend/src/types/models/code-tables/organization-unit.ts b/backend/src/types/models/code-tables/organization-unit.ts new file mode 100644 index 000000000..133cd8250 --- /dev/null +++ b/backend/src/types/models/code-tables/organization-unit.ts @@ -0,0 +1,6 @@ +import { BaseCodeTable } from "./code-table"; + +export interface OrganizationUnit extends BaseCodeTable { + organizationUnit: string + organizationUnitType?: string +} \ No newline at end of file diff --git a/backend/src/types/models/code-tables/person-complaint-type.ts b/backend/src/types/models/code-tables/person-complaint-type.ts new file mode 100644 index 000000000..7d52692e6 --- /dev/null +++ b/backend/src/types/models/code-tables/person-complaint-type.ts @@ -0,0 +1,5 @@ +import { BaseCodeTable } from "./code-table"; + +export interface PersonComplaintType extends BaseCodeTable { + personComplaintType: string +} \ No newline at end of file diff --git a/backend/src/types/models/code-tables/sector.ts b/backend/src/types/models/code-tables/sector.ts new file mode 100644 index 000000000..334e0ee25 --- /dev/null +++ b/backend/src/types/models/code-tables/sector.ts @@ -0,0 +1,4 @@ +export interface Sector { + code: string + name: string +} \ No newline at end of file diff --git a/backend/src/types/models/code-tables/species.ts b/backend/src/types/models/code-tables/species.ts new file mode 100644 index 000000000..b003420f2 --- /dev/null +++ b/backend/src/types/models/code-tables/species.ts @@ -0,0 +1,6 @@ +import { BaseCodeTable } from "./code-table"; + +export interface Species extends BaseCodeTable { + species: string; + legacy: string; +} diff --git a/backend/src/types/models/code-tables/violation.ts b/backend/src/types/models/code-tables/violation.ts new file mode 100644 index 000000000..5a5bf8220 --- /dev/null +++ b/backend/src/types/models/code-tables/violation.ts @@ -0,0 +1,5 @@ +import { BaseCodeTable } from "./code-table"; + +export interface Violation extends BaseCodeTable { + violation: string +} \ No newline at end of file diff --git a/backend/src/types/models/code-tables/zone.ts b/backend/src/types/models/code-tables/zone.ts new file mode 100644 index 000000000..aab65c99c --- /dev/null +++ b/backend/src/types/models/code-tables/zone.ts @@ -0,0 +1,5 @@ +import { Sector } from "./sector"; + +export interface Zone extends Sector { + region: string +} \ No newline at end of file diff --git a/backend/src/v1/agency_code/agency_code.controller.spec.ts b/backend/src/v1/agency_code/agency_code.controller.spec.ts deleted file mode 100644 index 6dd6138d7..000000000 --- a/backend/src/v1/agency_code/agency_code.controller.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { AgencyCodeController } from './agency_code.controller'; -import { AgencyCodeService } from './agency_code.service'; -import { getRepositoryToken } from '@nestjs/typeorm'; -import { AgencyCode } from './entities/agency_code.entity'; - -describe('AgencyCodeController', () => { - let controller: AgencyCodeController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [AgencyCodeController], - providers: [ - AgencyCodeService, - { - provide: getRepositoryToken(AgencyCode), - useValue: { - - }, - },], - }).compile(); - - controller = module.get(AgencyCodeController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/backend/src/v1/agency_code/agency_code.controller.ts b/backend/src/v1/agency_code/agency_code.controller.ts deleted file mode 100644 index 1ad68a63b..000000000 --- a/backend/src/v1/agency_code/agency_code.controller.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; -import { AgencyCodeService } from './agency_code.service'; -import { CreateAgencyCodeDto } from './dto/create-agency_code.dto'; -import { UpdateAgencyCodeDto } from './dto/update-agency_code.dto'; -import { JwtRoleGuard } from '../../auth/jwtrole.guard'; -import { ApiTags } from '@nestjs/swagger'; -import { Roles } from '../../auth/decorators/roles.decorator'; -import { Role } from '../../enum/role.enum'; - -@ApiTags("agency-code") -@UseGuards(JwtRoleGuard) -@Controller({ - path: 'agency-code', - version: '1'}) -export class AgencyCodeController { - constructor(private readonly agencyCodeService: AgencyCodeService) {} - - @Post() - @Roles(Role.COS_OFFICER) - create(@Body() createAgencyCodeDto: CreateAgencyCodeDto) { - return this.agencyCodeService.create(createAgencyCodeDto); - } - - @Get() - @Roles(Role.COS_OFFICER) - findAll() { - return this.agencyCodeService.findAll(); - } - - @Get(':id') - @Roles(Role.COS_OFFICER) - findOne(@Param('id') id: string) { - return this.agencyCodeService.findOne({where: {agency_code: id}}); - } - - @Patch(':id') - @Roles(Role.COS_OFFICER) - update(@Param('id') id: string, @Body() updateAgencyCodeDto: UpdateAgencyCodeDto) { - return this.agencyCodeService.update(id, updateAgencyCodeDto); - } - - @Delete(':id') - @Roles(Role.COS_OFFICER) - remove(@Param('id') id: string) { - return this.agencyCodeService.remove(id); - } -} diff --git a/backend/src/v1/agency_code/agency_code.module.ts b/backend/src/v1/agency_code/agency_code.module.ts index 0696740fa..0c2294d07 100644 --- a/backend/src/v1/agency_code/agency_code.module.ts +++ b/backend/src/v1/agency_code/agency_code.module.ts @@ -1,12 +1,10 @@ import { Module } from '@nestjs/common'; import { AgencyCodeService } from './agency_code.service'; -import { AgencyCodeController } from './agency_code.controller'; import { TypeOrmModule } from "@nestjs/typeorm"; import { AgencyCode } from './entities/agency_code.entity'; @Module({ imports: [TypeOrmModule.forFeature([AgencyCode])], - controllers: [AgencyCodeController], providers: [AgencyCodeService] }) export class AgencyCodeModule {} diff --git a/backend/src/v1/attractant_code/attractant_code.controller.spec.ts b/backend/src/v1/attractant_code/attractant_code.controller.spec.ts deleted file mode 100644 index 6af81d944..000000000 --- a/backend/src/v1/attractant_code/attractant_code.controller.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { AttractantCodeController } from './attractant_code.controller'; -import { AttractantCodeService } from './attractant_code.service'; -import { AttractantCode } from './entities/attractant_code.entity'; -import { getRepositoryToken } from '@nestjs/typeorm'; - -describe('AttractantCodeController', () => { - let controller: AttractantCodeController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [AttractantCodeController], - providers: [ - AttractantCodeService, - { - provide: getRepositoryToken(AttractantCode), - useValue: { - - }, - },], - }).compile(); - - controller = module.get(AttractantCodeController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/backend/src/v1/attractant_code/attractant_code.controller.ts b/backend/src/v1/attractant_code/attractant_code.controller.ts deleted file mode 100644 index f6b72d6bc..000000000 --- a/backend/src/v1/attractant_code/attractant_code.controller.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; -import { AttractantCodeService } from './attractant_code.service'; -import { CreateAttractantCodeDto } from './dto/create-attractant_code.dto'; -import { UpdateAttractantCodeDto } from './dto/update-attractant_code.dto'; -import { JwtRoleGuard } from '../../auth/jwtrole.guard'; -import { ApiTags } from '@nestjs/swagger'; -import { Role } from '../../enum/role.enum'; -import { Roles } from '../../auth/decorators/roles.decorator'; - -@ApiTags("attractant-code") -@UseGuards(JwtRoleGuard) -@Controller({ - path: 'attractant-code', - version: '1'}) -export class AttractantCodeController { - constructor(private readonly attractantCodeService: AttractantCodeService) {} - - @Post() - @Roles(Role.COS_OFFICER) - create(@Body() createAttractantCodeDto: CreateAttractantCodeDto) { - return this.attractantCodeService.create(createAttractantCodeDto); - } - - @Get() - @Roles(Role.COS_OFFICER) - findAll() { - return this.attractantCodeService.findAll(); - } - - @Get(':id') - @Roles(Role.COS_OFFICER) - findOne(@Param('id') id: string) { - return this.attractantCodeService.findOne({where: {attractant_code: id}}); - } - - @Patch(':id') - @Roles(Role.COS_OFFICER) - update(@Param('id') id: string, @Body() updateAttractantCodeDto: UpdateAttractantCodeDto) { - return this.attractantCodeService.update(id, updateAttractantCodeDto); - } - - @Delete(':id') - @Roles(Role.COS_OFFICER) - remove(@Param('id') id: string) { - return this.attractantCodeService.remove(id); - } -} diff --git a/backend/src/v1/attractant_code/attractant_code.module.ts b/backend/src/v1/attractant_code/attractant_code.module.ts index 8b62933cb..6eeae176a 100644 --- a/backend/src/v1/attractant_code/attractant_code.module.ts +++ b/backend/src/v1/attractant_code/attractant_code.module.ts @@ -1,12 +1,11 @@ import { Module } from '@nestjs/common'; import { AttractantCodeService } from './attractant_code.service'; -import { AttractantCodeController } from './attractant_code.controller'; import { TypeOrmModule } from '@nestjs/typeorm'; import { AttractantCode } from './entities/attractant_code.entity'; @Module({ imports: [TypeOrmModule.forFeature([AttractantCode])], - controllers: [AttractantCodeController], + controllers: [], providers: [AttractantCodeService] }) export class AttractantCodeModule {} diff --git a/backend/src/v1/code-table/code-table.controller.spec.ts b/backend/src/v1/code-table/code-table.controller.spec.ts new file mode 100644 index 000000000..9b9b17817 --- /dev/null +++ b/backend/src/v1/code-table/code-table.controller.spec.ts @@ -0,0 +1,178 @@ +import { Test, TestingModule } from "@nestjs/testing"; +import { getRepositoryToken } from "@nestjs/typeorm"; +import { INestApplication } from "@nestjs/common"; +import * as request from "supertest"; + +import { authGuardMock } from "../../../test/mocks/authGuardMock"; +import { roleGuardMock } from "../../../test/mocks/roleGuardMock"; +import { JwtAuthGuard } from "../../auth/jwtauth.guard"; +import { JwtRoleGuard } from "../../auth/jwtrole.guard"; + +import { CodeTableController } from "./code-table.controller"; +import { CodeTableService } from "./code-table.service"; +import { + MockAgencyCodeTableRepository, + MockAttractantCodeTableRepository, + MockCommunityCodeTableServiceRepository, + MockComplaintStatusCodeTableRepository, + MockComplaintTypeCodeTableRepository, + MockNatureOfComplaintCodeTableRepository, + MockOrganizationUnitCodeTableRepository, + MockOrganizationUnitTypeCodeTableRepository, + MockPersonComplaintCodeTableRepository, + MockSpeciesCodeTableRepository, + MockViolationsCodeTableRepository, +} from "../../../test/mocks/mock-code-table-repositories"; +import { AgencyCode } from "../agency_code/entities/agency_code.entity"; +import { AttractantCode } from "../attractant_code/entities/attractant_code.entity"; +import { ComplaintStatusCode } from "../complaint_status_code/entities/complaint_status_code.entity"; +import { HwcrComplaintNatureCode } from "../hwcr_complaint_nature_code/entities/hwcr_complaint_nature_code.entity"; +import { GeoOrgUnitTypeCode } from "../geo_org_unit_type_code/entities/geo_org_unit_type_code.entity"; +import { GeoOrganizationUnitCode } from "../geo_organization_unit_code/entities/geo_organization_unit_code.entity"; +import { PersonComplaintXrefCode } from "../person_complaint_xref_code/entities/person_complaint_xref_code.entity"; +import { SpeciesCode } from "../species_code/entities/species_code.entity"; +import { ViolationCode } from "../violation_code/entities/violation_code.entity"; +import { CosGeoOrgUnit } from "../cos_geo_org_unit/entities/cos_geo_org_unit.entity"; +import { ComplaintTypeCode } from "../complaint_type_code/entities/complaint_type_code.entity"; + +describe("Testing: CodeTable Controller", () => { + let app: INestApplication; + let controller: CodeTableController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [CodeTableController], + providers: [ + CodeTableService, + { + provide: getRepositoryToken(AgencyCode), + useFactory: MockAgencyCodeTableRepository, + }, + { + provide: getRepositoryToken(AttractantCode), + useFactory: MockAttractantCodeTableRepository, + }, + { + provide: getRepositoryToken(ComplaintStatusCode), + useFactory: MockComplaintStatusCodeTableRepository, + }, + { + provide: getRepositoryToken(HwcrComplaintNatureCode), + useFactory: MockNatureOfComplaintCodeTableRepository, + }, + { + provide: getRepositoryToken(GeoOrgUnitTypeCode), + useFactory: MockOrganizationUnitTypeCodeTableRepository, + }, + { + provide: getRepositoryToken(GeoOrganizationUnitCode), + useFactory: MockOrganizationUnitCodeTableRepository, + }, + { + provide: getRepositoryToken(PersonComplaintXrefCode), + useFactory: MockPersonComplaintCodeTableRepository, + }, + { + provide: getRepositoryToken(SpeciesCode), + useFactory: MockSpeciesCodeTableRepository, + }, + { + provide: getRepositoryToken(ViolationCode), + useFactory: MockViolationsCodeTableRepository, + }, + { + provide: getRepositoryToken(CosGeoOrgUnit), + useFactory: MockCommunityCodeTableServiceRepository, + }, + { + provide: getRepositoryToken(ComplaintTypeCode), + useFactory: MockComplaintTypeCodeTableRepository, + }, + ], + }) + .overrideGuard(JwtAuthGuard) + .useValue({ authGuardMock }) + .overrideGuard(JwtRoleGuard) + .useValue({ roleGuardMock }) + .compile(); + + app = module.createNestApplication(); + await app.init(); + + controller = module.get(CodeTableController); + }); + + it("should be defined", () => { + expect(controller).toBeDefined(); + }); + + it("should return 200 when a GET is called successfully", async () => { + //-- arrange + const _tableName = "agency"; + const _agency = "cos"; + + //-- act + let response = await request(app.getHttpServer()).get( + `/code-table/${_tableName}` + ); + expect(response.statusCode).toBe(200); + + response = await request(app.getHttpServer()).get( + `/code-table/organization-by-agency/${_agency}` + ); + expect(response.statusCode).toBe(200); + + response = await request(app.getHttpServer()).get( + `/code-table/regions-by-agency/${_agency}` + ); + expect(response.statusCode).toBe(200); + + response = await request(app.getHttpServer()).get( + `/code-table/zones-by-agency/${_agency}` + ); + expect(response.statusCode).toBe(200); + + response = await request(app.getHttpServer()).get( + `/code-table/communities-by-agency/${_agency}` + ); + expect(response.statusCode).toBe(200); + }); + + it("should return 404 when a requesting code table that doesn't exist", async () => { + //-- arrange + const _tableName = "test"; + + //-- act + let response = await request(app.getHttpServer()).get( + `/code-table/${_tableName}` + ); + expect(response.statusCode).toBe(404); + }); + + it("should return 404 when a requesting organization by an agency doesn't exist", async () => { + //-- arrange + const _agency = "test"; + + //-- act + let response = await request(app.getHttpServer()).get( + `/code-table/organization-by-agency/${_agency}` + ); + expect(response.statusCode).toBe(404); + + response = await request(app.getHttpServer()).get( + `/code-table/regions-by-agency/${_agency}` + ); + expect(response.statusCode).toBe(404); + + response = await request(app.getHttpServer()).get( + `/code-table/zones-by-agency/${_agency}` + ); + expect(response.statusCode).toBe(404); + + response = await request(app.getHttpServer()).get( + `/code-table/communities-by-agency/${_agency}` + ); + expect(response.statusCode).toBe(404); + }); + +}); diff --git a/backend/src/v1/code-table/code-table.controller.ts b/backend/src/v1/code-table/code-table.controller.ts new file mode 100644 index 000000000..ed18f8c32 --- /dev/null +++ b/backend/src/v1/code-table/code-table.controller.ts @@ -0,0 +1,88 @@ +import { + Controller, + Get, + NotFoundException, + Param, + UseGuards, +} from "@nestjs/common"; +import { ApiTags } from "@nestjs/swagger"; + +import { CodeTableService } from "./code-table.service"; +import { Role } from "../../enum/role.enum"; +import { Roles } from "../../auth/decorators/roles.decorator"; +import { JwtRoleGuard } from "../../auth/jwtrole.guard"; + +import BaseCodeTable, { + AvailableAgencies, + AvailableCodeTables, + OrganizationCodeTable, + Sector, +} from "../../types/models/code-tables"; + +@UseGuards(JwtRoleGuard) +@ApiTags("code-table") +@Controller({ path: "code-table", version: "1" }) +export class CodeTableController { + constructor(private readonly service: CodeTableService) {} + + @Get(":table") + @Roles(Role.COS_OFFICER) + async getCodeTableByName( + @Param("table") table: string + ): Promise { + if (!AvailableCodeTables.includes(table)) { + throw new NotFoundException(); + } + + const result = await this.service.getCodeTableByName(table); + return result; + } + + @Get("/organization-by-agency/:agency") + @Roles(Role.COS_OFFICER) + async getOrganizationsByAgency( + @Param("agency") agency: string + ): Promise { + if (!AvailableAgencies.includes(agency)) { + throw new NotFoundException(); + } + + const result = await this.service.getOrganizationsByAgency(agency); + return result; + } + + @Get("/regions-by-agency/:agency") + @Roles(Role.COS_OFFICER) + async getRegionsByAgency(@Param("agency") agency: string): Promise { + if (!AvailableAgencies.includes(agency)) { + throw new NotFoundException(); + } + + const result = await this.service.getRegionsByAgency(agency); + return result; + } + + @Get("/zones-by-agency/:agency") + @Roles(Role.COS_OFFICER) + async getZonesByAgency(@Param("agency") agency: string): Promise { + if (!AvailableAgencies.includes(agency)) { + throw new NotFoundException(); + } + + const result = await this.service.getZonesByAgency(agency); + return result; + } + + @Get("/communities-by-agency/:agency") + @Roles(Role.COS_OFFICER) + async getCommunitiesByAgency( + @Param("agency") agency: string + ): Promise { + if (!AvailableAgencies.includes(agency)) { + throw new NotFoundException(); + } + + const result = await this.service.getCommunitiesByAgency(agency); + return result; + } +} diff --git a/backend/src/v1/code-table/code-table.module.ts b/backend/src/v1/code-table/code-table.module.ts new file mode 100644 index 000000000..b33f1d269 --- /dev/null +++ b/backend/src/v1/code-table/code-table.module.ts @@ -0,0 +1,34 @@ +import { Module } from "@nestjs/common"; +import { CodeTableService } from "./code-table.service"; +import { CodeTableController } from "./code-table.controller"; +import { TypeOrmModule } from "@nestjs/typeorm"; +import { AgencyCode } from "../agency_code/entities/agency_code.entity"; +import { AttractantCode } from "../attractant_code/entities/attractant_code.entity"; +import { ComplaintStatusCode } from "../complaint_status_code/entities/complaint_status_code.entity"; +import { HwcrComplaintNatureCode } from "../hwcr_complaint_nature_code/entities/hwcr_complaint_nature_code.entity"; +import { GeoOrgUnitTypeCode } from "../geo_org_unit_type_code/entities/geo_org_unit_type_code.entity"; +import { GeoOrganizationUnitCode } from "../geo_organization_unit_code/entities/geo_organization_unit_code.entity"; +import { PersonComplaintXrefCode } from "../person_complaint_xref_code/entities/person_complaint_xref_code.entity"; +import { SpeciesCode } from "../species_code/entities/species_code.entity"; +import { ViolationCode } from "../violation_code/entities/violation_code.entity"; +import { CosGeoOrgUnit } from "../cos_geo_org_unit/entities/cos_geo_org_unit.entity"; +import { ComplaintTypeCode } from "../complaint_type_code/entities/complaint_type_code.entity"; + +@Module({ + imports: [ + TypeOrmModule.forFeature([AgencyCode]), + TypeOrmModule.forFeature([AttractantCode]), + TypeOrmModule.forFeature([ComplaintStatusCode]), + TypeOrmModule.forFeature([HwcrComplaintNatureCode]), + TypeOrmModule.forFeature([GeoOrgUnitTypeCode]), + TypeOrmModule.forFeature([GeoOrganizationUnitCode]), + TypeOrmModule.forFeature([PersonComplaintXrefCode]), + TypeOrmModule.forFeature([SpeciesCode]), + TypeOrmModule.forFeature([ViolationCode]), + TypeOrmModule.forFeature([CosGeoOrgUnit]), + TypeOrmModule.forFeature([ComplaintTypeCode]), + ], + controllers: [CodeTableController], + providers: [CodeTableService], +}) +export class CodeTableModule {} diff --git a/backend/src/v1/code-table/code-table.service.spec.ts b/backend/src/v1/code-table/code-table.service.spec.ts new file mode 100644 index 000000000..e028e382e --- /dev/null +++ b/backend/src/v1/code-table/code-table.service.spec.ts @@ -0,0 +1,464 @@ +import { Test, TestingModule } from "@nestjs/testing"; +import { CodeTableService } from "./code-table.service"; +import { getRepositoryToken } from "@nestjs/typeorm"; +import { AgencyCode } from "../agency_code/entities/agency_code.entity"; +import { AttractantCode } from "../attractant_code/entities/attractant_code.entity"; +import { ComplaintStatusCode } from "../complaint_status_code/entities/complaint_status_code.entity"; + +import { + MockAgencyCodeTableRepository, + MockAttractantCodeTableRepository, + MockComplaintStatusCodeTableRepository, + MockNatureOfComplaintCodeTableRepository, + MockOrganizationUnitCodeTableRepository, + MockOrganizationUnitTypeCodeTableRepository, + MockPersonComplaintCodeTableRepository, + MockSpeciesCodeTableRepository, + MockViolationsCodeTableRepository, + MockCosOrganizationUnitCodeTableRepository, + MockComplaintTypeCodeTableRepository, + MockCommunityCodeTableServiceRepository, + MockZoneCodeTableServiceRepository, + MockRegionCodeTableServiceRepository, +} from "../../../test/mocks/mock-code-table-repositories"; +import { HwcrComplaintNatureCode } from "../hwcr_complaint_nature_code/entities/hwcr_complaint_nature_code.entity"; +import { GeoOrgUnitTypeCode } from "../geo_org_unit_type_code/entities/geo_org_unit_type_code.entity"; +import { GeoOrganizationUnitCode } from "../geo_organization_unit_code/entities/geo_organization_unit_code.entity"; +import { PersonComplaintXrefCode } from "../person_complaint_xref_code/entities/person_complaint_xref_code.entity"; +import { SpeciesCode } from "../species_code/entities/species_code.entity"; +import { ViolationCode } from "../violation_code/entities/violation_code.entity"; +import { CosGeoOrgUnit } from "../cos_geo_org_unit/entities/cos_geo_org_unit.entity"; +import { ComplaintTypeCode } from "../complaint_type_code/entities/complaint_type_code.entity"; + +describe("Testing: CodeTable Service", () => { + let service: CodeTableService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [ + CodeTableService, + { + provide: getRepositoryToken(AgencyCode), + useFactory: MockAgencyCodeTableRepository, + }, + { + provide: getRepositoryToken(AttractantCode), + useFactory: MockAttractantCodeTableRepository, + }, + { + provide: getRepositoryToken(ComplaintStatusCode), + useFactory: MockComplaintStatusCodeTableRepository, + }, + { + provide: getRepositoryToken(HwcrComplaintNatureCode), + useFactory: MockNatureOfComplaintCodeTableRepository, + }, + { + provide: getRepositoryToken(GeoOrgUnitTypeCode), + useFactory: MockOrganizationUnitTypeCodeTableRepository, + }, + { + provide: getRepositoryToken(GeoOrganizationUnitCode), + useFactory: MockOrganizationUnitCodeTableRepository, + }, + { + provide: getRepositoryToken(PersonComplaintXrefCode), + useFactory: MockPersonComplaintCodeTableRepository, + }, + { + provide: getRepositoryToken(SpeciesCode), + useFactory: MockSpeciesCodeTableRepository, + }, + { + provide: getRepositoryToken(ViolationCode), + useFactory: MockViolationsCodeTableRepository, + }, + { + provide: getRepositoryToken(CosGeoOrgUnit), + useFactory: MockCosOrganizationUnitCodeTableRepository, + }, + { + provide: getRepositoryToken(ComplaintTypeCode), + useFactory: MockComplaintTypeCodeTableRepository, + }, + ], + }).compile(); + + service = module.get(CodeTableService); + }); + + it("should be defined", () => { + expect(service).toBeDefined(); + }); + + it("should return collection of agency codes", async () => { + //-- arrange + const _tableName = "agency"; + + //-- act + const results = await service.getCodeTableByName(_tableName); + + //-- assert + expect(results).not.toBe(null); + expect(results.length).not.toBe(0); + expect(results.length).toBe(8); + }); + + it("should return collection of attractants", async () => { + //-- arrange + const _tableName = "attractant"; + + //-- act + const results = await service.getCodeTableByName(_tableName); + + //-- assert + expect(results).not.toBe(null); + expect(results.length).not.toBe(0); + expect(results.length).toBe(8); + }); + + it("should return collection of complaint status types", async () => { + //-- arrange + const _tableName = "complaint-status"; + + //-- act + const results = await service.getCodeTableByName(_tableName); + + //-- assert + expect(results).not.toBe(null); + expect(results.length).not.toBe(0); + expect(results.length).toBe(2); + }); + + it("should return collection of nature of complaints", async () => { + //-- arrange + const _tableName = "nature-of-complaint"; + + //-- act + const results = await service.getCodeTableByName(_tableName); + + //-- assert + expect(results).not.toBe(null); + expect(results.length).not.toBe(0); + expect(results.length).toBe(6); + }); + + it("should return collection of organization unit types", async () => { + //-- arrange + const _tableName = "organization-unit-type"; + + //-- act + const results = await service.getCodeTableByName(_tableName); + + //-- assert + expect(results).not.toBe(null); + expect(results.length).not.toBe(0); + expect(results.length).toBe(4); + }); + + it("should return collection of organization types", async () => { + //-- arrange + const _tableName = "organization-unit"; + + //-- act + const results = await service.getCodeTableByName(_tableName); + + //-- assert + expect(results).not.toBe(null); + expect(results.length).not.toBe(0); + expect(results.length).toBe(5); + }); + + it("should return collection of person complaint types", async () => { + //-- arrange + const _tableName = "person-complaint"; + + //-- act + const results = await service.getCodeTableByName(_tableName); + + //-- assert + expect(results).not.toBe(null); + expect(results.length).not.toBe(0); + expect(results.length).toBe(2); + }); + + it("should return collection of species", async () => { + //-- arrange + const _tableName = "species"; + + //-- act + const results = await service.getCodeTableByName(_tableName); + + //-- assert + expect(results).not.toBe(null); + expect(results.length).not.toBe(0); + expect(results.length).toBe(6); + }); + + it("should return collection of violations", async () => { + //-- arrange + const _tableName = "violation"; + + //-- act + const results = await service.getCodeTableByName(_tableName); + + //-- assert + expect(results).not.toBe(null); + expect(results.length).not.toBe(0); + expect(results.length).toBe(9); + }); + + it("should return collection of organization by agency", async () => { + //-- arrange + const _agency = "cos"; + + //-- act + const results = await service.getOrganizationsByAgency(_agency); + + //-- assert + expect(results).not.toBe(null); + expect(results.length).not.toBe(0); + expect(results.length).toBe(14); + }); + + it("should return collection of complaint types", async () => { + //-- arrange + const _tableName = "complaint-type"; + + //-- act + const results = await service.getCodeTableByName(_tableName); + + //-- assert + expect(results).not.toBe(null); + expect(results.length).not.toBe(0); + expect(results.length).toBe(2); + }); +}); + +describe("Testing: CodeTable service", () => { + let service: CodeTableService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [ + CodeTableService, + { + provide: getRepositoryToken(AgencyCode), + useFactory: MockAgencyCodeTableRepository, + }, + { + provide: getRepositoryToken(AttractantCode), + useFactory: MockAttractantCodeTableRepository, + }, + { + provide: getRepositoryToken(ComplaintStatusCode), + useFactory: MockComplaintStatusCodeTableRepository, + }, + { + provide: getRepositoryToken(HwcrComplaintNatureCode), + useFactory: MockNatureOfComplaintCodeTableRepository, + }, + { + provide: getRepositoryToken(GeoOrgUnitTypeCode), + useFactory: MockOrganizationUnitTypeCodeTableRepository, + }, + { + provide: getRepositoryToken(GeoOrganizationUnitCode), + useFactory: MockOrganizationUnitCodeTableRepository, + }, + { + provide: getRepositoryToken(PersonComplaintXrefCode), + useFactory: MockPersonComplaintCodeTableRepository, + }, + { + provide: getRepositoryToken(SpeciesCode), + useFactory: MockSpeciesCodeTableRepository, + }, + { + provide: getRepositoryToken(ViolationCode), + useFactory: MockViolationsCodeTableRepository, + }, + { + provide: getRepositoryToken(CosGeoOrgUnit), + useFactory: MockRegionCodeTableServiceRepository, + }, + { + provide: getRepositoryToken(ComplaintTypeCode), + useFactory: MockComplaintTypeCodeTableRepository, + }, + ], + }).compile(); + + service = module.get(CodeTableService); + }); + + it("should be defined", () => { + expect(service).toBeDefined(); + }); + + it("should return collection of regions", async () => { + //-- arrange + const _agency = "cos"; + + //-- act + const results = await service.getRegionsByAgency(_agency); + + //-- assert + expect(results).not.toBe(null); + expect(results.length).not.toBe(0); + expect(results.length).toBe(8); + }); + +}); + +describe("Testing: CodeTable service", () => { + let service: CodeTableService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [ + CodeTableService, + { + provide: getRepositoryToken(AgencyCode), + useFactory: MockAgencyCodeTableRepository, + }, + { + provide: getRepositoryToken(AttractantCode), + useFactory: MockAttractantCodeTableRepository, + }, + { + provide: getRepositoryToken(ComplaintStatusCode), + useFactory: MockComplaintStatusCodeTableRepository, + }, + { + provide: getRepositoryToken(HwcrComplaintNatureCode), + useFactory: MockNatureOfComplaintCodeTableRepository, + }, + { + provide: getRepositoryToken(GeoOrgUnitTypeCode), + useFactory: MockOrganizationUnitTypeCodeTableRepository, + }, + { + provide: getRepositoryToken(GeoOrganizationUnitCode), + useFactory: MockOrganizationUnitCodeTableRepository, + }, + { + provide: getRepositoryToken(PersonComplaintXrefCode), + useFactory: MockPersonComplaintCodeTableRepository, + }, + { + provide: getRepositoryToken(SpeciesCode), + useFactory: MockSpeciesCodeTableRepository, + }, + { + provide: getRepositoryToken(ViolationCode), + useFactory: MockViolationsCodeTableRepository, + }, + { + provide: getRepositoryToken(CosGeoOrgUnit), + useFactory: MockZoneCodeTableServiceRepository, + }, + { + provide: getRepositoryToken(ComplaintTypeCode), + useFactory: MockComplaintTypeCodeTableRepository, + }, + ], + }).compile(); + + service = module.get(CodeTableService); + }); + + it("should be defined", () => { + expect(service).toBeDefined(); + }); + + + it("should return collection of zones", async () => { + //-- arrange + const _agency = "cos"; + + //-- act + const results = await service.getZonesByAgency(_agency); + + //-- assert + expect(results).not.toBe(null); + expect(results.length).not.toBe(0); + expect(results.length).toBe(9); + }); + +}); + +describe("Testing: CodeTable service", () => { + let service: CodeTableService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [ + CodeTableService, + { + provide: getRepositoryToken(AgencyCode), + useFactory: MockAgencyCodeTableRepository, + }, + { + provide: getRepositoryToken(AttractantCode), + useFactory: MockAttractantCodeTableRepository, + }, + { + provide: getRepositoryToken(ComplaintStatusCode), + useFactory: MockComplaintStatusCodeTableRepository, + }, + { + provide: getRepositoryToken(HwcrComplaintNatureCode), + useFactory: MockNatureOfComplaintCodeTableRepository, + }, + { + provide: getRepositoryToken(GeoOrgUnitTypeCode), + useFactory: MockOrganizationUnitTypeCodeTableRepository, + }, + { + provide: getRepositoryToken(GeoOrganizationUnitCode), + useFactory: MockOrganizationUnitCodeTableRepository, + }, + { + provide: getRepositoryToken(PersonComplaintXrefCode), + useFactory: MockPersonComplaintCodeTableRepository, + }, + { + provide: getRepositoryToken(SpeciesCode), + useFactory: MockSpeciesCodeTableRepository, + }, + { + provide: getRepositoryToken(ViolationCode), + useFactory: MockViolationsCodeTableRepository, + }, + { + provide: getRepositoryToken(CosGeoOrgUnit), + useFactory: MockCommunityCodeTableServiceRepository, + }, + { + provide: getRepositoryToken(ComplaintTypeCode), + useFactory: MockComplaintTypeCodeTableRepository, + }, + ], + }).compile(); + + service = module.get(CodeTableService); + }); + + it("should be defined", () => { + expect(service).toBeDefined(); + }); + + it("should return collection of communities", async () => { + //-- arrange + const _agency = "cos"; + + //-- act + const results = await service.getCommunitiesByAgency(_agency); + + //-- assert + expect(results).not.toBe(null); + expect(results.length).not.toBe(0); + expect(results.length).toBe(11); + }); +}); diff --git a/backend/src/v1/code-table/code-table.service.ts b/backend/src/v1/code-table/code-table.service.ts new file mode 100644 index 000000000..72f5676f0 --- /dev/null +++ b/backend/src/v1/code-table/code-table.service.ts @@ -0,0 +1,409 @@ +import { Injectable, Logger } from "@nestjs/common"; +import { InjectRepository } from "@nestjs/typeorm"; +import { Repository } from "typeorm"; + +import BaseCodeTable, { + Agency, + Attractant, + ComplaintStatus, + NatureOfComplaint, + OrganizationUnitType, + OrganizationUnit, + PersonComplaintType, + Species, + Violation, + OrganizationCodeTable, + ComplaintType, + Sector, + Zone, + Community, +} from "../../types/models/code-tables"; +import { AgencyCode } from "../agency_code/entities/agency_code.entity"; +import { AttractantCode } from "../attractant_code/entities/attractant_code.entity"; +import { ComplaintStatusCode } from "../complaint_status_code/entities/complaint_status_code.entity"; +import { HwcrComplaintNatureCode } from "../hwcr_complaint_nature_code/entities/hwcr_complaint_nature_code.entity"; +import { GeoOrgUnitTypeCode } from "../geo_org_unit_type_code/entities/geo_org_unit_type_code.entity"; +import { GeoOrganizationUnitCode } from "../geo_organization_unit_code/entities/geo_organization_unit_code.entity"; +import { PersonComplaintXrefCode } from "../person_complaint_xref_code/entities/person_complaint_xref_code.entity"; +import { SpeciesCode } from "../species_code/entities/species_code.entity"; +import { ViolationCode } from "../violation_code/entities/violation_code.entity"; +import { CosGeoOrgUnit } from "../cos_geo_org_unit/entities/cos_geo_org_unit.entity"; +import { ComplaintTypeCode } from "../complaint_type_code/entities/complaint_type_code.entity"; + +@Injectable() +export class CodeTableService { + private readonly logger = new Logger(CodeTableService.name); + + @InjectRepository(AgencyCode) + private _agencyRepository: Repository; + @InjectRepository(AttractantCode) + private _attractantRepository: Repository; + @InjectRepository(ComplaintStatusCode) + private _complaintStatusRepository: Repository; + @InjectRepository(HwcrComplaintNatureCode) + private _natureOfComplaintRepository: Repository; + @InjectRepository(GeoOrgUnitTypeCode) + private _organizationUnitTypeRepository: Repository; + @InjectRepository(GeoOrganizationUnitCode) + private _organizationUnitRepository: Repository; + @InjectRepository(PersonComplaintXrefCode) + private _personComplaintTypeRepository: Repository; + @InjectRepository(SpeciesCode) + private _speciesRepository: Repository; + @InjectRepository(ViolationCode) + private _violationsRepository: Repository; + @InjectRepository(CosGeoOrgUnit) + private _cosOrganizationUnitRepository: Repository; + @InjectRepository(ComplaintTypeCode) + private _complaintTypetRepository: Repository; + + getCodeTableByName = async (table: string): Promise => { + switch (table) { + case "agency": { + const data = await this._agencyRepository.find(); + let results = data.map( + ({ + agency_code, + short_description, + long_description, + display_order, + active_ind, + }) => { + let table: Agency = { + agency: agency_code, + shortDescription: short_description, + longDescription: long_description, + displayOrder: display_order, + isActive: active_ind, + }; + return table; + } + ); + + return results; + } + case "attractant": { + const data = await this._attractantRepository.find(); + let results = data.map( + ({ + attractant_code, + short_description, + long_description, + display_order, + active_ind, + }) => { + let table: Attractant = { + attractant: attractant_code, + shortDescription: short_description, + longDescription: long_description, + displayOrder: display_order, + isActive: active_ind, + }; + return table; + } + ); + return results; + } + case "complaint-status": { + const data = await this._complaintStatusRepository.find(); + let results = data.map( + ({ + complaint_status_code, + short_description, + long_description, + display_order, + active_ind, + }) => { + let table: ComplaintStatus = { + complaintStatus: complaint_status_code, + shortDescription: short_description, + longDescription: long_description, + displayOrder: display_order, + isActive: active_ind, + }; + return table; + } + ); + return results; + } + case "nature-of-complaint": { + const data = await this._natureOfComplaintRepository.find(); + let results = data.map( + ({ + hwcr_complaint_nature_code, + short_description, + long_description, + display_order, + active_ind, + }) => { + let table: NatureOfComplaint = { + natureOfComplaint: hwcr_complaint_nature_code, + shortDescription: short_description, + longDescription: long_description, + displayOrder: display_order, + isActive: active_ind, + }; + return table; + } + ); + return results; + } + case "organization-unit-type": { + const data = await this._organizationUnitTypeRepository.find(); + let results = data.map( + ({ + geo_org_unit_type_code, + short_description, + long_description, + display_order, + active_ind, + }) => { + let table: OrganizationUnitType = { + organizationUnitType: geo_org_unit_type_code, + shortDescription: short_description, + longDescription: long_description, + displayOrder: display_order, + isActive: active_ind, + }; + return table; + } + ); + return results; + } + case "organization-unit": { + const builder = this._organizationUnitRepository + .createQueryBuilder("organization_unit") + .leftJoinAndSelect( + "organization_unit.geo_org_unit_type_code", + "organization_unit_type" + ); + + const data = await builder.getMany(); + + let results = data.map( + ({ + geo_organization_unit_code, + short_description, + long_description, + geo_org_unit_type_code: organizationUnitType, + }) => { + let table: OrganizationUnit = { + organizationUnit: geo_organization_unit_code, + shortDescription: short_description, + longDescription: long_description, + }; + + if (organizationUnitType) { + const { geo_org_unit_type_code } = organizationUnitType; + return { + ...table, + organizationUnitType: geo_org_unit_type_code, + }; + } + return table; + } + ); + return results; + } + case "person-complaint": { + const data = await this._personComplaintTypeRepository.find(); + let results = data.map( + ({ + person_complaint_xref_code, + short_description, + long_description, + display_order, + }) => { + let table: PersonComplaintType = { + personComplaintType: person_complaint_xref_code, + shortDescription: short_description, + longDescription: long_description, + displayOrder: display_order, + }; + return table; + } + ); + return results; + } + case "species": { + const data = await this._speciesRepository.find(); + let results = data.map( + ({ + species_code, + short_description, + long_description, + display_order, + active_ind, + legacy_code, + }) => { + let table: Species = { + species: species_code, + legacy: legacy_code, + shortDescription: short_description, + longDescription: long_description, + displayOrder: display_order, + isActive: active_ind, + }; + return table; + } + ); + return results; + } + case "violation": { + const data = await this._violationsRepository.find(); + let results = data.map( + ({ + violation_code, + short_description, + long_description, + display_order, + active_ind, + }) => { + let table: Violation = { + violation: violation_code, + shortDescription: short_description, + longDescription: long_description, + displayOrder: display_order, + isActive: active_ind, + }; + return table; + } + ); + return results; + } + case "complaint-type": { + const data = await this._complaintTypetRepository.find(); + let results = data.map( + ({ + complaint_type_code, + short_description, + long_description, + display_order, + active_ind, + }) => { + let table: ComplaintType = { + complaintType: complaint_type_code, + shortDescription: short_description, + longDescription: long_description, + displayOrder: display_order, + isActive: active_ind, + }; + return table; + } + ); + return results; + } + } + }; + + getOrganizationsByAgency = async ( + agency: string + ): Promise => { + const data = await this._cosOrganizationUnitRepository.find(); + + const results = data.map( + ({ + area_code: area, + area_name: areaName, + office_location_code: officeLocation, + office_location_name: officeLocationName, + region_name: regionName, + region_code: region, + zone_name: zoneName, + zone_code: zone, + }) => { + let record: OrganizationCodeTable = { + area, + areaName, + officeLocation, + officeLocationName, + regionName, + region, + zone, + zoneName, + }; + + return record; + } + ); + + return results; + }; + + getRegionsByAgency = async (agency: string): Promise> => { + const data = await this._cosOrganizationUnitRepository + .createQueryBuilder("cos_geo_org_unit") + .select(["region_name", "region_code"]) + .distinctOn(["region_code"]) + .getRawMany(); + + const results = data.map(({ region_name: name, region_code: code }) => { + let record: Sector = { + code, + name, + }; + return record; + }); + + return results; + }; + + getZonesByAgency = async (agency: string): Promise> => { + const data = await this._cosOrganizationUnitRepository + .createQueryBuilder("cos_geo_org_unit") + .select(["zone_name", "zone_code", "region_code"]) + .distinctOn(["zone_code"]) + .getRawMany(); + + const results = data.map( + ({ zone_name: name, zone_code: code, region_code: region }) => { + let record: Zone = { + code, + name, + region, + }; + return record; + } + ); + + return results; + }; + + getCommunitiesByAgency = async ( + agency: string + ): Promise> => { + const data = await this._cosOrganizationUnitRepository + .createQueryBuilder("cos_geo_org_unit") + .select(["area_name", "area_code", "zone_code", "region_code"]) + .distinctOn(["area_code"]) + .getRawMany(); + + const results = data.map( + ({ + area_name: name, + area_code: code, + zone_code: zone, + region_code: region, + }) => { + let record: Community = { + code, + name, + zone, + region, + }; + return record; + } + ); + + return results; + }; +} + +/* + .createQueryBuilder("cos_geo_org_unit") + .where("cos_geo_org_unit.zone_code = :zone", { zone }) + .distinctOn(["cos_geo_org_unit.offloc_code"]) + .orderBy("cos_geo_org_unit.offloc_code"); + + const zoneOffices = await officeQuery.getMany(); +*/ diff --git a/backend/src/v1/complaint_status_code/complaint_status_code.controller.spec.ts b/backend/src/v1/complaint_status_code/complaint_status_code.controller.spec.ts deleted file mode 100644 index 1e5169ee0..000000000 --- a/backend/src/v1/complaint_status_code/complaint_status_code.controller.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { ComplaintStatusCodeController } from './complaint_status_code.controller'; -import { ComplaintStatusCodeService } from './complaint_status_code.service'; -import { getRepositoryToken } from '@nestjs/typeorm'; -import { ComplaintStatusCode } from './entities/complaint_status_code.entity'; - -describe('ComplaintStatusCodeController', () => { - let controller: ComplaintStatusCodeController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [ComplaintStatusCodeController], - providers: [ - ComplaintStatusCodeService, - { - provide: getRepositoryToken(ComplaintStatusCode), - useValue: { - - }, - },], - }).compile(); - - controller = module.get(ComplaintStatusCodeController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/backend/src/v1/complaint_status_code/complaint_status_code.controller.ts b/backend/src/v1/complaint_status_code/complaint_status_code.controller.ts deleted file mode 100644 index c6cedf45c..000000000 --- a/backend/src/v1/complaint_status_code/complaint_status_code.controller.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; -import { ComplaintStatusCodeService } from './complaint_status_code.service'; -import { CreateComplaintStatusCodeDto } from './dto/create-complaint_status_code.dto'; -import { UpdateComplaintStatusCodeDto } from './dto/update-complaint_status_code.dto'; -import { ApiTags } from '@nestjs/swagger'; -import { JwtRoleGuard } from '../../auth/jwtrole.guard'; -import { Roles } from '../../auth/decorators/roles.decorator'; -import { Role } from '../../enum/role.enum'; - -@ApiTags("complaint-status-code") -@UseGuards(JwtRoleGuard) -@Controller({ - path: 'complaint-status-code', - version: '1'}) -export class ComplaintStatusCodeController { - constructor(private readonly complaintStatusCodeService: ComplaintStatusCodeService) {} - - @Post() - @Roles(Role.COS_OFFICER) - create(@Body() createComplaintStatusCodeDto: CreateComplaintStatusCodeDto) { - return this.complaintStatusCodeService.create(createComplaintStatusCodeDto); - } - - @Get() - @Roles(Role.COS_OFFICER) - findAll() { - return this.complaintStatusCodeService.findAll(); - } - - @Get(':id') - @Roles(Role.COS_OFFICER) - findOne(@Param('id') id: string) { - return this.complaintStatusCodeService.findOne(id); - } - - @Patch(':id') - @Roles(Role.COS_OFFICER) - update(@Param('id') id: string, @Body() updateComplaintStatusCodeDto: UpdateComplaintStatusCodeDto) { - return this.complaintStatusCodeService.update(id, updateComplaintStatusCodeDto); - } - - @Delete(':id') - @Roles(Role.COS_OFFICER) - remove(@Param('id') id: string) { - return this.complaintStatusCodeService.remove(id); - } -} diff --git a/backend/src/v1/complaint_status_code/complaint_status_code.module.ts b/backend/src/v1/complaint_status_code/complaint_status_code.module.ts index 69d527783..0a9abc09a 100644 --- a/backend/src/v1/complaint_status_code/complaint_status_code.module.ts +++ b/backend/src/v1/complaint_status_code/complaint_status_code.module.ts @@ -1,12 +1,11 @@ import { Module } from '@nestjs/common'; import { ComplaintStatusCodeService } from './complaint_status_code.service'; -import { ComplaintStatusCodeController } from './complaint_status_code.controller'; import { TypeOrmModule } from "@nestjs/typeorm"; import { ComplaintStatusCode } from './entities/complaint_status_code.entity'; @Module({ imports: [TypeOrmModule.forFeature([ComplaintStatusCode])], - controllers: [ComplaintStatusCodeController], + controllers: [], providers: [ComplaintStatusCodeService] }) export class ComplaintStatusCodeModule {} diff --git a/backend/src/v1/complaint_type_code/complaint_type_code.controller.spec.ts b/backend/src/v1/complaint_type_code/complaint_type_code.controller.spec.ts deleted file mode 100644 index 8c41b5aad..000000000 --- a/backend/src/v1/complaint_type_code/complaint_type_code.controller.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { ComplaintTypeCodeController } from './complaint_type_code.controller'; -import { ComplaintTypeCodeService } from './complaint_type_code.service'; -import { getRepositoryToken } from '@nestjs/typeorm'; -import { ComplaintTypeCode } from './entities/complaint_type_code.entity'; - -describe('ComplaintTypeCodeController', () => { - let controller: ComplaintTypeCodeController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [ComplaintTypeCodeController], - providers: [ - ComplaintTypeCodeService, - { - provide: getRepositoryToken(ComplaintTypeCode), - useValue: { - - }, - },], - }).compile(); - - controller = module.get(ComplaintTypeCodeController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/backend/src/v1/complaint_type_code/complaint_type_code.controller.ts b/backend/src/v1/complaint_type_code/complaint_type_code.controller.ts deleted file mode 100644 index 523ec7367..000000000 --- a/backend/src/v1/complaint_type_code/complaint_type_code.controller.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; -import { ComplaintTypeCodeService } from './complaint_type_code.service'; -import { CreateComplaintTypeCodeDto } from './dto/create-complaint_type_code.dto'; -import { UpdateComplaintTypeCodeDto } from './dto/update-complaint_type_code.dto'; -import { JwtRoleGuard } from '../../auth/jwtrole.guard'; -import { ApiTags } from '@nestjs/swagger'; -import { Roles } from '../../auth/decorators/roles.decorator'; -import { Role } from '../../enum/role.enum'; - -@ApiTags("complaint-type-code") -@UseGuards(JwtRoleGuard) -@Controller({ - path: 'complaint-type-code', - version: '1'}) -export class ComplaintTypeCodeController { - constructor(private readonly complaintTypeCodeService: ComplaintTypeCodeService) {} - - @Post() - @Roles(Role.COS_OFFICER) - create(@Body() createAgencyCodeDto: CreateComplaintTypeCodeDto) { - return this.complaintTypeCodeService.create(createAgencyCodeDto); - } - - @Get() - @Roles(Role.COS_OFFICER) - findAll() { - return this.complaintTypeCodeService.findAll(); - } - - @Get(':id') - @Roles(Role.COS_OFFICER) - findOne(@Param('id') id: string) { - return this.complaintTypeCodeService.findOne({where: {complaint_type_code: id}}); - } - - @Patch(':id') - @Roles(Role.COS_OFFICER) - update(@Param('id') id: string, @Body() updateComplaintTypeCodeDto: UpdateComplaintTypeCodeDto) { - return this.complaintTypeCodeService.update(id, updateComplaintTypeCodeDto); - } - - @Delete(':id') - @Roles(Role.COS_OFFICER) - remove(@Param('id') id: string) { - return this.complaintTypeCodeService.remove(id); - } -} diff --git a/backend/src/v1/complaint_type_code/complaint_type_code.module.ts b/backend/src/v1/complaint_type_code/complaint_type_code.module.ts index fa6008e20..425ff0f9c 100644 --- a/backend/src/v1/complaint_type_code/complaint_type_code.module.ts +++ b/backend/src/v1/complaint_type_code/complaint_type_code.module.ts @@ -1,12 +1,11 @@ import { Module } from '@nestjs/common'; import { ComplaintTypeCodeService } from './complaint_type_code.service'; -import { ComplaintTypeCodeController } from './complaint_type_code.controller'; import { TypeOrmModule } from "@nestjs/typeorm"; import { ComplaintTypeCode } from './entities/complaint_type_code.entity'; @Module({ imports: [TypeOrmModule.forFeature([ComplaintTypeCode])], - controllers: [ComplaintTypeCodeController], + controllers: [], providers: [ComplaintTypeCodeService] }) export class ComplaintTypeCodeModule {} diff --git a/backend/src/v1/cos_geo_org_unit/cos_geo_org_unit.controller.spec.ts b/backend/src/v1/cos_geo_org_unit/cos_geo_org_unit.controller.spec.ts deleted file mode 100644 index 1152fb583..000000000 --- a/backend/src/v1/cos_geo_org_unit/cos_geo_org_unit.controller.spec.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { CosGeoOrgUnitController } from './cos_geo_org_unit.controller'; -import { CosGeoOrgUnitService } from './cos_geo_org_unit.service'; -import { getRepositoryToken } from '@nestjs/typeorm'; -import { CosGeoOrgUnit } from "../cos_geo_org_unit/entities/cos_geo_org_unit.entity" - -describe('CosGeoOrgUnitController', () => { - let controller: CosGeoOrgUnitController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [CosGeoOrgUnitController], - providers: [CosGeoOrgUnitService, - { - provide: getRepositoryToken(CosGeoOrgUnit), - useValue: { - - }, - },], - }).compile(); - - controller = module.get(CosGeoOrgUnitController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/backend/src/v1/cos_geo_org_unit/cos_geo_org_unit.controller.ts b/backend/src/v1/cos_geo_org_unit/cos_geo_org_unit.controller.ts deleted file mode 100644 index 5a6f58bd1..000000000 --- a/backend/src/v1/cos_geo_org_unit/cos_geo_org_unit.controller.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { Controller, Get, Param, UseGuards } from '@nestjs/common'; -import { CosGeoOrgUnitService } from './cos_geo_org_unit.service'; -// import { Roles } from "../../../src/auth/decorators/roles.decorator" -// import { Role } from "../../../src/enum/role.enum"; -// import { JwtRoleGuard } from '../../../src/auth/jwtrole.guard'; -// import { ApiTags } from '@nestjs/swagger'; -// import { Roles } from 'src/auth/decorators/roles.decorator'; -// import { Role } from 'src/enum/role.enum'; -// import { JwtRoleGuard } from '../../auth/jwtrole.guard'; - -import { JwtRoleGuard } from '../../auth/jwtrole.guard'; -import { ApiTags } from '@nestjs/swagger'; -import { Roles } from '../../auth/decorators/roles.decorator'; -import { Role } from '../../enum/role.enum'; - -@ApiTags("cos-geo-org-unit") -@UseGuards(JwtRoleGuard) -@Controller({ - path: 'cos-geo-org-unit', - version: '1'}) -export class CosGeoOrgUnitController { - constructor(private readonly cosGeoOrgUnitService: CosGeoOrgUnitService) {} - - @Get() - @Roles(Role.COS_OFFICER) - findAll() { - return this.cosGeoOrgUnitService.findAll(); - } - - @Get('/by-region-code/:code') - @Roles(Role.COS_OFFICER) - byRegionCode(@Param('code') code: string) { - return this.cosGeoOrgUnitService.findByRegionCode(code); - } - - @Get('/by-zone-code/:code') - @Roles(Role.COS_OFFICER) - byZoneCode(@Param('code') code: string) { - return this.cosGeoOrgUnitService.findByZoneCode(code); - } - - @Get('/by-office-location-code/:code') - @Roles(Role.COS_OFFICER) - byOfficeLocationCode(@Param('code') code: string) { - return this.cosGeoOrgUnitService.findByOfficeLocationCode(code); - } - - @Get('/by-area-code/:code') - @Roles(Role.COS_OFFICER) - byAreaCode(@Param('code') code: string) { - return this.cosGeoOrgUnitService.findByAreaCode(code); - } - - @Get('/by-region-name/:name') - @Roles(Role.COS_OFFICER) - byRegionName(@Param('name') name: string) { - return this.cosGeoOrgUnitService.findByRegionName(name); - } - - @Get('/by-zone-name/:name') - @Roles(Role.COS_OFFICER) - byZoneName(@Param('name') name: string) { - return this.cosGeoOrgUnitService.findByZoneName(name); - } - - @Get('/by-office-location-name/:name') - @Roles(Role.COS_OFFICER) - byOfficeLocationName(@Param('name') code: string) { - return this.cosGeoOrgUnitService.findByOfficeLocationName(code); - } - - @Get('/by-area-name/:code') - @Roles(Role.COS_OFFICER) - byAreaName(@Param('code') name: string) { - return this.cosGeoOrgUnitService.findByAreaName(name); - } -} diff --git a/backend/src/v1/cos_geo_org_unit/cos_geo_org_unit.module.ts b/backend/src/v1/cos_geo_org_unit/cos_geo_org_unit.module.ts index 97eadbf0a..faf2de3d0 100644 --- a/backend/src/v1/cos_geo_org_unit/cos_geo_org_unit.module.ts +++ b/backend/src/v1/cos_geo_org_unit/cos_geo_org_unit.module.ts @@ -1,12 +1,11 @@ import { Module } from '@nestjs/common'; import { CosGeoOrgUnitService } from './cos_geo_org_unit.service'; -import { CosGeoOrgUnitController } from './cos_geo_org_unit.controller'; import { TypeOrmModule } from '@nestjs/typeorm'; import { CosGeoOrgUnit } from './entities/cos_geo_org_unit.entity'; @Module({ imports: [TypeOrmModule.forFeature([CosGeoOrgUnit])], - controllers: [CosGeoOrgUnitController], + controllers: [], providers: [CosGeoOrgUnitService] }) export class CosGeoOrgUnitModule {} diff --git a/backend/src/v1/geo_org_unit_structure/geo_org_unit_structure.controller.spec.ts b/backend/src/v1/geo_org_unit_structure/geo_org_unit_structure.controller.spec.ts deleted file mode 100644 index 044305c84..000000000 --- a/backend/src/v1/geo_org_unit_structure/geo_org_unit_structure.controller.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { GeoOrgUnitStructureController } from './geo_org_unit_structure.controller'; -import { GeoOrgUnitStructureService } from './geo_org_unit_structure.service'; -import { getRepositoryToken } from '@nestjs/typeorm'; -import { GeoOrgUnitStructure } from './entities/geo_org_unit_structure.entity'; - -describe('GeoOrgUnitStructureController', () => { - let controller: GeoOrgUnitStructureController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [GeoOrgUnitStructureController], - providers: [ - GeoOrgUnitStructureService, - { - provide: getRepositoryToken(GeoOrgUnitStructure), - useValue: { - - }, - },], - }).compile(); - - controller = module.get(GeoOrgUnitStructureController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/backend/src/v1/geo_org_unit_structure/geo_org_unit_structure.controller.ts b/backend/src/v1/geo_org_unit_structure/geo_org_unit_structure.controller.ts deleted file mode 100644 index 3255673f4..000000000 --- a/backend/src/v1/geo_org_unit_structure/geo_org_unit_structure.controller.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; -import { GeoOrgUnitStructureService } from './geo_org_unit_structure.service'; -import { CreateGeoOrgUnitStructureDto } from './dto/create-geo_org_unit_structure.dto'; -import { UpdateGeoOrgUnitStructureDto } from './dto/update-geo_org_unit_structure.dto'; -import { JwtRoleGuard } from '../../auth/jwtrole.guard'; -import { ApiTags } from '@nestjs/swagger'; -import { Roles } from '../../auth/decorators/roles.decorator'; -import { Role } from '../../enum/role.enum'; - -@ApiTags("geo-org-unit-structure") -@UseGuards(JwtRoleGuard) -@Controller({ - path: 'geo-org-unit-structure', - version: '1'}) -export class GeoOrgUnitStructureController { - constructor(private readonly geoOrgUnitStructureService: GeoOrgUnitStructureService) {} - - @Post() - @Roles(Role.COS_OFFICER) - create(@Body() createGeoOrgUnitStructureDto: CreateGeoOrgUnitStructureDto) { - return this.geoOrgUnitStructureService.create(createGeoOrgUnitStructureDto); - } - - @Get() - @Roles(Role.COS_OFFICER) - findAll() { - return this.geoOrgUnitStructureService.findAll(); - } - - @Get(':id') - @Roles(Role.COS_OFFICER) - findOne(@Param('id') id: string) { - return this.geoOrgUnitStructureService.findOne(+id); - } - - @Patch(':id') - @Roles(Role.COS_OFFICER) - update(@Param('id') id: string, @Body() updateGeoOrgUnitStructureDto: UpdateGeoOrgUnitStructureDto) { - return this.geoOrgUnitStructureService.update(+id, updateGeoOrgUnitStructureDto); - } - - @Delete(':id') - @Roles(Role.COS_OFFICER) - remove(@Param('id') id: string) { - return this.geoOrgUnitStructureService.remove(+id); - } -} diff --git a/backend/src/v1/geo_org_unit_structure/geo_org_unit_structure.module.ts b/backend/src/v1/geo_org_unit_structure/geo_org_unit_structure.module.ts index 44d0951ec..44b825dc6 100644 --- a/backend/src/v1/geo_org_unit_structure/geo_org_unit_structure.module.ts +++ b/backend/src/v1/geo_org_unit_structure/geo_org_unit_structure.module.ts @@ -1,12 +1,11 @@ import { Module } from '@nestjs/common'; import { GeoOrgUnitStructureService } from './geo_org_unit_structure.service'; -import { GeoOrgUnitStructureController } from './geo_org_unit_structure.controller'; import { TypeOrmModule } from "@nestjs/typeorm"; import { GeoOrgUnitStructure } from './entities/geo_org_unit_structure.entity'; @Module({ imports: [TypeOrmModule.forFeature([GeoOrgUnitStructure])], - controllers: [GeoOrgUnitStructureController], + controllers: [], providers: [GeoOrgUnitStructureService] }) export class GeoOrgUnitStructureModule {} diff --git a/backend/src/v1/geo_org_unit_type_code/geo_org_unit_type_code.controller.spec.ts b/backend/src/v1/geo_org_unit_type_code/geo_org_unit_type_code.controller.spec.ts deleted file mode 100644 index 06cdd076c..000000000 --- a/backend/src/v1/geo_org_unit_type_code/geo_org_unit_type_code.controller.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { GeoOrgUnitTypeCodeController } from './geo_org_unit_type_code.controller'; -import { GeoOrgUnitTypeCodeService } from './geo_org_unit_type_code.service'; -import { getRepositoryToken } from '@nestjs/typeorm'; -import { GeoOrgUnitTypeCode } from './entities/geo_org_unit_type_code.entity'; - -describe('GeoOrgUnitTypeCodeController', () => { - let controller: GeoOrgUnitTypeCodeController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [GeoOrgUnitTypeCodeController], - providers: [ - GeoOrgUnitTypeCodeService, - { - provide: getRepositoryToken(GeoOrgUnitTypeCode), - useValue: { - - }, - },], - }).compile(); - - controller = module.get(GeoOrgUnitTypeCodeController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/backend/src/v1/geo_org_unit_type_code/geo_org_unit_type_code.controller.ts b/backend/src/v1/geo_org_unit_type_code/geo_org_unit_type_code.controller.ts deleted file mode 100644 index 883a549bb..000000000 --- a/backend/src/v1/geo_org_unit_type_code/geo_org_unit_type_code.controller.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; -import { GeoOrgUnitTypeCodeService } from './geo_org_unit_type_code.service'; -import { CreateGeoOrgUnitTypeCodeDto } from './dto/create-geo_org_unit_type_code.dto'; -import { UpdateGeoOrgUnitTypeCodeDto } from './dto/update-geo_org_unit_type_code.dto'; -import { JwtRoleGuard } from '../../auth/jwtrole.guard'; -import { ApiTags } from '@nestjs/swagger'; -import { Roles } from '../../auth/decorators/roles.decorator'; -import { Role } from '../../enum/role.enum'; - -@ApiTags("geo-org-unit-type-code") -@UseGuards(JwtRoleGuard) -@Controller({ - path: 'geo-org-unit-type-code', - version: '1'}) -export class GeoOrgUnitTypeCodeController { - constructor(private readonly geoOrgUnitTypeCodeService: GeoOrgUnitTypeCodeService) {} - - @Post() - @Roles(Role.COS_OFFICER) - create(@Body() createGeoOrgUnitTypeCodeDto: CreateGeoOrgUnitTypeCodeDto) { - return this.geoOrgUnitTypeCodeService.create(createGeoOrgUnitTypeCodeDto); - } - - @Get() - @Roles(Role.COS_OFFICER) - findAll() { - return this.geoOrgUnitTypeCodeService.findAll(); - } - - @Get(':id') - @Roles(Role.COS_OFFICER) - findOne(@Param('id') id: string) { - return this.geoOrgUnitTypeCodeService.findOne(id); - } - - @Patch(':id') - @Roles(Role.COS_OFFICER) - update(@Param('id') id: string, @Body() updateGeoOrgUnitTypeCodeDto: UpdateGeoOrgUnitTypeCodeDto) { - return this.geoOrgUnitTypeCodeService.update(id, updateGeoOrgUnitTypeCodeDto); - } - - @Delete(':id') - @Roles(Role.COS_OFFICER) - remove(@Param('id') id: string) { - return this.geoOrgUnitTypeCodeService.remove(id); - } -} diff --git a/backend/src/v1/geo_org_unit_type_code/geo_org_unit_type_code.module.ts b/backend/src/v1/geo_org_unit_type_code/geo_org_unit_type_code.module.ts index 2eca0bdb5..d50189648 100644 --- a/backend/src/v1/geo_org_unit_type_code/geo_org_unit_type_code.module.ts +++ b/backend/src/v1/geo_org_unit_type_code/geo_org_unit_type_code.module.ts @@ -1,12 +1,11 @@ import { Module } from '@nestjs/common'; import { GeoOrgUnitTypeCodeService } from './geo_org_unit_type_code.service'; -import { GeoOrgUnitTypeCodeController } from './geo_org_unit_type_code.controller'; import { TypeOrmModule } from "@nestjs/typeorm"; import { GeoOrgUnitTypeCode } from './entities/geo_org_unit_type_code.entity'; @Module({ imports: [TypeOrmModule.forFeature([GeoOrgUnitTypeCode])], - controllers: [GeoOrgUnitTypeCodeController], + controllers: [], providers: [GeoOrgUnitTypeCodeService] }) export class GeoOrgUnitTypeCodeModule {} diff --git a/backend/src/v1/geo_organization_unit_code/geo_organization_unit_code.controller.spec.ts b/backend/src/v1/geo_organization_unit_code/geo_organization_unit_code.controller.spec.ts deleted file mode 100644 index 905d50a77..000000000 --- a/backend/src/v1/geo_organization_unit_code/geo_organization_unit_code.controller.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { GeoOrganizationUnitCodeController } from './geo_organization_unit_code.controller'; -import { GeoOrganizationUnitCodeService } from './geo_organization_unit_code.service'; -import { getRepositoryToken } from '@nestjs/typeorm'; -import { GeoOrganizationUnitCode } from './entities/geo_organization_unit_code.entity'; - -describe('GeoOrganizationUnitCodeController', () => { - let controller: GeoOrganizationUnitCodeController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [GeoOrganizationUnitCodeController], - providers: [ - GeoOrganizationUnitCodeService, - { - provide: getRepositoryToken(GeoOrganizationUnitCode), - useValue: { - - }, - },], - }).compile(); - - controller = module.get(GeoOrganizationUnitCodeController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/backend/src/v1/geo_organization_unit_code/geo_organization_unit_code.controller.ts b/backend/src/v1/geo_organization_unit_code/geo_organization_unit_code.controller.ts deleted file mode 100644 index c1e663341..000000000 --- a/backend/src/v1/geo_organization_unit_code/geo_organization_unit_code.controller.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; -import { GeoOrganizationUnitCodeService } from './geo_organization_unit_code.service'; -import { CreateGeoOrganizationUnitCodeDto } from './dto/create-geo_organization_unit_code.dto'; -import { UpdateGeoOrganizationUnitCodeDto } from './dto/update-geo_organization_unit_code.dto'; -import { JwtRoleGuard } from '../../auth/jwtrole.guard'; -import { ApiTags } from '@nestjs/swagger'; -import { Role } from '../../enum/role.enum'; -import { Roles } from '../../auth/decorators/roles.decorator'; - -@ApiTags("geo-organization-unit-code") -@UseGuards(JwtRoleGuard) -@Controller({ - path: 'geo-organization-unit-code', - version: '1'}) -export class GeoOrganizationUnitCodeController { - constructor(private readonly geoOrganizationUnitCodeService: GeoOrganizationUnitCodeService) {} - - @Post() - @Roles(Role.COS_OFFICER) - create(@Body() createGeoOrganizationUnitCodeDto: CreateGeoOrganizationUnitCodeDto) { - return this.geoOrganizationUnitCodeService.create(createGeoOrganizationUnitCodeDto); - } - - @Get() - @Roles(Role.COS_OFFICER) - findAll() { - return this.geoOrganizationUnitCodeService.findAll(); - } - - @Get('/find-all-regions/') - @Roles(Role.COS_OFFICER) - findRegions() { - return this.geoOrganizationUnitCodeService.findDistinctGeoCodes("REGION"); - } - - @Get('/find-all-zones/') - @Roles(Role.COS_OFFICER) - findZones() { - return this.geoOrganizationUnitCodeService.findDistinctGeoCodes("ZONE"); - } - - @Get('/find-all-areas/') - @Roles(Role.COS_OFFICER) - findAreas() { - return this.geoOrganizationUnitCodeService.findDistinctGeoCodes("AREA"); - } - - @Get(':id') - @Roles(Role.COS_OFFICER) - findOne(@Param('id') id: string) { - return this.geoOrganizationUnitCodeService.findOne(id); - } - - @Patch(':id') - @Roles(Role.COS_OFFICER) - update(@Param('id') id: string, @Body() updateGeoOrganizationUnitCodeDto: UpdateGeoOrganizationUnitCodeDto) { - return this.geoOrganizationUnitCodeService.update(id, updateGeoOrganizationUnitCodeDto); - } - - @Delete(':id') - @Roles(Role.COS_OFFICER) - remove(@Param('id') id: string) { - return this.geoOrganizationUnitCodeService.remove(id); - } -} diff --git a/backend/src/v1/geo_organization_unit_code/geo_organization_unit_code.module.ts b/backend/src/v1/geo_organization_unit_code/geo_organization_unit_code.module.ts index c07706c1c..5f7b28524 100644 --- a/backend/src/v1/geo_organization_unit_code/geo_organization_unit_code.module.ts +++ b/backend/src/v1/geo_organization_unit_code/geo_organization_unit_code.module.ts @@ -1,12 +1,11 @@ import { Module } from '@nestjs/common'; import { GeoOrganizationUnitCodeService } from './geo_organization_unit_code.service'; -import { GeoOrganizationUnitCodeController } from './geo_organization_unit_code.controller'; import { TypeOrmModule } from "@nestjs/typeorm"; import { GeoOrganizationUnitCode } from './entities/geo_organization_unit_code.entity'; @Module({ imports: [TypeOrmModule.forFeature([GeoOrganizationUnitCode])], - controllers: [GeoOrganizationUnitCodeController], + controllers: [], providers: [GeoOrganizationUnitCodeService] }) export class GeoOrganizationUnitCodeModule {} diff --git a/backend/src/v1/hwcr_complaint_nature_code/hwcr_complaint_nature_code.controller.spec.ts b/backend/src/v1/hwcr_complaint_nature_code/hwcr_complaint_nature_code.controller.spec.ts deleted file mode 100644 index 4847da9e1..000000000 --- a/backend/src/v1/hwcr_complaint_nature_code/hwcr_complaint_nature_code.controller.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { HwcrComplaintNatureCodeController } from './hwcr_complaint_nature_code.controller'; -import { HwcrComplaintNatureCodeService } from './hwcr_complaint_nature_code.service'; -import { getRepositoryToken } from '@nestjs/typeorm'; -import { HwcrComplaintNatureCode } from './entities/hwcr_complaint_nature_code.entity'; - -describe('HwcrComplaintNatureCodeController', () => { - let controller: HwcrComplaintNatureCodeController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [HwcrComplaintNatureCodeController], - providers: [ - HwcrComplaintNatureCodeService, - { - provide: getRepositoryToken(HwcrComplaintNatureCode), - useValue: { - - }, - },], - }).compile(); - - controller = module.get(HwcrComplaintNatureCodeController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/backend/src/v1/hwcr_complaint_nature_code/hwcr_complaint_nature_code.controller.ts b/backend/src/v1/hwcr_complaint_nature_code/hwcr_complaint_nature_code.controller.ts deleted file mode 100644 index dba08c19d..000000000 --- a/backend/src/v1/hwcr_complaint_nature_code/hwcr_complaint_nature_code.controller.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; -import { HwcrComplaintNatureCodeService } from './hwcr_complaint_nature_code.service'; -import { CreateHwcrComplaintNatureCodeDto } from './dto/create-hwcr_complaint_nature_code.dto'; -import { UpdateHwcrComplaintNatureCodeDto } from './dto/update-hwcr_complaint_nature_code.dto'; -import { JwtRoleGuard } from '../../auth/jwtrole.guard'; -import { ApiTags } from '@nestjs/swagger'; -import { Roles } from '../../auth/decorators/roles.decorator'; -import { Role } from '../../enum/role.enum'; - -@ApiTags("hwcr-complaint-nature-code") -@UseGuards(JwtRoleGuard) -@Controller({ - path: 'hwcr-complaint-nature-code', - version: '1'}) -export class HwcrComplaintNatureCodeController { - constructor(private readonly hwcrComplaintNatureCodeService: HwcrComplaintNatureCodeService) {} - - @Post() - @Roles(Role.COS_OFFICER) - create(@Body() createHwcrComplaintNatureCodeService: CreateHwcrComplaintNatureCodeDto) { - return this.hwcrComplaintNatureCodeService.create(createHwcrComplaintNatureCodeService); - } - - @Get() - @Roles(Role.COS_OFFICER) - findAll() { - return this.hwcrComplaintNatureCodeService.findAll(); - } - - @Get(':id') - @Roles(Role.COS_OFFICER) - findOne(@Param('id') id: string) { - return this.hwcrComplaintNatureCodeService.findOne(id); - } - - @Patch(':id') - @Roles(Role.COS_OFFICER) - update(@Param('id') id: string, @Body() updateHwcrComplaintNatureCodeService: UpdateHwcrComplaintNatureCodeDto) { - return this.hwcrComplaintNatureCodeService.update(id, updateHwcrComplaintNatureCodeService); - } - - @Delete(':id') - @Roles(Role.COS_OFFICER) - remove(@Param('id') id: string) { - return this.hwcrComplaintNatureCodeService.remove(id); - } -} diff --git a/backend/src/v1/hwcr_complaint_nature_code/hwcr_complaint_nature_code.module.ts b/backend/src/v1/hwcr_complaint_nature_code/hwcr_complaint_nature_code.module.ts index 1c1baeea1..3eb26f336 100644 --- a/backend/src/v1/hwcr_complaint_nature_code/hwcr_complaint_nature_code.module.ts +++ b/backend/src/v1/hwcr_complaint_nature_code/hwcr_complaint_nature_code.module.ts @@ -1,12 +1,11 @@ import { Module } from '@nestjs/common'; import { HwcrComplaintNatureCodeService } from './hwcr_complaint_nature_code.service'; -import { HwcrComplaintNatureCodeController } from './hwcr_complaint_nature_code.controller'; import { TypeOrmModule } from '@nestjs/typeorm'; import { HwcrComplaintNatureCode } from './entities/hwcr_complaint_nature_code.entity'; @Module({ imports: [TypeOrmModule.forFeature([HwcrComplaintNatureCode])], - controllers: [HwcrComplaintNatureCodeController], + controllers: [], providers: [HwcrComplaintNatureCodeService] }) export class HwcrComplaintNatureCodeModule {} diff --git a/backend/src/v1/person_complaint_xref_code/entities/person_complaint_xref_code.entity.ts b/backend/src/v1/person_complaint_xref_code/entities/person_complaint_xref_code.entity.ts index 8cb15ec3e..5e0b33795 100644 --- a/backend/src/v1/person_complaint_xref_code/entities/person_complaint_xref_code.entity.ts +++ b/backend/src/v1/person_complaint_xref_code/entities/person_complaint_xref_code.entity.ts @@ -26,8 +26,8 @@ export class PersonComplaintXrefCode { @Column("integer", { name: "display_order" }) display_order: number; - @Column("boolean", { name: "active_ind" }) - active_ind: boolean; + // @Column("boolean", { name: "active_ind" }) + // active_ind: boolean; @Column("character varying", { name: "create_user_id", length: 32 }) create_user_id: string; diff --git a/backend/src/v1/person_complaint_xref_code/person_complaint_xref_code.controller.spec.ts b/backend/src/v1/person_complaint_xref_code/person_complaint_xref_code.controller.spec.ts deleted file mode 100644 index 4c2ede1d6..000000000 --- a/backend/src/v1/person_complaint_xref_code/person_complaint_xref_code.controller.spec.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { PersonComplaintXrefCodeController } from './person_complaint_xref_code.controller'; -import { PersonComplaintXrefCodeService } from './person_complaint_xref_code.service'; -import { getRepositoryToken } from '@nestjs/typeorm'; -import { PersonComplaintXrefCode } from './entities/person_complaint_xref_code.entity'; -import { DataSource } from 'typeorm'; -import { dataSourceMockFactory } from '../../../test/mocks/datasource'; - -describe('PersonComplaintXrefCodeController', () => { - let controller: PersonComplaintXrefCodeController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [PersonComplaintXrefCodeController], - providers: [ - PersonComplaintXrefCodeService, - { - provide: getRepositoryToken(PersonComplaintXrefCode), - useValue: { - - } - }, - { - provide: DataSource, - useFactory: dataSourceMockFactory - } - ], - }).compile(); - - controller = module.get(PersonComplaintXrefCodeController); - }); - - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/backend/src/v1/person_complaint_xref_code/person_complaint_xref_code.controller.ts b/backend/src/v1/person_complaint_xref_code/person_complaint_xref_code.controller.ts deleted file mode 100644 index 182e68d18..000000000 --- a/backend/src/v1/person_complaint_xref_code/person_complaint_xref_code.controller.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; -import { PersonComplaintXrefCodeService } from './person_complaint_xref_code.service'; -import { CreatePersonComplaintXrefCodeDto } from './dto/create-person_complaint_xref_code.dto'; -import { UpdatePersonComplaintXrefCodeDto } from './dto/update-person_complaint_xref_code.dto'; -import { JwtRoleGuard } from '../../auth/jwtrole.guard'; -import { ApiTags } from '@nestjs/swagger'; -import { Roles } from '../../auth/decorators/roles.decorator'; -import { Role } from '../../enum/role.enum'; - -@ApiTags("person-complaint-xref-code") -@UseGuards(JwtRoleGuard) -@Controller({ - path: 'person-complaint-xref-code', - version: '1'}) -export class PersonComplaintXrefCodeController { - constructor(private readonly personComplaintXrefCodeService: PersonComplaintXrefCodeService) {} - - @Post() - @Roles(Role.COS_OFFICER) - create(@Body() createPersonComplaintXrefCodeDto: CreatePersonComplaintXrefCodeDto) { - return this.personComplaintXrefCodeService.create(createPersonComplaintXrefCodeDto); - } - - @Get() - @Roles(Role.COS_OFFICER) - findAll() { - return this.personComplaintXrefCodeService.findAll(); - } - - @Get(':id') - @Roles(Role.COS_OFFICER) - findOne(@Param('id') id: string) { - return this.personComplaintXrefCodeService.findOne(+id); - } - - @Patch(':id') - @Roles(Role.COS_OFFICER) - update(@Param('id') id: string, @Body() updatePersonComplaintXrefCodeDto: UpdatePersonComplaintXrefCodeDto) { - return this.personComplaintXrefCodeService.update(+id, updatePersonComplaintXrefCodeDto); - } - - @Delete(':id') - @Roles(Role.COS_OFFICER) - remove(@Param('id') id: string) { - return this.personComplaintXrefCodeService.remove(+id); - } -} diff --git a/backend/src/v1/person_complaint_xref_code/person_complaint_xref_code.module.ts b/backend/src/v1/person_complaint_xref_code/person_complaint_xref_code.module.ts index 73a6baf6f..192a0698e 100644 --- a/backend/src/v1/person_complaint_xref_code/person_complaint_xref_code.module.ts +++ b/backend/src/v1/person_complaint_xref_code/person_complaint_xref_code.module.ts @@ -1,12 +1,11 @@ import { Module } from '@nestjs/common'; import { PersonComplaintXrefCodeService } from './person_complaint_xref_code.service'; -import { PersonComplaintXrefCodeController } from './person_complaint_xref_code.controller'; import { PersonComplaintXrefCode } from './entities/person_complaint_xref_code.entity'; import { TypeOrmModule } from '@nestjs/typeorm'; @Module({ imports: [TypeOrmModule.forFeature([PersonComplaintXrefCode])], - controllers: [PersonComplaintXrefCodeController], + controllers: [], providers: [PersonComplaintXrefCodeService] }) export class PersonComplaintXrefCodeModule {} diff --git a/backend/src/v1/species_code/species_code.controller.spec.ts b/backend/src/v1/species_code/species_code.controller.spec.ts deleted file mode 100644 index a6d5435af..000000000 --- a/backend/src/v1/species_code/species_code.controller.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { SpeciesCodeController } from './species_code.controller'; -import { SpeciesCodeService } from './species_code.service'; -import { SpeciesCode } from './entities/species_code.entity'; -import { getRepositoryToken } from '@nestjs/typeorm'; - -describe('SpeciesCodeController', () => { - let controller: SpeciesCodeController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [SpeciesCodeController], - providers: [ - SpeciesCodeService, - { - provide: getRepositoryToken(SpeciesCode), - useValue: { - - }, - },], - }).compile(); - - controller = module.get(SpeciesCodeController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/backend/src/v1/species_code/species_code.controller.ts b/backend/src/v1/species_code/species_code.controller.ts deleted file mode 100644 index 92d9b5e82..000000000 --- a/backend/src/v1/species_code/species_code.controller.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; -import { SpeciesCodeService } from './species_code.service'; -import { CreateSpeciesCodeDto } from './dto/create-species_code.dto'; -import { UpdateSpeciesCodeDto } from './dto/update-species_code.dto'; -import { JwtRoleGuard } from '../../auth/jwtrole.guard'; -import { ApiTags } from '@nestjs/swagger'; -import { Role } from '../../enum/role.enum'; -import { Roles } from '../../auth/decorators/roles.decorator'; - -@ApiTags("species-code") -@UseGuards(JwtRoleGuard) -@Controller({ - path: 'species-code', - version: '1'}) -export class SpeciesCodeController { - constructor(private readonly speciesCodeService: SpeciesCodeService) {} - - @Post() - @Roles(Role.COS_OFFICER) - create(@Body() createSpeciesCodeDto: CreateSpeciesCodeDto) { - return this.speciesCodeService.create(createSpeciesCodeDto); - } - - @Get() - @Roles(Role.COS_OFFICER) - findAll() { - return this.speciesCodeService.findAll(); - } - - @Get(':id') - @Roles(Role.COS_OFFICER) - findOne(@Param('id') id: string) { - return this.speciesCodeService.findOne(id); - } - - @Patch(':id') - @Roles(Role.COS_OFFICER) - update(@Param('id') id: string, @Body() updateSpeciesCodeDto: UpdateSpeciesCodeDto) { - return this.speciesCodeService.update(id, updateSpeciesCodeDto); - } - - @Delete(':id') - @Roles(Role.COS_OFFICER) - remove(@Param('id') id: string) { - return this.speciesCodeService.remove(id); - } -} diff --git a/backend/src/v1/species_code/species_code.module.ts b/backend/src/v1/species_code/species_code.module.ts index 61bcd7209..df0e7d117 100644 --- a/backend/src/v1/species_code/species_code.module.ts +++ b/backend/src/v1/species_code/species_code.module.ts @@ -1,12 +1,11 @@ import { Module } from '@nestjs/common'; import { SpeciesCodeService } from './species_code.service'; -import { SpeciesCodeController } from './species_code.controller'; import { TypeOrmModule } from '@nestjs/typeorm'; import { SpeciesCode } from './entities/species_code.entity'; @Module({ imports: [TypeOrmModule.forFeature([SpeciesCode])], - controllers: [SpeciesCodeController], + controllers: [], providers: [SpeciesCodeService] }) export class SpeciesCodeModule {} diff --git a/backend/src/v1/violation_code/violation_code.controller.spec.ts b/backend/src/v1/violation_code/violation_code.controller.spec.ts deleted file mode 100644 index 443f719c3..000000000 --- a/backend/src/v1/violation_code/violation_code.controller.spec.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { ViolationCodeController } from './violation_code.controller'; -import { ViolationCodeService } from './violation_code.service'; -import { ViolationCode } from './entities/violation_code.entity'; -import { getRepositoryToken } from '@nestjs/typeorm'; -import { ViolationCodeRepositoryMockFactory } from '../../../test/mocks/violationCodeRepositoryMockFactory'; -import { authGuardMock } from '../../../test/mocks/authGuardMock'; -import { roleGuardMock } from '../../../test/mocks/roleGuardMock'; -import { JwtAuthGuard } from '../../auth/jwtauth.guard' -import { JwtRoleGuard } from '../../auth/jwtrole.guard' -import { INestApplication } from '@nestjs/common'; -import * as request from 'supertest'; - -describe('ViolationCodeController', () => { - let app: INestApplication; - let controller: ViolationCodeController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [ViolationCodeController], - providers: [ViolationCodeService, - { - provide: getRepositoryToken(ViolationCode), - useFactory: ViolationCodeRepositoryMockFactory, - }, - ], - }) - .overrideGuard(JwtAuthGuard) - .useValue( {authGuardMock} ) - .overrideGuard(JwtRoleGuard) - .useValue({ roleGuardMock }).compile(); - - app = module.createNestApplication(); - await app.init(); - controller = module.get(ViolationCodeController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); - - it('should return 201 when a POST is called successfully', () => { - - const violationCodeDto = { - violation_code: "NEWCODE", - short_description: "New description", - long_description: "New long description", - display_order: "10", - active_ind: "Y" - }; - - return request(app.getHttpServer()) - .post('/violation-code/') - .send({violationCodeDto}) - .expect(201) - }); - - it('should return 200 when a GET is called successfully', async () => { - let response = await request(app.getHttpServer()).get('/violation-code/AINVSPC/'); - - expect(response.statusCode).toBe(200); - - response = await request(app.getHttpServer()).get('/violation-code/'); - - expect(response.statusCode).toBe(200); - }); - - it('should return 200 when a PATCH is called successfully', () => { - - const violationCodeDto = { - violation_code: "NEWCODE", - short_description: "New description", - long_description: "New long description", - display_order: "10", - active_ind: "Y" - }; - - return request(app.getHttpServer()) - .patch('/violation-code/AINVSPC/') - .send({violationCodeDto}) - .expect(200) - }); - - it('should return 201 when a DELETE is called successfully', () => { - return request(app.getHttpServer()) - .delete('/violation-code/AINVSPC/') - .expect(200) - }); - -}); diff --git a/backend/src/v1/violation_code/violation_code.controller.ts b/backend/src/v1/violation_code/violation_code.controller.ts deleted file mode 100644 index 515449f4f..000000000 --- a/backend/src/v1/violation_code/violation_code.controller.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; -import { ViolationCodeService } from './violation_code.service'; -import { CreateViolationCodeDto } from './dto/create-violation_code.dto'; -import { UpdateViolationCodeDto } from './dto/update-violation_code.dto'; -import { JwtRoleGuard } from '../../auth/jwtrole.guard'; -import { ApiTags } from '@nestjs/swagger'; -import { Role } from '../../enum/role.enum'; -import { Roles } from '../../auth/decorators/roles.decorator'; - -@ApiTags("violation-code") -@UseGuards(JwtRoleGuard) -@Controller({ - path: 'violation-code', - version: '1'}) -export class ViolationCodeController { - constructor(private readonly violationCodeService: ViolationCodeService) {} - - @Post() - @Roles(Role.COS_OFFICER) - create(@Body() createViolationCodeDto: CreateViolationCodeDto) { - return this.violationCodeService.create(createViolationCodeDto); - } - - @Get() - @Roles(Role.COS_OFFICER) - findAll() { - return this.violationCodeService.findAll(); - } - - @Get(':id') - @Roles(Role.COS_OFFICER) - findOne(@Param('id') id: string) { - return this.violationCodeService.findOne(id); - } - - @Patch(':id') - @Roles(Role.COS_OFFICER) - update(@Param('id') id: string, @Body() updateViolationCodeDto: UpdateViolationCodeDto) { - return this.violationCodeService.update(id, updateViolationCodeDto); - } - - @Delete(':id') - @Roles(Role.COS_OFFICER) - remove(@Param('id') id: string) { - return this.violationCodeService.remove(id); - } -} diff --git a/backend/src/v1/violation_code/violation_code.module.ts b/backend/src/v1/violation_code/violation_code.module.ts index 6618367bb..98560e8ab 100644 --- a/backend/src/v1/violation_code/violation_code.module.ts +++ b/backend/src/v1/violation_code/violation_code.module.ts @@ -1,12 +1,11 @@ import { Module } from '@nestjs/common'; import { ViolationCodeService } from './violation_code.service'; -import { ViolationCodeController } from './violation_code.controller'; import { TypeOrmModule } from "@nestjs/typeorm"; import { ViolationCode } from './entities/violation_code.entity'; @Module({ imports: [TypeOrmModule.forFeature([ViolationCode])], - controllers: [ViolationCodeController], + controllers: [], providers: [ViolationCodeService] }) export class ViolationCodeModule {} diff --git a/backend/test/mocks/mock-code-table-repositories.ts b/backend/test/mocks/mock-code-table-repositories.ts new file mode 100644 index 000000000..55b6ac74e --- /dev/null +++ b/backend/test/mocks/mock-code-table-repositories.ts @@ -0,0 +1,308 @@ +const agencyCollection = [ + { "agency_code": "BCWF", "short_description": "BCWF", "long_description": "BC Wildlife Federation", "display_order": 1, "active_ind": true }, + { "agency_code": "BYLAW", "short_description": "Bylaw Enforcement", "long_description": "Bylaw Enforcement", "display_order": 2, "active_ind": true }, + { "agency_code": "COS", "short_description": "COS", "long_description": "Conservation Officer Service", "display_order": 3, "active_ind": true }, + { "agency_code": "DFO", "short_description": "DFO", "long_description": "Department of Fisheries and Oceans", "display_order": 4, "active_ind": true }, + { "agency_code": "EPO", "short_description": "EPO", "long_description": "Environmental Protection Office", "display_order": 5, "active_ind": true }, + { "agency_code": "CEB", "short_description": "FOR", "long_description": "Forestry Compliance and Enforcement Branch", "display_order": 6, "active_ind": true }, + { "agency_code": "LE", "short_description": "Police", "long_description": "Municipal Police or RCMP", "display_order": 7, "active_ind": true }, + { "agency_code": "OTHER", "short_description": "Other", "long_description": "Other", "display_order": 8, "active_ind": true } +] + +const attractants = [ + { "attractant_code": "BEEHIVE", "short_description": "Beehive", "long_description": "Beehive", "display_order": 2, "active_ind": true}, + { "attractant_code": "BIRD FDR", "short_description": "Bird Feeder", "long_description": "Bird Feeder", "display_order": 3, "active_ind": true }, + { "attractant_code": "CAMP FD", "short_description": "Campground Food", "long_description": "Campground Food", "display_order": 4, "active_ind": true }, + { "attractant_code": "COMPOST", "short_description": "Compost", "long_description": "Compost", "display_order": 5, "active_ind": true }, + { "attractant_code": "CROPS", "short_description": "Crops", "long_description": "Crops", "display_order": 6, "active_ind": true }, + { "attractant_code": "FREEZER", "short_description": "Freezer", "long_description": "Freezer", "display_order": 7, "active_ind": true }, + { "attractant_code": "BBQ", "short_description": "BBQ", "long_description": "Barbeque", "display_order": 1, "active_ind": true }, + { "attractant_code": "RESFRUIT", "short_description": "Fruit/Berries", "long_description": "Residential Fruit/Berries", "display_order": 8, "active_ind": true } +]; + +const complaitStatus = [ + { "complaint_status_code": "OPEN", "short_description": "OPEN", "long_description": "Open", "display_order": 1, "active_ind": true }, + { "complaint_status_code": "CLOSED", "short_description": "CLOSED", "long_description": "Closed", "display_order": 1, "active_ind": true } +] + +const natureOfComplaints = [ + { "hwcr_complaint_nature_code": "AGGNOT", "short_description": "AGGNOT", "long_description": "Aggressive - not present", "display_order": 1, "active_ind": true }, + { "hwcr_complaint_nature_code": "AGGPRES", "short_description": "AGGPRES", "long_description": "Aggressive - present/recent", "display_order": 2, "active_ind": true }, + { "hwcr_complaint_nature_code": "CONFINED", "short_description": "CONFINED", "long_description": "Confined", "display_order": 3, "active_ind": true }, + { "hwcr_complaint_nature_code": "COUGARN", "short_description": "COUGARN", "long_description": "Cougar suspected - killed/injured livestock/pets - not present", "display_order": 4, "active_ind": true }, + { "hwcr_complaint_nature_code": "DAMNP", "short_description": "DAMNP", "long_description": "Damage to property - not present", "display_order": 5, "active_ind": true }, + { "hwcr_complaint_nature_code": "DEADNV", "short_description": "DEADNV", "long_description": "Dead wildlife - no violation suspected", "display_order": 6, "active_ind": true } +] + +const organizationUnitTypes = [ + { "geo_org_unit_type_code": "ZONE", "short_description": "Zone", "long_description": null, "display_order": 1, "active_ind": true }, + { "geo_org_unit_type_code": "REGION", "short_description": "Region", "long_description": null, "display_order": 2, "active_ind": true }, + { "geo_org_unit_type_code": "OFFLOC", "short_description": "Office Location", "long_description": null, "display_order": 3, "active_ind": true }, + { "geo_org_unit_type_code": "AREA", "short_description": "Area", "long_description": null, "display_order": 4, "active_ind": true } +] + +const organizationUnits = [ + { organizationUnit: "OKNGN", shortDescription: "Okanagan", longDescription: "Okanagan", organizationUnitType: "REGION", }, + { organizationUnit: "OMINECA", shortDescription: "Omineca", longDescription: "Omineca", organizationUnitType: "REGION", }, + { organizationUnit: "BLKYCSR", shortDescription: "Bulkley-Cassiar", longDescription: "Bulkley-Cassiar", organizationUnitType: "ZONE", }, + { organizationUnit: "CRBOCHLCTN", shortDescription: "Cariboo Chilcotin", longDescription: "Cariboo Chilcotin", organizationUnitType: "ZONE", }, + { organizationUnit: "CHTWD", shortDescription: "Chetwynd", longDescription: "Chetwynd", organizationUnitType: "OFFLOC", }, +]; + +const personTypes = [ + { "person_complaint_xref_code": "ASSIGNEE", "short_description": "Officer Assigned", "long_description": "The person to whom the complaint is assigned to.", "display_order": 1, }, + { "person_complaint_xref_code": "TEST", "short_description": "TEST", "long_description": "Test person type", "display_order": 2, } +] + +const species = [ + { "species_code": "BISON", "short_description": "Bison", "long_description": "Bison", "display_order": 1, "active_ind": true, "legacy_code": null, }, + { "species_code": "BLKBEAR", "short_description": "Black Bear", "long_description": "Black Bear", "display_order": 2, "active_ind": true, "legacy_code": null, }, + { "species_code": "BOBCAT", "short_description": "Bobcat", "long_description": "Bobcat", "display_order": 3, "active_ind": true, "legacy_code": null, }, + { "species_code": "COUGAR", "short_description": "Cougar", "long_description": "Cougar", "display_order": 4, "active_ind": true, "legacy_code": null, }, + { "species_code": "COYOTE", "short_description": "Coyote", "long_description": "Coyote", "display_order": 5, "active_ind": true, "legacy_code": null, }, + { "species_code": "DEER", "short_description": "Deer", "long_description": "Deer", "display_order": 6, "active_ind": true, "legacy_code": null, }] + +const violations = [ + { "violation_code": "AINVSPC", "short_description": "AINVSPC", "long_description": "Aquatic: Invasive Species", "display_order": 1, "active_ind": true, }, + { "violation_code": "BOATING", "short_description": "BOATING", "long_description": "Boating", "display_order": 2, "active_ind": true, }, + { "violation_code": "DUMPING", "short_description": "DUMPING", "long_description": "Dumping", "display_order": 3, "active_ind": true, }, + { "violation_code": "FISHERY", "short_description": "FISHERY", "long_description": "Fisheries", "display_order": 4, "active_ind": true, }, + { "violation_code": "ORV", "short_description": "ORV", "long_description": "Off-road vehicles (ORV)", "display_order": 5, "active_ind": true, }, + { "violation_code": "OPENBURN", "short_description": "OPENBURN", "long_description": "Open Burning", "display_order": 6, "active_ind": true, }, + { "violation_code": "OTHER", "short_description": "OTHER", "long_description": "Other", "display_order": 7, "active_ind": true, }, + { "violation_code": "PESTICDE", "short_description": "PESTICDE", "long_description": "Pesticide", "display_order": 8, "active_ind": true, }, + { "violation_code": "RECREATN", "short_description": "RECREATN", "long_description": "Recreation sites/ trails", "display_order": 9, "active_ind": true, } +] + +const cosOrganizationUnits = [ + { "zone_code": "CLMBAKTNY", "region_code": "KTNY", "region_name": "Kootenay", "zone_name": "Columbia/Kootenay", "office_location_code": "GLDN", "office_location_name": "Golden", "area_code": "BLBRY", "area_name": "Blaeberry" }, + { "zone_code": "CLMBAKTNY", "region_code": "KTNY", "region_name": "Kootenay", "zone_name": "Columbia/Kootenay", "office_location_code": "GLDN", "office_location_name": "Golden", "area_code": "BRS", "area_name": "Brisco" }, + { "zone_code": "CLMBAKTNY", "region_code": "KTNY", "region_name": "Kootenay", "zone_name": "Columbia/Kootenay", "office_location_code": "GLDN", "office_location_name": "Golden", "area_code": "CMB", "area_name": "Cambie" }, + { "zone_code": "CLMBAKTNY", "region_code": "KTNY", "region_name": "Kootenay", "zone_name": "Columbia/Kootenay", "office_location_code": "GLDN", "office_location_name": "Golden", "area_code": "CMRNE", "area_name": "Camborne" }, + { "zone_code": "CLMBAKTNY", "region_code": "KTNY", "region_name": "Kootenay", "zone_name": "Columbia/Kootenay", "office_location_code": "GLDN", "office_location_name": "Golden", "area_code": "CRSRLAKE", "area_name": "Coursier Lake" }, + { "zone_code": "CLMBAKTNY", "region_code": "KTNY", "region_name": "Kootenay", "zone_name": "Columbia/Kootenay", "office_location_code": "GLDN", "office_location_name": "Golden", "area_code": "DONALD", "area_name": "Donald" }, + { "zone_code": "CLMBAKTNY", "region_code": "KTNY", "region_name": "Kootenay", "zone_name": "Columbia/Kootenay", "office_location_code": "GLDN", "office_location_name": "Golden", "area_code": "FTRESSLK", "area_name": "Fortress Lake" }, + { "zone_code": "CLMBAKTNY", "region_code": "KTNY", "region_name": "Kootenay", "zone_name": "Columbia/Kootenay", "office_location_code": "GLDN", "office_location_name": "Golden", "area_code": "GOLDEN", "area_name": "Golden" }, + { "zone_code": "CLMBAKTNY", "region_code": "KTNY", "region_name": "Kootenay", "zone_name": "Columbia/Kootenay", "office_location_code": "GLDN", "office_location_name": "Golden", "area_code": "GRIFFNLK", "area_name": "Griffin Lake" }, + { "zone_code": "CLMBAKTNY", "region_code": "KTNY", "region_name": "Kootenay", "zone_name": "Columbia/Kootenay", "office_location_code": "GLDN", "office_location_name": "Golden", "area_code": "HARROGAT", "area_name": "Harrogate" }, + { "zone_code": "CLMBAKTNY", "region_code": "KTNY", "region_name": "Kootenay", "zone_name": "Columbia/Kootenay", "office_location_code": "GLDN", "office_location_name": "Golden", "area_code": "KINABSKT", "area_name": "Kinabasket Lake" }, + { "zone_code": "CLMBAKTNY", "region_code": "KTNY", "region_name": "Kootenay", "zone_name": "Columbia/Kootenay", "office_location_code": "GLDN", "office_location_name": "Golden", "area_code": "MCMURDO", "area_name": "McMurdo" }, + { "zone_code": "CLMBAKTNY", "region_code": "KTNY", "region_name": "Kootenay", "zone_name": "Columbia/Kootenay", "office_location_code": "GLDN", "office_location_name": "Golden", "area_code": "NICHOLN", "area_name": "Nicholson" }, + { "zone_code": "CLMBAKTNY", "region_code": "KTNY", "region_name": "Kootenay", "zone_name": "Columbia/Kootenay", "office_location_code": "GLDN", "office_location_name": "Golden", "area_code": "PARSON", "area_name": "Parson" } +] + +const complaintTypes = [ + { "complaint_type_code": "HWCR", "short_description": "HWCR", "long_description": "Human Wildlife Conflict", "display_order": 1, "active_ind": true, }, + { "complaint_type_code": "ERS", "short_description": "ERS", "long_description": "Enforcement", "display_order": 2, "active_ind": true, } +] + +const regions = [ + { "code": "KTNY", "name": "Kootenay" }, + { "code": "OKNGN", "name": "Okanagan" }, + { "code": "OMINECA", "name": "Omineca" }, + { "code": "PCLRD", "name": "Peace Liard" }, + { "code": "SKNA", "name": "Skeena" }, + { "code": "STHCST", "name": "South Coast" }, + { "code": "TMPSNCRBO", "name": "Thompson Cariboo" }, + { "code": "WSTCST", "name": "West Coast" } +] + +const zones = [ +{ "code": "NOKNGN", "name": "North Okanagan", "region": "OKNGN"}, +{ "code": "NPCE", "name": "North Peace", "region": "PCLRD"}, +{ "code": "OMNCA", "name": "Omineca", "region": "OMINECA"}, +{ "code": "SEA2SKY", "name": "Sea to Sky", "region": "STHCST"}, +{ "code": "SISL", "name": "South Island", "region": "WSTCST"}, +{ "code": "SNSHNCST", "name": "Sunshine Coast", "region": "STHCST"}, +{ "code": "SOKNGN", "name": "South Okanagan", "region": "OKNGN"}, +{ "code": "SPCE", "name": "South Peace", "region": "PCLRD"}, +{ "code": "TMPSNNCLA", "name": "Thompson Nicola", "region": "TMPSNCRBO"}, +] + +const communities = [ + { "code": "100MHHS", "name": "100 Mile House", "zone": "CRBOTMPSN", "region": "TMPSNCRBO" }, + { "code": "108MLRNH", "name": "108 Mile Ranch", "zone": "CRBOTMPSN", "region": "TMPSNCRBO" }, + { "code": "140MHHS", "name": "140 Mile House", "zone": "CRBOCHLCTN", "region": "TMPSNCRBO" }, + { "code": "150MHHS", "name": "150 Mile House", "zone": "CRBOCHLCTN", "region": "TMPSNCRBO" }, + { "code": "16MIL", "name": "16 Mile", "zone": "CRBOTMPSN", "region": "TMPSNCRBO" }, + { "code": "40MLFLTZ", "name": "40 Mile Flats", "zone": "CRBOCHLCTN", "region": "TMPSNCRBO" }, + { "code": "70MLHS", "name": "70 Mile House", "zone": "CRBOTMPSN", "region": "TMPSNCRBO" }, + { "code": "ABTFRD", "name": "Abbotsford", "zone": "FRSRS", "region": "STHCST" }, + { "code": "ADMSLKHS", "name": "Adams Lake", "zone": "TMPSNNCLA", "region": "TMPSNCRBO" }, + { "code": "AGSSZHS", "name": "Agassiz", "zone": "FRSRS", "region": "STHCST" }, + { "code": "AHST", "name": "Ahousat", "zone": "CENISL", "region": "WSTCST" } +] + +const single = (name: string = "default", idx: number = 0): any => { + switch (name) { + case "agency": { + return idx <= agencyCollection.length + ? agencyCollection[idx] + : agencyCollection[0]; + } + case "attractant": { + return idx <= attractants.length ? attractants[idx] : attractants[0]; + } + case "complaint-status": { + return idx <= complaitStatus.length + ? complaitStatus[idx] + : complaitStatus[0]; + } + case "nature-of-complaint": { + return idx <= natureOfComplaints.length + ? natureOfComplaints[idx] + : natureOfComplaints[0]; + } + case "person-complaint": { + return idx <= personTypes.length ? personTypes[idx] : personTypes[0]; + } + case "species": { + return idx <= species.length ? species[idx] : species[0]; + } + case "default": + default: + return null; + } +}; + +export const MockAgencyCodeTableRepository = () => ({ + find: jest.fn().mockResolvedValue(agencyCollection), + createQueryBuilder: jest.fn(() => ({ + leftJoinAndSelect: jest.fn().mockReturnThis(), + where: jest.fn().mockReturnThis(), + getMany: jest.fn().mockResolvedValue(agencyCollection), + })), +}); + +export const MockAttractantCodeTableRepository = () => ({ + find: jest.fn().mockResolvedValue(attractants), + createQueryBuilder: jest.fn(() => ({ + leftJoinAndSelect: jest.fn().mockReturnThis(), + where: jest.fn().mockReturnThis(), + getMany: jest.fn().mockResolvedValue(attractants), + })), +}); + +export const MockComplaintStatusCodeTableRepository = () => ({ + find: jest.fn().mockResolvedValue(complaitStatus), + createQueryBuilder: jest.fn(() => ({ + leftJoinAndSelect: jest.fn().mockReturnThis(), + where: jest.fn().mockReturnThis(), + getMany: jest.fn().mockResolvedValue(complaitStatus), + })), +}); + +export const MockNatureOfComplaintCodeTableRepository = () => ({ + find: jest.fn().mockResolvedValue(natureOfComplaints), + createQueryBuilder: jest.fn(() => ({ + leftJoinAndSelect: jest.fn().mockReturnThis(), + where: jest.fn().mockReturnThis(), + getMany: jest.fn().mockResolvedValue(natureOfComplaints), + })), +}); + +export const MockOrganizationUnitTypeCodeTableRepository = () => ({ + find: jest.fn().mockResolvedValue(organizationUnitTypes), + createQueryBuilder: jest.fn(() => ({ + leftJoinAndSelect: jest.fn().mockReturnThis(), + where: jest.fn().mockReturnThis(), + getMany: jest.fn().mockResolvedValue(organizationUnitTypes), + })), +}); + +export const MockOrganizationUnitCodeTableRepository = () => ({ + find: jest.fn().mockResolvedValue(organizationUnits), + createQueryBuilder: jest.fn(() => ({ + leftJoinAndSelect: jest.fn().mockReturnThis(), + where: jest.fn().mockReturnThis(), + getMany: jest.fn().mockResolvedValue(organizationUnits), + })), +}); + +export const MockPersonComplaintCodeTableRepository = () => ({ + find: jest.fn().mockResolvedValue(personTypes), + createQueryBuilder: jest.fn(() => ({ + leftJoinAndSelect: jest.fn().mockReturnThis(), + where: jest.fn().mockReturnThis(), + getMany: jest.fn().mockResolvedValue(personTypes), + })), +}); + +export const MockSpeciesCodeTableRepository = () => ({ + find: jest.fn().mockResolvedValue(species), + createQueryBuilder: jest.fn(() => ({ + leftJoinAndSelect: jest.fn().mockReturnThis(), + where: jest.fn().mockReturnThis(), + getMany: jest.fn().mockResolvedValue(species), + })), +}); + +export const MockViolationsCodeTableRepository = () => ({ + find: jest.fn().mockResolvedValue(violations), + createQueryBuilder: jest.fn(() => ({ + leftJoinAndSelect: jest.fn().mockReturnThis(), + where: jest.fn().mockReturnThis(), + getMany: jest.fn().mockResolvedValue(violations), + })), +}); + +export const MockCosOrganizationUnitCodeTableRepository = () => ({ + find: jest.fn().mockResolvedValue(cosOrganizationUnits), + map: jest.fn().mockReturnThis(), + createQueryBuilder: jest.fn(() => ({ + select: jest.fn().mockReturnThis(), + distinctOn: jest.fn().mockReturnThis(), + getRawMany: jest.fn().mockReturnThis(), + leftJoinAndSelect: jest.fn().mockReturnThis(), + where: jest.fn().mockReturnThis(), + getMany: jest.fn().mockResolvedValue(cosOrganizationUnits), + })), +}); + +export const MockComplaintTypeCodeTableRepository = () => ({ + find: jest.fn().mockResolvedValue(complaintTypes), + createQueryBuilder: jest.fn(() => ({ + leftJoinAndSelect: jest.fn().mockReturnThis(), + where: jest.fn().mockReturnThis(), + getMany: jest.fn().mockResolvedValue(complaintTypes), + })), +}); + +export const MockRegionCodeTableServiceRepository = () => ({ + find: jest.fn().mockReturnThis(), + map: jest.fn().mockReturnThis(), + createQueryBuilder: jest.fn(() => ({ + select: jest.fn().mockReturnThis(), + distinctOn: jest.fn().mockReturnThis(), + getRawMany: jest.fn().mockResolvedValue(regions), + leftJoinAndSelect: jest.fn().mockReturnThis(), + where: jest.fn().mockReturnThis(), + getMany: jest.fn().mockReturnThis(), + })), +}); + +export const MockZoneCodeTableServiceRepository = () => ({ + find: jest.fn().mockReturnThis(), + map: jest.fn().mockReturnThis(), + createQueryBuilder: jest.fn(() => ({ + select: jest.fn().mockReturnThis(), + distinctOn: jest.fn().mockReturnThis(), + getRawMany: jest.fn().mockResolvedValue(zones), + leftJoinAndSelect: jest.fn().mockReturnThis(), + where: jest.fn().mockReturnThis(), + getMany: jest.fn().mockReturnThis(), + })), +}); + +export const MockCommunityCodeTableServiceRepository = () => ({ + find: jest.fn().mockReturnThis(), + map: jest.fn().mockReturnThis(), + createQueryBuilder: jest.fn(() => ({ + select: jest.fn().mockReturnThis(), + distinctOn: jest.fn().mockReturnThis(), + getRawMany: jest.fn().mockResolvedValue(communities), + leftJoinAndSelect: jest.fn().mockReturnThis(), + where: jest.fn().mockReturnThis(), + getMany: jest.fn().mockReturnThis(), + })), +}); \ No newline at end of file diff --git a/backend/test/mocks/mock-office-repository.ts b/backend/test/mocks/mock-office-repository.ts index 8867cef89..d164dd441 100644 --- a/backend/test/mocks/mock-office-repository.ts +++ b/backend/test/mocks/mock-office-repository.ts @@ -47,9 +47,3 @@ export const MockOfficeRepository = () => ({ getMany: jest.fn().mockResolvedValue(collection), })), }); - -/* - - - -*/ diff --git a/frontend/src/app/components/containers/complaints/complaint-filter.tsx b/frontend/src/app/components/containers/complaints/complaint-filter.tsx index d2dfd10ed..6edc8f476 100644 --- a/frontend/src/app/components/containers/complaints/complaint-filter.tsx +++ b/frontend/src/app/components/containers/complaints/complaint-filter.tsx @@ -2,7 +2,15 @@ import { FC, useCallback, useContext } from "react"; import "../../../../../node_modules/react-datepicker/dist/react-datepicker.css"; import "../../../../../node_modules/react-datepicker/dist/react-datepicker-cssmodules.css"; import { useAppSelector } from "../../../hooks/hooks"; -import { selectCodeTable } from "../../../store/reducers/code-table"; +import { + selectRegionCodeDropdown, + selectZoneCodeDropdown, + selectCommunityCodeDropdown, + selectHwcrNatureOfComplaintCodeDropdown, + selectSpeciesCodeDropdown, + selectComplaintStatusCodeDropdown, + selectViolationCodeDropdown +} from "../../../store/reducers/code-table"; import { selectOfficersDropdown } from "../../../store/reducers/officer"; import COMPLAINT_TYPES from "../../../types/app/complaint-types"; import DatePicker from "react-datepicker"; @@ -38,23 +46,21 @@ export const ComplaintFilter: FC = ({ type, isOpen }) => { dispatch, } = useContext(ComplaintFilterContext); - const regions = useAppSelector(selectCodeTable("regions")); - const zones = useAppSelector(selectCodeTable("zones")); - const communities = useAppSelector(selectCodeTable("communities")); + const regions = useAppSelector(selectRegionCodeDropdown); + const zones = useAppSelector(selectZoneCodeDropdown); + const communities = useAppSelector(selectCommunityCodeDropdown); const officers = useAppSelector(selectOfficersDropdown); - const natureOfComplaintTypes = useAppSelector( - selectCodeTable("wildlifeNatureOfComplaintCodes"), - ); - const speciesTypes = useAppSelector(selectCodeTable("speciesCodes")); - const statusTypes = useAppSelector(selectCodeTable("complaintStatusCodes")); - const violationTypes = useAppSelector(selectCodeTable("violationCodes")); + const natureOfComplaintTypes = useAppSelector(selectHwcrNatureOfComplaintCodeDropdown); + const speciesTypes = useAppSelector(selectSpeciesCodeDropdown); + const statusTypes = useAppSelector(selectComplaintStatusCodeDropdown); + const violationTypes = useAppSelector(selectViolationCodeDropdown); const setFilter = useCallback( (name: string, value?: Option | Date | null) => { let payload: ComplaintFilterPayload = { filter: name, value }; dispatch(updateFilter(payload)); }, - [], + [dispatch] ); const handleDateRangeChange = (dates: [Date, Date]) => { @@ -110,34 +116,38 @@ export const ComplaintFilter: FC = ({ type, isOpen }) => { >
Nature of Complaint
- {setFilter("natureOfComplaint", option);}} - classNames={{ - menu: () => "top-layer-select", - }} - options={natureOfComplaintTypes} - placeholder="Select" - enableValidation={false} - value={natureOfComplaint} - /> + { + setFilter("natureOfComplaint", option); + }} + classNames={{ + menu: () => "top-layer-select", + }} + options={natureOfComplaintTypes} + placeholder="Select" + enableValidation={false} + value={natureOfComplaint} + />
Species
{setFilter("species", option);}} - classNames={{ - menu: () => "top-layer-select", - }} - options={speciesTypes} - placeholder="Select" - enableValidation={false} - value={species} + id="species-select-id" + classNamePrefix="comp-select" + onChange={(option) => { + setFilter("species", option); + }} + classNames={{ + menu: () => "top-layer-select", + }} + options={speciesTypes} + placeholder="Select" + enableValidation={false} + value={species} />
@@ -150,17 +160,19 @@ export const ComplaintFilter: FC = ({ type, isOpen }) => {
Violation Type
{setFilter("violationType", option);}} - classNames={{ - menu: () => "top-layer-select", - }} - options={violationTypes} - placeholder="Select" - enableValidation={false} - value={violationType} - /> + id="violation-type-select-id" + classNamePrefix="comp-select" + onChange={(option) => { + setFilter("violationType", option); + }} + classNames={{ + menu: () => "top-layer-select", + }} + options={violationTypes} + placeholder="Select" + enableValidation={false} + value={violationType} + />
)} @@ -241,7 +253,9 @@ export const ComplaintFilter: FC = ({ type, isOpen }) => { {setFilter("status", option);}} + onChange={(option) => { + setFilter("status", option); + }} classNames={{ menu: () => "top-layer-select", }} @@ -270,7 +284,9 @@ export const ComplaintFilter: FC = ({ type, isOpen }) => { {setFilter("region", option);}} + onChange={(option) => { + setFilter("region", option); + }} classNames={{ menu: () => "top-layer-select", }} @@ -286,16 +302,18 @@ export const ComplaintFilter: FC = ({ type, isOpen }) => {
Zone
{setFilter("zone", option);}} - classNames={{ - menu: () => "top-layer-select", - }} - options={zones} - placeholder="Select" - enableValidation={false} - value={zone} + id="zone-select-id" + classNamePrefix="comp-select" + onChange={(option) => { + setFilter("zone", option); + }} + classNames={{ + menu: () => "top-layer-select", + }} + options={zones} + placeholder="Select" + enableValidation={false} + value={zone} />
@@ -305,16 +323,18 @@ export const ComplaintFilter: FC = ({ type, isOpen }) => {
Community
{setFilter("community", option);}} - classNames={{ - menu: () => "top-layer-select", - }} - options={communities} - placeholder="Select" - enableValidation={false} - value={community} + id="community-select-id" + classNamePrefix="comp-select" + onChange={(option) => { + setFilter("community", option); + }} + classNames={{ + menu: () => "top-layer-select", + }} + options={communities} + placeholder="Select" + enableValidation={false} + value={community} />
@@ -324,18 +344,20 @@ export const ComplaintFilter: FC = ({ type, isOpen }) => {
Officer Assigned
{setFilter("officer", option);}} - classNames={{ - menu: () => "top-layer-select", - }} - options={officers} - defaultOption={{ label: "Unassigned", value: "Unassigned" }} - placeholder="Select" - enableValidation={false} - value={officer} - /> + id="officer-select-id" + classNamePrefix="comp-select" + onChange={(option) => { + setFilter("officer", option); + }} + classNames={{ + menu: () => "top-layer-select", + }} + options={officers} + defaultOption={{ label: "Unassigned", value: "Unassigned" }} + placeholder="Select" + enableValidation={false} + value={officer} + />
diff --git a/frontend/src/app/components/containers/complaints/details/complaint-details-create.tsx b/frontend/src/app/components/containers/complaints/details/complaint-details-create.tsx index 8cce014b2..685e8ffcb 100644 --- a/frontend/src/app/components/containers/complaints/details/complaint-details-create.tsx +++ b/frontend/src/app/components/containers/complaints/details/complaint-details-create.tsx @@ -44,6 +44,7 @@ import { ToggleError } from "../../../../common/toast"; import { ToastContainer } from "react-toastify"; import "react-toastify/dist/ReactToastify.css"; import { useNavigate } from "react-router-dom"; +import { DropdownOption } from "../../../../types/app/drop-down-option"; export const CreateComplaint: FC = () => { const dispatch = useAppDispatch(); @@ -835,7 +836,7 @@ export const CreateComplaint: FC = () => { selectHwcrNatureOfComplaintCodeDropdown, ) as Option[]; const complaintTypeCodes = useSelector(selectComplaintTypeDropdown) as Option[]; - const areaCodes = useSelector(selectAreaCodeDropdown) as Option[]; + const areaCodes = useSelector(selectAreaCodeDropdown) as DropdownOption[]; const attractantCodes = useSelector(selectAttractantCodeDropdown) as Option[]; const referredByAgencyCodes = useSelector(selectAgencyDropdown) as Option[]; const violationTypeCodes = useSelector( diff --git a/frontend/src/app/constants/code-table-types.ts b/frontend/src/app/constants/code-table-types.ts new file mode 100644 index 000000000..2060eaf85 --- /dev/null +++ b/frontend/src/app/constants/code-table-types.ts @@ -0,0 +1,16 @@ +export const CODE_TABLE_TYPES = { + AGENCY: "agency", + ATTRACTANT: "attractant", + COMPLAINT_STATUS: "complaint-status", + COMPLAINT_TYPE: "complaint-type", + NATURE_OF_COMPLAINT: "nature-of-complaint", + SPECIES: "species", + VIOLATIONS: "violation", + REGIONS: "regions", + ZONES: "zones", + COMMUNITIES: "communities", + AREA_CODES: "area-codes", + // ORGANIZATION_UNIT_TYPE: "organization-unit-type", + // ORGANIZATION_UNIT: "organization-unit", + // PERSON_TYPE: "person-complaint", +}; diff --git a/frontend/src/app/constants/code-table.enum.ts b/frontend/src/app/constants/code-table.enum.ts deleted file mode 100644 index 74e660e52..000000000 --- a/frontend/src/app/constants/code-table.enum.ts +++ /dev/null @@ -1,10 +0,0 @@ -export enum CodeTable { - AGENCY_CODE = "agency-code", - ATTRACTANT_CODE = "attractant-code", - COMPLAINT_STATUS_CODE = "complaint-status-code", - GEO_ORG_UNIT_TYPE_CODE = "geo-org-unit-type-code", - GEO_ORGANIZATION_UNIT_CODE = "geo-organization-unit-code", - HWCR_COMPLAINT_NATURE_CODE = "hwcr-complaint-nature-code", - SPECIES_CODE = "species-code", - VIOLATION_CODE = "violation-code", -} diff --git a/frontend/src/app/store/reducers/app.ts b/frontend/src/app/store/reducers/app.ts index f9d431d26..845ffd12f 100644 --- a/frontend/src/app/store/reducers/app.ts +++ b/frontend/src/app/store/reducers/app.ts @@ -9,7 +9,7 @@ import config from "../../../config"; import { generateApiParameters, get } from "../../common/api"; import { AUTH_TOKEN } from "../../service/user-service"; -import { DropdownOption } from "../../types/code-tables/option"; +import { DropdownOption } from "../../types/app/drop-down-option"; import { Configurations } from "../../constants/configurations"; import { ConfigurationType } from "../../types/configurations/configuration"; diff --git a/frontend/src/app/store/reducers/code-table.ts b/frontend/src/app/store/reducers/code-table.ts index 700cfc117..858c403f9 100644 --- a/frontend/src/app/store/reducers/code-table.ts +++ b/frontend/src/app/store/reducers/code-table.ts @@ -3,33 +3,34 @@ import { AppThunk, RootState, store } from "../store"; import { from } from "linq-to-typescript"; import config from "../../../config"; import { CodeTableState } from "../../types/state/code-table-state"; -import { AgencyCode } from "../../types/code-tables/agency-code"; -import { CodeTable } from "../../types/code-tables/code-table"; import { ComplaintStatusCode } from "../../types/code-tables/complaint-status-code"; -import { ViolationCode } from "../../types/code-tables/violation-code"; -import { SpeciesCode } from "../../types/code-tables/species-code"; -import { HwcrNatureOfComplaintCode } from "../../types/code-tables/hwcr-nature-of-complaint-code"; -import { CosGeoOrgUnit } from "../../types/person/person"; -import { AttractantCode } from "../../types/code-tables/attractant-code"; import Option from "../../types/app/option"; import { generateApiParameters, get } from "../../common/api"; -import { GeoOrganizationCode } from "../../types/code-tables/geo-orginaization-code"; -import { DropdownOption } from "../../types/code-tables/option"; -import { ComplaintTypeCode } from "../../types/code-tables/complaint-type-code"; +import { DropdownOption } from "../../types/app/drop-down-option"; +import { Agency } from "../../types/app/code-tables/agency"; +import { Attractant } from "../../types/app/code-tables/attactant"; +import { CODE_TABLE_TYPES } from "../../constants/code-table-types"; +import { NatureOfComplaint } from "../../types/app/code-tables/nature-of-complaint"; +import { Species } from "../../types/app/code-tables/species"; +import { Violation } from "../../types/app/code-tables/violation"; +import { ComplaintType } from "../../types/app/code-tables/complaint-type"; +import { Region } from "../../types/app/code-tables/region"; +import { Zone } from "../../types/app/code-tables/zone"; +import { Community } from "../../types/app/code-tables/community"; +import { OrganizationCodeTable } from "../../types/app/code-tables/organization-code-table"; const initialState: CodeTableState = { - agencyCodes: [], - complaintStatusCodes: [], - violationCodes: [], - speciesCodes: [], - wildlifeNatureOfComplaintCodes: [], - areaCodes: [], - attractantCodes: [], + agency: [], + attractant: [], + "complaint-status": [], + "complaint-type": [], + "nature-of-complaint": [], + species: [], + violation: [], regions: [], zones: [], communities: [], - complaintCodes: [], - complaintTypeCodes: [], + "area-codes": [], }; export const codeTableSlice = createSlice({ @@ -37,193 +38,14 @@ export const codeTableSlice = createSlice({ initialState, reducers: { - setAgencyCodes: ( + setCodeTable: ( state: CodeTableState, - action: PayloadAction>, + action: PayloadAction<{ key: string; data: Array }> ) => { - const { payload } = action; - const data = payload.map( - ({ - agency_code: value, - long_description: label, - short_description: description, - }) => { - return { value, label, description } as CodeTable; - }, - ); - - return { ...state, agencyCodes: data }; - }, - setComplaintStatusCodes: ( - state: CodeTableState, - action: PayloadAction>, - ) => { - const { payload } = action; - const data = payload.map( - ({ - complaint_status_code: value, - long_description: label, - short_description: description, - }) => { - return { value, label, description } as CodeTable; - }, - ); - return { ...state, complaintStatusCodes: data }; - }, - setViolationCodes: ( - state: CodeTableState, - action: PayloadAction>, - ) => { - const { payload } = action; - const data = payload.map( - ({ - violation_code: value, - long_description: label, - short_description: description, - }) => { - return { value, label, description } as CodeTable; - }, - ); - return { ...state, violationCodes: data }; - }, - setSpeciesCodes: ( - state: CodeTableState, - action: PayloadAction>, - ) => { - const { payload } = action; - const data = payload.map( - ({ - species_code: value, - long_description: label, - short_description: description, - }) => { - return { value, label, description } as CodeTable; - }, - ); - return { ...state, speciesCodes: data }; - }, - setWildlifeNatureOfComplaintCodes: ( - state: CodeTableState, - action: PayloadAction>, - ) => { - const { payload } = action; - const data = payload.map( - ({ - hwcr_complaint_nature_code: value, - long_description: label, - short_description: description, - }) => { - return { value, label, description } as CodeTable; - }, - ); - return { ...state, wildlifeNatureOfComplaintCodes: data }; - }, - setAreaCodes: ( - state: CodeTableState, - action: PayloadAction>, - ) => { - const { payload } = action; - const data = payload.map(({ area_code: value, area_name: label }) => { - return { value, label, description: label } as CodeTable; - }); - return { ...state, areaCodes: data }; - }, - setAttractantCodes: ( - state: CodeTableState, - action: PayloadAction>, - ) => { - const { payload } = action; - const data = payload.map( - ({ - attractant_code: value, - short_description: label, - short_description: description, - }) => { - return { value, label, description } as CodeTable; - }, - ); - return { ...state, attractantCodes: data }; - }, - setRegions: ( - state: CodeTableState, - action: PayloadAction>, - ) => { - const { payload } = action; - const data = payload.map( - ({ - geo_organization_unit_code: value, - long_description: label, - short_description: description, - }) => { - return { value, label, description } as CodeTable; - }, - ); - return { ...state, regions: data }; - }, - setZones: ( - state: CodeTableState, - action: PayloadAction>, - ) => { - const { payload } = action; - const data = payload.map( - ({ - geo_organization_unit_code: value, - long_description: label, - short_description: description, - }) => { - return { value, label, description } as CodeTable; - }, - ); - return { ...state, zones: data }; - }, - setCommunities: ( - state: CodeTableState, - action: PayloadAction>, - ) => { - const { payload } = action; - const data = payload.map( - ({ - geo_organization_unit_code: value, - long_description: label, - short_description: description, - }) => { - return { value, label, description } as CodeTable; - }, - ); - return { ...state, communities: data }; - }, - setComplaintCodes: ( - state: CodeTableState, - action: PayloadAction>, - ) => { - const { payload } = action; - const data = payload.map( - ({ - geo_organization_unit_code: value, - long_description: label, - short_description: description, - }) => { - return { value, label, description } as CodeTable; - }, - ); - return { ...state, complaintCodes: data }; - }, - setComplaintTypeCodes: ( - state: CodeTableState, - action: PayloadAction>, - ) => { - const { payload } = action; - const data = payload.map( - ({ - complaint_type_code: value, - long_description: label, - short_description: description, - }) => { - return { value, label, description } as CodeTable; - }, - ); - - return { ...state, complaintTypeCodes: data }; + const { + payload: { key, data }, + } = action; + return { ...state, [key]: data }; }, }, @@ -232,66 +54,49 @@ export const codeTableSlice = createSlice({ extraReducers: (builder) => {}, }); -export const { - setAgencyCodes, - setComplaintStatusCodes, - setViolationCodes, - setSpeciesCodes, - setWildlifeNatureOfComplaintCodes, - setAreaCodes, - setAttractantCodes, - setRegions, - setZones, - setCommunities, - setComplaintCodes, - setComplaintTypeCodes, -} = codeTableSlice.actions; +export const { setCodeTable } = codeTableSlice.actions; export const fetchCodeTables = (): AppThunk => async (dispatch) => { const state = store.getState(); const { codeTables: { - agencyCodes, - complaintStatusCodes, - violationCodes, - speciesCodes, - wildlifeNatureOfComplaintCodes, - areaCodes, - attractantCodes, + "complaint-type": complaintType, + "area-codes": areaCodes, + "complaint-status": complaintStatus, + attractant, + agency, + violation, + species, + "nature-of-complaint": natureOfComplaint, regions, zones, communities, - complaintTypeCodes, }, } = state; try { - if (!from(agencyCodes).any()) { - dispatch(fetchAgencyCodes()); + if (!from(agency).any()) { + dispatch(fetchAgencies()); } - if (!from(complaintStatusCodes).any()) { - dispatch(fetchComplaintStatusCodes()); + if (!from(complaintStatus).any()) { + dispatch(fetchComplaintStatus()); } - if (!from(violationCodes).any()) { - dispatch(fetchViolationCodes()); + if (!from(violation).any()) { + dispatch(fetchViolations()); } - if (!from(speciesCodes).any()) { - dispatch(fetchSpeciesCodes()); + if (!from(species).any()) { + dispatch(fetchSpecies()); } - if (!from(wildlifeNatureOfComplaintCodes).any()) { - dispatch(fetchWildlifeNatureOfComplaintCodes()); - } - - if (!from(areaCodes).any()) { - dispatch(fetchAreaCodes()); + if (!from(natureOfComplaint).any()) { + dispatch(fetchNatureOfComplaints()); } - if (!from(attractantCodes).any()) { - dispatch(fetchAttractantCodes()); + if (!from(attractant).any()) { + dispatch(fetchAttractants()); } if (!from(regions).any()) { @@ -306,141 +111,187 @@ export const fetchCodeTables = (): AppThunk => async (dispatch) => { dispatch(fetchCommunities()); } - if (!from(complaintTypeCodes).any()) { + if (!from(areaCodes).any()) { + dispatch(fetchAreaCodes()); + } + + if (!from(complaintType).any()) { dispatch(fetchComplaintTypeCodes()); } - } catch (error) { - } + } catch (error) {} }; -export const fetchAgencyCodes = (): AppThunk => async (dispatch) => { +export const fetchAgencies = (): AppThunk => async (dispatch) => { const parameters = generateApiParameters( - `${config.API_BASE_URL}/v1/agency-code`, + `${config.API_BASE_URL}/v1/code-table/${CODE_TABLE_TYPES.AGENCY}` ); - const response = await get>(dispatch, parameters); + const response = await get>(dispatch, parameters); if (response && from(response).any()) { - dispatch(setAgencyCodes(response)); + const payload = { key: CODE_TABLE_TYPES.AGENCY, data: response }; + dispatch(setCodeTable(payload)); } }; -export const fetchViolationCodes = (): AppThunk => async (dispatch) => { +export const fetchAttractants = (): AppThunk => async (dispatch) => { const parameters = generateApiParameters( - `${config.API_BASE_URL}/v1/violation-code`, + `${config.API_BASE_URL}/v1/code-table/${CODE_TABLE_TYPES.ATTRACTANT}` ); - const response = await get>(dispatch, parameters); + const response = await get>(dispatch, parameters); if (response && from(response).any()) { - dispatch(setViolationCodes(response)); + const payload = { key: CODE_TABLE_TYPES.ATTRACTANT, data: response }; + dispatch(setCodeTable(payload)); } }; -export const fetchSpeciesCodes = (): AppThunk => async (dispatch) => { +export const fetchComplaintStatus = (): AppThunk => async (dispatch) => { const parameters = generateApiParameters( - `${config.API_BASE_URL}/v1/species-code`, + `${config.API_BASE_URL}/v1/code-table/${CODE_TABLE_TYPES.COMPLAINT_STATUS}` ); - const response = await get>(dispatch, parameters); + const response = await get>(dispatch, parameters); if (response && from(response).any()) { - dispatch(setSpeciesCodes(response)); + const payload = { key: CODE_TABLE_TYPES.COMPLAINT_STATUS, data: response }; + dispatch(setCodeTable(payload)); } }; -export const fetchWildlifeNatureOfComplaintCodes = - (): AppThunk => async (dispatch) => { - const parameters = generateApiParameters( - `${config.API_BASE_URL}/v1/hwcr-complaint-nature-code`, - ); - const response = await get>( - dispatch, - parameters, - ); +export const fetchNatureOfComplaints = (): AppThunk => async (dispatch) => { + const parameters = generateApiParameters( + `${config.API_BASE_URL}/v1/code-table/${CODE_TABLE_TYPES.NATURE_OF_COMPLAINT}` + ); + const response = await get>(dispatch, parameters); - if (response && from(response).any()) { - dispatch(setWildlifeNatureOfComplaintCodes(response)); - } - }; + if (response && from(response).any()) { + const payload = { + key: CODE_TABLE_TYPES.NATURE_OF_COMPLAINT, + data: response, + }; + dispatch(setCodeTable(payload)); + } +}; -export const fetchComplaintStatusCodes = (): AppThunk => async (dispatch) => { +export const fetchSpecies = (): AppThunk => async (dispatch) => { const parameters = generateApiParameters( - `${config.API_BASE_URL}/v1/complaint-status-code`, + `${config.API_BASE_URL}/v1/code-table/${CODE_TABLE_TYPES.SPECIES}` ); - const response = await get>(dispatch, parameters); + const response = await get>(dispatch, parameters); if (response && from(response).any()) { - dispatch(setComplaintStatusCodes(response)); + const payload = { + key: CODE_TABLE_TYPES.SPECIES, + data: response, + }; + dispatch(setCodeTable(payload)); } }; -export const fetchAreaCodes = (): AppThunk => async (dispatch) => { +export const fetchViolations = (): AppThunk => async (dispatch) => { const parameters = generateApiParameters( - `${config.API_BASE_URL}/v1/cos-geo-org-unit`, + `${config.API_BASE_URL}/v1/code-table/${CODE_TABLE_TYPES.VIOLATIONS}` ); - const response = await get>(dispatch, parameters); + const response = await get>(dispatch, parameters); if (response && from(response).any()) { - dispatch(setAreaCodes(response)); + const payload = { + key: CODE_TABLE_TYPES.VIOLATIONS, + data: response, + }; + dispatch(setCodeTable(payload)); } }; -export const fetchAttractantCodes = (): AppThunk => async (dispatch) => { +export const fetchComplaintTypeCodes = (): AppThunk => async (dispatch) => { const parameters = generateApiParameters( - `${config.API_BASE_URL}/v1/attractant-code`, + `${config.API_BASE_URL}/v1/code-table/${CODE_TABLE_TYPES.COMPLAINT_TYPE}` ); - const response = await get>(dispatch, parameters); + const response = await get>(dispatch, parameters); if (response && from(response).any()) { - dispatch(setAttractantCodes(response)); + const payload = { + key: CODE_TABLE_TYPES.COMPLAINT_TYPE, + data: response, + }; + dispatch(setCodeTable(payload)); } }; -export const fetchRegions = (): AppThunk => async (dispatch) => { +//-- these are going to need to come from the organizations +export const fetchAreaCodes = (): AppThunk => async (dispatch) => { + const agency = "cos"; //-- TODO: when CE-212 is started this needs to be updated + const parameters = generateApiParameters( - `${config.API_BASE_URL}/v1/geo-organization-unit-code/find-all-regions`, + `${config.API_BASE_URL}/v1/code-table/organization-by-agency/${agency}` + ); + const response = await get>( + dispatch, + parameters ); - const response = await get>(dispatch, parameters); if (response && from(response).any()) { - dispatch(setRegions(response)); + const payload = { + key: CODE_TABLE_TYPES.AREA_CODES, + data: response, + }; + dispatch(setCodeTable(payload)); } }; -export const fetchZones = (): AppThunk => async (dispatch) => { +export const fetchRegions = (): AppThunk => async (dispatch) => { + const agency = "cos"; //-- TODO: when CE-212 is started this needs to be updated + const parameters = generateApiParameters( - `${config.API_BASE_URL}/v1/geo-organization-unit-code/find-all-zones`, + `${config.API_BASE_URL}/v1/code-table/regions-by-agency/${agency}` ); - const response = await get>(dispatch, parameters); + const response = await get>(dispatch, parameters); if (response && from(response).any()) { - dispatch(setZones(response)); + const payload = { + key: CODE_TABLE_TYPES.REGIONS, + data: response, + }; + dispatch(setCodeTable(payload)); } }; -export const fetchCommunities = (): AppThunk => async (dispatch) => { +export const fetchZones = (): AppThunk => async (dispatch) => { + const agency = "cos"; //-- TODO: when CE-212 is started this needs to be updated + const parameters = generateApiParameters( - `${config.API_BASE_URL}/v1/geo-organization-unit-code/find-all-areas`, + `${config.API_BASE_URL}/v1/code-table/zones-by-agency/${agency}` ); - const response = await get>(dispatch, parameters); + const response = await get>(dispatch, parameters); if (response && from(response).any()) { - dispatch(setCommunities(response)); + const payload = { + key: CODE_TABLE_TYPES.ZONES, + data: response, + }; + dispatch(setCodeTable(payload)); } }; -export const fetchComplaintTypeCodes = (): AppThunk => async (dispatch) => { +export const fetchCommunities = (): AppThunk => async (dispatch) => { + const agency = "cos"; //-- TODO: when CE-212 is started this needs to be updated + const parameters = generateApiParameters( - `${config.API_BASE_URL}/v1/complaint-type-code`, + `${config.API_BASE_URL}/v1/code-table/communities-by-agency/${agency}` ); - const response = await get>(dispatch, parameters); + const response = await get>(dispatch, parameters); if (response && from(response).any()) { - dispatch(setComplaintTypeCodes(response)); + const payload = { + key: CODE_TABLE_TYPES.COMMUNITIES, + data: response, + }; + dispatch(setCodeTable(payload)); } }; export const selectCodeTable = (table: string) => - (state: RootState): Array => { + (state: RootState): Array => { const { codeTables } = state; const selected = codeTables[table as keyof CodeTableState]; @@ -449,115 +300,178 @@ export const selectCodeTable = export const selectSortedCodeTable = (table: string, sortBy: string) => - (state: RootState): Array => { + (state: RootState): Array => { const { codeTables } = state; const data = codeTables[table as keyof CodeTableState]; let sorted = data.sort((a: any, b: any) => - a[sortBy].localeCompare(b[sortBy]), + a[sortBy].localeCompare(b[sortBy]) ); return sorted; }; - export const selectComplaintTypeDropdown = (state: RootState): Array