diff --git a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts index 58467e1e1b77..92f4a9dc9036 100644 --- a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts +++ b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts @@ -273,9 +273,9 @@ export class RecyclingRequestService { // If we encounter error with 'partnerId' then there is no request saved if (requestType == 'deregistered') { // 0. Ee need to be sure that the current owner is registered in our database - /* await this.icelandicTransportAuthorityServices.checkIfCurrentUser( + await this.icelandicTransportAuthorityServices.checkIfCurrentUser( permno, - )*/ + ) // 1. Check 'pendingRecycle'/'handOver' requestType const resRequestType = await this.findAllWithPermno(permno) diff --git a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts index 49c5f202d2f0..ce62cce725bb 100644 --- a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts +++ b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts @@ -85,6 +85,11 @@ export class VehicleService { if (findVehicle) { findVehicle.mileage = vehicle.mileage if (vehicle.ownerNationalId !== findVehicle.ownerNationalId) { + this.logger.info( + `car-recycling: Changing owner of the vehicle: ${vehicle.vehicleId.slice( + -3, + )}`, + ) findVehicle.ownerNationalId = vehicle.ownerNationalId } await findVehicle.save() diff --git a/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts b/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts index e437e8070a95..13c63f98197b 100644 --- a/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts +++ b/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts @@ -60,7 +60,10 @@ export class IcelandicTransportAuthorityServices { } } - async doGet(restURL: string, queryParams: { [key: string]: string }) { + async doGet( + restURL: string, + queryParams: { [key: string]: string } | undefined, + ) { const { restAuthUrl, restUsername, restPassword } = environment.samgongustofa @@ -70,16 +73,14 @@ export class IcelandicTransportAuthorityServices { restPassword, ) - // Convert the query parameters to a query string - const queryString = Object.entries(queryParams) - .map( - ([key, value]) => - `${encodeURIComponent(key)}=${encodeURIComponent(value)}`, - ) - .join('&') + let fullUrl = restURL + + if (queryParams) { + const searchParams = new URLSearchParams(queryParams) - // Concatenate the URL with the query string - const fullUrl = `${restURL}?${queryString}` + // Concatenate the URL with the query string + fullUrl = `${restURL}?${searchParams.toString()}` + } const headers = { 'Content-Type': 'application/json', @@ -106,13 +107,11 @@ export class IcelandicTransportAuthorityServices { try { const { restDeRegUrl } = environment.samgongustofa - const queryParams = { - permno, - } - return this.doGet( - this.getInformationURL(restDeRegUrl) + 'basic', - queryParams, + this.getInformationURL(restDeRegUrl) + + 'vehicleinformationmini/' + + permno, + undefined, ) } catch (err) { throw new Error( @@ -128,25 +127,23 @@ export class IcelandicTransportAuthorityServices { const result = await this.getVehicleInformation(permno) if (result && result.data) { - const currentOwnerInfo = result.data.owners.find((owner) => { - return owner.current - }) + const ownerSocialSecurityNumber = result.data.ownerSocialSecurityNumber - if (!currentOwnerInfo) { + if (!ownerSocialSecurityNumber) { logger.error( - `car-recycling: Didnt find the current owner in the basic info ${permno.slice( + `car-recycling: Didnt find the current owner in the vehicleinformationmini ${permno.slice( -3, )}`, ) throw new Error( - 'car-recycling: Didnt find the current owner in the basic info', + 'car-recycling: Didnt find the current owner in the vehicleinformationmini', ) } // If current owner hasn't sent in an car-recycling application, then he is not registered in Vehicle_Owner and therefore he needs to be registered. const owner = new VehicleOwnerModel() - owner.nationalId = currentOwnerInfo.persidno - owner.personname = currentOwnerInfo.fullname + owner.nationalId = ownerSocialSecurityNumber + owner.personname = ownerSocialSecurityNumber //Samgongustofa REST endpoint doesn't have owner name const isOwner = await this.ownerService.create(owner)