All files / src/lib/patient app-programme-patient.ts

75% Statements 3/4
50% Branches 1/2
100% Functions 1/1
75% Lines 3/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                        7x     7x           7x    
import { NextResponse } from "next/server";
import type { AppIdentity } from "@/lib/app-auth";
import { ownPatientIdForSession } from "@/lib/overview/patient";
 
/**
 * The record a Klarbefund programme route acts on: the one the app's login
 * owns, and no other (#934, step 4). There is no patientId parameter, as on
 * /api/patient/app/record, so the phone cannot name someone else's record.
 */
export function appProgrammePatient(
  app: AppIdentity,
): { patientId: string } | NextResponse {
  const patientId = ownPatientIdForSession({
    preferredUsername: app.username,
  });
  Iif (!patientId) {
    return NextResponse.json(
      { error: "No record is assigned to this login" },
      { status: 404 },
    );
  }
  return { patientId };
}