Skip to content

Commit

Permalink
fix(skilavottord): Check current owner on deregistration (#14763)
Browse files Browse the repository at this point in the history
* TRS-17 Add custom to allowedDelegations

* TRS-12
- Fix after review

* TRS-12
- Added logger when changing owner

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
birkirkristmunds and kodiakhq[bot] authored May 13, 2024
1 parent f30ad71 commit 9a55ec1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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',
Expand All @@ -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(
Expand All @@ -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)

Expand Down

0 comments on commit 9a55ec1

Please sign in to comment.