fix: return 409 or clear hidden twins on work experience PUT conflicts#4323
fix: return 409 or clear hidden twins on work experience PUT conflicts#4323skwowet wants to merge 2 commits into
Conversation
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
There was a problem hiding this comment.
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 newsameUniqueKeyhelper 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
isCollapsibleMemberOrganizationfrom 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.
Summary
Public work-experience PUT could 500 with
SequelizeUniqueConstraintErrorwhen 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
project-registry/email-domain), then continue the PUT + fan-outConflictErrorwhen the conflicting row is another visible work experienceisCollapsibleMemberOrganizationfrom the mapper for reuse