Skip to content

Commit

Permalink
Rec speed and speed limit is now number
Browse files Browse the repository at this point in the history
  • Loading branch information
oddsson committed Jan 22, 2025
1 parent 1b79e40 commit f3f78fe
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Allow, IsArray, IsEnum, IsOptional, IsString } from 'class-validator'
import {
Allow,
IsArray,
IsEnum,
IsNumber,
IsOptional,
Min,
} from 'class-validator'
import { GraphQLJSONObject } from 'graphql-type-json'

import { Field, ID, InputType } from '@nestjs/graphql'
import { Field, ID, InputType, Int } from '@nestjs/graphql'

import type { SubstanceMap } from '@island.is/judicial-system/types'
import {
Expand Down Expand Up @@ -66,13 +73,15 @@ export class UpdateIndictmentCountInput {

@Allow()
@IsOptional()
@IsString()
@Field(() => String, { nullable: true })
readonly recordedSpeed?: string
@IsNumber()
@Min(0)
@Field(() => Int, { nullable: true })
readonly recordedSpeed?: number

@Allow()
@IsOptional()
@IsString()
@Field(() => String, { nullable: true })
readonly speedLimit?: string
@IsNumber()
@Min(0)
@Field(() => Int, { nullable: true })
readonly speedLimit?: number
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GraphQLJSONObject } from 'graphql-type-json'

import { Field, ID, ObjectType, registerEnumType } from '@nestjs/graphql'
import { Field, ID, Int, ObjectType, registerEnumType } from '@nestjs/graphql'

import type { SubstanceMap } from '@island.is/judicial-system/types'
import {
Expand Down Expand Up @@ -49,9 +49,9 @@ export class IndictmentCount {
@Field(() => [IndictmentSubtype], { nullable: true })
readonly indictmentCountSubtypes?: IndictmentSubtype[]

@Field(() => String, { nullable: true })
readonly recordedSpeed?: string
@Field(() => Int, { nullable: true })
readonly recordedSpeed?: number

@Field(() => String, { nullable: true })
readonly speedLimit?: string
@Field(() => Int, { nullable: true })
readonly speedLimit?: number
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
'indictment_count',
'recorded_speed',
{
type: Sequelize.STRING,
type: Sequelize.INTEGER,
allowNull: true,
},
{ transaction: t },
Expand All @@ -15,7 +15,7 @@ module.exports = {
'indictment_count',
'speed_limit',
{
type: Sequelize.STRING,
type: Sequelize.INTEGER,
allowNull: true,
},
{ transaction: t },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
IsArray,
IsEnum,
IsNumber,
IsObject,
IsOptional,
IsString,
MaxLength,
Min,
} from 'class-validator'

import { ApiPropertyOptional } from '@nestjs/swagger'
Expand Down Expand Up @@ -61,12 +63,14 @@ export class UpdateIndictmentCountDto {
readonly indictmentCountSubtypes?: IndictmentSubtype[]

@IsOptional()
@IsString()
@ApiPropertyOptional({ type: String })
readonly recordedSpeed?: string
@IsNumber()
@Min(0)
@ApiPropertyOptional({ type: Number })
readonly recordedSpeed?: number

@IsOptional()
@IsString()
@ApiPropertyOptional({ type: String })
readonly speedLimit?: string
@IsNumber()
@Min(0)
@ApiPropertyOptional({ type: Number })
readonly speedLimit?: number
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ export class IndictmentCount extends Model {
@ApiPropertyOptional({ enum: IndictmentSubtype, isArray: true })
indictmentCountSubtypes?: IndictmentSubtype[]

@Column({ type: DataType.STRING, allowNull: true })
@ApiPropertyOptional({ type: String })
recordedSpeed?: string
@Column({ type: DataType.INTEGER, allowNull: true })
@ApiPropertyOptional({ type: Number })
recordedSpeed?: number

@Column({ type: DataType.STRING, allowNull: true })
@ApiPropertyOptional({ type: String })
speedLimit?: string
@Column({ type: DataType.INTEGER, allowNull: true })
@ApiPropertyOptional({ type: Number })
speedLimit?: number
}
Original file line number Diff line number Diff line change
Expand Up @@ -805,96 +805,96 @@ export const IndictmentCount: FC<Props> = ({
heading="h4"
marginBottom={2}
/>
<Box display="flex" rowGap={1} columnGap={1} flexWrap="wrap">
<Box flexGrow={1}>
<InputMask
mask={'999'}
maskPlaceholder={null}
value={indictmentCount.recordedSpeed ?? ''}
onChange={(event) => {
removeErrorMessageIfValid(
['empty'],
event.target.value,
recordedSpeedErrorMessage,
setRecordedSpeedErrorMessage,
)

updateIndictmentCountState(
indictmentCount.id,
{ recordedSpeed: event.target.value },
setWorkingCase,
)
}}
onBlur={(event) => {
const recordedSpeed = event.target.value

validateAndSetErrorMessage(
['empty'],
recordedSpeed,
setRecordedSpeedErrorMessage,
)
<Box marginBottom={1}>
<InputMask
mask={'999'}
maskPlaceholder={null}
value={indictmentCount.recordedSpeed?.toString() ?? ''}
onChange={(event) => {
const recordedSpeed = parseInt(event.target.value)

removeErrorMessageIfValid(
['empty'],
event.target.value,
recordedSpeedErrorMessage,
setRecordedSpeedErrorMessage,
)

updateIndictmentCountState(
indictmentCount.id,
{ recordedSpeed },
setWorkingCase,
)
}}
onBlur={(event) => {
const recordedSpeed = parseInt(event.target.value)

validateAndSetErrorMessage(
['empty'],
recordedSpeed.toString(),
setRecordedSpeedErrorMessage,
)

handleIndictmentCountChanges({
recordedSpeed,
})
}}
>
<Input
name="recordedSpeed"
autoComplete="off"
label={formatMessage(strings.recordedSpeedLabel)}
placeholder="0"
required
errorMessage={recordedSpeedErrorMessage}
hasError={recordedSpeedErrorMessage !== ''}
/>
</InputMask>
</Box>
<InputMask
mask={'999'}
maskPlaceholder={null}
value={indictmentCount.speedLimit?.toString() ?? ''}
onChange={(event) => {
const speedLimit = parseInt(event.target.value)

handleIndictmentCountChanges({
recordedSpeed,
})
}}
>
<Input
name="recordedSpeed"
autoComplete="off"
label={formatMessage(strings.recordedSpeedLabel)}
placeholder="0"
required
errorMessage={recordedSpeedErrorMessage}
hasError={recordedSpeedErrorMessage !== ''}
/>
</InputMask>
</Box>
<Box flexGrow={1}>
<InputMask
mask={'999'}
maskPlaceholder={null}
value={indictmentCount.speedLimit ?? ''}
onChange={(event) => {
removeErrorMessageIfValid(
['empty'],
event.target.value,
speedLimitErrorMessage,
setSpeedLimitErrorMessage,
)
removeErrorMessageIfValid(
['empty'],
event.target.value,
speedLimitErrorMessage,
setSpeedLimitErrorMessage,
)

updateIndictmentCountState(
indictmentCount.id,
{ speedLimit: event.target.value },
setWorkingCase,
)
}}
onBlur={(event) => {
const speedLimit = event.target.value
updateIndictmentCountState(
indictmentCount.id,
{ speedLimit },
setWorkingCase,
)
}}
onBlur={(event) => {
const speedLimit = parseInt(event.target.value)

validateAndSetErrorMessage(
['empty'],
speedLimit,
setSpeedLimitErrorMessage,
)
validateAndSetErrorMessage(
['empty'],
speedLimit.toString(),
setSpeedLimitErrorMessage,
)

handleIndictmentCountChanges({
speedLimit,
})
}}
>
<Input
name="speedLimit"
autoComplete="off"
label={formatMessage(strings.speedLimitLabel)}
placeholder="0"
required
errorMessage={speedLimitErrorMessage}
hasError={speedLimitErrorMessage !== ''}
/>
</InputMask>
</Box>
</Box>
handleIndictmentCountChanges({
speedLimit,
})
}}
>
<Input
name="speedLimit"
autoComplete="off"
label={formatMessage(strings.speedLimitLabel)}
placeholder="0"
required
errorMessage={speedLimitErrorMessage}
hasError={speedLimitErrorMessage !== ''}
/>
</InputMask>
</Box>
)}
{indictmentCount.offenses
Expand Down

0 comments on commit f3f78fe

Please sign in to comment.