8c86c988c1
Uniform stock management for healthcare linen rooms: the coordinator app, the phone counter and the staff app, for your own server. Built from 2d04e45 on 2026-09-15. Licensed under the Functional Source License (FSL-1.1-ALv2).
26 lines
1.2 KiB
TypeScript
26 lines
1.2 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { currentUser } from "@/lib/session";
|
|
import { prisma } from "@/lib/db";
|
|
import { exportBackup } from "@/lib/ops";
|
|
import { facilityToday } from "@/lib/compute";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export async function GET() {
|
|
const user = await currentUser();
|
|
if (!user) return NextResponse.json({ error: "Not signed in" }, { status: 401 });
|
|
if (user.role !== "ADMIN") return NextResponse.json({ error: "Admin only" }, { status: 403 });
|
|
const data = await exportBackup(user);
|
|
// The date on the filename is the day where the linen room stands, not where the box is. It has
|
|
// to agree with the lastBackup stamp exportBackup writes against the same facility, or a room
|
|
// taking a backup at eight in the morning ends up with a file named for yesterday sitting beside
|
|
// a settings screen that says it was taken today.
|
|
const fac = await prisma.facility.findUniqueOrThrow({ where: { id: user.facilityId }, select: { timezone: true } });
|
|
return new NextResponse(JSON.stringify(data, null, 1), {
|
|
headers: {
|
|
"content-type": "application/json; charset=utf-8",
|
|
"content-disposition": `attachment; filename="threadcount-backup-${facilityToday(fac.timezone)}.json"`,
|
|
},
|
|
});
|
|
}
|