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

fix(skilavottord): Check current owner on deregistration #14763

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading