Skip to content

Commit

Permalink
Revert "Add prison api builder to test memory (#202)"
Browse files Browse the repository at this point in the history
This reverts commit 04caac5.
  • Loading branch information
danielburnley authored Jun 21, 2023
1 parent 04caac5 commit 64d3189
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 327 deletions.
18 changes: 0 additions & 18 deletions server/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,19 @@
* Do appinsights first as it does some magic instrumentation work, i.e. it affects other 'require's
* In particular, applicationinsights automatically collects bunyan logs
*/
import config, { ApiConfig } from '../config'
import { buildAppInsightsClient, initialiseAppInsights } from '../utils/azureAppInsights'
import HmppsAuthClient from './hmppsAuthClient'
import { PrisonApiClient } from './interfaces/prisonApiClient'
import PrisonApiRestClientTwo from './prisonApiClientTwo'

import { createRedisClient } from './redisClient'
import RestClient, { RestClientBuilder as CreateRestClientBuilder } from './restClient'
import TokenStore from './tokenStore'

initialiseAppInsights()
buildAppInsightsClient()

type RestClientBuilder<T> = (token: string) => T

export default function restClientBuilder<T>(
name: string,
options: ApiConfig,
constructor: new (client: RestClient) => T,
): RestClientBuilder<T> {
const restClient = CreateRestClientBuilder(name, options)
return token => new constructor(restClient(token))
}

export const dataAccess = () => ({
hmppsAuthClient: new HmppsAuthClient(new TokenStore(createRedisClient())),
prisonApiClientBuilder: restClientBuilder<PrisonApiClient>(
'Prison API',
config.apis.prisonApi,
PrisonApiRestClientTwo,
),
})

export type DataAccess = ReturnType<typeof dataAccess>
Expand Down
297 changes: 0 additions & 297 deletions server/data/prisonApiClientTwo.ts

This file was deleted.

4 changes: 0 additions & 4 deletions server/data/restClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ interface StreamRequest {
errorLogger?: (e: UnsanitisedError) => void
}

export function RestClientBuilder(name: string, config: ApiConfig) {
return (token: string): RestClient => new RestClient(name, config, token)
}

export default class RestClient {
agent: Agent

Expand Down
4 changes: 2 additions & 2 deletions server/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import PrisonerSearchService from './prisonerSearch'
import UserService from './userService'

export const services = () => {
const { hmppsAuthClient, prisonApiClientBuilder } = dataAccess()
const { hmppsAuthClient } = dataAccess()
const userService = new UserService(hmppsAuthClient)
const offenderService = new OffenderService(prisonApiClientBuilder)
const offenderService = new OffenderService()
const commonApiRoutes = new CommonApiRoutes(offenderService)

return {
Expand Down
9 changes: 3 additions & 6 deletions server/services/offenderService.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { Readable } from 'stream'
import { RestClientBuilder } from '../data'
import { PrisonApiClient } from '../data/interfaces/prisonApiClient'
import PrisonApiClient from '../data/prisonApiClient'

export default class OffenderService {
constructor(private readonly prisonClientBuilder: RestClientBuilder<PrisonApiClient>) {}

getPrisonerImage(token: string, offenderNumber: string): Promise<Readable> {
return this.prisonClientBuilder(token).getPrisonerImage(offenderNumber, true)
return new PrisonApiClient(token).getPrisonerImage(offenderNumber, true)
}

getImage(token: string, imageId: string): Promise<Readable> {
return this.prisonClientBuilder(token).getImage(imageId, true)
return new PrisonApiClient(token).getImage(imageId, true)
}
}

0 comments on commit 64d3189

Please sign in to comment.