fix party job/skill API calls

- use shortcode instead of id for job updates
- wrap job_id in party object for rails API
- only send editable skill slots (1-3), skip null values
- add updateAccessory method stub
This commit is contained in:
Justin Edmund 2025-11-28 11:04:26 -08:00
parent 5403aebe48
commit b1bfe82507
2 changed files with 28 additions and 16 deletions

View file

@ -213,7 +213,9 @@ export class PartyAdapter extends BaseAdapter {
return this.request<Party>(`/parties/${shortcode}/jobs`, {
method: 'PUT',
body: {
job_id: jobId
party: {
job_id: jobId
}
}
})
}
@ -228,17 +230,17 @@ export class PartyAdapter extends BaseAdapter {
console.log('[updateJobSkills] Input skills array:', skills)
// Convert skills array to Rails expected format
const party: Record<string, string | null> = {}
// Rails has skill0_id (main, locked), skill1_id, skill2_id, skill3_id
// Only include skills that have actual IDs - don't send null values
// as Rails will try to validate them
const party: Record<string, string> = {}
// Initialize all slots with null
for (let i = 1; i <= 4; i++) {
party[`skill${i}_id`] = null
}
// Set the provided skills
skills.forEach(skill => {
// Rails expects skill1_id, skill2_id, skill3_id, skill4_id
party[`skill${skill.slot + 1}_id`] = skill.id
// Set the provided skills - slot number maps directly to skill{N}_id
skills.forEach((skill) => {
// Only set editable slots (1, 2, 3) and only if skill has an ID
if (skill.slot >= 1 && skill.slot <= 3 && skill.id) {
party[`skill${skill.slot}_id`] = skill.id
}
})
const requestBody = {
@ -256,6 +258,16 @@ export class PartyAdapter extends BaseAdapter {
})
}
/**
* Updates the accessory for a party
*/
async updateAccessory(partyId: string, accessoryId: string): Promise<Party> {
return this.request<Party>(`/parties/${partyId}/accessory`, {
method: 'PUT',
body: { accessory_id: accessoryId }
})
}
/**
* Removes a job skill from a party
*/

View file

@ -369,8 +369,8 @@
error = null
try {
// Update job via API
const updated = await partyAdapter.updateJob(party.id, job.id)
// Update job via API (use shortcode for party identification)
const updated = await partyAdapter.updateJob(party.shortcode, job.id)
party = updated
} catch (e) {
error = e instanceof Error ? e.message : 'Failed to update job'
@ -415,7 +415,7 @@
console.log('[Party] Skills array to send:', skillsArray)
const updated = await partyAdapter.updateJobSkills(
party.id,
party.shortcode,
skillsArray
)
party = updated
@ -476,7 +476,7 @@
console.log('[Party] Skills array to send after removal:', skillsArray)
const updated = await partyAdapter.updateJobSkills(
party.id,
party.shortcode,
skillsArray
)
party = updated
@ -537,7 +537,7 @@
}))
const updated = await partyAdapter.updateJobSkills(
party.id,
party.shortcode,
skillsArray
)
party = updated