File size: 1,004 Bytes
dddedae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// POST feedback (rating + comment) attached to a specific measurement
// run. The endpoint requires a run_id and either a rating or a message
// (or both). Returns { success, error? } — the server returns 200 even
// when persistence is offline so callers only need to handle network
// errors and 4xx validation failures.
export async function submitFeedback({ runId, rating, message }) {
  if (!runId) {
    return { success: false, error: "Missing run_id" };
  }
  const body = { run_id: runId };
  if (rating) body.rating = rating;
  if (message) body.message = message;
  const resp = await fetch("/api/feedback", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(body),
  });
  let data = null;
  try {
    data = await resp.json();
  } catch {
    /* ignore parse errors — fall back to status code */
  }
  if (!resp.ok) {
    return { success: false, error: (data && data.error) || `HTTP ${resp.status}` };
  }
  return { success: true };
}