Skip to content

Commit

Permalink
fix(assets): bulk mileage fixes (#16253)
Browse files Browse the repository at this point in the history
* fix: random 0 in table

* fix: fixes

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
thorkellmani and kodiakhq[bot] authored Oct 3, 2024
1 parent 7eb0c62 commit 4706157
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
14 changes: 10 additions & 4 deletions libs/api/domains/vehicles/src/lib/resolvers/mileage.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ResolveField,
Resolver,
} from '@nestjs/graphql'
import { UseGuards } from '@nestjs/common'
import { Inject, UseGuards } from '@nestjs/common'
import {
IdsUserGuard,
ScopesGuard,
Expand All @@ -34,14 +34,18 @@ import {
Features,
} from '@island.is/nest/feature-flags'
import { mileageDetailConstructor } from '../utils/helpers'
import { LOGGER_PROVIDER, type Logger } from '@island.is/logging'

@UseGuards(IdsUserGuard, ScopesGuard, FeatureFlagGuard)
@FeatureFlag(Features.servicePortalVehicleMileagePageEnabled)
@Resolver(() => VehicleMileageOverview)
@Audit({ namespace: '@island.is/api/vehicles' })
@Scopes(ApiScope.vehicles)
export class VehiclesMileageResolver {
constructor(private readonly vehiclesService: VehiclesService) {}
constructor(
private readonly vehiclesService: VehiclesService,
@Inject(LOGGER_PROVIDER) private readonly logger: Logger,
) {}

@Query(() => VehicleMileageOverview, {
name: 'vehicleMileageDetails',
Expand Down Expand Up @@ -88,9 +92,11 @@ export class VehiclesMileageResolver {
mileage: Number(input.mileage ?? input.mileageNumber),
})

if (!res?.length) return undefined
if (!res) {
return
}

return mileageDetailConstructor(res[0])
return mileageDetailConstructor(res)
}

@ResolveField('canRegisterMileage', () => Boolean, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ export class VehiclesService {
async putMileageReading(
auth: User,
input: RootPutRequest['putMileageReadingModel'],
): Promise<Array<MileageReadingDto> | null> {
): Promise<MileageReadingDto | null> {
if (!input) return null

const isAllowed = await this.isAllowedMileageRegistration(
Expand All @@ -458,10 +458,9 @@ export class VehiclesService {
throw new ForbiddenException(UNAUTHORIZED_OWNERSHIP_LOG)
}

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

async canRegisterMileage(
Expand Down
7 changes: 2 additions & 5 deletions libs/clients/vehicles-mileage/src/clientConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,11 @@
}
},
"responses": {
"200": {
"201": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": { "$ref": "#/components/schemas/MileageReadingDto" }
}
"schema": { "$ref": "#/components/schemas/MileageReadingDto" }
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const VehicleBulkMileageRow = ({ vehicle }: Props) => {
usePutSingleVehicleMileageMutation({
onError: () => {
setPostError(formatMessage(m.errorTitle))
setPostSuccess(false)
},
onCompleted: () => {
setPostError(null)
Expand All @@ -58,10 +59,11 @@ export const VehicleBulkMileageRow = ({ vehicle }: Props) => {
usePostSingleVehicleMileageMutation({
onError: () => {
setPostError(formatMessage(m.errorTitle))
setPostSuccess(false)
},
onCompleted: () => {
setPostError(null)
setPostSuccess(false)
setPostSuccess(true)
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ const VehicleMileage = () => {
: [...details]

const latestRegistration =
detailArray[0].mileageNumber ?? 0
detailArray?.[0]?.mileageNumber ?? 0

if (latestRegistration > value) {
return formatMessage(messages.mileageInputTooLow)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const NestedFullTable = ({
}: Props) => {
return (
<Box className={styles.wrapper} background="white">
{!loading && data.length && (
{!loading && !!data.length && (
<T.Table>
<T.Head>
<T.Row>
Expand Down

0 comments on commit 4706157

Please sign in to comment.