fix(integration-map): stop creating duplicate entities and maps when a sync update fails

Merged
CE
3d ago
+482-75

Problem

The integration-map sync handlers for labels, projects, organizations, screenshots and activities wrap the integration-map lookup and the update of the mapped entity in one try. When the update failed, the catch took it for "no map yet" and created a new entity and a second integration map for the same sourceId, so every failed sync added a duplicate. The label handler also re-created the tag under its existing id when only the tag update failed, and the activity handler wrote the Gauzy id into the caller's entity with Object.assign(entity, { id }).

Fix

  • The integration map is looked up on its own; only a miss leads to "create entity + map".
  • With a map, the update runs and its errors reach the caller.
  • Label: the mapped tag is looked up on its own and re-created under the mapped id only when it no longer exists.
  • Activity: ActivityUpdateCommand receives { ...entity, id } instead of a mutated input.
  • Return values are unchanged.

Tests

New integration-map.sync-label.handler.spec.ts and integration-map.sync-activity.handler.spec.ts: an update failure with an existing map rejects and creates nothing; a missing map creates the entity and its map once; label: a missing mapped tag is re-created with the mapped id; activity: the update gets a copy carrying the mapped id and the input is unchanged.

Notes

Not built or run locally.


Summary by cubic

Fixes the integration-map sync handlers for labels, projects, organizations, screenshots, and activities so a failed entity update no longer creates duplicate entities and maps.

Previously the map lookup and the entity update shared one try/catch: a failed update was mistaken for "no map yet", so every failure created a new entity and a second integration map for the same sourceId. Now only a NotFoundException during lookup counts as "no map yet"; any other lookup or update error propagates to the caller.

Behavior details

  • A shared nullIfNotFound helper turns a lookup miss into null and rethrows any other error.
  • Project, organization, and screenshot handlers re-create a mapped entity deleted here and point the existing map at it instead of creating a second map.
  • Label: the mapped tag is looked up separately and re-created under the mapped id only when it no longer exists.
  • Activity: the update receives a copy carrying the mapped id; the caller's entity is no longer mutated.
  • ScreenshotUpdateHandler lets a NotFoundException propagate unchanged so a deleted screenshot is re-created.
  • Added unit tests covering mapped, unmapped, and deleted-entity paths for all five handlers.