import { addLog } from "./log";

export const updateJadwal = async ({ number, ptId }, data) => {
	try {
		const myHeaders = new Headers();
		myHeaders.append("Content-Type", "application/json");

		const raw = JSON.stringify(data);

		const requestOptions = {
			method: "POST",
			body: raw,
			headers: myHeaders,
		};

		const updated = await fetch(`http://localhost:5000/pelaporan/jadwal/add?number=${number}&ptId=${ptId}`, requestOptions);
		const result = await updated.json();
		addLog({ status: "SUCCESS", action: "UPDATE", from: { id: result.added._id, data: "penjadwalan" }, description: "mengubah jadwal pemeriksaan" });
		return result;
	} catch (error) {
		console.log("error", error);
		addLog({ status: "FAIL", action: "UPDATE", from: { data: "penjadwalan" }, description: error.message || "mengubah jadwal pemeriksaan" });
		return false;
	}
};
