feat: Update user authentication data and enhance routine item handling in RoutineEditView
All checks were successful
Chore App Build, Test, and Push Docker Images / build-and-push (push) Successful in 3m16s

This commit is contained in:
2026-05-18 16:39:05 -04:00
parent 5392e5af70
commit ad8a8bf867
5 changed files with 91 additions and 24 deletions

View File

@@ -372,12 +372,23 @@ async function handleSubmit(form: { name: string; points: number; image_id: stri
})
if (!resp.ok) throw new Error('Failed to save routine')
const routineData = await resp.json()
const routineId = routineData.id || props.id
const routineId =
props.id ||
(typeof routineData?.id === 'string' && routineData.id) ||
(typeof routineData?.routine?.id === 'string' && routineData.routine.id) ||
''
if (!routineId) {
throw new Error('Failed to resolve routine id after save')
}
for (const itemId of removedItemIds.value) {
await fetch(`/api/routine/${routineId}/item/${itemId}`, {
const deleteResp = await fetch(`/api/routine/${routineId}/item/${itemId}`, {
method: 'DELETE',
})
if (!deleteResp.ok) {
throw new Error('Failed to delete routine item')
}
}
for (const item of items.value) {
@@ -385,17 +396,23 @@ async function handleSubmit(form: { name: string; points: number; image_id: stri
const payload = { name: item.name, image_id: resolvedImageId, order: item.order }
if (item.id?.startsWith('temp-') || !item.id) {
await fetch(`/api/routine/${routineId}/item/add`, {
const addItemResp = await fetch(`/api/routine/${routineId}/item/add`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
})
if (!addItemResp.ok) {
throw new Error('Failed to add routine item')
}
} else {
await fetch(`/api/routine/${routineId}/item/${item.id}/edit`, {
const editItemResp = await fetch(`/api/routine/${routineId}/item/${item.id}/edit`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
})
if (!editItemResp.ok) {
throw new Error('Failed to edit routine item')
}
}
}