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:
parent
5403aebe48
commit
b1bfe82507
2 changed files with 28 additions and 16 deletions
|
|
@ -213,7 +213,9 @@ export class PartyAdapter extends BaseAdapter {
|
||||||
return this.request<Party>(`/parties/${shortcode}/jobs`, {
|
return this.request<Party>(`/parties/${shortcode}/jobs`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: {
|
body: {
|
||||||
job_id: jobId
|
party: {
|
||||||
|
job_id: jobId
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -228,17 +230,17 @@ export class PartyAdapter extends BaseAdapter {
|
||||||
console.log('[updateJobSkills] Input skills array:', skills)
|
console.log('[updateJobSkills] Input skills array:', skills)
|
||||||
|
|
||||||
// Convert skills array to Rails expected format
|
// 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
|
// Set the provided skills - slot number maps directly to skill{N}_id
|
||||||
for (let i = 1; i <= 4; i++) {
|
skills.forEach((skill) => {
|
||||||
party[`skill${i}_id`] = null
|
// 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
|
||||||
// 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
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const requestBody = {
|
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
|
* Removes a job skill from a party
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -369,8 +369,8 @@
|
||||||
error = null
|
error = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Update job via API
|
// Update job via API (use shortcode for party identification)
|
||||||
const updated = await partyAdapter.updateJob(party.id, job.id)
|
const updated = await partyAdapter.updateJob(party.shortcode, job.id)
|
||||||
party = updated
|
party = updated
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e instanceof Error ? e.message : 'Failed to update job'
|
error = e instanceof Error ? e.message : 'Failed to update job'
|
||||||
|
|
@ -415,7 +415,7 @@
|
||||||
console.log('[Party] Skills array to send:', skillsArray)
|
console.log('[Party] Skills array to send:', skillsArray)
|
||||||
|
|
||||||
const updated = await partyAdapter.updateJobSkills(
|
const updated = await partyAdapter.updateJobSkills(
|
||||||
party.id,
|
party.shortcode,
|
||||||
skillsArray
|
skillsArray
|
||||||
)
|
)
|
||||||
party = updated
|
party = updated
|
||||||
|
|
@ -476,7 +476,7 @@
|
||||||
console.log('[Party] Skills array to send after removal:', skillsArray)
|
console.log('[Party] Skills array to send after removal:', skillsArray)
|
||||||
|
|
||||||
const updated = await partyAdapter.updateJobSkills(
|
const updated = await partyAdapter.updateJobSkills(
|
||||||
party.id,
|
party.shortcode,
|
||||||
skillsArray
|
skillsArray
|
||||||
)
|
)
|
||||||
party = updated
|
party = updated
|
||||||
|
|
@ -537,7 +537,7 @@
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const updated = await partyAdapter.updateJobSkills(
|
const updated = await partyAdapter.updateJobSkills(
|
||||||
party.id,
|
party.shortcode,
|
||||||
skillsArray
|
skillsArray
|
||||||
)
|
)
|
||||||
party = updated
|
party = updated
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue