Update validateCurrentMonth and confirmRefuseTimesheet with tableUrl and
1 file changed+22−10
index.html+22−10View file
| @@ -3637,6 +3637,10 @@ | ||
| } | ||
| async function validateCurrentMonth() { | ||
| + if (!currentUser || currentUser.role !== 'admin') { | ||
| + showToast('Access Denied', 'Administrator permissions required.', 'error'); | ||
| + return; | ||
| + } | ||
| if (!inspectTimesheetId) return; | ||
| const ts = state.timesheets.find(t => t._id === inspectTimesheetId); | ||
| if (!ts) return; | ||
| @@ -3647,17 +3651,19 @@ | ||
| if (!isTempId(ts._id)) { | ||
| try { | ||
| - const res = await apiFetch(`/api/timesheets/${ts._id}`, { | ||
| + const res = await apiFetch(tableUrl('timesheets', ts._id), { | ||
| method: 'PATCH', | ||
| body: JSON.stringify({ status: 'validated', adminFeedback: '' }) | ||
| }); | ||
| if (res.ok) { | ||
| - const serverTs = await res.json(); | ||
| - Object.assign(ts, serverTs); | ||
| - saveStore(); | ||
| + const serverTs = unwrapRow(await res.json()); | ||
| + if (serverTs) { | ||
| + Object.assign(ts, serverTs); | ||
| + saveStore(); | ||
| + } | ||
| } | ||
| } catch (err) { | ||
| - console.warn('PATCH /api/timesheets/:id failed, updated locally:', err); | ||
| + console.warn('PATCH timesheet failed, updated locally:', err); | ||
| } | ||
| } | ||
| @@ -3677,6 +3683,10 @@ | ||
| } | ||
| async function confirmRefuseTimesheet() { | ||
| + if (!currentUser || currentUser.role !== 'admin') { | ||
| + showToast('Access Denied', 'Administrator permissions required.', 'error'); | ||
| + return; | ||
| + } | ||
| const feedback = document.getElementById('refusal-feedback-input').value.trim(); | ||
| if (!feedback) { | ||
| alert("Please provide refusal feedback notes so the freelancer knows what to adjust."); | ||
| @@ -3692,17 +3702,19 @@ | ||
| if (!isTempId(ts._id)) { | ||
| try { | ||
| - const res = await apiFetch(`/api/timesheets/${ts._id}`, { | ||
| + const res = await apiFetch(tableUrl('timesheets', ts._id), { | ||
| method: 'PATCH', | ||
| body: JSON.stringify({ status: 'refused', adminFeedback: feedback }) | ||
| }); | ||
| if (res.ok) { | ||
| - const serverTs = await res.json(); | ||
| - Object.assign(ts, serverTs); | ||
| - saveStore(); | ||
| + const serverTs = unwrapRow(await res.json()); | ||
| + if (serverTs) { | ||
| + Object.assign(ts, serverTs); | ||
| + saveStore(); | ||
| + } | ||
| } | ||
| } catch (err) { | ||
| - console.warn('PATCH /api/timesheets/:id failed, updated locally:', err); | ||
| + console.warn('PATCH timesheet failed, updated locally:', err); | ||
| } | ||
| } | ||