From d04808884399c578b822c21608b171a2ca05d4f5 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Thu, 29 Aug 2024 13:50:40 +0000 Subject: [PATCH 01/18] TS-866 Rough first implementation --- .../CarDetailsBox/CarDetailsBox.tsx | 74 +++++++++++- .../components/InlineError/InlineError.tsx | 16 +-- apps/skilavottord/web/i18n/locales/is.json | 3 +- .../web/i18n/locales/translation.d.ts | 1 + .../DeregisterVehicle/Confirm/Confirm.tsx | 114 +++++++++++++----- apps/skilavottord/web/utils/consts.ts | 5 + ...08263210715-addcolumns-numberplate-info.js | 24 ++++ .../recyclingRequest.resolver.ts | 9 +- .../recyclingRequest.service.ts | 18 ++- .../samgongustofa/samgongustofa.model.ts | 22 ++++ .../samgongustofa/samgongustofa.module.ts | 7 +- .../samgongustofa/samgongustofa.resolver.ts | 15 ++- .../samgongustofa/samgongustofa.service.ts | 14 ++- .../src/app/modules/vehicle/vehicle.model.ts | 24 ++++ .../app/modules/vehicle/vehicle.resolver.ts | 24 +++- .../app/modules/vehicle/vehicle.service.ts | 13 +- .../icelandicTransportAuthority.services.ts | 10 +- 17 files changed, 327 insertions(+), 66 deletions(-) create mode 100644 apps/skilavottord/ws/migrations/202408263210715-addcolumns-numberplate-info.js diff --git a/apps/skilavottord/web/components/CarDetailsBox/CarDetailsBox.tsx b/apps/skilavottord/web/components/CarDetailsBox/CarDetailsBox.tsx index 7b226468f4d2..86fd966e0120 100644 --- a/apps/skilavottord/web/components/CarDetailsBox/CarDetailsBox.tsx +++ b/apps/skilavottord/web/components/CarDetailsBox/CarDetailsBox.tsx @@ -1,10 +1,21 @@ -import { Box, Stack, Text } from '@island.is/island-ui/core' +import { + AlertMessage, + Box, + ContentBlock, + Stack, + Text, +} from '@island.is/island-ui/core' import { OutlinedBox } from '@island.is/skilavottord-web/components' -import React, { FC } from 'react' +import React, { FC, useState } from 'react' import { useI18n } from '@island.is/skilavottord-web/i18n' -import { InputController } from '@island.is/shared/form-fields' +import { + InputController, + RadioController, + SelectController, +} from '@island.is/shared/form-fields' +import { PlateInfo } from '@island.is/skilavottord-web/utils/consts' import { Control, FieldValues } from 'react-hook-form' interface BoxProps { @@ -15,6 +26,7 @@ interface BoxProps { mileage?: number control?: Control showMileage?: boolean + isDeregistered?: boolean } export const CarDetailsBox: FC> = ({ @@ -23,8 +35,8 @@ export const CarDetailsBox: FC> = ({ modelYear, vehicleOwner, mileage, - control, showMileage, + isDeregistered, }) => { const { t: { @@ -32,8 +44,23 @@ export const CarDetailsBox: FC> = ({ }, } = useI18n() + isDeregistered = true + + const [missingPlates, setMissingPlates] = useState(false) + return ( + {isDeregistered && ( + + + + + + )} > = ({ {`${vehicleType}, ${modelYear}`} {vehicleOwner} - {showMileage && ( > = ({ )} + {!isDeregistered && ( + + { + setMissingPlates(option?.value !== 2 ? true : false) + }} + /> + + + + )} ) } diff --git a/apps/skilavottord/web/components/InlineError/InlineError.tsx b/apps/skilavottord/web/components/InlineError/InlineError.tsx index 7078847692a9..77ad20b6cfb7 100644 --- a/apps/skilavottord/web/components/InlineError/InlineError.tsx +++ b/apps/skilavottord/web/components/InlineError/InlineError.tsx @@ -4,7 +4,7 @@ import { Box, Button, Icon, Stack, Text } from '@island.is/island-ui/core' export interface InlineErrorProps { title: string message: string - primaryButton: Button + primaryButton?: Button secondaryButton?: Button } @@ -40,12 +40,14 @@ export const InlineError: FC> = ({ {secondaryButton.text} )} - + {primaryButton && ( + + )} ) diff --git a/apps/skilavottord/web/i18n/locales/is.json b/apps/skilavottord/web/i18n/locales/is.json index 7b4cfc5c7825..ca72ef76207e 100644 --- a/apps/skilavottord/web/i18n/locales/is.json +++ b/apps/skilavottord/web/i18n/locales/is.json @@ -329,7 +329,8 @@ "primaryButton": "Reyna aftur", "secondaryButton": "Hætta við" }, - "currentMileage": "Núverandi kílómetrastaða" + "currentMileage": "Núverandi kílómetrastaða", + "alreadyDeregistered": "Ökutækið er nú þegar skráð úr umferð hjá Samgöngustofu" } }, "recyclingFundOverview": { diff --git a/apps/skilavottord/web/i18n/locales/translation.d.ts b/apps/skilavottord/web/i18n/locales/translation.d.ts index a43d1c7e44e9..b8c99434b0bc 100644 --- a/apps/skilavottord/web/i18n/locales/translation.d.ts +++ b/apps/skilavottord/web/i18n/locales/translation.d.ts @@ -273,6 +273,7 @@ export interface Deregister { success: string error: CompletedError currentMileage: string + alreadyDeregistered: string } export interface DeregisterButtons { diff --git a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx index d89e2f6c7ea1..2c5c013b284f 100644 --- a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx +++ b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx @@ -34,7 +34,8 @@ import { } from '@island.is/skilavottord-web/graphql/schema' import { useI18n } from '@island.is/skilavottord-web/i18n' import { getYear } from '@island.is/skilavottord-web/utils/dateUtils' -import { useForm } from 'react-hook-form' +import { FormProvider, useForm } from 'react-hook-form' +import { PlateInfo } from '@island.is/skilavottord-web/utils/consts' const SkilavottordVehicleReadyToDeregisteredQuery = gql` query skilavottordVehicleReadyToDeregisteredQuery($permno: String!) { @@ -50,6 +51,16 @@ const SkilavottordVehicleReadyToDeregisteredQuery = gql` } ` +const SkilavottordVehicleInformationQuery = gql` + query skilavottordVehicleInformationQuery($permno: String!) { + skilavottordVehicleInformation(permno: $permno) { + permno + ownerSocialSecurityNumber + vehicleStatus + } + } +` + const SkilavottordRecyclingRequestMutation = gql` mutation skilavottordRecyclingRequestMutation( $permno: String! @@ -70,19 +81,31 @@ const SkilavottordRecyclingRequestMutation = gql` } ` -const UpdateSkilavottordVehicleMileageMutation = gql` - mutation updateSkilavottordVehicleMileage( +const UpdateSkilavottordVehicleInfoMutation = gql` + mutation updateSkilavottordVehicleInfo( $permno: String! $mileage: Float! + $plateCount: Float! + $plateDestroyed: Float! + $plateLost: Float! + $deregistered: Boolean! ) { - updateSkilavottordVehicleMileage(permno: $permno, mileage: $mileage) + updateSkilavottordVehicleInfo( + permno: $permno + mileage: $mileage + plateCount: $plateCount + plateDestroyed: $plateDestroyed + plateLost: $plateLost + deregistered: $deregistered + ) } ` const Confirm: FC> = () => { - const { control, watch } = useForm({ + const methods = useForm({ mode: 'onChange', }) + const { watch } = methods const { user } = useContext(UserContext) const { @@ -95,6 +118,8 @@ const Confirm: FC> = () => { const { id } = router.query const mileageValue = watch('mileage') + const plateInfo = watch('plateInfo') + const plateCountValue = watch('plateCount') const { data, loading } = useQuery( SkilavottordVehicleReadyToDeregisteredQuery, @@ -105,6 +130,18 @@ const Confirm: FC> = () => { const vehicle = data?.skilavottordVehicleReadyToDeregistered + const { data: info, loading: loadingInfo } = useQuery( + SkilavottordVehicleInformationQuery, + { + variables: { permno: id }, + }, + ) + + const vehicleInfo = info?.skilavottordVehicleInformation + console.log('vehicleInfo', vehicleInfo) + const isDeregistered = + vehicleInfo?.vehicleStatus.toLocaleLowerCase() === 'afskráð' + const [ setRecyclingRequest, { data: mutationData, error: mutationError, loading: mutationLoading }, @@ -129,7 +166,7 @@ const Confirm: FC> = () => { error: vehicleMutationError, loading: vehicleMutationLoading, }, - ] = useMutation(UpdateSkilavottordVehicleMileageMutation, { + ] = useMutation(UpdateSkilavottordVehicleInfoMutation, { onError() { return vehicleMutationError }, @@ -144,20 +181,33 @@ const Confirm: FC> = () => { }, [vehicleMutationResponse, router, routes, t.success]) const handleConfirm = () => { - if (mileageValue !== undefined) { - const newMilage = +mileageValue.trim().replace(/\./g, '') + let newMileage = mileageValue - // If registered mileage is not the same as the one when vehicle is confirmed for de-registration we need to update it - if (vehicle?.mileage !== newMilage) { - setVehicleRequest({ - variables: { - permno: vehicle?.vehicleId, - mileage: newMilage, - }, - }) - } + if (mileageValue !== undefined) { + newMileage = +mileageValue.trim().replace(/\./g, '') } + console.log('handleConfirm', { + plateCountValue, + plateLostValue: plateInfo === PlateInfo.PLATE_LOST ? 1 : 0, + plateDestroyedValue: plateInfo === PlateInfo.PLATE_DESTROYED ? 1 : 0, + isDeregistered, + mileageValue, + }) + + // Update vehicle table with latests information + setVehicleRequest({ + variables: { + permno: vehicle?.vehicleId, + mileage: newMileage, + plateCount: plateCountValue, + plateLost: plateInfo === PlateInfo.PLATE_LOST ? 1 : 0, + plateDestroyed: plateInfo === PlateInfo.PLATE_DESTROYED ? 1 : 0, + deregistered: isDeregistered, + }, + }) + + // Send recycling request setRecyclingRequest({ variables: { permno: id, @@ -165,7 +215,6 @@ const Confirm: FC> = () => { }, }) } - const handleBack = () => { router.replace(routes.select) } @@ -221,22 +270,24 @@ const Confirm: FC> = () => { {t.titles.success} {t.info.success} - + + + ) : ( - {loading ? ( + {loading || loadingInfo ? ( @@ -280,5 +331,4 @@ const Confirm: FC> = () => { ) } - export default Confirm diff --git a/apps/skilavottord/web/utils/consts.ts b/apps/skilavottord/web/utils/consts.ts index 675f1b64953d..3657bc3303e0 100644 --- a/apps/skilavottord/web/utils/consts.ts +++ b/apps/skilavottord/web/utils/consts.ts @@ -1 +1,6 @@ export const ACCEPTED_TERMS_AND_CONDITION = 'acceptedTermsAndConditions' + +export enum PlateInfo { + PLATE_LOST = '0', + PLATE_DESTROYED = '1', +} diff --git a/apps/skilavottord/ws/migrations/202408263210715-addcolumns-numberplate-info.js b/apps/skilavottord/ws/migrations/202408263210715-addcolumns-numberplate-info.js new file mode 100644 index 000000000000..8145e7eada85 --- /dev/null +++ b/apps/skilavottord/ws/migrations/202408263210715-addcolumns-numberplate-info.js @@ -0,0 +1,24 @@ +'use strict' + +//add number plate & deregistered info change +module.exports = { + up: (queryInterface) => { + return queryInterface.sequelize.query(` + BEGIN; + ALTER TABLE vehicle ADD COLUMN plate_count INT; + ALTER TABLE vehicle ADD COLUMN plate_lost INT; + ALTER TABLE vehicle ADD COLUMN plate_destroyed INT; + ALTER TABLE vehicle ADD COLUMN deregistered BOOLEAN; + COMMIT; + `) + }, + + down: (queryInterface) => { + return queryInterface.sequelize.query(` + ALTER TABLE vehicle DROP COLUMN plate_count; + ALTER TABLE vehicle DROP COLUMN plate_lost; + ALTER TABLE vehicle DROP COLUMN plate_destroyed; + ALTER TABLE vehicle DROP COLUMN deregistered; + `) + }, +} diff --git a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.resolver.ts b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.resolver.ts index 0ba166e195d0..218314fa7557 100644 --- a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.resolver.ts +++ b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.resolver.ts @@ -76,11 +76,10 @@ export class RecyclingRequestResolver { @Args('recyclingPartner') station: string, @Args('mileage', { type: () => Int, nullable: true }) mileage: number, ): Promise { - return this.recyclingRequestService.deRegisterVehicle( - permno, - station, - mileage, - ) + console.log('skilavottordDeRegisterVehicle -- HVER ER AÐ KALLA') + throw new Error('Not implemented') + + return undefined //this.recyclingRequestService.deRegisterVehicle(permno, station, 0) } @Authorize({ 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 653525a1e904..ca004ef7356e 100644 --- a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts +++ b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts @@ -39,7 +39,7 @@ export class RecyclingRequestService { async deRegisterVehicle( vehiclePermno: string, disposalStation: string, - mileage = 0, + vehicle: VehicleModel, ) { try { const { restAuthUrl, restDeRegUrl, restUsername, restPassword } = @@ -68,19 +68,26 @@ export class RecyclingRequestService { const jsonDeRegBody = JSON.stringify({ permno: vehiclePermno, deRegisterDate: format(new Date(), "yyyy-MM-dd'T'HH:mm:ss"), - disposalstation: disposalStation, + disposalStation: disposalStation, explanation: 'Rafrænt afskráning', - mileage: mileage, + mileage: vehicle.mileage ?? 0, + plateCount: vehicle.plateCount, + destroyed: vehicle.plateDestroyed ?? 0, + lost: vehicle.plateLost ?? 0, }) + + console.log('XXXXjsonDeRegBodyXXXXXX', jsonDeRegBody) const headerDeRegRequest = { 'Content-Type': 'application/json', Authorization: 'Bearer ' + jToken, } + const deRegRes = await lastValueFrom( this.httpService.post(restDeRegUrl, jsonDeRegBody, { headers: headerDeRegRequest, }), ) + if (deRegRes.status < 300 && deRegRes.status >= 200) { return true } else { @@ -89,7 +96,8 @@ export class RecyclingRequestService { ) } } catch (err) { - delete err.data + delete err?.data + delete err?.response?.config?.data this.logger.error(`Failed to deregister vehicle`, { error: err }) throw new Error(`Failed to deregister vehicle ${vehiclePermno.slice(-3)}`) } @@ -340,7 +348,7 @@ export class RecyclingRequestService { }, ) - await this.deRegisterVehicle(permno, partnerId, vehicle.mileage ?? 0) + await this.deRegisterVehicle(permno, partnerId, vehicle) } catch (err) { // Saved requestType back to 'pendingRecycle' const req = new RecyclingRequestModel() diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.model.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.model.ts index 74e49c8d5db7..39e6a21f4bb3 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.model.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.model.ts @@ -46,3 +46,25 @@ export class VehicleInformation { @Field() status: string } + +@ObjectType() +export class VehicleInformationMini { + constructor( + permno: string, + ownerSocialSecurityNumber: string, + vehicleStatus: string, + ) { + this.permno = permno + this.ownerSocialSecurityNumber = ownerSocialSecurityNumber + this.vehicleStatus = vehicleStatus + } + + @Field() + permno: string + + @Field() + ownerSocialSecurityNumber: string + + @Field() + vehicleStatus: string +} diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.module.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.module.ts index 5f4511c1a420..c8ea7b09da62 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.module.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.module.ts @@ -5,9 +5,14 @@ import { RecyclingRequestModule } from '../recyclingRequest/recyclingRequest.mod import { SamgongustofaService } from './samgongustofa.service' import { SamgongustofaResolver } from './samgongustofa.resolver' +import { IcelandicTransportAuthorityModule } from '../../services/icelandicTransportAuthority.module' @Module({ - imports: [HttpModule, forwardRef(() => RecyclingRequestModule)], + imports: [ + HttpModule, + forwardRef(() => RecyclingRequestModule), + forwardRef(() => IcelandicTransportAuthorityModule), + ], providers: [SamgongustofaResolver, SamgongustofaService], exports: [SamgongustofaService], }) diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.resolver.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.resolver.ts index 2c87339b8508..ecab171d2ebd 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.resolver.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.resolver.ts @@ -1,6 +1,9 @@ -import { Query, Resolver } from '@nestjs/graphql' +import { Args, Query, Resolver } from '@nestjs/graphql' import { Authorize, CurrentUser, User } from '../auth' -import { VehicleInformation } from './samgongustofa.model' +import { + VehicleInformation, + VehicleInformationMini, +} from './samgongustofa.model' import { SamgongustofaService } from './samgongustofa.service' @Authorize() @@ -14,4 +17,12 @@ export class SamgongustofaResolver { ): Promise> { return this.samgongustofaService.getUserVehiclesInformation(user.nationalId) } + + @Query(() => VehicleInformationMini) + async skilavottordVehicleInformation( + @CurrentUser() user: User, + @Args('permno') permno: string, + ): Promise { + return this.samgongustofaService.getVehicleInformation(permno) + } } diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts index 87610c34a5d3..0583df02ca9f 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts @@ -5,8 +5,12 @@ import * as xml2js from 'xml2js' import { environment } from '../../../environments' import { RecyclingRequestService } from '../recyclingRequest' -import { VehicleInformation } from './samgongustofa.model' +import { + VehicleInformation, + VehicleInformationMini, +} from './samgongustofa.model' import { logger } from '@island.is/logging' +import { IcelandicTransportAuthorityServices } from '../../services/icelandicTransportAuthority.services' @Injectable() export class SamgongustofaService { @@ -14,6 +18,8 @@ export class SamgongustofaService { private httpService: HttpService, @Inject(forwardRef(() => RecyclingRequestService)) private recyclingRequestService: RecyclingRequestService, + @Inject(forwardRef(() => IcelandicTransportAuthorityServices)) + private icelandicTransportAuthorityServices: IcelandicTransportAuthorityServices, ) {} async getUserVehiclesInformation( @@ -321,4 +327,10 @@ export class SamgongustofaService { } return car } + + async getVehicleInformation(permno: string): Promise { + return await this.icelandicTransportAuthorityServices.checkIfCurrentUser( + permno, + ) + } } diff --git a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts index fb9a15d3b634..9ad08f8a9d22 100644 --- a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts +++ b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts @@ -80,6 +80,30 @@ export class VehicleModel extends Model { @Field(() => [RecyclingRequestModel], { nullable: true }) @HasMany(() => RecyclingRequestModel) recyclingRequests!: RecyclingRequestModel[] + + @Field({ nullable: true }) + @Column({ + type: DataType.INTEGER, + }) + plateLost?: number + + @Field({ nullable: true }) + @Column({ + type: DataType.INTEGER, + }) + plateDestroyed?: number + + @Field({ nullable: true }) + @Column({ + type: DataType.INTEGER, + }) + plateCount?: number + + @Field({ nullable: true }) + @Column({ + type: DataType.BOOLEAN, + }) + deregistered?: boolean } @ObjectType() diff --git a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts index b52c8fd483c2..c9f5e184ef5d 100644 --- a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts +++ b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts @@ -104,11 +104,31 @@ export class VehicleResolver { } @Mutation(() => Boolean) - async updateSkilavottordVehicleMileage( + async updateSkilavottordVehicleInfo( @CurrentUser() user: User, @Args('permno') permno: string, @Args('mileage') mileage: number, + @Args('plateCount') plateCount: number, + @Args('plateDestroyed') plateDestroyed: number, + @Args('plateLost') plateLost: number, + @Args('deregistered') deregistered: boolean, ) { - return await this.vehicleService.updateMileage(permno, mileage) + console.log('updateSkilavottordVehicleInfo -Resolver', { + permno, + mileage, + plateCount, + plateDestroyed, + plateLost, + deregistered, + }) + + return await this.vehicleService.updateVehicleInfo( + permno, + mileage, + plateCount, + plateDestroyed, + plateLost, + deregistered, + ) } } 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 ce62cce725bb..59d681d551bd 100644 --- a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts +++ b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts @@ -60,10 +60,21 @@ export class VehicleService { } } - async updateMileage(permno: string, mileage: number): Promise { + async updateVehicleInfo( + permno: string, + mileage: number, + plateCount: number, + plateDestroyed: number, + plateLost: number, + deregistered: boolean, + ): Promise { const findVehicle = await this.findByVehicleId(permno) if (findVehicle) { findVehicle.mileage = mileage ?? 0 + findVehicle.plateCount = plateCount ?? 0 + findVehicle.plateDestroyed = plateDestroyed ?? 0 + findVehicle.plateLost = plateLost ?? 0 + findVehicle.deregistered = deregistered ?? false await findVehicle.save() return true } else { diff --git a/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts b/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts index 83062615d9e5..1dff07d119fd 100644 --- a/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts +++ b/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts @@ -6,6 +6,7 @@ import { logger } from '@island.is/logging' import { VehicleModel, VehicleService } from '../modules/vehicle' import { VehicleOwnerModel } from '../modules/vehicleOwner' import { VehicleOwnerService } from '../modules/vehicleOwner/vehicleOwner.service' +import { VehicleInformationMini } from '../modules/samgongustofa/samgongustofa.model' @Injectable() export class IcelandicTransportAuthorityServices { @@ -55,7 +56,8 @@ export class IcelandicTransportAuthorityServices { return authRes.data['jwtToken'] } catch (error) { - delete error.config + delete error?.config + delete error?.response?.config?.data logger.error('car-recycling: Authentication failed on information', error) throw error } @@ -108,6 +110,8 @@ export class IcelandicTransportAuthorityServices { try { const { restDeRegUrl } = environment.samgongustofa + console.log('getVehicleInformation', permno) + return this.doGet( this.getInformationURL(restDeRegUrl) + 'vehicleinformationmini/' + @@ -123,7 +127,7 @@ export class IcelandicTransportAuthorityServices { } } - async checkIfCurrentUser(permno: string): Promise { + async checkIfCurrentUser(permno: string): Promise { //Get the latest vehicle information from Samgongustofa const result = await this.getVehicleInformation(permno) @@ -157,7 +161,7 @@ export class IcelandicTransportAuthorityServices { await this.vehicleService.create(vehicle) } - return true + return result.data } logger.error( From c8cfd53c7809fa849a2758ead58045332b82dace Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Wed, 4 Sep 2024 10:31:46 +0000 Subject: [PATCH 02/18] =?UTF-8?q?TS-866=20Implemented=20Samg=C3=B6ngustofa?= =?UTF-8?q?=20Traffic=20REST=20call.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CarDetailsBox/CarDetailsBox.tsx | 16 ++- .../DeregisterVehicle/Confirm/Confirm.tsx | 36 ++++--- apps/skilavottord/web/utils/consts.ts | 1 - ...9033210715-addcolumns-numberplate-info.js} | 4 +- .../recyclingRequest.service.ts | 6 +- .../samgongustofa/samgongustofa.model.ts | 32 ++++++ .../samgongustofa/samgongustofa.module.ts | 10 +- .../samgongustofa/samgongustofa.resolver.ts | 13 +-- .../samgongustofa/samgongustofa.service.ts | 64 +++++++++--- .../modules/samgongustofa/transport/index.ts | 1 + .../transport/transport.service.ts | 98 +++++++++++++++++++ .../src/app/modules/vehicle/vehicle.model.ts | 6 -- .../app/modules/vehicle/vehicle.resolver.ts | 3 - .../app/modules/vehicle/vehicle.service.ts | 3 +- 14 files changed, 226 insertions(+), 67 deletions(-) rename apps/skilavottord/ws/migrations/{202408263210715-addcolumns-numberplate-info.js => 202409033210715-addcolumns-numberplate-info.js} (76%) create mode 100644 apps/skilavottord/ws/src/app/modules/samgongustofa/transport/index.ts create mode 100644 apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts diff --git a/apps/skilavottord/web/components/CarDetailsBox/CarDetailsBox.tsx b/apps/skilavottord/web/components/CarDetailsBox/CarDetailsBox.tsx index 86fd966e0120..d5c1093ab711 100644 --- a/apps/skilavottord/web/components/CarDetailsBox/CarDetailsBox.tsx +++ b/apps/skilavottord/web/components/CarDetailsBox/CarDetailsBox.tsx @@ -11,12 +11,13 @@ import React, { FC, useState } from 'react' import { useI18n } from '@island.is/skilavottord-web/i18n' import { + CheckboxController, InputController, - RadioController, SelectController, } from '@island.is/shared/form-fields' -import { PlateInfo } from '@island.is/skilavottord-web/utils/consts' + import { Control, FieldValues } from 'react-hook-form' +import { PlateInfo } from '@island.is/skilavottord-web/utils/consts' interface BoxProps { vehicleId: string @@ -44,7 +45,7 @@ export const CarDetailsBox: FC> = ({ }, } = useI18n() - isDeregistered = true + //isDeregistered = true const [missingPlates, setMissingPlates] = useState(false) @@ -86,7 +87,7 @@ export const CarDetailsBox: FC> = ({ )} - {!isDeregistered && ( + {isDeregistered && ( > = ({ }} /> - diff --git a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx index 2c5c013b284f..38a344f1fdb6 100644 --- a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx +++ b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx @@ -51,6 +51,17 @@ const SkilavottordVehicleReadyToDeregisteredQuery = gql` } ` +const SkilavottordTrafficQuery = gql` + query skilavottordTrafficQuery($permno: String!) { + skilavottordTraffic(permno: $permno) { + permno + outInStatus + useStatus + useStatusName + } + } +` + const SkilavottordVehicleInformationQuery = gql` query skilavottordVehicleInformationQuery($permno: String!) { skilavottordVehicleInformation(permno: $permno) { @@ -86,7 +97,6 @@ const UpdateSkilavottordVehicleInfoMutation = gql` $permno: String! $mileage: Float! $plateCount: Float! - $plateDestroyed: Float! $plateLost: Float! $deregistered: Boolean! ) { @@ -94,7 +104,7 @@ const UpdateSkilavottordVehicleInfoMutation = gql` permno: $permno mileage: $mileage plateCount: $plateCount - plateDestroyed: $plateDestroyed + plateLost: $plateLost deregistered: $deregistered ) @@ -130,17 +140,22 @@ const Confirm: FC> = () => { const vehicle = data?.skilavottordVehicleReadyToDeregistered - const { data: info, loading: loadingInfo } = useQuery( - SkilavottordVehicleInformationQuery, + const { data: traffic, loading: loadingTraffic } = useQuery( + SkilavottordTrafficQuery, { variables: { permno: id }, }, ) - const vehicleInfo = info?.skilavottordVehicleInformation - console.log('vehicleInfo', vehicleInfo) + const vehicleTrafficData = traffic?.skilavottordTraffic + console.log( + 'vehicle TRAFFIC', + vehicleTrafficData?.outInStatus.toLocaleUpperCase(), + ) const isDeregistered = - vehicleInfo?.vehicleStatus.toLocaleLowerCase() === 'afskráð' + vehicleTrafficData?.outInStatus.toLocaleUpperCase() === 'OUT' + + console.log('fsadfadsfa ', { isDeregistered }) const [ setRecyclingRequest, @@ -190,7 +205,7 @@ const Confirm: FC> = () => { console.log('handleConfirm', { plateCountValue, plateLostValue: plateInfo === PlateInfo.PLATE_LOST ? 1 : 0, - plateDestroyedValue: plateInfo === PlateInfo.PLATE_DESTROYED ? 1 : 0, + isDeregistered, mileageValue, }) @@ -201,8 +216,7 @@ const Confirm: FC> = () => { permno: vehicle?.vehicleId, mileage: newMileage, plateCount: plateCountValue, - plateLost: plateInfo === PlateInfo.PLATE_LOST ? 1 : 0, - plateDestroyed: plateInfo === PlateInfo.PLATE_DESTROYED ? 1 : 0, + plateLost: plateInfo === PlateInfo.PLATE_LOST ? true : false, deregistered: isDeregistered, }, }) @@ -287,7 +301,7 @@ const Confirm: FC> = () => { ) : ( - {loading || loadingInfo ? ( + {loading || loadingTraffic ? ( diff --git a/apps/skilavottord/web/utils/consts.ts b/apps/skilavottord/web/utils/consts.ts index 3657bc3303e0..cc2eb30dcc38 100644 --- a/apps/skilavottord/web/utils/consts.ts +++ b/apps/skilavottord/web/utils/consts.ts @@ -2,5 +2,4 @@ export const ACCEPTED_TERMS_AND_CONDITION = 'acceptedTermsAndConditions' export enum PlateInfo { PLATE_LOST = '0', - PLATE_DESTROYED = '1', } diff --git a/apps/skilavottord/ws/migrations/202408263210715-addcolumns-numberplate-info.js b/apps/skilavottord/ws/migrations/202409033210715-addcolumns-numberplate-info.js similarity index 76% rename from apps/skilavottord/ws/migrations/202408263210715-addcolumns-numberplate-info.js rename to apps/skilavottord/ws/migrations/202409033210715-addcolumns-numberplate-info.js index 8145e7eada85..0ed143d0f28c 100644 --- a/apps/skilavottord/ws/migrations/202408263210715-addcolumns-numberplate-info.js +++ b/apps/skilavottord/ws/migrations/202409033210715-addcolumns-numberplate-info.js @@ -6,8 +6,7 @@ module.exports = { return queryInterface.sequelize.query(` BEGIN; ALTER TABLE vehicle ADD COLUMN plate_count INT; - ALTER TABLE vehicle ADD COLUMN plate_lost INT; - ALTER TABLE vehicle ADD COLUMN plate_destroyed INT; + ALTER TABLE vehicle ADD COLUMN plate_lost BOOLEAN; ALTER TABLE vehicle ADD COLUMN deregistered BOOLEAN; COMMIT; `) @@ -17,7 +16,6 @@ module.exports = { return queryInterface.sequelize.query(` ALTER TABLE vehicle DROP COLUMN plate_count; ALTER TABLE vehicle DROP COLUMN plate_lost; - ALTER TABLE vehicle DROP COLUMN plate_destroyed; ALTER TABLE vehicle DROP COLUMN deregistered; `) }, 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 ca004ef7356e..99333544ea52 100644 --- a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts +++ b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts @@ -72,16 +72,16 @@ export class RecyclingRequestService { explanation: 'Rafrænt afskráning', mileage: vehicle.mileage ?? 0, plateCount: vehicle.plateCount, - destroyed: vehicle.plateDestroyed ?? 0, - lost: vehicle.plateLost ?? 0, + lost: vehicle.plateLost ? 1 : 0, }) - console.log('XXXXjsonDeRegBodyXXXXXX', jsonDeRegBody) const headerDeRegRequest = { 'Content-Type': 'application/json', Authorization: 'Bearer ' + jToken, } + console.log('Sending TO Samgögnustafa', jsonDeRegBody) + const deRegRes = await lastValueFrom( this.httpService.post(restDeRegUrl, jsonDeRegBody, { headers: headerDeRegRequest, diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.model.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.model.ts index 39e6a21f4bb3..67ffc5b2c271 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.model.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.model.ts @@ -68,3 +68,35 @@ export class VehicleInformationMini { @Field() vehicleStatus: string } + +@ObjectType() +export class Traffic { + constructor( + permno: string, + outInStatus: string, + useStatus: string, + useStatusName: string, + useDate: string, + ) { + this.permno = permno + this.outInStatus = outInStatus + this.useStatus = useStatus + this.useStatusName = useStatusName + this.useDate = useDate + } + + @Field() + permno: string + + @Field() + outInStatus: string + + @Field() + useStatus: string + + @Field() + useStatusName: string + + @Field() + useDate: string +} diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.module.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.module.ts index c8ea7b09da62..ccee791fd703 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.module.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.module.ts @@ -5,15 +5,11 @@ import { RecyclingRequestModule } from '../recyclingRequest/recyclingRequest.mod import { SamgongustofaService } from './samgongustofa.service' import { SamgongustofaResolver } from './samgongustofa.resolver' -import { IcelandicTransportAuthorityModule } from '../../services/icelandicTransportAuthority.module' +import { TransportService } from './transport/transport.service' @Module({ - imports: [ - HttpModule, - forwardRef(() => RecyclingRequestModule), - forwardRef(() => IcelandicTransportAuthorityModule), - ], - providers: [SamgongustofaResolver, SamgongustofaService], + imports: [HttpModule, forwardRef(() => RecyclingRequestModule)], + providers: [SamgongustofaResolver, SamgongustofaService, TransportService], exports: [SamgongustofaService], }) export class SamgongustofaModule {} diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.resolver.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.resolver.ts index ecab171d2ebd..5e343fc54532 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.resolver.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.resolver.ts @@ -1,9 +1,6 @@ import { Args, Query, Resolver } from '@nestjs/graphql' import { Authorize, CurrentUser, User } from '../auth' -import { - VehicleInformation, - VehicleInformationMini, -} from './samgongustofa.model' +import { Traffic, VehicleInformation } from './samgongustofa.model' import { SamgongustofaService } from './samgongustofa.service' @Authorize() @@ -18,11 +15,11 @@ export class SamgongustofaResolver { return this.samgongustofaService.getUserVehiclesInformation(user.nationalId) } - @Query(() => VehicleInformationMini) - async skilavottordVehicleInformation( + @Query(() => Traffic) + async skilavottordTraffic( @CurrentUser() user: User, @Args('permno') permno: string, - ): Promise { - return this.samgongustofaService.getVehicleInformation(permno) + ): Promise { + return this.samgongustofaService.getTraffic(permno) } } diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts index 0583df02ca9f..4e78d6ea0834 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts @@ -1,16 +1,14 @@ -import { Injectable, Inject, forwardRef } from '@nestjs/common' import { HttpService } from '@nestjs/axios' +import { forwardRef, Inject, Injectable } from '@nestjs/common' import { lastValueFrom } from 'rxjs' import * as xml2js from 'xml2js' import { environment } from '../../../environments' import { RecyclingRequestService } from '../recyclingRequest' -import { - VehicleInformation, - VehicleInformationMini, -} from './samgongustofa.model' -import { logger } from '@island.is/logging' -import { IcelandicTransportAuthorityServices } from '../../services/icelandicTransportAuthority.services' +import { Traffic, VehicleInformation } from './samgongustofa.model' + +import { Logger, logger, LOGGER_PROVIDER } from '@island.is/logging' +import { TransportService } from './transport/transport.service' @Injectable() export class SamgongustofaService { @@ -18,10 +16,16 @@ export class SamgongustofaService { private httpService: HttpService, @Inject(forwardRef(() => RecyclingRequestService)) private recyclingRequestService: RecyclingRequestService, - @Inject(forwardRef(() => IcelandicTransportAuthorityServices)) - private icelandicTransportAuthorityServices: IcelandicTransportAuthorityServices, + @Inject(LOGGER_PROVIDER) private logger: Logger, + private transportService: TransportService, ) {} + /** + * + * @param nationalId + * @deprecated + * @returns + */ async getUserVehiclesInformation( nationalId: string, ): Promise { @@ -312,6 +316,14 @@ export class SamgongustofaService { } } + /** + * + * @param nationalId + * @param permno + * @param requireRecyclable + * @deprecated + * @returns + */ async getUserVehicle( nationalId: string, permno: string, @@ -328,9 +340,35 @@ export class SamgongustofaService { return car } - async getVehicleInformation(permno: string): Promise { - return await this.icelandicTransportAuthorityServices.checkIfCurrentUser( - permno, - ) + async getTraffic(permno: string): Promise { + try { + const url = this.transportService.getRegistrationURL() + + const result = await this.transportService.doGet( + url + 'traffic/' + 'LT579', + undefined, + ) + + if (result.status === 200) { + console.log('GOT TRAFFIC', result.data) + + // Get the latest registered traffic data + return Object.values(result.data).reduce( + (prev: Traffic, current: Traffic) => + new Date(prev.useDate) > new Date(current.useDate) ? prev : current, + {} as Traffic, + ) as Traffic + } + + throw new Error( + `car-recycling: #1 Failed on getTraffic ${permno.slice(-3)}`, + ) + } catch (err) { + throw new Error( + `car-recycling: #2 Failed on getTraffic ${permno.slice( + -3, + )} because: ${err}`, + ) + } } } diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/index.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/index.ts new file mode 100644 index 000000000000..8d7c134af4ac --- /dev/null +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/index.ts @@ -0,0 +1 @@ +export { TransportService } from './transport.service' diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts new file mode 100644 index 000000000000..a5c2e1827445 --- /dev/null +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts @@ -0,0 +1,98 @@ +import { Injectable } from '@nestjs/common' +import { HttpService } from '@nestjs/axios' +import { lastValueFrom } from 'rxjs' +import { environment } from '../../../../environments' +import { logger } from '@island.is/logging' + +@Injectable() +export class TransportService { + constructor(private httpService: HttpService) {} + + async authenticate() { + try { + const { restAuthUrl, restUsername, restPassword } = + environment.samgongustofa + + if (!restAuthUrl || !restUsername || !restPassword) { + throw new Error('Missing environment variables for Samgöngustofa') + } + + const jsonObj = { + username: restUsername, + password: restPassword, + } + const jsonAuthBody = JSON.stringify(jsonObj) + + const headerAuthRequest = { + 'Content-Type': 'application/json', + } + + const authRes = await lastValueFrom( + this.httpService.post(restAuthUrl, jsonAuthBody, { + headers: headerAuthRequest, + }), + ) + + if (authRes.status > 299 || authRes.status < 200) { + const errorMessage = `Authentication failed to Samgöngustofa services: ${authRes.statusText}` + logger.error(`car-recycling: ${errorMessage}`) + throw new Error(errorMessage) + } + + return authRes.data['jwtToken'] + } catch (error) { + delete error?.config + delete error?.response?.config?.data + logger.error('car-recycling: Authentication failed', error) + throw error + } + } + + async doGet( + restURL: string, + queryParams: { [key: string]: string } | undefined, + ) { + console.log('DOGet #1') + const jwtToken = await this.authenticate() + + console.log('DOGet #2', { restURL }) + + let fullUrl = restURL + + if (queryParams) { + const searchParams = new URLSearchParams(queryParams) + + // Concatenate the URL with the query string + fullUrl = `${restURL}?${searchParams.toString()}` + } + + const headers = { + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + jwtToken, + } + + console.log('fullUrl', fullUrl) + + const result = await lastValueFrom( + this.httpService.get(fullUrl, { + headers: headers, + }), + ) + + if (result.status < 300 && result.status >= 200) { + return result + } else { + throw new Error( + `car-recycling: Failed on doGet with status: ${result.statusText}`, + ) + } + } + + // Hack to re-use the url from the secret + getRegistrationURL(): string { + const { restDeRegUrl } = environment.samgongustofa + + const positionOfChar = restDeRegUrl.lastIndexOf('/') + return restDeRegUrl.substring(0, positionOfChar) + '/' + } +} diff --git a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts index 9ad08f8a9d22..3b5d2d917c04 100644 --- a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts +++ b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts @@ -87,12 +87,6 @@ export class VehicleModel extends Model { }) plateLost?: number - @Field({ nullable: true }) - @Column({ - type: DataType.INTEGER, - }) - plateDestroyed?: number - @Field({ nullable: true }) @Column({ type: DataType.INTEGER, diff --git a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts index c9f5e184ef5d..8dd0d55d66a4 100644 --- a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts +++ b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts @@ -109,7 +109,6 @@ export class VehicleResolver { @Args('permno') permno: string, @Args('mileage') mileage: number, @Args('plateCount') plateCount: number, - @Args('plateDestroyed') plateDestroyed: number, @Args('plateLost') plateLost: number, @Args('deregistered') deregistered: boolean, ) { @@ -117,7 +116,6 @@ export class VehicleResolver { permno, mileage, plateCount, - plateDestroyed, plateLost, deregistered, }) @@ -126,7 +124,6 @@ export class VehicleResolver { permno, mileage, plateCount, - plateDestroyed, plateLost, deregistered, ) 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 59d681d551bd..c283258f1943 100644 --- a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts +++ b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts @@ -64,7 +64,7 @@ export class VehicleService { permno: string, mileage: number, plateCount: number, - plateDestroyed: number, + plateLost: number, deregistered: boolean, ): Promise { @@ -72,7 +72,6 @@ export class VehicleService { if (findVehicle) { findVehicle.mileage = mileage ?? 0 findVehicle.plateCount = plateCount ?? 0 - findVehicle.plateDestroyed = plateDestroyed ?? 0 findVehicle.plateLost = plateLost ?? 0 findVehicle.deregistered = deregistered ?? false await findVehicle.save() From d6d07feedcc8e9538433ebd35aead2dc80138145 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Wed, 4 Sep 2024 12:51:34 +0000 Subject: [PATCH 03/18] TS-866 Fix unit test --- .../src/app/modules/samgongustofa/samgongustofa.service.ts | 3 +-- .../modules/samgongustofa/test/samgongustofa.service.spec.ts | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts index 4e78d6ea0834..3d8ea978aa75 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts @@ -7,7 +7,7 @@ import { environment } from '../../../environments' import { RecyclingRequestService } from '../recyclingRequest' import { Traffic, VehicleInformation } from './samgongustofa.model' -import { Logger, logger, LOGGER_PROVIDER } from '@island.is/logging' +import { logger } from '@island.is/logging' import { TransportService } from './transport/transport.service' @Injectable() @@ -16,7 +16,6 @@ export class SamgongustofaService { private httpService: HttpService, @Inject(forwardRef(() => RecyclingRequestService)) private recyclingRequestService: RecyclingRequestService, - @Inject(LOGGER_PROVIDER) private logger: Logger, private transportService: TransportService, ) {} diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/test/samgongustofa.service.spec.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/test/samgongustofa.service.spec.ts index 45ff1cf5d3b8..bf5f6ce7acfb 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/test/samgongustofa.service.spec.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/test/samgongustofa.service.spec.ts @@ -10,6 +10,7 @@ import { import { SamgongustofaService } from '../samgongustofa.service' import { MockData } from './mock-data' +import { TransportService } from '../transport/transport.service' const recyclingRequestModel = { id: '1234', @@ -50,6 +51,10 @@ describe('skilavottordApiTest', () => { findAllWithPermno: () => ({}), })), }, + { + provide: TransportService, + useClass: jest.fn(() => ({})), + }, ], }).compile() samgongustofaService = From 0d079e1ddb9334a7107aabf6db02f7c92f7e2416 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Thu, 5 Sep 2024 15:29:05 +0000 Subject: [PATCH 04/18] TS-866 Continue working - Translations - UI --- .../CarDetailsBox/CarDetailsBox.tsx | 93 +--------- .../CarDetailsBox2/CarDetailsBox2.tsx | 172 ++++++++++++++++++ .../web/components/CarDetailsBox2/index.ts | 1 + apps/skilavottord/web/components/index.ts | 1 + apps/skilavottord/web/i18n/locales/en.json | 18 +- apps/skilavottord/web/i18n/locales/is.json | 17 +- .../web/i18n/locales/translation.d.ts | 19 +- .../DeregisterVehicle/Confirm/Confirm.tsx | 44 ++--- apps/skilavottord/web/utils/consts.ts | 9 + .../samgongustofa/samgongustofa.service.ts | 4 +- .../transport/transport.service.ts | 12 +- .../src/app/modules/vehicle/vehicle.model.ts | 4 +- .../app/modules/vehicle/vehicle.resolver.ts | 10 +- .../app/modules/vehicle/vehicle.service.ts | 10 +- 14 files changed, 269 insertions(+), 145 deletions(-) create mode 100644 apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx create mode 100644 apps/skilavottord/web/components/CarDetailsBox2/index.ts diff --git a/apps/skilavottord/web/components/CarDetailsBox/CarDetailsBox.tsx b/apps/skilavottord/web/components/CarDetailsBox/CarDetailsBox.tsx index d5c1093ab711..08f270833fd8 100644 --- a/apps/skilavottord/web/components/CarDetailsBox/CarDetailsBox.tsx +++ b/apps/skilavottord/web/components/CarDetailsBox/CarDetailsBox.tsx @@ -1,33 +1,12 @@ -import { - AlertMessage, - Box, - ContentBlock, - Stack, - Text, -} from '@island.is/island-ui/core' +import { Box, Stack, Text } from '@island.is/island-ui/core' import { OutlinedBox } from '@island.is/skilavottord-web/components' -import React, { FC, useState } from 'react' - -import { useI18n } from '@island.is/skilavottord-web/i18n' - -import { - CheckboxController, - InputController, - SelectController, -} from '@island.is/shared/form-fields' - -import { Control, FieldValues } from 'react-hook-form' -import { PlateInfo } from '@island.is/skilavottord-web/utils/consts' +import React, { FC } from 'react' interface BoxProps { vehicleId: string vehicleType: string modelYear: string vehicleOwner?: string | null - mileage?: number - control?: Control - showMileage?: boolean - isDeregistered?: boolean } export const CarDetailsBox: FC> = ({ @@ -35,33 +14,9 @@ export const CarDetailsBox: FC> = ({ vehicleType, modelYear, vehicleOwner, - mileage, - showMileage, - isDeregistered, }) => { - const { - t: { - deregisterVehicle: { deregister: t }, - }, - } = useI18n() - - //isDeregistered = true - - const [missingPlates, setMissingPlates] = useState(false) - return ( - {isDeregistered && ( - - - - - - )} > = ({ > {vehicleId} - {showMileage && {mileage} km} {`${vehicleType}, ${modelYear}`} {vehicleOwner} - {showMileage && ( - - - - )} - {isDeregistered && ( - - { - setMissingPlates(option?.value !== 2 ? true : false) - }} - /> - - - - )} ) } diff --git a/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx b/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx new file mode 100644 index 000000000000..9355aa7a59d9 --- /dev/null +++ b/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx @@ -0,0 +1,172 @@ +import { + AlertMessage, + Box, + Checkbox, + GridColumn, + GridContainer, + GridRow, + Stack, + Text, +} from '@island.is/island-ui/core' +import React, { FC, useState } from 'react' + +import { useI18n } from '@island.is/skilavottord-web/i18n' + +import { + InputController, + SelectController, +} from '@island.is/shared/form-fields' + +import { + OutInUsage, + PlateInfo, + UseStatus, +} from '@island.is/skilavottord-web/utils/consts' +import { Controller } from 'react-hook-form' + +interface BoxProps { + vehicleId: string + vehicleType: string + modelYear: string + vehicleOwner?: string | null + mileage?: number + isDeregistered?: boolean + outInStatus: number + useStatus: string +} + +export const CarDetailsBox2: FC> = ({ + vehicleId, + vehicleType, + modelYear, + vehicleOwner, + mileage, + isDeregistered, + outInStatus, + useStatus, +}) => { + const { + t: { + deregisterVehicle: { deregister: t }, + }, + } = useI18n() + + const [missingPlates, setMissingPlates] = useState(false) + const [lostPlate, setLostPlate] = useState(false) + + return ( + + + + + + + {vehicleId} + {mileage} km + {`${vehicleType}, ${modelYear}`} + + {vehicleOwner} + + + + + + + + + {t.numberplate.sectionTitle} + + + + {outInStatus === OutInUsage.OUT && ( + + + {useStatus !== UseStatus.OUT_TICKET && ( + + )} + {useStatus === UseStatus.OUT_TICKET && ( + + )} + + + )} + + + {isDeregistered && ( + { + if (option?.value === 2) { + setMissingPlates(false) + setLostPlate(false) + } else { + setMissingPlates(true) + } + }} + defaultValue={2} + /> + )} + + + {missingPlates && ( + + + { + return ( + { + setLostPlate(!lostPlate) + onChange(PlateInfo.PLATE_LOST) + }} + /> + ) + }} + /> + + + )} + {lostPlate && ( + + + + + + )} + + + ) +} diff --git a/apps/skilavottord/web/components/CarDetailsBox2/index.ts b/apps/skilavottord/web/components/CarDetailsBox2/index.ts new file mode 100644 index 000000000000..9007f2a0b0b7 --- /dev/null +++ b/apps/skilavottord/web/components/CarDetailsBox2/index.ts @@ -0,0 +1 @@ +export * from './CarDetailsBox2' diff --git a/apps/skilavottord/web/components/index.ts b/apps/skilavottord/web/components/index.ts index bf898f6a3fe5..29e01cd92868 100644 --- a/apps/skilavottord/web/components/index.ts +++ b/apps/skilavottord/web/components/index.ts @@ -13,6 +13,7 @@ export * from './Sidenav/Sidenav' export * from './GDPR' export * from './Modal/Modal' export * from './CarDetailsBox/CarDetailsBox' +export * from './CarDetailsBox2/CarDetailsBox2' export * from './LinkProvider/LinkProvider' export * from './Layouts/AppLayout' export * from './Layouts/PageLayout' diff --git a/apps/skilavottord/web/i18n/locales/en.json b/apps/skilavottord/web/i18n/locales/en.json index 44b282fe1f66..cb3f7c2f3f2c 100644 --- a/apps/skilavottord/web/i18n/locales/en.json +++ b/apps/skilavottord/web/i18n/locales/en.json @@ -329,7 +329,23 @@ "primaryButton": "Try again", "secondaryButton": "Cancel" }, - "currentMileage": "Current mileage" + "currentMileage": "Current mileage", + "numberplate": { + "sectionTitle": "Number plates information", + "alert": { + "info": { + "title": "The vehicle is registered out of use at the Icelandic Transport Authority.", + "message": "The number plates are deposited at the Icelandic Transport Authority" + }, + "warning": { + "title": "The vehicle is registered out of use with a sticker at the Icelandic Transport Authority.", + "message": "The number plates must accompany the vehicle" + } + }, + "count": "Number of license plates returned with the vehicle", + "lost": "Number plates are missing", + "missingInfo": "If the number plates are found, they must be returned to the Icelandic Transport Authority" + } } }, "recyclingFundOverview": { diff --git a/apps/skilavottord/web/i18n/locales/is.json b/apps/skilavottord/web/i18n/locales/is.json index ca72ef76207e..d8ec320474ca 100644 --- a/apps/skilavottord/web/i18n/locales/is.json +++ b/apps/skilavottord/web/i18n/locales/is.json @@ -330,7 +330,22 @@ "secondaryButton": "Hætta við" }, "currentMileage": "Núverandi kílómetrastaða", - "alreadyDeregistered": "Ökutækið er nú þegar skráð úr umferð hjá Samgöngustofu" + "numberplate": { + "sectionTitle": "Upplýsingar um númeraplötur", + "alert": { + "info": { + "title": "Ökutækið er skráð úr umferð hjá Samgöngustofu", + "message": "Númeraplöturnar eru innlagðar hjá Samgöngustofu" + }, + "warning": { + "title": "Ökutækið er skráð úr umferð (miði) hjá Samgöngustofu", + "message": "Númeraplöturnar eiga að fylgja ökutækinu" + } + }, + "count": "Fjöldi númeraplatna skilað með ökutækinu", + "lost": "Númeraplötur eru týndar", + "missingInfo": "Ef að númeraplöturnar finnast skal skila þeim til Samgöngustofu" + } } }, "recyclingFundOverview": { diff --git a/apps/skilavottord/web/i18n/locales/translation.d.ts b/apps/skilavottord/web/i18n/locales/translation.d.ts index b8c99434b0bc..28dd89be7eb0 100644 --- a/apps/skilavottord/web/i18n/locales/translation.d.ts +++ b/apps/skilavottord/web/i18n/locales/translation.d.ts @@ -273,7 +273,24 @@ export interface Deregister { success: string error: CompletedError currentMileage: string - alreadyDeregistered: string + numberplate: NumberPlate +} + +export interface NumberPlate { + sectionTitle: string + alert: DeregisteredMessages + count: string + lost: string + missingInfo: string +} + +export interface DeregisteredMessages { + info: Message + warning: Message +} +export interface Message { + title: string + message: string } export interface DeregisterButtons { diff --git a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx index 38a344f1fdb6..68f20ef831c6 100644 --- a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx +++ b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx @@ -1,7 +1,7 @@ import { useMutation, useQuery } from '@apollo/client' import gql from 'graphql-tag' import { useRouter } from 'next/router' -import React, { FC, useContext, useEffect } from 'react' +import React, { FC, useContext, useEffect, useState } from 'react' import { Box, @@ -18,7 +18,7 @@ import { import { hasPermission } from '@island.is/skilavottord-web/auth/utils' import { - CarDetailsBox, + CarDetailsBox2, NotFound, OutlinedError, ProcessPageLayout, @@ -35,7 +35,7 @@ import { import { useI18n } from '@island.is/skilavottord-web/i18n' import { getYear } from '@island.is/skilavottord-web/utils/dateUtils' import { FormProvider, useForm } from 'react-hook-form' -import { PlateInfo } from '@island.is/skilavottord-web/utils/consts' +import { OutInUsage } from '@island.is/skilavottord-web/utils/consts' const SkilavottordVehicleReadyToDeregisteredQuery = gql` query skilavottordVehicleReadyToDeregisteredQuery($permno: String!) { @@ -62,16 +62,6 @@ const SkilavottordTrafficQuery = gql` } ` -const SkilavottordVehicleInformationQuery = gql` - query skilavottordVehicleInformationQuery($permno: String!) { - skilavottordVehicleInformation(permno: $permno) { - permno - ownerSocialSecurityNumber - vehicleStatus - } - } -` - const SkilavottordRecyclingRequestMutation = gql` mutation skilavottordRecyclingRequestMutation( $permno: String! @@ -97,14 +87,13 @@ const UpdateSkilavottordVehicleInfoMutation = gql` $permno: String! $mileage: Float! $plateCount: Float! - $plateLost: Float! + $plateLost: Boolean! $deregistered: Boolean! ) { updateSkilavottordVehicleInfo( permno: $permno mileage: $mileage plateCount: $plateCount - plateLost: $plateLost deregistered: $deregistered ) @@ -128,7 +117,7 @@ const Confirm: FC> = () => { const { id } = router.query const mileageValue = watch('mileage') - const plateInfo = watch('plateInfo') + const plateLost = watch('plateLost') const plateCountValue = watch('plateCount') const { data, loading } = useQuery( @@ -152,10 +141,14 @@ const Confirm: FC> = () => { 'vehicle TRAFFIC', vehicleTrafficData?.outInStatus.toLocaleUpperCase(), ) - const isDeregistered = + const outInStatus = vehicleTrafficData?.outInStatus.toLocaleUpperCase() === 'OUT' + ? OutInUsage.OUT + : OutInUsage.IN - console.log('fsadfadsfa ', { isDeregistered }) + const useStatus = vehicleTrafficData?.useStatus + + console.log('fsadfadsfa ', { outInStatus }) const [ setRecyclingRequest, @@ -202,11 +195,11 @@ const Confirm: FC> = () => { newMileage = +mileageValue.trim().replace(/\./g, '') } + console.log('plateLost', { plateLost }) console.log('handleConfirm', { plateCountValue, - plateLostValue: plateInfo === PlateInfo.PLATE_LOST ? 1 : 0, - - isDeregistered, + plateLostValue: plateLost?.length ? true : false, + outInStatus, mileageValue, }) @@ -216,8 +209,8 @@ const Confirm: FC> = () => { permno: vehicle?.vehicleId, mileage: newMileage, plateCount: plateCountValue, - plateLost: plateInfo === PlateInfo.PLATE_LOST ? true : false, - deregistered: isDeregistered, + plateLost: plateLost?.length ? true : false, + deregistered: false, //isDeregistered, ?? Finna út úr hvort afksráð í stað úr umferð }, }) @@ -285,7 +278,7 @@ const Confirm: FC> = () => { {t.titles.success} {t.info.success} - > = () => { vehicle.recyclingRequests[0].nameOfRequestor } mileage={vehicle.mileage || 0} - showMileage isDeregistered + outInStatus={outInStatus} + useStatus={useStatus || ''} /> diff --git a/apps/skilavottord/web/utils/consts.ts b/apps/skilavottord/web/utils/consts.ts index cc2eb30dcc38..3567ecffb468 100644 --- a/apps/skilavottord/web/utils/consts.ts +++ b/apps/skilavottord/web/utils/consts.ts @@ -3,3 +3,12 @@ export const ACCEPTED_TERMS_AND_CONDITION = 'acceptedTermsAndConditions' export enum PlateInfo { PLATE_LOST = '0', } + +export enum UseStatus { + OUT_TICKET = '16', // Úr umferð (miði) +} + +export enum OutInUsage { + OUT = 0, + IN = 1, +} diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts index 3d8ea978aa75..d1a1b697b642 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts @@ -344,13 +344,11 @@ export class SamgongustofaService { const url = this.transportService.getRegistrationURL() const result = await this.transportService.doGet( - url + 'traffic/' + 'LT579', + url + 'traffic/' + permno, undefined, ) if (result.status === 200) { - console.log('GOT TRAFFIC', result.data) - // Get the latest registered traffic data return Object.values(result.data).reduce( (prev: Traffic, current: Traffic) => diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts index a5c2e1827445..9945682b4b8b 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts @@ -25,6 +25,7 @@ export class TransportService { const headerAuthRequest = { 'Content-Type': 'application/json', + 'Api-version': '3.0', } const authRes = await lastValueFrom( @@ -41,8 +42,10 @@ export class TransportService { return authRes.data['jwtToken'] } catch (error) { - delete error?.config - delete error?.response?.config?.data + if (error?.config) { + error.config.data = undefined + } + logger.error('car-recycling: Authentication failed', error) throw error } @@ -52,11 +55,8 @@ export class TransportService { restURL: string, queryParams: { [key: string]: string } | undefined, ) { - console.log('DOGet #1') const jwtToken = await this.authenticate() - console.log('DOGet #2', { restURL }) - let fullUrl = restURL if (queryParams) { @@ -71,8 +71,6 @@ export class TransportService { Authorization: 'Bearer ' + jwtToken, } - console.log('fullUrl', fullUrl) - const result = await lastValueFrom( this.httpService.get(fullUrl, { headers: headers, diff --git a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts index 3b5d2d917c04..ebd440c66d17 100644 --- a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts +++ b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts @@ -83,9 +83,9 @@ export class VehicleModel extends Model { @Field({ nullable: true }) @Column({ - type: DataType.INTEGER, + type: DataType.BOOLEAN, }) - plateLost?: number + plateLost?: boolean @Field({ nullable: true }) @Column({ diff --git a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts index 8dd0d55d66a4..9e979645673e 100644 --- a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts +++ b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts @@ -109,17 +109,9 @@ export class VehicleResolver { @Args('permno') permno: string, @Args('mileage') mileage: number, @Args('plateCount') plateCount: number, - @Args('plateLost') plateLost: number, + @Args('plateLost') plateLost: boolean, @Args('deregistered') deregistered: boolean, ) { - console.log('updateSkilavottordVehicleInfo -Resolver', { - permno, - mileage, - plateCount, - plateLost, - deregistered, - }) - return await this.vehicleService.updateVehicleInfo( permno, mileage, 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 c283258f1943..3748933d3975 100644 --- a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts +++ b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts @@ -64,24 +64,24 @@ export class VehicleService { permno: string, mileage: number, plateCount: number, - - plateLost: number, + plateLost: boolean, deregistered: boolean, ): Promise { const findVehicle = await this.findByVehicleId(permno) if (findVehicle) { findVehicle.mileage = mileage ?? 0 findVehicle.plateCount = plateCount ?? 0 - findVehicle.plateLost = plateLost ?? 0 + findVehicle.plateLost = plateLost ? true : false findVehicle.deregistered = deregistered ?? false await findVehicle.save() return true } else { - const errorMsg = `failed to update mileage: ${mileage} on vehicle: ${permno}` + const errorMsg = `Failed to update vehicleInfo for vehicle: ${permno}` this.logger.error( - `car-recycling: Failed to update mileage: ${mileage} on vehicle: ${permno.slice( + `car-recycling: Failed to update vehicleInfo for vehicle: ${permno.slice( -3, )}`, + { mileage, plateCount, plateLost, deregistered }, ) throw new Error(errorMsg) } From f875da133df86eaef8ed756c07f462349263b204 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Mon, 9 Sep 2024 09:50:13 +0000 Subject: [PATCH 05/18] TS-866 Remove deregister column --- .../CarDetailsBox2/CarDetailsBox2.tsx | 43 +++++++++---------- .../DeregisterVehicle/Confirm/Confirm.tsx | 23 ++-------- ...9083210715-addcolumns-numberplate-info.js} | 2 - .../src/app/modules/vehicle/vehicle.model.ts | 6 --- .../app/modules/vehicle/vehicle.resolver.ts | 2 - .../app/modules/vehicle/vehicle.service.ts | 5 +-- 6 files changed, 25 insertions(+), 56 deletions(-) rename apps/skilavottord/ws/migrations/{202409033210715-addcolumns-numberplate-info.js => 202409083210715-addcolumns-numberplate-info.js} (81%) diff --git a/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx b/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx index 9355aa7a59d9..3ece7513cd9c 100644 --- a/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx +++ b/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx @@ -30,7 +30,7 @@ interface BoxProps { modelYear: string vehicleOwner?: string | null mileage?: number - isDeregistered?: boolean + outInStatus: number useStatus: string } @@ -41,7 +41,6 @@ export const CarDetailsBox2: FC> = ({ modelYear, vehicleOwner, mileage, - isDeregistered, outInStatus, useStatus, }) => { @@ -113,27 +112,25 @@ export const CarDetailsBox2: FC> = ({ )} - {isDeregistered && ( - { - if (option?.value === 2) { - setMissingPlates(false) - setLostPlate(false) - } else { - setMissingPlates(true) - } - }} - defaultValue={2} - /> - )} + { + if (option?.value === 2) { + setMissingPlates(false) + setLostPlate(false) + } else { + setMissingPlates(true) + } + }} + defaultValue={2} + /> {missingPlates && ( diff --git a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx index 68f20ef831c6..b4401211b6f2 100644 --- a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx +++ b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx @@ -88,14 +88,12 @@ const UpdateSkilavottordVehicleInfoMutation = gql` $mileage: Float! $plateCount: Float! $plateLost: Boolean! - $deregistered: Boolean! ) { updateSkilavottordVehicleInfo( permno: $permno mileage: $mileage plateCount: $plateCount plateLost: $plateLost - deregistered: $deregistered ) } ` @@ -137,10 +135,7 @@ const Confirm: FC> = () => { ) const vehicleTrafficData = traffic?.skilavottordTraffic - console.log( - 'vehicle TRAFFIC', - vehicleTrafficData?.outInStatus.toLocaleUpperCase(), - ) + const outInStatus = vehicleTrafficData?.outInStatus.toLocaleUpperCase() === 'OUT' ? OutInUsage.OUT @@ -148,8 +143,6 @@ const Confirm: FC> = () => { const useStatus = vehicleTrafficData?.useStatus - console.log('fsadfadsfa ', { outInStatus }) - const [ setRecyclingRequest, { data: mutationData, error: mutationError, loading: mutationLoading }, @@ -195,22 +188,13 @@ const Confirm: FC> = () => { newMileage = +mileageValue.trim().replace(/\./g, '') } - console.log('plateLost', { plateLost }) - console.log('handleConfirm', { - plateCountValue, - plateLostValue: plateLost?.length ? true : false, - outInStatus, - mileageValue, - }) - // Update vehicle table with latests information setVehicleRequest({ variables: { permno: vehicle?.vehicleId, - mileage: newMileage, - plateCount: plateCountValue, + mileage: newMileage || vehicle?.mileage, + plateCount: plateCountValue === 0 ? 0 : plateCountValue, plateLost: plateLost?.length ? true : false, - deregistered: false, //isDeregistered, ?? Finna út úr hvort afksráð í stað úr umferð }, }) @@ -287,7 +271,6 @@ const Confirm: FC> = () => { vehicle.recyclingRequests[0].nameOfRequestor } mileage={vehicle.mileage || 0} - isDeregistered outInStatus={outInStatus} useStatus={useStatus || ''} /> diff --git a/apps/skilavottord/ws/migrations/202409033210715-addcolumns-numberplate-info.js b/apps/skilavottord/ws/migrations/202409083210715-addcolumns-numberplate-info.js similarity index 81% rename from apps/skilavottord/ws/migrations/202409033210715-addcolumns-numberplate-info.js rename to apps/skilavottord/ws/migrations/202409083210715-addcolumns-numberplate-info.js index 0ed143d0f28c..96e7948d80d7 100644 --- a/apps/skilavottord/ws/migrations/202409033210715-addcolumns-numberplate-info.js +++ b/apps/skilavottord/ws/migrations/202409083210715-addcolumns-numberplate-info.js @@ -7,7 +7,6 @@ module.exports = { BEGIN; ALTER TABLE vehicle ADD COLUMN plate_count INT; ALTER TABLE vehicle ADD COLUMN plate_lost BOOLEAN; - ALTER TABLE vehicle ADD COLUMN deregistered BOOLEAN; COMMIT; `) }, @@ -16,7 +15,6 @@ module.exports = { return queryInterface.sequelize.query(` ALTER TABLE vehicle DROP COLUMN plate_count; ALTER TABLE vehicle DROP COLUMN plate_lost; - ALTER TABLE vehicle DROP COLUMN deregistered; `) }, } diff --git a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts index ebd440c66d17..ad6e8bc929f3 100644 --- a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts +++ b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.model.ts @@ -92,12 +92,6 @@ export class VehicleModel extends Model { type: DataType.INTEGER, }) plateCount?: number - - @Field({ nullable: true }) - @Column({ - type: DataType.BOOLEAN, - }) - deregistered?: boolean } @ObjectType() diff --git a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts index 9e979645673e..a5f2af14ec32 100644 --- a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts +++ b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.resolver.ts @@ -110,14 +110,12 @@ export class VehicleResolver { @Args('mileage') mileage: number, @Args('plateCount') plateCount: number, @Args('plateLost') plateLost: boolean, - @Args('deregistered') deregistered: boolean, ) { return await this.vehicleService.updateVehicleInfo( permno, mileage, plateCount, plateLost, - deregistered, ) } } 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 3748933d3975..9e79dfc4950a 100644 --- a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts +++ b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts @@ -65,14 +65,13 @@ export class VehicleService { mileage: number, plateCount: number, plateLost: boolean, - deregistered: boolean, ): Promise { const findVehicle = await this.findByVehicleId(permno) if (findVehicle) { findVehicle.mileage = mileage ?? 0 findVehicle.plateCount = plateCount ?? 0 findVehicle.plateLost = plateLost ? true : false - findVehicle.deregistered = deregistered ?? false + await findVehicle.save() return true } else { @@ -81,7 +80,7 @@ export class VehicleService { `car-recycling: Failed to update vehicleInfo for vehicle: ${permno.slice( -3, )}`, - { mileage, plateCount, plateLost, deregistered }, + { mileage, plateCount, plateLost }, ) throw new Error(errorMsg) } From 434cc76b5e2cb1e47b528a3b8c9a3d94b5daa2bf Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Mon, 9 Sep 2024 12:20:24 +0000 Subject: [PATCH 06/18] =?UTF-8?q?TS-866=20Fixing=20wrong=20data=20sent=20t?= =?UTF-8?q?o=20Samg=C3=B6ngustofu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/CarDetailsBox2/CarDetailsBox2.tsx | 7 ++++++- .../DeregisterVehicle/Confirm/Confirm.tsx | 16 ++++++++-------- .../recyclingRequest/recyclingRequest.service.ts | 3 +-- .../icelandicTransportAuthority.services.ts | 2 -- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx b/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx index 3ece7513cd9c..30f245959dbf 100644 --- a/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx +++ b/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx @@ -146,8 +146,13 @@ export const CarDetailsBox2: FC> = ({ label={t.numberplate.lost} backgroundColor="blue" onChange={() => { + if (!lostPlate) { + onChange(PlateInfo.PLATE_LOST) + } else { + onChange() + } + setLostPlate(!lostPlate) - onChange(PlateInfo.PLATE_LOST) }} /> ) diff --git a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx index b4401211b6f2..af8c5bf9273d 100644 --- a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx +++ b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx @@ -196,14 +196,14 @@ const Confirm: FC> = () => { plateCount: plateCountValue === 0 ? 0 : plateCountValue, plateLost: plateLost?.length ? true : false, }, - }) - - // Send recycling request - setRecyclingRequest({ - variables: { - permno: id, - requestType: RecyclingRequestTypes.deregistered, - }, + }).then(() => { + // Send recycling request + setRecyclingRequest({ + variables: { + permno: id, + requestType: RecyclingRequestTypes.deregistered, + }, + }) }) } const handleBack = () => { 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 5959c96eab47..c21440a22803 100644 --- a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts +++ b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts @@ -68,6 +68,7 @@ export class RecyclingRequestService { this.logger.error(errorMessage) throw new Error(errorMessage) } + // DeRegisterd vehicle const jToken = authRes.data['jwtToken'] const jsonDeRegBody = JSON.stringify({ @@ -86,8 +87,6 @@ export class RecyclingRequestService { 'Api-version': apiVersion, } - console.log('Sending TO Samgögnustafa', jsonDeRegBody) - const deRegRes = await lastValueFrom( this.httpService.post(restDeRegUrl + apiVersionParam, jsonDeRegBody, { headers: headerDeRegRequest, diff --git a/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts b/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts index 6b952f07cff6..67e62fb27b80 100644 --- a/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts +++ b/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts @@ -111,8 +111,6 @@ export class IcelandicTransportAuthorityServices { try { const { restDeRegUrl } = environment.samgongustofa - console.log('getVehicleInformation', permno) - return this.doGet( this.getInformationURL(restDeRegUrl) + 'vehicleinformationmini/' + From 1877970d1a868f2cc46d1b6a4ef0594350b08210 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Mon, 9 Sep 2024 13:01:38 +0000 Subject: [PATCH 07/18] TS-866 Fixing show right alert box and hide selection box --- .../CarDetailsBox2/CarDetailsBox2.tsx | 52 +++++++++++-------- .../DeregisterVehicle/Confirm/Confirm.tsx | 2 +- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx b/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx index 30f245959dbf..5ccb886adbe0 100644 --- a/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx +++ b/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx @@ -110,29 +110,34 @@ export const CarDetailsBox2: FC> = ({ )} - - - { - if (option?.value === 2) { - setMissingPlates(false) - setLostPlate(false) - } else { - setMissingPlates(true) - } - }} - defaultValue={2} - /> - - + + {(outInStatus === OutInUsage.IN || + (outInStatus === OutInUsage.OUT && + useStatus === UseStatus.OUT_TICKET)) && ( + + + { + if (option?.value === 2) { + setMissingPlates(false) + setLostPlate(false) + } else { + setMissingPlates(true) + } + }} + defaultValue={2} + /> + + + )} {missingPlates && ( @@ -161,6 +166,7 @@ export const CarDetailsBox2: FC> = ({ )} + {lostPlate && ( diff --git a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx index af8c5bf9273d..bf4dc908b8a2 100644 --- a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx +++ b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx @@ -141,7 +141,7 @@ const Confirm: FC> = () => { ? OutInUsage.OUT : OutInUsage.IN - const useStatus = vehicleTrafficData?.useStatus + const useStatus = vehicleTrafficData?.useStatus || '01' const [ setRecyclingRequest, From 0ffdfc334790f36b7eb73423bbabfba626bde4bd Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Mon, 9 Sep 2024 14:09:27 +0000 Subject: [PATCH 08/18] TS-866 Refactoring code --- apps/skilavottord/ws/src/app/const.ts | 4 + .../recyclingRequest.service.ts | 12 +- .../samgongustofa/samgongustofa.service.ts | 23 ++++ .../transport/transport.service.ts | 41 ++++-- .../icelandicTransportAuthority.module.ts | 7 +- .../icelandicTransportAuthority.services.ts | 122 +----------------- 6 files changed, 73 insertions(+), 136 deletions(-) create mode 100644 apps/skilavottord/ws/src/app/const.ts diff --git a/apps/skilavottord/ws/src/app/const.ts b/apps/skilavottord/ws/src/app/const.ts new file mode 100644 index 000000000000..724710e087c5 --- /dev/null +++ b/apps/skilavottord/ws/src/app/const.ts @@ -0,0 +1,4 @@ +export enum ApiVersion { + REGISTRATIONS = '3.0', + INFORMATION = '1.0', +} 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 c21440a22803..ab1e1f5ef7db 100644 --- a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts +++ b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts @@ -21,6 +21,7 @@ import { } from './recyclingRequest.model' import { VehicleService, VehicleModel } from '../vehicle' import { IcelandicTransportAuthorityServices } from '../../services/icelandicTransportAuthority.services' +import { ApiVersion } from '../../const' @Injectable() export class RecyclingRequestService { @@ -41,9 +42,6 @@ export class RecyclingRequestService { disposalStation: string, vehicle: VehicleModel, ) { - const apiVersion = '3.0' - const apiVersionParam = '?api-version=' + apiVersion - try { const { restAuthUrl, restDeRegUrl, restUsername, restPassword } = environment.samgongustofa @@ -54,12 +52,12 @@ export class RecyclingRequestService { const jsonAuthBody = JSON.stringify(jsonObj) const headerAuthRequest = { 'Content-Type': 'application/json', - 'Api-version': apiVersion, + 'Api-version': ApiVersion.REGISTRATIONS, } // TODO: saved jToken and use it in next 7 days ( until it expires ) const authRes = await lastValueFrom( - this.httpService.post(restAuthUrl + apiVersionParam, jsonAuthBody, { + this.httpService.post(restAuthUrl, jsonAuthBody, { headers: headerAuthRequest, }), ) @@ -84,11 +82,11 @@ export class RecyclingRequestService { const headerDeRegRequest = { 'Content-Type': 'application/json', Authorization: 'Bearer ' + jToken, - 'Api-version': apiVersion, + 'Api-version': ApiVersion.REGISTRATIONS, } const deRegRes = await lastValueFrom( - this.httpService.post(restDeRegUrl + apiVersionParam, jsonDeRegBody, { + this.httpService.post(restDeRegUrl, jsonDeRegBody, { headers: headerDeRegRequest, }), ) diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts index d1a1b697b642..61433a620aa6 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts @@ -9,6 +9,7 @@ import { Traffic, VehicleInformation } from './samgongustofa.model' import { logger } from '@island.is/logging' import { TransportService } from './transport/transport.service' +import { ApiVersion } from '../../const' @Injectable() export class SamgongustofaService { @@ -344,8 +345,10 @@ export class SamgongustofaService { const url = this.transportService.getRegistrationURL() const result = await this.transportService.doGet( + url, url + 'traffic/' + permno, undefined, + ApiVersion.REGISTRATIONS, ) if (result.status === 200) { @@ -368,4 +371,24 @@ export class SamgongustofaService { ) } } + + // Get the Vehicle information from Icelandic Transport Authority (Samgöngustofa) + async getVehicleInformation(permno: string) { + try { + const url = this.transportService.getInformationURL() + + return this.transportService.doGet( + url, + url + 'vehicleinformationmini/' + permno, + undefined, + ApiVersion.INFORMATION, + ) + } catch (err) { + throw new Error( + `car-recycling: Failed on getVehicleInformation vehicle ${permno.slice( + -3, + )} because: ${err}`, + ) + } + } } diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts index 9945682b4b8b..76a11ee505c4 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts @@ -8,12 +8,11 @@ import { logger } from '@island.is/logging' export class TransportService { constructor(private httpService: HttpService) {} - async authenticate() { + async authenticate(url: string, apiVersion = '1.0'): Promise { try { - const { restAuthUrl, restUsername, restPassword } = - environment.samgongustofa + const { restUsername, restPassword } = environment.samgongustofa - if (!restAuthUrl || !restUsername || !restPassword) { + if (!restUsername || !restPassword) { throw new Error('Missing environment variables for Samgöngustofa') } @@ -25,11 +24,11 @@ export class TransportService { const headerAuthRequest = { 'Content-Type': 'application/json', - 'Api-version': '3.0', + 'Api-version': apiVersion, } const authRes = await lastValueFrom( - this.httpService.post(restAuthUrl, jsonAuthBody, { + this.httpService.post(url + 'authenticate', jsonAuthBody, { headers: headerAuthRequest, }), ) @@ -53,17 +52,17 @@ export class TransportService { async doGet( restURL: string, + fullUrl: string, queryParams: { [key: string]: string } | undefined, + apiVersion: string, ) { - const jwtToken = await this.authenticate() - - let fullUrl = restURL + const jwtToken = await this.authenticate(restURL, apiVersion) if (queryParams) { const searchParams = new URLSearchParams(queryParams) // Concatenate the URL with the query string - fullUrl = `${restURL}?${searchParams.toString()}` + fullUrl = `${fullUrl}?${searchParams.toString()}` } const headers = { @@ -86,11 +85,31 @@ export class TransportService { } } - // Hack to re-use the url from the secret + /** + * Get the Samgöngustofa's registration REST url + * @returns + */ getRegistrationURL(): string { const { restDeRegUrl } = environment.samgongustofa const positionOfChar = restDeRegUrl.lastIndexOf('/') return restDeRegUrl.substring(0, positionOfChar) + '/' } + + /** + * Get the Samgöngustofa's information REST url + * @returns + */ + getInformationURL(): string { + const { restDeRegUrl } = environment.samgongustofa + + // + // Small hack to get the information url + const restInformationURL = restDeRegUrl.replace( + '/registrations/', + '/information/', + ) + const positionOfChar = restInformationURL.lastIndexOf('/') + return restInformationURL.substring(0, positionOfChar) + '/' + } } diff --git a/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.module.ts b/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.module.ts index 8207430e01de..e5fecff38762 100644 --- a/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.module.ts +++ b/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.module.ts @@ -1,13 +1,18 @@ import { Module, forwardRef } from '@nestjs/common' import { IcelandicTransportAuthorityServices } from './icelandicTransportAuthority.services' import { HttpModule } from '@nestjs/axios' -import { VehicleModule, VehicleOwnerModule } from '../modules' +import { + SamgongustofaModule, + VehicleModule, + VehicleOwnerModule, +} from '../modules' @Module({ imports: [ HttpModule, forwardRef(() => VehicleModule), forwardRef(() => VehicleOwnerModule), + forwardRef(() => SamgongustofaModule), ], providers: [IcelandicTransportAuthorityServices], exports: [IcelandicTransportAuthorityServices], diff --git a/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts b/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts index 67e62fb27b80..24254b673c06 100644 --- a/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts +++ b/apps/skilavottord/ws/src/app/services/icelandicTransportAuthority.services.ts @@ -1,134 +1,22 @@ -import { Injectable } from '@nestjs/common/decorators/core' -import { lastValueFrom } from 'rxjs' -import { HttpService } from '@nestjs/axios/dist' -import { environment } from '../../environments' import { logger } from '@island.is/logging' +import { Injectable } from '@nestjs/common/decorators/core' +import { SamgongustofaService } from '../modules/samgongustofa' +import { VehicleInformationMini } from '../modules/samgongustofa/samgongustofa.model' import { VehicleModel, VehicleService } from '../modules/vehicle' import { VehicleOwnerModel } from '../modules/vehicleOwner' import { VehicleOwnerService } from '../modules/vehicleOwner/vehicleOwner.service' -import { VehicleInformationMini } from '../modules/samgongustofa/samgongustofa.model' @Injectable() export class IcelandicTransportAuthorityServices { constructor( - private http: HttpService, private vehicleService: VehicleService, private ownerService: VehicleOwnerService, + private samgongustofaService: SamgongustofaService, ) {} - // Hack to re-use the url from the secret - private getInformationURL(restURL: string): string { - const restInformationURL = restURL.replace( - '/registrations/', - '/information/', - ) - const positionOfChar = restInformationURL.lastIndexOf('/') - return restInformationURL.substring(0, positionOfChar) + '/' - } - - async authenticate(authURL: string, userName: string, password: string) { - try { - const jsonObj = { - username: userName, - password: password, - } - const jsonAuthBody = JSON.stringify(jsonObj) - - const headerAuthRequest = { - 'Content-Type': 'application/json', - } - - const authRes = await lastValueFrom( - this.http.post( - this.getInformationURL(authURL) + 'authenticate', - jsonAuthBody, - { - headers: headerAuthRequest, - }, - ), - ) - - if (authRes.status > 299 || authRes.status < 200) { - const errorMessage = `Authentication failed to information services: ${authRes.statusText}` - logger.error(`car-recycling: ${errorMessage}`) - throw new Error(errorMessage) - } - - return authRes.data['jwtToken'] - } catch (error) { - if (error?.config) { - error.config.data = undefined - } - logger.error('car-recycling: Authentication failed on information', error) - throw error - } - } - - async doGet( - restURL: string, - queryParams: { [key: string]: string } | undefined, - ) { - const { restAuthUrl, restUsername, restPassword } = - environment.samgongustofa - - const jwtToken = await this.authenticate( - restAuthUrl, - restUsername, - restPassword, - ) - - let fullUrl = restURL - - if (queryParams) { - const searchParams = new URLSearchParams(queryParams) - - // Concatenate the URL with the query string - fullUrl = `${restURL}?${searchParams.toString()}` - } - - const headers = { - 'Content-Type': 'application/json', - Authorization: 'Bearer ' + jwtToken, - } - - const result = await lastValueFrom( - this.http.get(fullUrl, { - headers: headers, - }), - ) - - if (result.status < 300 && result.status >= 200) { - return result - } else { - throw new Error( - `car-recycling: Failed on doGet with status: ${result.statusText}`, - ) - } - } - - // Get the Vehicle information from Icelandic Transport Authority (Samgöngustofa) - async getVehicleInformation(permno: string) { - try { - const { restDeRegUrl } = environment.samgongustofa - - return this.doGet( - this.getInformationURL(restDeRegUrl) + - 'vehicleinformationmini/' + - permno, - undefined, - ) - } catch (err) { - throw new Error( - `car-recycling: Failed on getVehicleInformation vehicle ${permno.slice( - -3, - )} because: ${err}`, - ) - } - } - async checkIfCurrentUser(permno: string): Promise { //Get the latest vehicle information from Samgongustofa - const result = await this.getVehicleInformation(permno) + const result = await this.samgongustofaService.getVehicleInformation(permno) if (result && result.data) { const ownerSocialSecurityNumber = result.data.ownerSocialSecurityNumber From 39fd638a6a05ff7a328d64cba10b14fedea458b2 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Mon, 9 Sep 2024 14:33:25 +0000 Subject: [PATCH 09/18] TS-866 Fix after Coderabbit review --- apps/skilavottord/ws/migrations/20201008200611-vehicle_owner.js | 2 -- apps/skilavottord/ws/migrations/20201008210611-vehicle.js | 1 - .../ws/migrations/20201008210711-recycling-partners.js | 2 -- .../ws/migrations/20201008220611-recycling_request.js | 2 -- apps/skilavottord/ws/migrations/20201008230611-gdpr.js | 2 -- .../skilavottord/ws/migrations/20211207210715-access-control.js | 2 -- .../migrations/20220318210711-addcolumn-recycling-partners.js | 2 -- .../ws/migrations/20220318210715-addcolumn-access-control.js | 2 -- .../migrations/20220318210715-alow-null-recycling-partners.js | 2 -- .../ws/migrations/20231113210715-addcolumn-mileage.js | 2 -- apps/skilavottord/ws/migrations/20240307280301-add-indexes.js | 2 -- .../migrations/202409083210715-addcolumns-numberplate-info.js | 2 -- 12 files changed, 23 deletions(-) diff --git a/apps/skilavottord/ws/migrations/20201008200611-vehicle_owner.js b/apps/skilavottord/ws/migrations/20201008200611-vehicle_owner.js index f4170a4404d7..f179c3da7af0 100644 --- a/apps/skilavottord/ws/migrations/20201008200611-vehicle_owner.js +++ b/apps/skilavottord/ws/migrations/20201008200611-vehicle_owner.js @@ -1,5 +1,3 @@ -'use strict' - module.exports.up = (queryInterface, DataTypes) => { return queryInterface.createTable( 'vehicle_owner', diff --git a/apps/skilavottord/ws/migrations/20201008210611-vehicle.js b/apps/skilavottord/ws/migrations/20201008210611-vehicle.js index 100f501066d6..7993f667c03f 100644 --- a/apps/skilavottord/ws/migrations/20201008210611-vehicle.js +++ b/apps/skilavottord/ws/migrations/20201008210611-vehicle.js @@ -1,4 +1,3 @@ -'use strict' // newreg_date TIMESTAMP WITH TIME ZONE DEFAULT now(), // vin_number VARCHAR, module.exports.up = (queryInterface, DataTypes) => { diff --git a/apps/skilavottord/ws/migrations/20201008210711-recycling-partners.js b/apps/skilavottord/ws/migrations/20201008210711-recycling-partners.js index b44b3ffe0fee..9823d0c2723e 100644 --- a/apps/skilavottord/ws/migrations/20201008210711-recycling-partners.js +++ b/apps/skilavottord/ws/migrations/20201008210711-recycling-partners.js @@ -1,5 +1,3 @@ -'use strict' - module.exports.up = (queryInterface, DataTypes) => { return queryInterface.createTable( 'recycling_partner', diff --git a/apps/skilavottord/ws/migrations/20201008220611-recycling_request.js b/apps/skilavottord/ws/migrations/20201008220611-recycling_request.js index d1eb3b08decc..d6c4e8e8e1f8 100644 --- a/apps/skilavottord/ws/migrations/20201008220611-recycling_request.js +++ b/apps/skilavottord/ws/migrations/20201008220611-recycling_request.js @@ -1,5 +1,3 @@ -'use strict' - module.exports.up = (queryInterface, DataTypes) => { return queryInterface.createTable( 'recycling_request', diff --git a/apps/skilavottord/ws/migrations/20201008230611-gdpr.js b/apps/skilavottord/ws/migrations/20201008230611-gdpr.js index 5af67b0129ea..cfd1cf8c7d14 100644 --- a/apps/skilavottord/ws/migrations/20201008230611-gdpr.js +++ b/apps/skilavottord/ws/migrations/20201008230611-gdpr.js @@ -1,5 +1,3 @@ -'use strict' - module.exports.up = (queryInterface, DataTypes) => { return queryInterface.createTable( 'gdpr', diff --git a/apps/skilavottord/ws/migrations/20211207210715-access-control.js b/apps/skilavottord/ws/migrations/20211207210715-access-control.js index 1ff3e3462013..3df1d4b2c6af 100644 --- a/apps/skilavottord/ws/migrations/20211207210715-access-control.js +++ b/apps/skilavottord/ws/migrations/20211207210715-access-control.js @@ -1,5 +1,3 @@ -'use strict' - module.exports.up = (queryInterface, DataTypes) => { return queryInterface.createTable( 'access_control', diff --git a/apps/skilavottord/ws/migrations/20220318210711-addcolumn-recycling-partners.js b/apps/skilavottord/ws/migrations/20220318210711-addcolumn-recycling-partners.js index f1b24e25d48c..90c9e7040264 100644 --- a/apps/skilavottord/ws/migrations/20220318210711-addcolumn-recycling-partners.js +++ b/apps/skilavottord/ws/migrations/20220318210711-addcolumn-recycling-partners.js @@ -1,5 +1,3 @@ -'use strict' - module.exports = { up: (queryInterface) => { return queryInterface.sequelize.query(` diff --git a/apps/skilavottord/ws/migrations/20220318210715-addcolumn-access-control.js b/apps/skilavottord/ws/migrations/20220318210715-addcolumn-access-control.js index 0e8d44c80476..63ce3c22fcbd 100644 --- a/apps/skilavottord/ws/migrations/20220318210715-addcolumn-access-control.js +++ b/apps/skilavottord/ws/migrations/20220318210715-addcolumn-access-control.js @@ -1,5 +1,3 @@ -'use strict' - module.exports = { up: (queryInterface) => { return queryInterface.sequelize.query(` diff --git a/apps/skilavottord/ws/migrations/20220318210715-alow-null-recycling-partners.js b/apps/skilavottord/ws/migrations/20220318210715-alow-null-recycling-partners.js index 1839c87917f4..111883805f16 100644 --- a/apps/skilavottord/ws/migrations/20220318210715-alow-null-recycling-partners.js +++ b/apps/skilavottord/ws/migrations/20220318210715-alow-null-recycling-partners.js @@ -1,5 +1,3 @@ -'use strict' - module.exports = { up: (queryInterface) => { return queryInterface.sequelize.query(` diff --git a/apps/skilavottord/ws/migrations/20231113210715-addcolumn-mileage.js b/apps/skilavottord/ws/migrations/20231113210715-addcolumn-mileage.js index 08959859c3af..8aa4b76bd3e2 100644 --- a/apps/skilavottord/ws/migrations/20231113210715-addcolumn-mileage.js +++ b/apps/skilavottord/ws/migrations/20231113210715-addcolumn-mileage.js @@ -1,5 +1,3 @@ -'use strict' - //add mileage change module.exports = { up: (queryInterface) => { diff --git a/apps/skilavottord/ws/migrations/20240307280301-add-indexes.js b/apps/skilavottord/ws/migrations/20240307280301-add-indexes.js index 68ec78a3044e..fced6fe46ab7 100644 --- a/apps/skilavottord/ws/migrations/20240307280301-add-indexes.js +++ b/apps/skilavottord/ws/migrations/20240307280301-add-indexes.js @@ -1,5 +1,3 @@ -'use strict' - //add mileage change module.exports = { up: (queryInterface) => { diff --git a/apps/skilavottord/ws/migrations/202409083210715-addcolumns-numberplate-info.js b/apps/skilavottord/ws/migrations/202409083210715-addcolumns-numberplate-info.js index 96e7948d80d7..4bfadb7ad42d 100644 --- a/apps/skilavottord/ws/migrations/202409083210715-addcolumns-numberplate-info.js +++ b/apps/skilavottord/ws/migrations/202409083210715-addcolumns-numberplate-info.js @@ -1,5 +1,3 @@ -'use strict' - //add number plate & deregistered info change module.exports = { up: (queryInterface) => { From ee01473acd26c77369efa9aeb37097e6d0949c5c Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Mon, 9 Sep 2024 14:52:02 +0000 Subject: [PATCH 10/18] TS-866 Fix after Coderabbit review --- .../modules/recyclingRequest/recyclingRequest.resolver.ts | 5 ++--- .../ws/src/app/modules/vehicle/vehicle.service.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.resolver.ts b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.resolver.ts index 218314fa7557..8ade0d8de42a 100644 --- a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.resolver.ts +++ b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.resolver.ts @@ -76,10 +76,9 @@ export class RecyclingRequestResolver { @Args('recyclingPartner') station: string, @Args('mileage', { type: () => Int, nullable: true }) mileage: number, ): Promise { - console.log('skilavottordDeRegisterVehicle -- HVER ER AÐ KALLA') - throw new Error('Not implemented') + throw new Error('Not used anymore') - return undefined //this.recyclingRequestService.deRegisterVehicle(permno, station, 0) + //this.recyclingRequestService.deRegisterVehicle(permno, station, 0) } @Authorize({ 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 9e79dfc4950a..3be43b3a65b8 100644 --- a/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts +++ b/apps/skilavottord/ws/src/app/modules/vehicle/vehicle.service.ts @@ -70,7 +70,7 @@ export class VehicleService { if (findVehicle) { findVehicle.mileage = mileage ?? 0 findVehicle.plateCount = plateCount ?? 0 - findVehicle.plateLost = plateLost ? true : false + findVehicle.plateLost = plateLost await findVehicle.save() return true From 022bcad5de3077a0ab4e7ee235cb2b5ec0db8ff0 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Mon, 9 Sep 2024 15:02:19 +0000 Subject: [PATCH 11/18] TS-866 Fix after Coderabbit review --- .../modules/samgongustofa/test/samgongustofa.service.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/test/samgongustofa.service.spec.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/test/samgongustofa.service.spec.ts index bf5f6ce7acfb..9f0cfc08a388 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/test/samgongustofa.service.spec.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/test/samgongustofa.service.spec.ts @@ -53,7 +53,9 @@ describe('skilavottordApiTest', () => { }, { provide: TransportService, - useClass: jest.fn(() => ({})), + useClass: jest.fn(() => ({ + getRegistrationURL: () => ({}), + })), }, ], }).compile() From 606a42deab9a768197ac3b4ec4fb1beafc900e95 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Mon, 9 Sep 2024 15:06:49 +0000 Subject: [PATCH 12/18] TS-866 Fix after Coderabbit review --- .../app/modules/recyclingRequest/recyclingRequest.resolver.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.resolver.ts b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.resolver.ts index 8ade0d8de42a..46d61f0d0a4c 100644 --- a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.resolver.ts +++ b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.resolver.ts @@ -76,9 +76,8 @@ export class RecyclingRequestResolver { @Args('recyclingPartner') station: string, @Args('mileage', { type: () => Int, nullable: true }) mileage: number, ): Promise { - throw new Error('Not used anymore') - //this.recyclingRequestService.deRegisterVehicle(permno, station, 0) + throw new Error('Not used anymore') } @Authorize({ From e565f9c7dc72c012e17fc6f6be1d1e09c3b11103 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Tue, 10 Sep 2024 08:40:50 +0000 Subject: [PATCH 13/18] TS-866 Code refactoring --- .../recyclingRequest.service.ts | 11 ++++--- .../samgongustofa/samgongustofa.service.ts | 29 +++++++++++-------- .../transport/transport.service.ts | 22 ++++++-------- .../modules/vehicle/vehicleAppSys.resolver.ts | 10 +++++-- .../ws/src/app/{ => utils}/const.ts | 1 + apps/skilavottord/ws/src/app/utils/index.ts | 2 ++ .../ws/src/app/utils/skilavottordUtils.ts | 8 +++++ 7 files changed, 51 insertions(+), 32 deletions(-) rename apps/skilavottord/ws/src/app/{ => utils}/const.ts (68%) create mode 100644 apps/skilavottord/ws/src/app/utils/index.ts create mode 100644 apps/skilavottord/ws/src/app/utils/skilavottordUtils.ts 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 ab1e1f5ef7db..74e9bb064d83 100644 --- a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts +++ b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts @@ -21,7 +21,8 @@ import { } from './recyclingRequest.model' import { VehicleService, VehicleModel } from '../vehicle' import { IcelandicTransportAuthorityServices } from '../../services/icelandicTransportAuthority.services' -import { ApiVersion } from '../../const' +import { ApiVersion } from '../../utils/const' +import { getShortPermno } from '../../utils/skilavottordUtils' @Injectable() export class RecyclingRequestService { @@ -103,7 +104,9 @@ export class RecyclingRequestService { error.config.data = undefined } this.logger.error(`Failed to deregister vehicle`, { error }) - throw new Error(`Failed to deregister vehicle ${vehiclePermno.slice(-3)}`) + throw new Error( + `Failed to deregister vehicle ${getShortPermno(vehiclePermno)}`, + ) } } @@ -142,7 +145,7 @@ export class RecyclingRequestService { permno: string, ): Promise { // We are only logging the last 3 chars in the vehicle number - const loggedPermno = permno.slice(-3) + const loggedPermno = getShortPermno(permno) try { // Check 'pendingRecycle' status @@ -188,7 +191,7 @@ export class RecyclingRequestService { const errors = new RequestErrors() // We are only logging the last 3 chars in the vehicle number - const loggedPermno = permno.slice(-3) + const loggedPermno = getShortPermno(permno) this.logger.info(`car-recycling: Recycling request ${loggedPermno}`, { requestType: requestType, diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts index 61433a620aa6..58bd1fc96afd 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/samgongustofa.service.ts @@ -9,7 +9,8 @@ import { Traffic, VehicleInformation } from './samgongustofa.model' import { logger } from '@island.is/logging' import { TransportService } from './transport/transport.service' -import { ApiVersion } from '../../const' +import { ApiVersion } from '../../utils/const' +import { getShortPermno } from '../../utils/skilavottordUtils' @Injectable() export class SamgongustofaService { @@ -317,12 +318,7 @@ export class SamgongustofaService { } /** - * - * @param nationalId - * @param permno - * @param requireRecyclable * @deprecated - * @returns */ async getUserVehicle( nationalId: string, @@ -347,26 +343,36 @@ export class SamgongustofaService { const result = await this.transportService.doGet( url, url + 'traffic/' + permno, - undefined, ApiVersion.REGISTRATIONS, ) if (result.status === 200) { // Get the latest registered traffic data - return Object.values(result.data).reduce( + const traffic = Object.values(result.data).reduce( (prev: Traffic, current: Traffic) => new Date(prev.useDate) > new Date(current.useDate) ? prev : current, {} as Traffic, ) as Traffic + + logger.info( + `car-recycling: Got traffic data for ${getShortPermno(permno)}`, + { + outInStatus: traffic.outInStatus, + useStatus: traffic.useStatus, + useStatusName: traffic.useStatusName, + }, + ) + + return traffic } throw new Error( - `car-recycling: #1 Failed on getTraffic ${permno.slice(-3)}`, + `car-recycling: #1 Failed on getTraffic ${getShortPermno(permno)}`, ) } catch (err) { throw new Error( - `car-recycling: #2 Failed on getTraffic ${permno.slice( - -3, + `car-recycling: #2 Failed on getTraffic ${getShortPermno( + permno, )} because: ${err}`, ) } @@ -380,7 +386,6 @@ export class SamgongustofaService { return this.transportService.doGet( url, url + 'vehicleinformationmini/' + permno, - undefined, ApiVersion.INFORMATION, ) } catch (err) { diff --git a/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts b/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts index 76a11ee505c4..5ec134cb39f0 100644 --- a/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts +++ b/apps/skilavottord/ws/src/app/modules/samgongustofa/transport/transport.service.ts @@ -50,24 +50,20 @@ export class TransportService { } } - async doGet( - restURL: string, - fullUrl: string, - queryParams: { [key: string]: string } | undefined, - apiVersion: string, - ) { + /** + * + * @param restURL - the base Samgöngustofa API url + * @param fullUrl - the full url to the Samgöngustofa API endpoint + * @param apiVersion - Samgöngustofa API version + * @returns + */ + async doGet(restURL: string, fullUrl: string, apiVersion: string) { const jwtToken = await this.authenticate(restURL, apiVersion) - if (queryParams) { - const searchParams = new URLSearchParams(queryParams) - - // Concatenate the URL with the query string - fullUrl = `${fullUrl}?${searchParams.toString()}` - } - const headers = { 'Content-Type': 'application/json', Authorization: 'Bearer ' + jwtToken, + 'Api-version': apiVersion, } const result = await lastValueFrom( diff --git a/apps/skilavottord/ws/src/app/modules/vehicle/vehicleAppSys.resolver.ts b/apps/skilavottord/ws/src/app/modules/vehicle/vehicleAppSys.resolver.ts index ddf2133b3f9c..d15060f93a12 100644 --- a/apps/skilavottord/ws/src/app/modules/vehicle/vehicleAppSys.resolver.ts +++ b/apps/skilavottord/ws/src/app/modules/vehicle/vehicleAppSys.resolver.ts @@ -8,6 +8,7 @@ import { logger } from '@island.is/logging' import { CreateVehicleInput } from './dto/createVehicle.input' import { VehicleModel } from './vehicle.model' import { VehicleService } from './vehicle.service' +import { getShortPermno } from '../../utils/skilavottordUtils' @UseGuards(IdsUserGuard, ScopesGuard) @Resolver(() => VehicleModel) @@ -19,9 +20,12 @@ export class VehicleAppSysResolver { @CurrentUser() user: User, @Args('input') input: CreateVehicleInput, ) { - logger.info(`car-recycling: Creating Vehicle ${input.permno.slice(-3)}`, { - mileage: input.mileage, - }) + logger.info( + `car-recycling: Creating Vehicle ${getShortPermno(input.permno)}`, + { + mileage: input.mileage, + }, + ) const newVehicle = new VehicleModel() newVehicle.vinNumber = input.vin diff --git a/apps/skilavottord/ws/src/app/const.ts b/apps/skilavottord/ws/src/app/utils/const.ts similarity index 68% rename from apps/skilavottord/ws/src/app/const.ts rename to apps/skilavottord/ws/src/app/utils/const.ts index 724710e087c5..b4b53f7da574 100644 --- a/apps/skilavottord/ws/src/app/const.ts +++ b/apps/skilavottord/ws/src/app/utils/const.ts @@ -1,3 +1,4 @@ +/** Samgöngustofa API versions */ export enum ApiVersion { REGISTRATIONS = '3.0', INFORMATION = '1.0', diff --git a/apps/skilavottord/ws/src/app/utils/index.ts b/apps/skilavottord/ws/src/app/utils/index.ts new file mode 100644 index 000000000000..05d610c5e491 --- /dev/null +++ b/apps/skilavottord/ws/src/app/utils/index.ts @@ -0,0 +1,2 @@ +export * from './const' +export * from './skilavottordUtils' diff --git a/apps/skilavottord/ws/src/app/utils/skilavottordUtils.ts b/apps/skilavottord/ws/src/app/utils/skilavottordUtils.ts new file mode 100644 index 000000000000..77120b29d8e4 --- /dev/null +++ b/apps/skilavottord/ws/src/app/utils/skilavottordUtils.ts @@ -0,0 +1,8 @@ +/** + * Shorten the permno for logging purpose + * @param permno + * @returns + */ +export const getShortPermno = (permno: string) => { + return permno.slice(-3) +} From 4718dfa335f46176e243f3b255f20ac57b0596ac Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Tue, 10 Sep 2024 13:24:08 +0000 Subject: [PATCH 14/18] TS-866 Removed checkbox blue background --- .../web/components/CarDetailsBox2/CarDetailsBox2.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx b/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx index 5ccb886adbe0..132a9b961c79 100644 --- a/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx +++ b/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx @@ -149,7 +149,6 @@ export const CarDetailsBox2: FC> = ({ large name={name} label={t.numberplate.lost} - backgroundColor="blue" onChange={() => { if (!lostPlate) { onChange(PlateInfo.PLATE_LOST) From 93bd06e21dad77791726735878caaea7ccd98087 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Tue, 10 Sep 2024 14:46:45 +0000 Subject: [PATCH 15/18] TS-866 Fix 0 mileage --- .../web/screens/DeregisterVehicle/Confirm/Confirm.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx index bf4dc908b8a2..00a99f8174ff 100644 --- a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx +++ b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx @@ -186,13 +186,15 @@ const Confirm: FC> = () => { if (mileageValue !== undefined) { newMileage = +mileageValue.trim().replace(/\./g, '') + } else { + newMileage = vehicle?.mileage } // Update vehicle table with latests information setVehicleRequest({ variables: { permno: vehicle?.vehicleId, - mileage: newMileage || vehicle?.mileage, + mileage: newMileage, plateCount: plateCountValue === 0 ? 0 : plateCountValue, plateLost: plateLost?.length ? true : false, }, From 619845149eb7f33b898e86c6d1c85f2dad41f0d8 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Tue, 10 Sep 2024 15:30:28 +0000 Subject: [PATCH 16/18] TS-866 Fix after coderabbit review --- .../components/CarDetailsBox2/CarDetailsBox2.tsx | 7 +++---- .../screens/DeregisterVehicle/Confirm/Confirm.tsx | 15 +++++---------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx b/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx index 132a9b961c79..c65487ba8047 100644 --- a/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx +++ b/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx @@ -28,9 +28,8 @@ interface BoxProps { vehicleId: string vehicleType: string modelYear: string - vehicleOwner?: string | null mileage?: number - + vinNumber?: string outInStatus: number useStatus: string } @@ -39,7 +38,7 @@ export const CarDetailsBox2: FC> = ({ vehicleId, vehicleType, modelYear, - vehicleOwner, + vinNumber, mileage, outInStatus, useStatus, @@ -67,8 +66,8 @@ export const CarDetailsBox2: FC> = ({ {vehicleId} {mileage} km {`${vehicleType}, ${modelYear}`} + vin: {vinNumber} - {vehicleOwner} > = () => { permno: vehicle?.vehicleId, mileage: newMileage, plateCount: plateCountValue === 0 ? 0 : plateCountValue, - plateLost: plateLost?.length ? true : false, + plateLost: !!plateLost?.length, }, }).then(() => { // Send recycling request @@ -268,10 +266,7 @@ const Confirm: FC> = () => { vehicleId={vehicle.vehicleId} vehicleType={vehicle.vehicleType} modelYear={getYear(vehicle.newregDate)} - vehicleOwner={ - vehicle.recyclingRequests && - vehicle.recyclingRequests[0].nameOfRequestor - } + vinNumber={vehicle.vinNumber} mileage={vehicle.mileage || 0} outInStatus={outInStatus} useStatus={useStatus || ''} From db1486663d9bf9a6c25c8a12ddbc112a201fd0a9 Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Wed, 11 Sep 2024 10:29:11 +0000 Subject: [PATCH 17/18] TS-866 Add back owner --- .../web/components/CarDetailsBox2/CarDetailsBox2.tsx | 5 ++++- .../web/screens/DeregisterVehicle/Confirm/Confirm.tsx | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx b/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx index c65487ba8047..b76419da7cf3 100644 --- a/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx +++ b/apps/skilavottord/web/components/CarDetailsBox2/CarDetailsBox2.tsx @@ -29,6 +29,7 @@ interface BoxProps { vehicleType: string modelYear: string mileage?: number + vehicleOwner?: string | null vinNumber?: string outInStatus: number useStatus: string @@ -38,6 +39,7 @@ export const CarDetailsBox2: FC> = ({ vehicleId, vehicleType, modelYear, + vehicleOwner, vinNumber, mileage, outInStatus, @@ -66,7 +68,8 @@ export const CarDetailsBox2: FC> = ({ {vehicleId} {mileage} km {`${vehicleType}, ${modelYear}`} - vin: {vinNumber} + {vinNumber && VIN: {vinNumber}} + {vehicleOwner} diff --git a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx index 98d26dfd0f3b..293ac53554ed 100644 --- a/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx +++ b/apps/skilavottord/web/screens/DeregisterVehicle/Confirm/Confirm.tsx @@ -45,6 +45,9 @@ const SkilavottordVehicleReadyToDeregisteredQuery = gql` newregDate vinNumber mileage + recyclingRequests { + nameOfRequestor + } } } ` @@ -266,6 +269,7 @@ const Confirm: FC> = () => { vehicleId={vehicle.vehicleId} vehicleType={vehicle.vehicleType} modelYear={getYear(vehicle.newregDate)} + vehicleOwner={vehicle.recyclingRequests?.[0]?.nameOfRequestor} vinNumber={vehicle.vinNumber} mileage={vehicle.mileage || 0} outInStatus={outInStatus} From 02878b69b674977021f75c2f30506dd7ccc7445c Mon Sep 17 00:00:00 2001 From: bkristmundsson Date: Wed, 11 Sep 2024 10:43:51 +0000 Subject: [PATCH 18/18] TS-866 improve logging --- .../app/modules/recyclingRequest/recyclingRequest.service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 74e9bb064d83..b84bedcff8ea 100644 --- a/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts +++ b/apps/skilavottord/ws/src/app/modules/recyclingRequest/recyclingRequest.service.ts @@ -350,8 +350,10 @@ export class RecyclingRequestService { this.logger.info( `car-recycling: Degregistering vehicle ${loggedPermno} from Samgongustofa`, { - mileage: vehicle.mileage ?? 0, partnerId, + mileage: vehicle.mileage ?? 0, + plateCount: vehicle.plateCount, + lost: vehicle.plateLost ? 1 : 0, }, )