fix: tighten real operations data paths
This commit is contained in:
@@ -4,8 +4,8 @@ import { jsonFailure, jsonSuccess, readJsonBody } from "@/modules/core/server/ap
|
||||
import { recordAuditLog } from "@/modules/core/server/audit";
|
||||
import { requirePermission } from "@/modules/core/server/auth";
|
||||
import { getDatabase } from "@/modules/core/server/db";
|
||||
import { listOperationalBeds } from "@/modules/core/server/operations";
|
||||
import { beds, rooms } from "@/modules/core/server/schema";
|
||||
import { readData } from "@/modules/core/server/store";
|
||||
import type { BedStatus } from "@/modules/core/types";
|
||||
|
||||
const BED_STATUS_VALUES: BedStatus[] = ["available", "occupied", "maintenance", "disabled"];
|
||||
@@ -19,8 +19,12 @@ function readString(source: Record<string, unknown>, key: string): string {
|
||||
return typeof value === "string" ? value.trim() : "";
|
||||
}
|
||||
|
||||
function readBedStatus(value: string): BedStatus {
|
||||
return BED_STATUS_VALUES.find((status) => status === value) ?? "available";
|
||||
function readOptionalBedStatus(value: string): BedStatus | null | undefined {
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return BED_STATUS_VALUES.find((status) => status === value) ?? null;
|
||||
}
|
||||
|
||||
export async function GET(): Promise<Response> {
|
||||
@@ -33,11 +37,8 @@ export async function GET(): Promise<Response> {
|
||||
return auth.response;
|
||||
}
|
||||
|
||||
const data = await readData();
|
||||
const organizationId = auth.context.organization?.id;
|
||||
return jsonSuccess("床位列表已加载", {
|
||||
beds: organizationId ? data.beds.filter((bed) => bed.organizationId === organizationId) : data.beds,
|
||||
});
|
||||
const bedsData = await listOperationalBeds(auth.context.organization?.id);
|
||||
return jsonSuccess("床位列表已加载", { beds: bedsData });
|
||||
}
|
||||
|
||||
export async function POST(request: Request): Promise<Response> {
|
||||
@@ -65,6 +66,10 @@ export async function POST(request: Request): Promise<Response> {
|
||||
if (!roomId || !code) {
|
||||
return jsonFailure("房间和床位编号不能为空");
|
||||
}
|
||||
const status = readOptionalBedStatus(readString(body, "status"));
|
||||
if (status === null) {
|
||||
return jsonFailure("床位状态无效");
|
||||
}
|
||||
|
||||
const database = getDatabase();
|
||||
const roomRows = await database
|
||||
@@ -83,7 +88,7 @@ export async function POST(request: Request): Promise<Response> {
|
||||
organizationId,
|
||||
roomId,
|
||||
code,
|
||||
status: readBedStatus(readString(body, "status")),
|
||||
status: status ?? "available",
|
||||
notes: readString(body, "notes"),
|
||||
})
|
||||
.returning();
|
||||
|
||||
Reference in New Issue
Block a user