Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bulk-mileage): update errors #16720

Merged
merged 20 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libs/api/domains/vehicles/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
"options": {
"jestConfig": "libs/api/domains/vehicles/jest.config.ts"
}
},
"extract-strings": {
"executor": "nx:run-commands",
"options": {
"command": "yarn ts-node -P libs/localization/tsconfig.lib.json libs/localization/scripts/extract 'libs/api/domains/vehicles/src/lib/messages.ts'"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Field, ID, InputType } from '@nestjs/graphql'
import type { Locale } from '@island.is/shared/types'

@InputType()
export class BulkVehicleMileageRequestOverviewInput {
@Field(() => String)
locale!: Locale

@Field(() => ID)
guid!: string
}
83 changes: 83 additions & 0 deletions libs/api/domains/vehicles/src/lib/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { defineMessages } from 'react-intl'

export const m = defineMessages({
tooManyPermno: {
id: 'api.bulk-vehicle-mileage:too-many-permno',
defaultMessage: 'Sama fastanúmer birtist oft í skjali',
},
missingPermno: {
id: 'api.bulk-vehicle-mileage:missing-permno',
defaultMessage: 'Fastanúmer vantar',
},
dateMissing: {
id: 'api.bulk-vehicle-mileage:date-missing',
defaultMessage: 'Dagsetning álesturs vantar',
},
originMissing: {
id: 'api.bulk-vehicle-mileage:missing-origin',
defaultMessage: 'Uppruna álesturs vantar',
},
mileageMissing: {
id: 'api.bulk-vehicle-mileage:missing-mileage',
defaultMessage: 'Álestur vantar',
},
mileageTooLow: {
id: 'api.bulk-vehicle-mileage:mileage-too-low',
defaultMessage: 'Km staða getur ekki verið minna en 0',
},
mileageLowerThanBefore: {
id: 'api.bulk-vehicle-mileage:mileage-lower-than-before',
defaultMessage:
'Km staða álesturs getur ekki verið minni en síðasta gildi sem skráð hefur verið á ökutækið',
},
originNotFound: {
id: 'api.bulk-vehicle-mileage:origin-not-found',
defaultMessage: 'Staðartegund í álestri finnst ekki',
},
carNotFound: {
id: 'api.bulk-vehicle-mileage:car-not-found',
defaultMessage: 'Ökutæki finnst ekki',
},
dateTooEarly: {
id: 'api.bulk-vehicle-mileage:date-too-early',
defaultMessage: 'Dagsetning færslu minni en nýjasta færsla á ökutæki',
},
invalidUpdate: {
id: 'api.bulk-vehicle-mileage:invalid-update',
defaultMessage: 'Ekki má breyta færslu sem er ekki innan dagsins í dag',
},
registerTooEarly: {
id: 'api.bulk-vehicle-mileage:register-too-early',
defaultMessage:
'Villa við skráningu, ekki má skrá innan 30 daga frá síðustu færslu',
},
forbiddenUpdate: {
id: 'api.bulk-vehicle-mileage:forbidden-update',
defaultMessage: 'Ekki má breyta færslu sem er ekki nýjasta færsla ökutækis',
},
unauthorizedUpdater: {
id: 'api.bulk-vehicle-mileage:unauthorized-updater',
defaultMessage:
'Tilkynnandi eða innsendur tilkynnandi er hvorki umráðamaður né eigandi ökutækis',
},
invalidMileage: {
id: 'api.bulk-vehicle-mileage:invalid-mileage',
defaultMessage: 'Tegund álesturs ekki til',
},
invalidDelete: {
id: 'api.bulk-vehicle-mileage:invalid-delete',
defaultMessage: 'Aðeins er leyfilegt að eyða nýjustu km skráningu',
},
notFoundDelete: {
id: 'api.bulk-vehicle-mileage:not-found-delete',
defaultMessage: 'Færsla til að eyða finnst ekki',
},
unnecessaryRegistration: {
id: 'api.bulk-vehicle-mileage:unnecessary-registration',
defaultMessage: 'Ökutæki krefst ekki aflesturs',
},
tooHighMileage: {
id: 'api.bulk-vehicle-mileage:too-high-mileage',
defaultMessage: 'Km staða fer yfir hámark per dag',
},
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Field, ObjectType } from '@nestjs/graphql'
import { Field, Int, ObjectType } from '@nestjs/graphql'

@ObjectType()
export class VehiclesBulkMileageRegistrationRequestError {
Expand All @@ -7,4 +7,10 @@ export class VehiclesBulkMileageRegistrationRequestError {

@Field({ nullable: true })
message?: string

@Field(() => Int, { nullable: true })
warningSerialCode?: number

@Field({ nullable: true })
warningText?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class VehiclesBulkMileageResolver {
) {
return this.bulkService.getBulkMileageRegistrationRequestOverview(
user,
input.locale,
input.guid,
)
disaerna marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ import { AuthMiddleware } from '@island.is/auth-nest-tools'
import type { Auth, User } from '@island.is/auth-nest-tools'
import { PostVehicleBulkMileageInput } from '../dto/postBulkVehicleMileage.input'
import { isDefined } from '@island.is/shared/utils'
import type { Locale } from '@island.is/shared/types'
import { LOG_CATEGORY } from '../constants'
import { LOGGER_PROVIDER, type Logger } from '@island.is/logging'
import { VehiclesBulkMileageReadingResponse } from '../models/v3/bulkMileage/bulkMileageReadingResponse.model'
import { VehiclesBulkMileageRegistrationJobHistory } from '../models/v3/bulkMileage/bulkMileageRegistrationJobHistory.model'
import { VehiclesBulkMileageRegistrationRequestStatus } from '../models/v3/bulkMileage/bulkMileageRegistrationRequestStatus.model'
import { VehiclesBulkMileageRegistrationRequestOverview } from '../models/v3/bulkMileage/bulkMileageRegistrationRequestOverview.model'
import { FetchError } from '@island.is/clients/middlewares'
import { IntlService } from '@island.is/cms-translations'
import { errorCodeMessageMap } from './errorCodes'

const namespaces = ['api.bulk-vehicle-mileage']

@Injectable()
export class BulkMileageService {
constructor(
private mileageReadingApi: MileageReadingApi,
private readonly intlService: IntlService,
@Inject(LOGGER_PROVIDER) private readonly logger: Logger,
) {}

Expand Down Expand Up @@ -59,7 +65,6 @@ export class BulkMileageService {

return {
requestId: res.guid,
errorMessage: res.errorMessage ?? undefined,
}
} catch (e) {
const error: Error = e
Expand Down Expand Up @@ -127,8 +132,10 @@ export class BulkMileageService {

async getBulkMileageRegistrationRequestOverview(
auth: User,
locale: Locale,
input: GetbulkmileagereadingrequeststatusGuidGetRequest['guid'],
): Promise<VehiclesBulkMileageRegistrationRequestOverview> {
const { formatMessage } = await this.intlService.useIntl(namespaces, locale)
const data = await this.getMileageWithAuth(
auth,
).getbulkmileagereadingrequestdetailsGuidGet({ guid: input })
Expand All @@ -139,15 +146,25 @@ export class BulkMileageService {
if (!d.guid || !d.permno) {
return null
}

return {
guid: d.guid,
vehicleId: d.permno,
mileage: d.mileage ?? undefined,
returnCode: d.returnCode ?? undefined,
errors: d.errors?.map((e) => ({
code: e.errorCode ?? undefined,
message: e.errorText ?? undefined,
})),
errors: d.errors?.map((e) => {
const warningSerial =
e.warningSerial === -1 ? 999 : e.warningSerial

return {
code: e.errorCode ?? undefined,
message: e.errorText ?? undefined,
warningSerialCode: e.warningSerial,
warningText: warningSerial
? formatMessage(errorCodeMessageMap[warningSerial])
: undefined,
}
}),
}
})
.filter(isDefined),
Expand Down
24 changes: 24 additions & 0 deletions libs/api/domains/vehicles/src/lib/services/errorCodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { MessageDescriptor } from 'react-intl'
import { m } from '../../lib/messages'
disaerna marked this conversation as resolved.
Show resolved Hide resolved

export const errorCodeMessageMap: Record<number, MessageDescriptor> = {
999: m.tooManyPermno, //returned error code is -1, which cant be used to index. Transform to 999
3: m.missingPermno,
4: m.dateMissing,
5: m.originMissing,
6: m.mileageMissing,
7: m.mileageTooLow,
8: m.mileageLowerThanBefore,
9: m.originNotFound,
10: m.carNotFound,
11: m.dateTooEarly,
12: m.invalidUpdate,
13: m.registerTooEarly,
14: m.forbiddenUpdate,
15: m.unauthorizedUpdater,
16: m.invalidMileage,
17: m.invalidDelete,
18: m.notFoundDelete,
19: m.unnecessaryRegistration,
20: m.tooHighMileage,
}
disaerna marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 6 additions & 8 deletions libs/api/domains/vehicles/src/lib/services/vehicles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import {
VehicleDtoListPagedResponse,
PersidnoLookupResultDto,
CurrentVehiclesWithMilageAndNextInspDtoListPagedResponse,
ApiResponse,
} from '@island.is/clients/vehicles'
import {
CanregistermileagePermnoGetRequest,
GetMileageReadingRequest,
MileageReadingApi,
MileageReadingDto,
PostMileageReadingModel,
PutMileageReadingModel,
RequiresmileageregistrationPermnoGetRequest,
RootPostRequest,
RootPutRequest,
Expand All @@ -35,10 +33,7 @@ import {
GetVehiclesForUserInput,
GetVehiclesListV2Input,
} from '../dto/getVehiclesForUserInput'
import {
VehicleMileageDetail,
VehicleMileageOverview,
} from '../models/getVehicleMileage.model'
import { VehicleMileageOverview } from '../models/getVehicleMileage.model'
import isSameDay from 'date-fns/isSameDay'
import { mileageDetailConstructor } from '../utils/helpers'
import { FetchError, handle404 } from '@island.is/clients/middlewares'
Expand Down Expand Up @@ -470,9 +465,11 @@ export class VehiclesService {
throw new ForbiddenException(UNAUTHORIZED_OWNERSHIP_LOG)
}

return this.getMileageWithAuth(auth).rootPut({
const dtos = await this.getMileageWithAuth(auth).rootPut({
putMileageReadingModel: input,
})

return dtos.length > 0 ? dtos[0] : null
}

async postMileageReadingV2(
Expand Down Expand Up @@ -537,9 +534,10 @@ export class VehiclesService {
}

try {
return this.getMileageWithAuth(auth).rootPut({
const dtos = await this.getMileageWithAuth(auth).rootPut({
putMileageReadingModel: input,
})
return dtos.length > 0 ? dtos[0] : null
} catch (e) {
if (e instanceof FetchError && (e.status === 400 || e.status === 429)) {
const errorBody = e.body as UpdateResponseError
Expand Down
2 changes: 2 additions & 0 deletions libs/api/domains/vehicles/src/lib/vehicles.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { FeatureFlagModule } from '@island.is/nest/feature-flags'
import { BulkMileageService } from './services/bulkMileage.service'
import { VehiclesV3Resolver } from './resolvers/vehicleV3.resolver'
import { VehiclesBulkMileageResolver } from './resolvers/bulkMileage.resolver'
import { CmsTranslationsModule } from '@island.is/cms-translations'
disaerna marked this conversation as resolved.
Show resolved Hide resolved

@Module({
providers: [
Expand All @@ -26,6 +27,7 @@ import { VehiclesBulkMileageResolver } from './resolvers/bulkMileage.resolver'
VehiclesClientModule,
VehiclesMileageClientModule,
AuthModule,
CmsTranslationsModule,
FeatureFlagModule,
],
exports: [VehiclesService],
Expand Down
20 changes: 12 additions & 8 deletions libs/clients/vehicles-mileage/src/clientConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"openapi": "3.0.1",
"info": {
"title": "SGS Rest API",
"description": "Mileage reading API developed in .Net8.0 - Release-6 : 20231122.2",
"description": "Mileage reading API developed in .Net8.0 - Release-21 : 20241105.1",
"contact": {
"name": "Samgöngustofa",
"email": "tolvuhjalp@samgongustofa.is"
},
"version": "1.0"
},
"servers": [{ "url": "/vehicle/mileagereading" }],
"paths": {
"/authenticate": {
"post": {
Expand Down Expand Up @@ -243,11 +244,14 @@
}
},
"responses": {
"201": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/MileageReadingDto" }
"schema": {
"type": "array",
"items": { "$ref": "#/components/schemas/MileageReadingDto" }
}
disaerna marked this conversation as resolved.
Show resolved Hide resolved
}
}
},
Expand Down Expand Up @@ -788,6 +792,11 @@
"description": "Error code",
"nullable": true
},
"warningSerial": {
"type": "integer",
"description": "Warning serial",
"format": "int32"
},
"errorText": {
"type": "string",
"description": "Error text",
Expand Down Expand Up @@ -850,11 +859,6 @@
"type": "string",
"description": "Guid to check for status and results",
"nullable": true
},
"errorMessage": {
"type": "string",
"description": "Error message if any",
"nullable": true
}
},
"additionalProperties": false,
Expand Down
19 changes: 19 additions & 0 deletions libs/service-portal/assets/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ export const vehicleMessage = defineMessages({
id: 'sp.vehicles:not-found',
defaultMessage: 'Ökutæki fannst ekki',
},
invalidFileType: {
id: 'sp.vehicles:invalid-file-type',
defaultMessage:
'Ógild skráargerð. Einungis .xlsx og .csv skrár eru samþykktar',
},
infoNote: {
id: 'sp.vehicles:detail-info-note',
defaultMessage:
Expand Down Expand Up @@ -981,6 +986,10 @@ export const vehicleMessage = defineMessages({
id: 'sp.vehicles:upload-failed',
defaultMessage: 'Upphleðsla mistókst',
},
noDataInUploadedFile: {
id: 'sp.vehicles:no-data-in-uploaded-file',
defaultMessage: 'Upphleðsla mistókst. Engin gögn í skjali',
},
wrongFileType: {
id: 'sp.vehicles:wrong-file-type',
defaultMessage: 'Vitlaus skráartýpa. Skrá verður að vera .csv eða .xslx',
Expand All @@ -989,6 +998,16 @@ export const vehicleMessage = defineMessages({
id: 'sp.vehicles:error-while-processing',
defaultMessage: 'Villa við að meðhöndla skjal. Villur: ',
},
invalidPermNoColumn: {
id: 'sp.vehicles:invalid-perm-no-column',
defaultMessage:
'Fastanúmersdálk vantar eða er skrifaður rangt. Dálkanafn þarf að vera eitt af eftirfarandi; "permno", "vehicleid", "bilnumer","okutaeki","fastanumer"',
},
invalidMileageColumn: {
id: 'sp.vehicles:invalid-mileage-column',
defaultMessage:
'Kílómetrastöðudálk vantar eða er skrifaður rangt. Dálkanafn þarf að vera eitt af eftirfarandi; "kilometrastada", "mileage", "odometer"',
},
downloadFailed: {
id: 'sp.vehicles:download-failed',
defaultMessage: 'Niðurhal mistókst',
Expand Down
Loading
Loading