fix: use swap API endpoints for drag-and-drop rearrangement

The handleSwap function was calling move methods (moveWeapon,
moveCharacter, moveSummon) which validate that target positions are
empty. This caused 422 errors when dragging items to swap positions.

Switch to using swap methods (swapWeapons, swapCharacters, swapSummons)
which perform atomic swaps in a transaction and bypass position
validation, allowing items to correctly swap positions.

Also remove unreachable throw statement after return.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Justin Edmund 2025-11-29 02:22:03 -08:00
parent a0939ec695
commit 65f5521c74

View file

@ -127,25 +127,37 @@
throw new Error('Invalid swap operation - missing items')
}
// Call appropriate grid service method based on type
// Call appropriate swap method based on type
if (source.type === 'weapon') {
await gridService.moveWeapon(party.id, source.itemId, target.position, editKey || undefined, {
shortcode: party.shortcode
})
} else if (source.type === 'character') {
await gridService.moveCharacter(
await gridService.swapWeapons(
party.id,
source.itemId,
target.position,
target.itemId,
editKey || undefined,
{
shortcode: party.shortcode
}
)
} else if (source.type === 'character') {
await gridService.swapCharacters(
party.id,
source.itemId,
target.itemId,
editKey || undefined,
{
shortcode: party.shortcode
}
)
} else if (source.type === 'summon') {
await gridService.moveSummon(party.id, source.itemId, target.position, editKey || undefined, {
shortcode: party.shortcode
})
await gridService.swapSummons(
party.id,
source.itemId,
target.itemId,
editKey || undefined,
{
shortcode: party.shortcode
}
)
} else {
throw new Error(`Unknown item type: ${source.type}`)
}
@ -154,8 +166,6 @@
partyService.clearPartyCache(party.shortcode)
const updated = await partyService.getByShortcode(party.shortcode)
return updated
throw new Error(`Unknown item type: ${source.type}`)
}
async function handleMove(source: any, target: any): Promise<Party> {