Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(application-dld): Entry requirements in DP #15430

Merged
merged 11 commits into from
Jul 4, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ApplicationEligibilityRequirement,
QualitySignatureResult,
NewBEDrivingLicenseInput,
DrivinglicenseDuplicateValidityStatus,
} from './drivingLicense.type'
import {
CanApplyErrorCodeBFull,
Expand Down Expand Up @@ -44,6 +45,7 @@ import {
import { info } from 'kennitala'
import { computeCountryResidence } from '@island.is/residence-history'
import { Jurisdiction } from './graphql/models'
import addMonths from 'date-fns/addMonths'

const LOGTAG = '[api-domains-driving-license]'

Expand Down Expand Up @@ -384,6 +386,51 @@ export class DrivingLicenseService {
})
}

async canGetNewDuplicate(
token: string,
): Promise<DrivinglicenseDuplicateValidityStatus> {
const license = await this.drivingLicenseApi.getCurrentLicense({
token,
})

if (license.comments?.some((comment) => comment?.nr == '400')) {
return {
canGetNewDuplicate: false,
meta: '',
}
}

const inSixMonths = addMonths(new Date(), 6)

for (const category of license.categories ?? []) {
if (category.expires === null) {
// Technically this will result in the wrong error message
// towards the user, however, contacting the registry
// with the category information should result in the error
// being discovered anyway. We log it here for good measure though.
this.logger.warn(`${LOGTAG} Category has no expiration date`, {
category: category.name,
})
return {
canGetNewDuplicate: false,
meta: category.name,
}
}

if (category.expires < inSixMonths) {
return {
canGetNewDuplicate: false,
meta: category.name,
}
}
}

return {
canGetNewDuplicate: true,
meta: '',
}
}

async drivingLicenseDuplicateSubmission(params: {
districtId: number
token: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export interface TeachingRightsStatus {
hasTeachingRights: boolean
}

export interface DrivinglicenseDuplicateValidityStatus {
canGetNewDuplicate: boolean
meta: string
}

export interface StudentQueryInput {
nationalId: string
}
Expand Down
17 changes: 17 additions & 0 deletions libs/application/core/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,23 @@ export const coreErrorMessages = defineMessages({
description:
'Error message summary when a user already has icelandic citizenship',
},
drivingLicenseDuplicateEntryValidationErrorTitle: {
id: 'application.system:core.fetch.data.drivingLicenseDuplicateEntryValidationError',
defaultMessage: 'Ökuskírteini hæfir ekki umsókn um samrit',
description: 'Driving License duplicate entry validation error',
},
drivingLicenseDuplicateEntryValidationSign400Error: {
id: 'application.system:core.fetch.data.drivingLicenseDuplicateEntryValidationSign400Error',
defaultMessage: 'Ógild tákntala, 400, fannst á ökuskírteini',
description:
'Driving License duplicate entry validation error for sign (is: tákntala)',
},
drivingLicenseDuplicateEntryValidationExpiredCategoryLicenseError: {
id: 'application.system:core.fetch.data.drivingLicenseDuplicateEntryValidationExpiredLicenseError',
defaultMessage:
'Flokkur "{categoryName}" á ökukírteini er útrunninn eða rennur út innan 6 mánaða',
description: 'Driving License duplicate entry validation error',
},
drivingLicenseNoTeachingRightsTitle: {
id: 'application.system:core.fetch.data.drivingLicenseNoTeachingRightsTitle',
defaultMessage: 'Þú hefur ekki ökukennararéttindi í ökuskírteinaskrá.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { ApplicationTypes } from '@island.is/application/types'
import type { Logger } from '@island.is/logging'
import { LOGGER_PROVIDER } from '@island.is/logging'
import { BaseTemplateApiService } from '../../base-template-api.service'
import { TemplateApiError } from '@island.is/nest/problem'
import { coreErrorMessages } from '@island.is/application/core'

@Injectable()
export class DrivingLicenseDuplicateService extends BaseTemplateApiService {
Expand All @@ -19,6 +21,35 @@ export class DrivingLicenseDuplicateService extends BaseTemplateApiService {
super(ApplicationTypes.DRIVING_LICENSE_DUPLICATE)
}

async canGetNewDuplicate({ auth }: TemplateApiModuleActionProps) {
const can = await this.drivingLicenseService.canGetNewDuplicate(
auth.authorization,
)
if (!can.canGetNewDuplicate) {
let summary =
coreErrorMessages.drivingLicenseDuplicateEntryValidationSign400Error
if (can.meta) {
summary =
coreErrorMessages.drivingLicenseDuplicateEntryValidationExpiredCategoryLicenseError
}
throw new TemplateApiError(
{
title:
coreErrorMessages.drivingLicenseDuplicateEntryValidationErrorTitle,
description: '',
summary: {
...summary,
values: {
categoryName: can.meta,
},
},
defaultMessage: '',
},
400,
)
}
}

async submitApplication({
application,
auth,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
InstitutionNationalIds,
PaymentCatalogApi,
defineTemplateApi,
} from '@island.is/application/types'

export const SyslumadurPaymentCatalogApi = PaymentCatalogApi.configure({
Expand All @@ -9,3 +10,8 @@ export const SyslumadurPaymentCatalogApi = PaymentCatalogApi.configure({
},
externalDataId: 'payment',
})

export const DuplicateEligibilityApi = defineTemplateApi({
action: 'canGetNewDuplicate',
shouldPersistToExternalData: false,
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
QualitySignatureApi,
UserProfileApi,
} from '@island.is/application/types'
import { SyslumadurPaymentCatalogApi } from '../../dataProviders'
import {
DuplicateEligibilityApi,
SyslumadurPaymentCatalogApi,
} from '../../dataProviders'

export const sectionDataProviders = buildExternalDataProvider({
id: 'approveExternalData',
Expand All @@ -35,6 +38,11 @@ export const sectionDataProviders = buildExternalDataProvider({
title: '',
subTitle: '',
}),
buildDataProviderItem({
provider: DuplicateEligibilityApi,
title: '',
subTitle: '',
}),
buildDataProviderItem({
provider: UserProfileApi,
title: m.dataCollectionUserProfileTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import {
DrivingLicenseDuplicateFeatureFlags,
getApplicationFeatureFlags,
} from './getApplicationFeatureFlags'
import { SyslumadurPaymentCatalogApi } from '../dataProviders'
import {
DuplicateEligibilityApi,
SyslumadurPaymentCatalogApi,
} from '../dataProviders'
import {
coreHistoryMessages,
getValueViaPath,
Expand Down Expand Up @@ -121,6 +124,7 @@ const DrivingLicenseDuplicateTemplate: ApplicationTemplate<
QualitySignatureApi,
QualityPhotoApi,
UserProfileApi,
DuplicateEligibilityApi,
],
write: 'all',
delete: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface DriversLicense {
disqualification?: Disqualification | null
birthCountry?: string | null
publishPlaceName?: string | null
comments?: LicenseComments[] | null
}

export interface RemarkCode {
Expand Down
Loading