-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backoffice REG] Correction de la mise-à-jour d'une géometrie (#2557)
## Linked issues - Resolve #2556 ---- - [ ] Tests E2E (Cypress)
- Loading branch information
Showing
4 changed files
with
39 additions
and
39 deletions.
There are no files selected for viewing
28 changes: 0 additions & 28 deletions
28
frontend/src/domain/use_cases/layer/regulation/createOrUpdateRegulation.js
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
frontend/src/domain/use_cases/layer/regulation/createOrUpdateRegulation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters