const a="/api/log";class i{static async log(e){try{const r=await fetch(`${a}/write`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!r.ok)throw new Error("Failed to record log entry");return(await r.json()).id}catch(r){console.error("Error while sending log to server:",r)}}static async exportToJson(e,r){try{const o=new URLSearchParams;e&&o.append("dateFrom",e.toISOString()),r&&o.append("dateTo",r.toISOString());const t=await fetch(`${a}/export/json?${o.toString()}`);if(!t.ok)throw new Error("Failed to export logs to JSON");const s=await t.json();console.log(s.message)}catch(o){console.error("Error while exporting logs to JSON:",o)}}static async exportToExcel(e,r){try{const o=new URLSearchParams;e&&o.append("dateFrom",e.toISOString()),r&&o.append("dateTo",r.toISOString());const t=await fetch(`${a}/export/excel?${o.toString()}`);if(!t.ok)throw new Error("Failed to export logs to Excel");return await t.blob()}catch(o){console.error("Error while exporting logs to Excel:",o)}return null}static async logUserScore(e,r,o){const t=await fetch("/api/log/write/userScore",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e,score:r,comment:o})});if(!t.ok)throw new Error("Failed to update user score");if((await t.json()).message!=="User score updated successfully")throw new Error("User score update failed")}}export{i as L}; | |