Newer
Older
client_dwatch / lib / clean-logs / advice-url.ts
import type { CleanLogItem } from "@/lib/types";

/**
 * 清掃詳細ログの1行を開いたときに取るアドバイス API の URL。
 * `null` を返すのは、予定ありで `id` が null、または予定なしで `report_id` が null のとき
 * (API の不変条件違反)だけ。
 * ★判定(◎○△×)と結果待ちは見ない★ — ◎○・結果待ちの行を開かない判断は呼び出し側
 * (`cleanLogRowView().expandable`。偽なら `CleanLogTable` が `onToggleRow` を呼ばない)で行う(指示書BI)。
 */
export function cleanLogAdviceUrl(
  row: Pick<CleanLogItem, "id" | "unscheduled" | "report_id">
): string | null {
  if (row.unscheduled) {
    if (row.report_id === null) return null;
    return `/api/clean-logs/unscheduled/${encodeURIComponent(row.report_id)}/advice`;
  }
  if (row.id === null) return null;
  return `/api/clean-logs/${row.id}/advice`;
}