Skip to content

Commit

Permalink
feat(driving-license): check if 65+ renewal is possible (#16292) (#16307
Browse files Browse the repository at this point in the history
)

* check if 65 renewal is possible

* remove console log

* cleanup

* coderabbit tweaks

* coderabbit changes

* quick fix

* add type?

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
stjanilofts and kodiakhq[bot] authored Oct 8, 2024
1 parent d62e8bc commit 994ec88
Show file tree
Hide file tree
Showing 10 changed files with 550 additions and 1,065 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,15 @@ export class DrivingLicenseService {
}
}

async canApplyFor(type: 'B-full' | 'B-temp' | 'BE', token: string) {
if (type === 'B-full') {
async canApplyFor(
type: 'B-full' | 'B-temp' | 'BE' | 'B-full-renewal-65',
token: string,
) {
if (type === 'B-full-renewal-65') {
return this.drivingLicenseApi.getCanApplyForRenewal65({
token,
})
} else if (type === 'B-full') {
return this.drivingLicenseApi.getCanApplyForCategoryFull({
category: 'B',
token,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export enum RequirementKey {
hasHadValidCategoryForFiveYearsOrMore = 'HasHadValidCategoryForFiveYearsOrMore',
//TODO: Remove when RLS/SGS supports health certificate in BE license
beRequiresHealthCertificate = 'beRequiresHealthCertificate',
noExtendedDrivingLicense = 'NoExtendedDrivingLicense',
}

export interface ApplicationEligibilityRequirement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const getDeniedByServiceMessageDescription = (
case RequirementKey.HasDeprivation:
case RequirementKey.HasPoints:
return requirementsMessages.hasPointsOrDeprivation
case RequirementKey.NoExtendedDrivingLicense:
return requirementsMessages.noExtendedDrivingLicenseTitle
default:
return requirementsMessages.rlsDefaultDeniedDescription
}
Expand Down Expand Up @@ -85,6 +87,11 @@ const requirementKeyToStep = (
title: requirementsMessages.beLicenseQualityPhotoTitle,
description: requirementsMessages.beLicenseQualityPhotoDescription,
}
case RequirementKey.NoExtendedDrivingLicense:
return {
title: requirementsMessages.noExtendedDrivingLicenseTitle,
description: requirementsMessages.noExtendedDrivingLicenseDescription,
}
default:
throw new Error('Unknown requirement reason - should not happen')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { getValueViaPath } from '@island.is/application/core'
import { Application } from '@island.is/application/types'
import { ApplicationEligibility, RequirementKey } from '../../types/schema'
import {
ApplicationEligibility,
ApplicationEligibilityRequirement,
RequirementKey,
} from '../../types/schema'
import { useQuery, gql } from '@apollo/client'
import {
B_FULL,
B_FULL_RENEWAL_65,
BE,
codesExtendedLicenseCategories,
codesRequiringHealthCertificate,
DrivingLicenseApplicationFor,
DrivingLicenseFakeData,
otherLicenseCategories,
remarksCannotRenew65,
YES,
} from '../../lib/constants'
import { fakeEligibility } from './fakeEligibility'
Expand Down Expand Up @@ -90,6 +97,23 @@ export const useEligibility = (
)
}

const hasExtendedDrivingLicense = (
currentLicense: DrivingLicense | undefined,
drivingLicenseIssued: string | undefined,
): boolean => {
if (!drivingLicenseIssued) return false

const relevantCategories = currentLicense?.categories?.filter((x) =>
codesExtendedLicenseCategories.includes(x.nr),
)

if (!relevantCategories?.length) return false

// Check if any category was issued on a different date than the 'B' license
// (indicating an extended license)
return relevantCategories.some((x) => x.issued !== drivingLicenseIssued)
}

if (usingFakeData) {
return {
loading: false,
Expand All @@ -111,13 +135,11 @@ export const useEligibility = (
}
}

const eligibility: ApplicationEligibilityRequirement[] =
data.drivingLicenseApplicationEligibility?.requirements ?? []

//TODO: Remove when RLS/SGS supports health certificate in BE license
if (application.answers.applicationFor === BE) {
const eligibility =
data.drivingLicenseApplicationEligibility === undefined
? []
: (data.drivingLicenseApplicationEligibility as ApplicationEligibility)
.requirements
return {
loading: loading,
eligibility: {
Expand All @@ -143,6 +165,52 @@ export const useEligibility = (
}
}

if (application.answers.applicationFor === B_FULL_RENEWAL_65) {
const licenseB = currentLicense?.categories?.find(
(license) => license.nr === 'B',
)
const drivingLicenseIssued = licenseB?.issued

const hasExtendedLicense = hasExtendedDrivingLicense(
currentLicense,
drivingLicenseIssued,
)

const hasAnyInvalidRemarks =
currentLicense?.remarks?.some((remark) =>
remarksCannotRenew65.includes(remark.code),
) ?? false

const requirements = [
...eligibility,
{
key: RequirementKey.HasNoPhoto,
requirementMet: hasQualityPhoto,
},
...(hasExtendedLicense
? [
{
key: RequirementKey.NoExtendedDrivingLicense,
requirementMet: false,
},
]
: []),
]

return {
loading: loading,
eligibility: {
isEligible: loading
? undefined
: (data.drivingLicenseApplicationEligibility?.isEligible ?? false) &&
hasQualityPhoto &&
!hasExtendedLicense &&
!hasAnyInvalidRemarks,
requirements,
},
}
}

return {
loading,
eligibility: data.drivingLicenseApplicationEligibility,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const sectionApplicationFor = (
'currentLicense.data',
) ?? { categories: null }

const age =
let age =
getValueViaPath<number>(
app.externalData,
'nationalRegistry.data.age',
Expand All @@ -53,6 +53,7 @@ export const sectionApplicationFor = (
app.answers,
'fakeData',
)

if (fakeData?.useFakeData === 'yes') {
currentLicense = fakeData.currentLicense ?? null
categories =
Expand All @@ -66,6 +67,8 @@ export const sectionApplicationFor = (
{ nr: 'BE', validToCode: 9 },
]
: []

age = fakeData?.age
}

let options = [
Expand All @@ -91,9 +94,7 @@ export const sectionApplicationFor = (
subLabel:
m.applicationForRenewalLicenseDescription.defaultMessage,
value: B_FULL_RENEWAL_65,
disabled:
!currentLicense ||
(fakeData && fakeData.age ? fakeData.age < 65 : age < 65),
disabled: !currentLicense || age < 65,
})
}

Expand Down
14 changes: 14 additions & 0 deletions libs/application/templates/driving-license/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ export enum Pickup {

export const otherLicenseCategories = ['C', 'C1', 'CE', 'D', 'D1', 'DE']
export const codesRequiringHealthCertificate = ['400', '01.06']
export const codesExtendedLicenseCategories = [
'C1',
'C1E',
'C',
'CE',
'D1',
'D1E',
'D',
'DE',
'Bfar',
'Far',
'FAR',
]
export const remarksCannotRenew65 = ['400', '450', '95']

export type DrivingLicenseApplicationFor =
| typeof B_FULL
Expand Down
10 changes: 10 additions & 0 deletions libs/application/templates/driving-license/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -974,4 +974,14 @@ export const requirementsMessages = defineMessages({
description:
'requirement unmet api returned false for an unspecified reason',
},
noExtendedDrivingLicenseTitle: {
id: 'dl.application:requirementunmet.noExtendedDrivingLicenseTitle',
defaultMessage: 'Ekki hægt að sækja um endurnýjun á 65+ ökuskírteini.',
description: 'requirement unmet 65 plus renewal',
},
noExtendedDrivingLicenseDescription: {
id: 'dl.application:requirementunmet.noExtendedDrivingLicenseDescription#markdown',
defaultMessage: 'Ekki hægt að sækja um endurnýjun á 65+ ökuskírteini.',
description: 'requirement unmet 65 plus renewal',
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type ConditionFn = (answer: FormValue) => boolean
export type DrivingLicenseCategory = {
nr: string
validToCode: number
issued?: string
}

export interface Remark {
Expand Down
17 changes: 17 additions & 0 deletions libs/clients/driving-license/src/lib/drivingLicenseApi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,23 @@ export class DrivingLicenseApi {
}
}

public async getCanApplyForRenewal65(params: {
token: string
}): Promise<CanApplyForCategoryResult<CanApplyErrorCodeBFull>> {
const response = await this.v5.apiDrivinglicenseV5CanapplyforRenewal65Get({
apiVersion: v5.DRIVING_LICENSE_API_VERSION_V5,
apiVersion2: v5.DRIVING_LICENSE_API_VERSION_V5,
jwttoken: params.token,
})

return {
result: !!response.result,
errorCode: response.errorCode
? (response.errorCode as CanApplyErrorCodeBFull)
: undefined,
}
}

public async getCanApplyForCategoryTemporary(params: {
token: string
}): Promise<CanApplyForCategoryResult<CanApplyErrorCodeBTemporary>> {
Expand Down
Loading

0 comments on commit 994ec88

Please sign in to comment.