import { addLog } from "./log";

export const addBanding = async ({ noSanksi, ptId }, data) => {
	try {
		const res = await fetch(`http://localhost:5000/banding/add?noSanksi=${noSanksi}&ptId=${ptId}`, {
			method: "POST",
			body: data,
		});
		const result = await res.json();
		console.log(result);
		// addLog({ status: "SUCCESS", action: "CREATE", from: { id: result.added._id, data: "banding" }, description: "membuat permohonan banding" });
		return result;
	} catch (error) {
		console.log("error", error);
		addLog({ status: "FAIL", action: "ADD", from: { data: "banding" }, description: error.message || "membuat permohonan banding" });
		return false;
	}
};

export const addJawabanBanding = async ({ noSanksi, ptId }, data) => {
	try {
		const res = await fetch(`http://localhost:5000/banding/jawaban/add?noSanksi=${noSanksi}&ptId=${ptId}`, {
			method: "POST",
			body: data,
		});
		const result = await res.json();
		console.log(result);
		// addLog({ status: "SUCCESS", action: "CREATE", from: { id: result.added._id, data: "banding" }, description: "membuat permohonan banding" });
		return result;
	} catch (error) {
		console.log("error", error);
		addLog({ status: "FAIL", action: "ADD", from: { data: "banding" }, description: error.message || "membuat permohonan banding" });
		return false;
	}
};
