Skip to content

fix: return 409 or clear hidden twins on work experience PUT conflicts#4323

Open
skwowet wants to merge 2 commits into
mainfrom
fix/work-experience-put-unique-conflict
Open

fix: return 409 or clear hidden twins on work experience PUT conflicts#4323
skwowet wants to merge 2 commits into
mainfrom
fix/work-experience-put-unique-conflict

Conversation

@skwowet

@skwowet skwowet commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Public work-experience PUT could 500 with SequelizeUniqueConstraintError when the update reused another active row’s (organizationId, dateStart, dateEnd). Align with create: conflict with a visible row returns 409; conflict with a grouped/hidden twin soft-deletes that twin so the visible update can proceed.

Changes

  • Before updating, detect other active member orgs with the same unique key
  • Soft-delete conflicting collapsible rows (project-registry / email-domain), then continue the PUT + fan-out
  • Throw ConflictError when the conflicting row is another visible work experience
  • Export isCollapsibleMemberOrganization from the mapper for reuse

skwowet added 2 commits July 10, 2026 00:37
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
@skwowet skwowet self-assigned this Jul 9, 2026
Copilot AI review requested due to automatic review settings July 9, 2026 19:08
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a 500 error (SequelizeUniqueConstraintError) on the public work-experience PUT endpoint. When an update reused another active row's (organizationId, dateStart, dateEnd) unique key, the request would crash. The fix aligns update behavior with the create path: conflicts with a visible work experience now return 409, while conflicts with a grouped/hidden "twin" row soft-delete that twin so the visible update can proceed.

Changes:

  • Detect other active member-org rows sharing the target unique key (org + date range) before the UPDATE, using a new sameUniqueKey helper that mirrors the DB partial unique indexes with null-aware date normalization.
  • Throw ConflictError (409) when the conflicting row is a visible work experience; soft-delete conflicting collapsible rows (email-domain/project-registry) and exclude them from the subsequent fan-out.
  • Export isCollapsibleMemberOrganization from the mapper so the endpoint can classify conflicting rows.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
backend/src/api/public/v1/members/work-experiences/updateMemberWorkExperience.ts Adds pre-update conflict detection, 409 for visible conflicts, soft-delete of hidden twins, and filters fan-out to exclude deleted rows.
backend/src/utils/mapper.ts Exports isCollapsibleMemberOrganization for reuse by the update endpoint.

I verified the imports (ConflictError, deleteMemberOrganizations, normalizeMemberOrganizationDate, IMemberOrganization, isCollapsibleMemberOrganization) are all valid and used; that ConflictError maps to HTTP 409; that sameUniqueKey correctly captures the three partial unique indexes on memberOrganizations; and that the nested-transaction helper pattern is consistent with the existing create/delete/verify endpoints. I did not find concrete issues warranting inline comments. Because this is a data-mutation change on a public API with subtle unique-index/soft-delete/fan-out interactions, I recommend a final human review.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants