diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlUnitResourceModel.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlUnitResourceModel.kt index 873f7a0c8..c8a7c4240 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlUnitResourceModel.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlUnitResourceModel.kt @@ -1,12 +1,13 @@ package fr.gouv.cacem.monitorenv.infrastructure.database.model import com.fasterxml.jackson.annotation.JsonBackReference +import com.vladmihalcea.hibernate.type.basic.PostgreSQLEnumType import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceEntity import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceType import fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit.dtos.FullControlUnitResourceDTO import jakarta.persistence.* -import org.hibernate.annotations.ColumnTransformer import org.hibernate.annotations.CreationTimestamp +import org.hibernate.annotations.Type import org.hibernate.annotations.UpdateTimestamp import java.time.Instant @@ -37,9 +38,9 @@ data class ControlUnitResourceModel( @Column(name = "photo") var photo: ByteArray? = byteArrayOf(), + @Column(name = "type", nullable = false, columnDefinition = "control_unit_resource_type") @Enumerated(EnumType.STRING) - @Column(name = "type", nullable = false) - @ColumnTransformer(write = "?::control_unit_resource_type") + @Type(PostgreSQLEnumType::class) var type: ControlUnitResourceType, @Column(name = "created_at_utc", nullable = false, updatable = false) diff --git a/frontend/src/features/ControlUnit/components/ControlUnitDialog/ControlUnitResourceList/Item.tsx b/frontend/src/features/ControlUnit/components/ControlUnitDialog/ControlUnitResourceList/Item.tsx index 1ad49298e..ee04203c9 100644 --- a/frontend/src/features/ControlUnit/components/ControlUnitDialog/ControlUnitResourceList/Item.tsx +++ b/frontend/src/features/ControlUnit/components/ControlUnitDialog/ControlUnitResourceList/Item.tsx @@ -22,7 +22,7 @@ export function Item({ controlUnitResource, onEdit }: ItemProps) {
- {ControlUnit.ControlUnitResourceType[controlUnitResource.type]} – {controlUnitResource.name} + {ControlUnit.ControlUnitResourceTypeLabel[controlUnitResource.type]} – {controlUnitResource.name}

{controlUnitResource.base.name}

diff --git a/frontend/src/features/ControlUnit/components/ControlUnitDialog/ControlUnitResourceList/constants.ts b/frontend/src/features/ControlUnit/components/ControlUnitDialog/ControlUnitResourceList/constants.ts index 5655bf06e..76ed1b3c7 100644 --- a/frontend/src/features/ControlUnit/components/ControlUnitDialog/ControlUnitResourceList/constants.ts +++ b/frontend/src/features/ControlUnit/components/ControlUnitDialog/ControlUnitResourceList/constants.ts @@ -11,11 +11,8 @@ export const CONTROL_UNIT_RESOURCE_FORM_SCHEMA = object().shape({ }) export const CONTROL_UNIT_RESOURCE_TYPES_AS_OPTIONS = getOptionsFromLabelledEnum( - ControlUnit.ControlUnitResourceType, + ControlUnit.ControlUnitResourceTypeLabel, true -).filter( - controlUnitResourceTypeAsOption => - controlUnitResourceTypeAsOption.label !== ControlUnit.ControlUnitResourceType.UNKNOWN ) export const INITIAL_CONTROL_UNIT_RESOURCE_FORM_VALUES: ControlUnitResourceFormValues = { diff --git a/frontend/src/features/ControlUnit/components/ControlUnitDialog/ControlUnitResourceList/index.tsx b/frontend/src/features/ControlUnit/components/ControlUnitDialog/ControlUnitResourceList/index.tsx index 25af78104..1f07026ca 100644 --- a/frontend/src/features/ControlUnit/components/ControlUnitDialog/ControlUnitResourceList/index.tsx +++ b/frontend/src/features/ControlUnit/components/ControlUnitDialog/ControlUnitResourceList/index.tsx @@ -45,7 +45,7 @@ export function ControlUnitResourceList({ controlUnit }: ControlUnitResourceList ...controlUnitResourceFormValues, // We set the resource type as the resource name if no name has been provided by the user name: isEmptyish(controlUnitResourceFormValues.name) - ? ControlUnit.ControlUnitResourceType[controlUnitResourceFormValues.type as string] + ? ControlUnit.ControlUnitResourceTypeLabel[controlUnitResourceFormValues.type as string] : controlUnitResourceFormValues.name }