Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions api/controllers/agencyController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Path, GET, PathParam } from 'typescript-rest';
import { Tags } from 'typescript-rest-swagger';
import AgencyDto from '../models/dto/agencyDto';
import { getAgencies } from '../services/agencyService';

@Path('/api/agency')
@Tags('Agency')
export default class AgencyController {
/**
* Returns Agencies.
*/
@GET
@Path('/:id/agency')
async getSubcategories(@PathParam('id') id: string): Promise<AgencyDto[]> {
return getAgencies(id);
}
}
3 changes: 2 additions & 1 deletion api/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import healthController from './healthController';
import taxonomyController from './taxonomyController';
import agencyController from './agencyController';

export default [healthController, taxonomyController];
export default [agencyController, healthController, taxonomyController];
7 changes: 7 additions & 0 deletions api/models/dto/agencyDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default interface AgencyDto {
id: string;
name: string;
locationId: string;
taxonomyId: string;
}

21 changes: 21 additions & 0 deletions api/services/agencyService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { makeSCOSRequest } from './scosService';
import getLogger from '../utils/logger';
import AgencyDto from '../models/dto/AgencyDto';
import { AGENCIES_TABLE } from '../utils/constants';
import { NotFoundError } from 'typescript-rest/dist/server/model/errors';

const log = getLogger('agencyService');

async function getAgencies(id: string): Promise<AgencyDto[]> {
log.debug(`Getting agencies with ID ${id}`);

const query = `SELECT * FROM ${AGENCIES_TABLE} WHERE id = '${id}'`;
const response: AgencyDto[] = await makeSCOSRequest(query);

if (response?.length === 0) {
throw new NotFoundError(`Invalid category ID ${id}`);
}
return response;
}

export { getAgencies };