/* eslint-disable @typescript-eslint/no-explicit-any */ import { PUBLIC_BASE_API_URL } from '$env/static/public'; import { fail } from '@sveltejs/kit'; export async function load({ cookies }) { return { accessToken: cookies.get('accessToken') }; } export const actions = { update: async ({ cookies, request, getClientAddress }) => { const data = await request.formData(); const id = data.get('id'); const sundayRatePer = Number(data.get('sundayRatePer')); const normalRatePer = Number(data.get('normalRatePer')); const publicHolidayRatePer = Number(data.get('publicHolidayRatePer')); const reqBody = JSON.stringify({ sundayRatePer, normalRatePer, publicHolidayRatePer }); const response = await fetch(`${PUBLIC_BASE_API_URL}/ot-setting/${id}`, { body: reqBody, headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${cookies.get('accessToken')}`, 'x-forwarded-for': getClientAddress(), 'x-real-ip': getClientAddress() }, method: 'PATCH' }); const responseData = await response.json(); if (responseData.statusCode) { return fail(responseData.statusCode, { id: 'inputData', message: JSON.stringify(responseData.message) }); } return { id: 'inputData', message: 'Updated' }; }, getTableData: async ({ cookies, getClientAddress }) => { try { const res = await fetch(`${PUBLIC_BASE_API_URL}/ot-setting`, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${cookies.get('accessToken')}`, 'x-forwarded-for': getClientAddress(), 'x-real-ip': getClientAddress() } }); const resData = await res.json(); const returnData = [ { ...resData, createdAt: new Date(resData.createdAt).toISOString().split('T')[0], updatedAt: new Date(resData.updatedAt).toISOString().split('T')[0] } ]; return { returnData, id: 'tableData' }; } catch (err: any) { return err.message; } } };