Unlink Then Relink
This page explains focused correction flow where CTT moves from one NTT to another.
API Endpoints
POST /ticket/ctt/unlink-then-link
Purpose
Unlink-then-relink safely rewires wrong existing relationship without forcing operator to do two unrelated manual steps.
Business meaning
This flow:
- resolves target NTT first
- checks each CTT independently
- skips relink when item already points to target
- unlinks current NTT when needed
- links to target NTT after cleanup
- returns aggregated mixed result
Flow summary
| Step | Business meaning |
|---|---|
| receive target NTT ticket number and CTT ids | correction request starts |
resolve target NTT by ticketNo | destination must exist first |
| initialize result counters | success, failed, skipped tracked separately |
| loop each CTT id | items run independently |
| load current CTT | source item must exist |
| already linked to target? | item is skipped as success |
| linked to another NTT? | old relation must be removed first |
| run full unlink helper if needed | cleanup uses normal unlink path |
| run full link helper to target | new relation uses normal link path |
| capture success or failure | aggregated result is built |
| any success at all? | zero-success batch fails, mixed batch can still return |
Implementation note
Current repo confirms:
- controller exposes
POST /ticket/ctt/unlink-then-link - service resolves target NTT before loop
- service reuses both
unlinkCttNttWithAudit(...)andlinkCttNttWithAudit(...)
Code refs:
mvp3-ticket-service/src/modules/ctt/ctt.controller.ts:304mvp3-ticket-service/src/modules/ctt/ctt.service.ts:2699