Skip to content

Commit

Permalink
feat: add auth to getAccidentNotificationStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnigs committed Oct 7, 2024
1 parent 1438de9 commit 97886bc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
AccidentNotificationStatus,
} from './graphql/models'
import { AccidentreportsApi } from '@island.is/clients/icelandic-health-insurance/rights-portal'
import { Auth, AuthMiddleware } from '@island.is/auth-nest-tools'

const mapStatus = (statusId: number) => {
switch (statusId) {
Expand Down Expand Up @@ -60,17 +61,21 @@ export class AccidentNotificationService {
private logger: Logger,
) {}

private accidentsReportsApiWithAuth(auth: Auth) {
return this.accidentReportsApi.withMiddleware(new AuthMiddleware(auth))
}

async getAccidentNotificationStatus(
auth: Auth,
ihiDocumentID: number,
): Promise<AccidentNotificationStatus | null> {
this.logger.log('starting call to get accident', ihiDocumentID)
console.log('!!!Hér í getAccidentNotificationStatus!!!', `${ihiDocumentID}`)

const accidentStatus =
await this.accidentReportsApi.getAccidentReportStatus({
reportId: ihiDocumentID,
})
console.log('!!!accidentStatus!!!', accidentStatus)
const accidentStatus = await this.accidentsReportsApiWithAuth(
auth,
).getAccidentReportStatus({
reportId: ihiDocumentID,
})

if (!accidentStatus) return null
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { Inject, UseGuards } from '@nestjs/common'
import { Args, Query, Resolver } from '@nestjs/graphql'
import { Audit } from '@island.is/nest/audit'
import { ApiScope } from '@island.is/auth/scopes'
import { IdsUserGuard, Scopes, ScopesGuard } from '@island.is/auth-nest-tools'
import {
CurrentUser,
IdsUserGuard,
Scopes,
ScopesGuard,
User,
} from '@island.is/auth-nest-tools'
import { LOGGER_PROVIDER } from '@island.is/logging'
import type { Logger } from '@island.is/logging'
import { HealthInsuranceAccidentStatusInput } from './dto/accidentStatus.input'
Expand All @@ -27,10 +33,12 @@ export class HealthInsuranceAccidentNotificationResolver {
async accidentStatus(
@Args('input', { type: () => HealthInsuranceAccidentStatusInput })
input: HealthInsuranceAccidentStatusInput,
@CurrentUser() user: User,
): Promise<AccidentNotificationStatus | null> {
this.logger.debug(`Getting company information`)
const accidentStatus =
await this.accidentNotificationService.getAccidentNotificationStatus(
user,
input.ihiDocumentID,
)
this.logger.debug(`Getting accident status for id ${input.ihiDocumentID}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import {
import { HealthInsuranceService } from './healthInsurance.service'
import { HealthInsuranceV2ClientModule } from '@island.is/clients/icelandic-health-insurance/health-insurance'
import { AccidentNotificationService } from './accident-notification.service'
import { AccidentreportsApi } from '@island.is/clients/icelandic-health-insurance/rights-portal'
import {
AccidentreportsApi,
RightsPortalClientModule,
} from '@island.is/clients/icelandic-health-insurance/rights-portal'

@Module({
imports: [HealthInsuranceV2ClientModule],
imports: [HealthInsuranceV2ClientModule, RightsPortalClientModule],
providers: [
HealthInsuranceService,
AccidentNotificationService,
HealthInsuranceResolver,
HealthInsuranceAccidentNotificationResolver,
AccidentreportsApi,
],
exports: [],
})
Expand Down

0 comments on commit 97886bc

Please sign in to comment.