From bfa85195c75a565e9dfd924216ffa803dc32e877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Wed, 13 Nov 2024 15:44:52 +0000 Subject: [PATCH 01/16] fix: check app version --- .../src/lib/licenceService.type.ts | 2 ++ .../src/lib/licenseService.service.ts | 6 +++- .../src/lib/mappers/firearmLicenseMapper.ts | 10 ++++++- .../resolvers/licenseCollection.resolver.ts | 29 +++++++++++++------ .../src/lib/utils/appCompatibilityMode.ts | 15 ++++++++++ 5 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 libs/api/domains/license-service/src/lib/utils/appCompatibilityMode.ts diff --git a/libs/api/domains/license-service/src/lib/licenceService.type.ts b/libs/api/domains/license-service/src/lib/licenceService.type.ts index 3423724deb9a..8cb7e33f39f8 100644 --- a/libs/api/domains/license-service/src/lib/licenceService.type.ts +++ b/libs/api/domains/license-service/src/lib/licenceService.type.ts @@ -2,6 +2,7 @@ import { Locale } from '@island.is/shared/types' import { GenericLicenseError } from './dto/GenericLicenseError.dto' import { Payload } from './dto/Payload.dto' import { GenericUserLicense as GenericUserLicenseModel } from './dto/GenericUserLicense.dto' +import { UserAgent } from '@island.is/nest/core' export interface GenericLicenseMappedPayloadResponse { licenseName: string @@ -145,5 +146,6 @@ export interface GenericLicenseMapper { parsePayload: ( payload: Array, locale: Locale, + userAgent?: UserAgent, ) => Promise> } diff --git a/libs/api/domains/license-service/src/lib/licenseService.service.ts b/libs/api/domains/license-service/src/lib/licenseService.service.ts index c6cd333d783e..60de968dd761 100644 --- a/libs/api/domains/license-service/src/lib/licenseService.service.ts +++ b/libs/api/domains/license-service/src/lib/licenseService.service.ts @@ -47,6 +47,7 @@ import { BarcodeService, TOKEN_EXPIRED_ERROR, } from '@island.is/services/license' +import { UserAgent } from '@island.is/nest/core' const LOG_CATEGORY = 'license-service' @@ -96,6 +97,7 @@ export class LicenseService { user: User, locale: Locale, { includedTypes, excludedTypes, onlyList }: GetGenericLicenseOptions = {}, + userAgent?: UserAgent, ): Promise { const fetchPromises = AVAILABLE_LICENSES.map(async (license) => { if (excludedTypes && excludedTypes.indexOf(license.type) >= 0) { @@ -107,7 +109,7 @@ export class LicenseService { } if (!onlyList) { - return this.getLicensesOfType(user, locale, license.type) + return this.getLicensesOfType(user, locale, license.type, userAgent) } return null @@ -140,6 +142,7 @@ export class LicenseService { user: User, locale: Locale, licenseType: GenericLicenseType, + agent?: UserAgent, ): Promise { const licenseTypeDefinition = AVAILABLE_LICENSES.find( (i) => i.type === licenseType, @@ -187,6 +190,7 @@ export class LicenseService { const licensesPayload = await mapper.parsePayload( licensesFetchResponse.data, locale, + agent, ) const mappedLicenses: Array = await Promise.all( diff --git a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts index 089afc2143b3..a16d21388998 100644 --- a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts +++ b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts @@ -21,6 +21,8 @@ import { FormatMessage, IntlService } from '@island.is/cms-translations' import { m } from '../messages' import { expiryTag, formatDate } from '../utils' import { GenericLicenseDataField } from '../dto/GenericLicenseDataField.dto' +import { UserAgent } from '@island.is/nest/core' +import { enableAppCompatibilityMode } from '../utils/appCompatibilityMode' @Injectable() export class FirearmLicensePayloadMapper implements GenericLicenseMapper { @@ -28,9 +30,15 @@ export class FirearmLicensePayloadMapper implements GenericLicenseMapper { async parsePayload( payload: Array, locale: Locale = 'is', + userAgent?: UserAgent, ): Promise> { if (!payload) return Promise.resolve([]) + const enableAppCompatibility = enableAppCompatibilityMode( + userAgent?.app.version, + '1.4.7', + ) + const typedPayload = payload as Array const { formatMessage } = await this.intlService.useIntl( @@ -97,7 +105,7 @@ export class FirearmLicensePayloadMapper implements GenericLicenseMapper { formatMessage, ) : null, - properties + properties && enableAppCompatibility ? { type: GenericLicenseDataFieldType.Group, hideFromServicePortal: true, diff --git a/libs/api/domains/license-service/src/lib/resolvers/licenseCollection.resolver.ts b/libs/api/domains/license-service/src/lib/resolvers/licenseCollection.resolver.ts index 2cc6e34ef319..fd60fe8dfc11 100644 --- a/libs/api/domains/license-service/src/lib/resolvers/licenseCollection.resolver.ts +++ b/libs/api/domains/license-service/src/lib/resolvers/licenseCollection.resolver.ts @@ -9,19 +9,24 @@ import { ApiScope } from '@island.is/auth/scopes' import { Audit } from '@island.is/nest/audit' import type { Locale } from '@island.is/shared/types' -import { UseGuards } from '@nestjs/common' +import { Inject, UseGuards } from '@nestjs/common' import { Args, Query, Resolver } from '@nestjs/graphql' import { GetGenericLicensesInput } from '../dto/GetGenericLicenses.input' import { LicenseService } from '../licenseService.service' import { LicenseCollection } from '../dto/GenericLicenseCollection.dto' import { GenericUserLicense } from '../dto/GenericUserLicense.dto' +import { LOGGER_PROVIDER, type Logger } from '@island.is/logging' +import { ParsedUserAgent, UserAgent } from '@island.is/nest/core' @UseGuards(IdsUserGuard, ScopesGuard) @Scopes(ApiScope.internal, ApiScope.licenses) @Resolver(() => LicenseCollection) @Audit({ namespace: '@island.is/api/license-service' }) export class LicenseCollectionResolver { - constructor(private readonly licenseServiceService: LicenseService) {} + constructor( + private readonly licenseServiceService: LicenseService, + @Inject(LOGGER_PROVIDER) private readonly logger: Logger, + ) {} @Query(() => [GenericUserLicense], { deprecationReason: 'Use genericLicenseCollection instead', @@ -54,18 +59,24 @@ export class LicenseCollectionResolver { @Audit() async genericLicenseCollection( @CurrentUser() user: User, + @ParsedUserAgent() agent: UserAgent, @Args('locale', { type: () => String, nullable: true }) locale: Locale = 'is', @Args('input') input: GetGenericLicensesInput, ) { const licenseCollection = - await this.licenseServiceService.getLicenseCollection(user, locale, { - ...input, - includedTypes: input?.includedTypes ?? ['DriversLicense'], - excludedTypes: input?.excludedTypes, - force: input?.force, - onlyList: input?.onlyList, - }) + await this.licenseServiceService.getLicenseCollection( + user, + locale, + { + ...input, + includedTypes: input?.includedTypes ?? ['DriversLicense'], + excludedTypes: input?.excludedTypes, + force: input?.force, + onlyList: input?.onlyList, + }, + agent, + ) return licenseCollection } } diff --git a/libs/api/domains/license-service/src/lib/utils/appCompatibilityMode.ts b/libs/api/domains/license-service/src/lib/utils/appCompatibilityMode.ts new file mode 100644 index 000000000000..2f06d75754de --- /dev/null +++ b/libs/api/domains/license-service/src/lib/utils/appCompatibilityMode.ts @@ -0,0 +1,15 @@ +export const enableAppCompatibilityMode = ( + version?: string, + versionToCompare?: string, +): boolean => { + if (!version || !versionToCompare) { + return false + } + + const isVersionLater = version.localeCompare(versionToCompare, undefined, { + numeric: true, + sensitivity: 'base', + }) + + return isVersionLater > 0 +} From cc9e48879a1cf04d7d0bd39b38e34b8dbbf1844c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Thu, 14 Nov 2024 09:29:43 +0000 Subject: [PATCH 02/16] fix: add app ver constant --- .../license-service/src/lib/mappers/firearmLicenseMapper.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts index a16d21388998..7bf7cee9810c 100644 --- a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts +++ b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts @@ -24,6 +24,8 @@ import { GenericLicenseDataField } from '../dto/GenericLicenseDataField.dto' import { UserAgent } from '@island.is/nest/core' import { enableAppCompatibilityMode } from '../utils/appCompatibilityMode' +const APP_VERSION_CUTOFF = '1.4.7' + @Injectable() export class FirearmLicensePayloadMapper implements GenericLicenseMapper { constructor(private readonly intlService: IntlService) {} @@ -36,7 +38,7 @@ export class FirearmLicensePayloadMapper implements GenericLicenseMapper { const enableAppCompatibility = enableAppCompatibilityMode( userAgent?.app.version, - '1.4.7', + APP_VERSION_CUTOFF, ) const typedPayload = payload as Array From af486e96bc4e38a58fbf780cb1f6b851839fa6e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Thu, 14 Nov 2024 09:30:49 +0000 Subject: [PATCH 03/16] chore: add comment --- .../license-service/src/lib/mappers/firearmLicenseMapper.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts index 7bf7cee9810c..46736e215f98 100644 --- a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts +++ b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts @@ -36,6 +36,7 @@ export class FirearmLicensePayloadMapper implements GenericLicenseMapper { ): Promise> { if (!payload) return Promise.resolve([]) + //App version before 1.4.7 doesn't know how to handle table const enableAppCompatibility = enableAppCompatibilityMode( userAgent?.app.version, APP_VERSION_CUTOFF, From 3881ffb3008cdb875e86716d9f501a32d9d91cdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Thu, 14 Nov 2024 16:48:34 +0000 Subject: [PATCH 04/16] fix: import type --- .../src/lib/resolvers/licenseCollection.resolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/api/domains/license-service/src/lib/resolvers/licenseCollection.resolver.ts b/libs/api/domains/license-service/src/lib/resolvers/licenseCollection.resolver.ts index fd60fe8dfc11..d0ce6e74b8c7 100644 --- a/libs/api/domains/license-service/src/lib/resolvers/licenseCollection.resolver.ts +++ b/libs/api/domains/license-service/src/lib/resolvers/licenseCollection.resolver.ts @@ -16,7 +16,7 @@ import { LicenseService } from '../licenseService.service' import { LicenseCollection } from '../dto/GenericLicenseCollection.dto' import { GenericUserLicense } from '../dto/GenericUserLicense.dto' import { LOGGER_PROVIDER, type Logger } from '@island.is/logging' -import { ParsedUserAgent, UserAgent } from '@island.is/nest/core' +import { ParsedUserAgent, type UserAgent } from '@island.is/nest/core' @UseGuards(IdsUserGuard, ScopesGuard) @Scopes(ApiScope.internal, ApiScope.licenses) From 4c819ed362fdcffa11e4d9a1687e4490c1dc260c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Fri, 15 Nov 2024 09:18:00 +0000 Subject: [PATCH 05/16] chore: update version --- .../license-service/src/lib/mappers/firearmLicenseMapper.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts index 46736e215f98..38b10567cea1 100644 --- a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts +++ b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts @@ -24,7 +24,7 @@ import { GenericLicenseDataField } from '../dto/GenericLicenseDataField.dto' import { UserAgent } from '@island.is/nest/core' import { enableAppCompatibilityMode } from '../utils/appCompatibilityMode' -const APP_VERSION_CUTOFF = '1.4.7' +const APP_VERSION_CUTOFF = '1.4.8' @Injectable() export class FirearmLicensePayloadMapper implements GenericLicenseMapper { @@ -36,7 +36,7 @@ export class FirearmLicensePayloadMapper implements GenericLicenseMapper { ): Promise> { if (!payload) return Promise.resolve([]) - //App version before 1.4.7 doesn't know how to handle table + //App version before 1.4.8 doesn't know how to handle table const enableAppCompatibility = enableAppCompatibilityMode( userAgent?.app.version, APP_VERSION_CUTOFF, From 3f3b9465a42a5afe1e81052b21de963336353ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Fri, 15 Nov 2024 11:23:53 +0000 Subject: [PATCH 06/16] chore: add MOCKS --- .../src/lib/services/firearmApi.services.ts | 71 +++++++++++++++++-- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/libs/clients/firearm-license/src/lib/services/firearmApi.services.ts b/libs/clients/firearm-license/src/lib/services/firearmApi.services.ts index 7f6f6ee122dc..9482934062f1 100644 --- a/libs/clients/firearm-license/src/lib/services/firearmApi.services.ts +++ b/libs/clients/firearm-license/src/lib/services/firearmApi.services.ts @@ -55,7 +55,7 @@ export class FirearmApi { this.api.withMiddleware(new AuthMiddleware(user as Auth)) public async getLicenseInfo(user: User): Promise> { - const licenseInfo: Result = + /*const licenseInfo: Result = await this.firearmApiWithAuth(user) .apiFirearmApplicationLicenseInfoGet() .then((data) => { @@ -67,13 +67,27 @@ export class FirearmApi { }) .catch((e) => this.handleError(e)) - return licenseInfo + return licenseInfo*/ + + return { + ok: true, + data: { + ssn: '9742', + name: 'Bubbi byssukall', + expirationDate: '2030-04-22T15:30:23Z', + issueDate: '2017-04-22T15:30:23Z', + licenseNumber: '987654321', + qualifications: 'ABCD', + collectorLicenseExpirationDate: '2017-04-22T15:30:23Z', + address: 'Hvergigata 8', + }, + } } public async getPropertyInfo( user: User, ): Promise> { - const propertyInfo: Result = + /*const propertyInfo: Result = await this.firearmApiWithAuth(user) .apiFirearmApplicationPropertyInfoGet() .then((data) => { @@ -85,12 +99,39 @@ export class FirearmApi { }) .catch((e) => this.handleError(e)) - return propertyInfo + return propertyInfo*/ + + return { + ok: true, + data: { + licenseNumber: '987654321', + properties: [ + { + category: 'A', + typeOfFirearm: 'cannon', + name: 'Howitzer', + serialNumber: '1337', + caliber: 'vverylarge', + landsnumer: '999', + limitation: 'aint no brakes', + }, + { + category: 'B', + typeOfFirearm: 'laserrailgun', + name: 'Macguffin', + serialNumber: '010101', + caliber: '2cm', + landsnumer: '9123', + limitation: 'imagination', + }, + ], + }, + } } public async getCategories( user: User, ): Promise> { - const categories = await this.firearmApiWithAuth(user) + /*const categories = await this.firearmApiWithAuth(user) .apiFirearmApplicationCategoriesGet() .then((data) => { const result: Result = { @@ -101,6 +142,24 @@ export class FirearmApi { }) .catch((e) => this.handleError(e)) - return categories + return categories*/ + + return { + ok: true, + data: { + 'Flokkur A': + '1. Haglabyssum nr. 12 og minni, þó eigi sjálfvirkum eða hálfsjálfvirkum.\n2. Rifflum cal. 22 (long rifle og minni), þ.m.t. loftrifflum, þó eigi sjálfvirkum eða hálfsjálfvirkum.', + 'Flokkur B': + 'Leyfi fyrir rifflum með hlaupvídd allt að cal. 30 og hálfsjálfvirkum haglabyssum skal ekki veitt nema sérstakar ástæður mæli með því, enda hafi umsækjandi haft skotvopnaleyfi í a.m.k. eitt ár.', + 'Flokkur C': + 'Leyfi fyrir skotvopnum sem sérstaklega eru ætluð til minkaveiða eða meindýraeyðingar (t.d. skammbyssur fyrir haglaskot) má aðeins veita að fenginni umsögn veiðistjóra. Áskilið er að umsækjandi hafi haft aukin skotvopnaréttindi (B flokkur) í eitt ár. Slík leyfi vegna þeirra sem stunda minkaveiðar skal ekki veita til að eignast skotvopn heldur einungis til láns eða leigu. Lögreglustjóri skal senda slíkar umsóknir með umsögn sinni ríkislögreglustjóra til ákvörðunar.', + 'Flokkur D': + 'Leyfi sem sérstaklega er veitt einstaklingi eða skotfélagi fyrir skammbyssum vegna íþróttaskotfimi sbr. 11. gr. Lögreglustjóri skal senda slíkar umsóknir með umsögn sinni ríkislögreglustjóra til ákvörðunar.', + 'Flokkur E': + 'Leyfi lögreglustjóra til að hlaða skothylki til eigin nota í þau skotvopn sem viðkomandi hefur leyfi fyrir, enda sé að öðru leyti heimilt að nota slík skotfæri hér á landi.', + 'Flokkur S': + 'Söfnunarleyfi sbr. 20. gr. Reglugerð um skotvopn, skotfæri o.fl.', + }, + } } } From 695a7bb954a8107403e0361376aa25e5a6acb877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Fri, 15 Nov 2024 15:09:22 +0000 Subject: [PATCH 07/16] chore: nullcheck app --- .../license-service/src/lib/mappers/firearmLicenseMapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts index 38b10567cea1..7420335163b1 100644 --- a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts +++ b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts @@ -38,7 +38,7 @@ export class FirearmLicensePayloadMapper implements GenericLicenseMapper { //App version before 1.4.8 doesn't know how to handle table const enableAppCompatibility = enableAppCompatibilityMode( - userAgent?.app.version, + userAgent?.app?.version, APP_VERSION_CUTOFF, ) From 6d8309815c92141d8c883f4759de6c656cae8e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Mon, 18 Nov 2024 10:00:36 +0000 Subject: [PATCH 08/16] fix: reverse flag --- .../license-service/src/lib/utils/appCompatibilityMode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/api/domains/license-service/src/lib/utils/appCompatibilityMode.ts b/libs/api/domains/license-service/src/lib/utils/appCompatibilityMode.ts index 2f06d75754de..114264171863 100644 --- a/libs/api/domains/license-service/src/lib/utils/appCompatibilityMode.ts +++ b/libs/api/domains/license-service/src/lib/utils/appCompatibilityMode.ts @@ -11,5 +11,5 @@ export const enableAppCompatibilityMode = ( sensitivity: 'base', }) - return isVersionLater > 0 + return isVersionLater <= 0 } From 31e02538034921336103c06c16406191d2c0c3ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Fri, 22 Nov 2024 16:12:02 +0000 Subject: [PATCH 09/16] fix: wrong resoler method --- .../src/lib/resolvers/licenseCollection.resolver.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/api/domains/license-service/src/lib/resolvers/licenseCollection.resolver.ts b/libs/api/domains/license-service/src/lib/resolvers/licenseCollection.resolver.ts index d0ce6e74b8c7..102d14857c0f 100644 --- a/libs/api/domains/license-service/src/lib/resolvers/licenseCollection.resolver.ts +++ b/libs/api/domains/license-service/src/lib/resolvers/licenseCollection.resolver.ts @@ -34,6 +34,7 @@ export class LicenseCollectionResolver { @Audit() async genericLicenses( @CurrentUser() user: User, + @ParsedUserAgent() agent: UserAgent, @Args('locale', { type: () => String, nullable: true }) locale: Locale = 'is', @Args('input', { nullable: true }) input?: GetGenericLicensesInput, @@ -48,6 +49,7 @@ export class LicenseCollectionResolver { force: input?.force, onlyList: input?.onlyList, }, + agent, ) return collection.licenses From 206e1224910524451cb49b1c17ba9b9d1fbfdc95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Mon, 25 Nov 2024 09:54:18 +0000 Subject: [PATCH 10/16] fix: add table --- .../src/lib/mappers/firearmLicenseMapper.ts | 7 +++++-- .../license-service/src/lib/utils/appCompatibilityMode.ts | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts index 7420335163b1..68d7e5c98cd9 100644 --- a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts +++ b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts @@ -36,11 +36,14 @@ export class FirearmLicensePayloadMapper implements GenericLicenseMapper { ): Promise> { if (!payload) return Promise.resolve([]) + /* //App version before 1.4.8 doesn't know how to handle table const enableAppCompatibility = enableAppCompatibilityMode( userAgent?.app?.version, APP_VERSION_CUTOFF, - ) + ) */ + + const enableAppCompatibility = true const typedPayload = payload as Array @@ -111,7 +114,7 @@ export class FirearmLicensePayloadMapper implements GenericLicenseMapper { properties && enableAppCompatibility ? { type: GenericLicenseDataFieldType.Group, - hideFromServicePortal: true, + //hideFromServicePortal: true, label: formatMessage(m.firearmProperties), fields: (properties.properties ?? []).map((property) => ({ type: GenericLicenseDataFieldType.Category, diff --git a/libs/api/domains/license-service/src/lib/utils/appCompatibilityMode.ts b/libs/api/domains/license-service/src/lib/utils/appCompatibilityMode.ts index 114264171863..ff1cec1c61e6 100644 --- a/libs/api/domains/license-service/src/lib/utils/appCompatibilityMode.ts +++ b/libs/api/domains/license-service/src/lib/utils/appCompatibilityMode.ts @@ -6,10 +6,10 @@ export const enableAppCompatibilityMode = ( return false } - const isVersionLater = version.localeCompare(versionToCompare, undefined, { + const versionComparison = version.localeCompare(versionToCompare, undefined, { numeric: true, sensitivity: 'base', }) - return isVersionLater <= 0 + return versionComparison <= 0 } From ce00467b03d856962157dda47220d5d7b1745b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Wed, 27 Nov 2024 11:16:44 +0000 Subject: [PATCH 11/16] fix: wrong resolver method --- .../license-service/src/lib/licenseService.service.ts | 2 ++ .../src/lib/mappers/firearmLicenseMapper.ts | 7 ++----- .../src/lib/resolvers/userLicense.resolver.ts | 5 +++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libs/api/domains/license-service/src/lib/licenseService.service.ts b/libs/api/domains/license-service/src/lib/licenseService.service.ts index 60de968dd761..404777a2cf97 100644 --- a/libs/api/domains/license-service/src/lib/licenseService.service.ts +++ b/libs/api/domains/license-service/src/lib/licenseService.service.ts @@ -250,11 +250,13 @@ export class LicenseService { locale: Locale, licenseType: GenericLicenseType, licenseId?: string, + agent?: UserAgent, ): Promise { const licensesOfType = await this.getLicensesOfType( user, locale, licenseType, + agent, ) if (!licensesOfType) { diff --git a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts index 68d7e5c98cd9..7420335163b1 100644 --- a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts +++ b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts @@ -36,14 +36,11 @@ export class FirearmLicensePayloadMapper implements GenericLicenseMapper { ): Promise> { if (!payload) return Promise.resolve([]) - /* //App version before 1.4.8 doesn't know how to handle table const enableAppCompatibility = enableAppCompatibilityMode( userAgent?.app?.version, APP_VERSION_CUTOFF, - ) */ - - const enableAppCompatibility = true + ) const typedPayload = payload as Array @@ -114,7 +111,7 @@ export class FirearmLicensePayloadMapper implements GenericLicenseMapper { properties && enableAppCompatibility ? { type: GenericLicenseDataFieldType.Group, - //hideFromServicePortal: true, + hideFromServicePortal: true, label: formatMessage(m.firearmProperties), fields: (properties.properties ?? []).map((property) => ({ type: GenericLicenseDataFieldType.Category, diff --git a/libs/api/domains/license-service/src/lib/resolvers/userLicense.resolver.ts b/libs/api/domains/license-service/src/lib/resolvers/userLicense.resolver.ts index ba5f75e6c076..cc42079d6065 100644 --- a/libs/api/domains/license-service/src/lib/resolvers/userLicense.resolver.ts +++ b/libs/api/domains/license-service/src/lib/resolvers/userLicense.resolver.ts @@ -15,6 +15,8 @@ import { GenericUserLicense } from '../dto/GenericUserLicense.dto' import { GetGenericLicenseInput } from '../dto/GetGenericLicense.input' import { LicenseService } from '../licenseService.service' import { GenericLicenseError } from '../dto/GenericLicenseError.dto' +import { logger } from '@island.is/logging' +import { ParsedUserAgent, type UserAgent } from '@island.is/nest/core' @UseGuards(IdsUserGuard, ScopesGuard) @Scopes(ApiScope.internal, ApiScope.licenses) @@ -29,6 +31,8 @@ export class UserLicenseResolver { @Audit() async genericLicense( @CurrentUser() user: User, + @ParsedUserAgent() + agent: UserAgent, @Args('locale', { type: () => String, nullable: true }) locale: Locale = 'is', @Args('input') input: GetGenericLicenseInput, @@ -38,6 +42,7 @@ export class UserLicenseResolver { locale, input.licenseType, input.licenseId, + agent, ) if (license instanceof GenericLicenseError) { From 37ac338feaaa78eb2efafe4503c43f2683e8754d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Wed, 27 Nov 2024 13:17:28 +0000 Subject: [PATCH 12/16] fix: add logger --- .../src/lib/mappers/firearmLicenseMapper.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts index 7420335163b1..d98bd8df2727 100644 --- a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts +++ b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts @@ -15,7 +15,7 @@ import { GenericUserLicenseMetaLinksType, } from '../licenceService.type' import { FirearmLicenseDto } from '@island.is/clients/license-client' -import { Injectable } from '@nestjs/common' +import { Inject, Injectable } from '@nestjs/common' import { isDefined } from '@island.is/shared/utils' import { FormatMessage, IntlService } from '@island.is/cms-translations' import { m } from '../messages' @@ -23,12 +23,16 @@ import { expiryTag, formatDate } from '../utils' import { GenericLicenseDataField } from '../dto/GenericLicenseDataField.dto' import { UserAgent } from '@island.is/nest/core' import { enableAppCompatibilityMode } from '../utils/appCompatibilityMode' +import { LOGGER_PROVIDER, Logger } from '@island.is/logging' const APP_VERSION_CUTOFF = '1.4.8' @Injectable() export class FirearmLicensePayloadMapper implements GenericLicenseMapper { - constructor(private readonly intlService: IntlService) {} + constructor( + private readonly intlService: IntlService, + @Inject(LOGGER_PROVIDER) private readonly logger: Logger, + ) {} async parsePayload( payload: Array, locale: Locale = 'is', @@ -36,6 +40,8 @@ export class FirearmLicensePayloadMapper implements GenericLicenseMapper { ): Promise> { if (!payload) return Promise.resolve([]) + this.logger.info('USER INFO AGENT VERSION', userAgent?.app?.version) + //App version before 1.4.8 doesn't know how to handle table const enableAppCompatibility = enableAppCompatibilityMode( userAgent?.app?.version, From 425125e17237a87bcb37095de1f25075a4c5a6c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Wed, 27 Nov 2024 14:09:31 +0000 Subject: [PATCH 13/16] Update firearmLicenseMapper.ts --- .../license-service/src/lib/mappers/firearmLicenseMapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts index d98bd8df2727..e9f6441fe770 100644 --- a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts +++ b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts @@ -23,7 +23,7 @@ import { expiryTag, formatDate } from '../utils' import { GenericLicenseDataField } from '../dto/GenericLicenseDataField.dto' import { UserAgent } from '@island.is/nest/core' import { enableAppCompatibilityMode } from '../utils/appCompatibilityMode' -import { LOGGER_PROVIDER, Logger } from '@island.is/logging' +import { LOGGER_PROVIDER, type Logger } from '@island.is/logging' const APP_VERSION_CUTOFF = '1.4.8' From ff8eb99e39d1f1b51e9ce91723ac92db9dbd005c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Thu, 28 Nov 2024 10:19:10 +0000 Subject: [PATCH 14/16] fix: conditional return --- .../src/lib/mappers/firearmLicenseMapper.ts | 25 +++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts index e9f6441fe770..8eb16daa6f5e 100644 --- a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts +++ b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts @@ -29,10 +29,7 @@ const APP_VERSION_CUTOFF = '1.4.8' @Injectable() export class FirearmLicensePayloadMapper implements GenericLicenseMapper { - constructor( - private readonly intlService: IntlService, - @Inject(LOGGER_PROVIDER) private readonly logger: Logger, - ) {} + constructor(private readonly intlService: IntlService) {} async parsePayload( payload: Array, locale: Locale = 'is', @@ -40,8 +37,6 @@ export class FirearmLicensePayloadMapper implements GenericLicenseMapper { ): Promise> { if (!payload) return Promise.resolve([]) - this.logger.info('USER INFO AGENT VERSION', userAgent?.app?.version) - //App version before 1.4.8 doesn't know how to handle table const enableAppCompatibility = enableAppCompatibilityMode( userAgent?.app?.version, @@ -114,23 +109,11 @@ export class FirearmLicensePayloadMapper implements GenericLicenseMapper { formatMessage, ) : null, - properties && enableAppCompatibility - ? { - type: GenericLicenseDataFieldType.Group, - hideFromServicePortal: true, - label: formatMessage(m.firearmProperties), - fields: (properties.properties ?? []).map((property) => ({ - type: GenericLicenseDataFieldType.Category, - fields: this.parseProperties( - property, - formatMessage, - )?.filter(isDefined), - })), - } - : null, properties ? { - type: GenericLicenseDataFieldType.Table, + type: enableAppCompatibility + ? GenericLicenseDataFieldType.Group + : GenericLicenseDataFieldType.Table, label: formatMessage(m.firearmProperties), fields: (properties.properties ?? []).map((property) => ({ type: GenericLicenseDataFieldType.Category, From ff81c57deb41862d8e33aaf77fcd2e62469c8bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Thu, 28 Nov 2024 15:42:02 +0000 Subject: [PATCH 15/16] Update firearmLicenseMapper.ts --- .../license-service/src/lib/mappers/firearmLicenseMapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts index 8eb16daa6f5e..dd22f02159f1 100644 --- a/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts +++ b/libs/api/domains/license-service/src/lib/mappers/firearmLicenseMapper.ts @@ -25,7 +25,7 @@ import { UserAgent } from '@island.is/nest/core' import { enableAppCompatibilityMode } from '../utils/appCompatibilityMode' import { LOGGER_PROVIDER, type Logger } from '@island.is/logging' -const APP_VERSION_CUTOFF = '1.4.8' +const APP_VERSION_CUTOFF = '1.4.7' @Injectable() export class FirearmLicensePayloadMapper implements GenericLicenseMapper { From fa78c377da9c96f5dc3504159af13c56e300f8cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Eorkell=20M=C3=A1ni=20=C3=9Eorkelsson?= Date: Thu, 28 Nov 2024 15:43:21 +0000 Subject: [PATCH 16/16] fix: erase mocks --- .../src/lib/services/firearmApi.services.ts | 71 ++----------------- 1 file changed, 6 insertions(+), 65 deletions(-) diff --git a/libs/clients/firearm-license/src/lib/services/firearmApi.services.ts b/libs/clients/firearm-license/src/lib/services/firearmApi.services.ts index 9482934062f1..7f6f6ee122dc 100644 --- a/libs/clients/firearm-license/src/lib/services/firearmApi.services.ts +++ b/libs/clients/firearm-license/src/lib/services/firearmApi.services.ts @@ -55,7 +55,7 @@ export class FirearmApi { this.api.withMiddleware(new AuthMiddleware(user as Auth)) public async getLicenseInfo(user: User): Promise> { - /*const licenseInfo: Result = + const licenseInfo: Result = await this.firearmApiWithAuth(user) .apiFirearmApplicationLicenseInfoGet() .then((data) => { @@ -67,27 +67,13 @@ export class FirearmApi { }) .catch((e) => this.handleError(e)) - return licenseInfo*/ - - return { - ok: true, - data: { - ssn: '9742', - name: 'Bubbi byssukall', - expirationDate: '2030-04-22T15:30:23Z', - issueDate: '2017-04-22T15:30:23Z', - licenseNumber: '987654321', - qualifications: 'ABCD', - collectorLicenseExpirationDate: '2017-04-22T15:30:23Z', - address: 'Hvergigata 8', - }, - } + return licenseInfo } public async getPropertyInfo( user: User, ): Promise> { - /*const propertyInfo: Result = + const propertyInfo: Result = await this.firearmApiWithAuth(user) .apiFirearmApplicationPropertyInfoGet() .then((data) => { @@ -99,39 +85,12 @@ export class FirearmApi { }) .catch((e) => this.handleError(e)) - return propertyInfo*/ - - return { - ok: true, - data: { - licenseNumber: '987654321', - properties: [ - { - category: 'A', - typeOfFirearm: 'cannon', - name: 'Howitzer', - serialNumber: '1337', - caliber: 'vverylarge', - landsnumer: '999', - limitation: 'aint no brakes', - }, - { - category: 'B', - typeOfFirearm: 'laserrailgun', - name: 'Macguffin', - serialNumber: '010101', - caliber: '2cm', - landsnumer: '9123', - limitation: 'imagination', - }, - ], - }, - } + return propertyInfo } public async getCategories( user: User, ): Promise> { - /*const categories = await this.firearmApiWithAuth(user) + const categories = await this.firearmApiWithAuth(user) .apiFirearmApplicationCategoriesGet() .then((data) => { const result: Result = { @@ -142,24 +101,6 @@ export class FirearmApi { }) .catch((e) => this.handleError(e)) - return categories*/ - - return { - ok: true, - data: { - 'Flokkur A': - '1. Haglabyssum nr. 12 og minni, þó eigi sjálfvirkum eða hálfsjálfvirkum.\n2. Rifflum cal. 22 (long rifle og minni), þ.m.t. loftrifflum, þó eigi sjálfvirkum eða hálfsjálfvirkum.', - 'Flokkur B': - 'Leyfi fyrir rifflum með hlaupvídd allt að cal. 30 og hálfsjálfvirkum haglabyssum skal ekki veitt nema sérstakar ástæður mæli með því, enda hafi umsækjandi haft skotvopnaleyfi í a.m.k. eitt ár.', - 'Flokkur C': - 'Leyfi fyrir skotvopnum sem sérstaklega eru ætluð til minkaveiða eða meindýraeyðingar (t.d. skammbyssur fyrir haglaskot) má aðeins veita að fenginni umsögn veiðistjóra. Áskilið er að umsækjandi hafi haft aukin skotvopnaréttindi (B flokkur) í eitt ár. Slík leyfi vegna þeirra sem stunda minkaveiðar skal ekki veita til að eignast skotvopn heldur einungis til láns eða leigu. Lögreglustjóri skal senda slíkar umsóknir með umsögn sinni ríkislögreglustjóra til ákvörðunar.', - 'Flokkur D': - 'Leyfi sem sérstaklega er veitt einstaklingi eða skotfélagi fyrir skammbyssum vegna íþróttaskotfimi sbr. 11. gr. Lögreglustjóri skal senda slíkar umsóknir með umsögn sinni ríkislögreglustjóra til ákvörðunar.', - 'Flokkur E': - 'Leyfi lögreglustjóra til að hlaða skothylki til eigin nota í þau skotvopn sem viðkomandi hefur leyfi fyrir, enda sé að öðru leyti heimilt að nota slík skotfæri hér á landi.', - 'Flokkur S': - 'Söfnunarleyfi sbr. 20. gr. Reglugerð um skotvopn, skotfæri o.fl.', - }, - } + return categories } }