Skip to content

Commit

Permalink
[Backoffice REG] Correction de la mise-à-jour d'une géometrie (#2557)
Browse files Browse the repository at this point in the history
## Linked issues

- Resolve #2556

----

- [ ] Tests E2E (Cypress)
  • Loading branch information
louptheron authored Oct 3, 2023
2 parents c91fdde + 5f611de commit 1de50bc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Feature from 'ol/Feature'

import resetPreviousRegulation from './resetRegulation'
import updateRegulation from './updateRegulation'
import {
getRegulatoryFeatureId,
mapToRegulatoryFeatureObject,
REGULATION_ACTION_TYPE
} from '../../../entities/regulation'

export const createOrUpdateRegulation = (processingRegulation, id, previousId) => async dispatch => {
const featureObject = mapToRegulatoryFeatureObject({
...processingRegulation,
region: processingRegulation.region?.join(', ')
})

const feature = new Feature(featureObject)
feature.setId(getRegulatoryFeatureId(id))
if (isGeometryModified(previousId, id)) {
/**
* We first need to reset the previous regulation as there is an UNIQUE CONSTRAINT (topic, zone) of the table.
* /!\ This constraint is only applied to the local (CROSS) regulations table.
*/
await dispatch(resetPreviousRegulation(previousId, id))
}

/**
* Then, we update the new regulation with the values of the previous one
*/
await dispatch(updateRegulation(feature, REGULATION_ACTION_TYPE.UPDATE))
}

function isGeometryModified(previousId, id) {
return previousId && previousId !== id
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
setRegulatoryTopics,
setRegulatoryZoneMetadata
} from '../../../domain/shared_slices/Regulatory'
import createOrUpdateRegulation from '../../../domain/use_cases/layer/regulation/createOrUpdateRegulation'
import { createOrUpdateRegulation } from '../../../domain/use_cases/layer/regulation/createOrUpdateRegulation'
import getAllRegulatoryLayersByRegTerritory from '../../../domain/use_cases/layer/regulation/getAllRegulatoryLayersByRegTerritory'
import getGeometryWithoutRegulationReference from '../../../domain/use_cases/layer/regulation/getGeometryWithoutRegulationReference'
import showRegulatoryZone from '../../../domain/use_cases/layer/regulation/showRegulatoryZone'
Expand Down
13 changes: 3 additions & 10 deletions infra/local/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,11 @@ COPY public.reglementation_peche (id, law_type,
## Reset a regulation from the local PostGIS regulation referential

```
update prod.reglementation_peche set regulatory_references = null, topic = null, zones = null, facade = null, region = null, law_type = null where id = 10014;
insert into prod.regulations (id, topic, zone, region, law_type) VALUES (11053, 'Un topic de test', 'Zone de test', 'Bretagne', 'Reg. NAMO');
```

## Create a test regulatory entry

```
insert into prod.reglementation_peche (law_type, facade, topic, zones, region, date_fermeture,date_ouverture, fishing_period, periodes, engins, engins_interdits,mesures_techniques, especes, species, quantites, taille,especes_interdites, autre_reglementation_especes,documents_obligatoires, autre_reglementation, regulatory_references, row_hash) select law_type,
facade, 'Topic de test', 'Zone de test', region, date_fermeture,
date_ouverture, fishing_period, periodes, engins, engins_interdits,
mesures_techniques, especes, species, quantites, taille,
especes_interdites, autre_reglementation_especes,
documents_obligatoires, autre_reglementation,
regulatory_references, row_hash from prod.reglementation_peche where id = 10294;
```
insert into prod.regulations (geometry) select geometry from prod.regulations where id = 654;
```

0 comments on commit 1de50bc

Please sign in to comment.