You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.2 KiB

import { fail, ok, parseBigIntId, requireSession } from "@/lib/api";
import { runWithMailCcOwner } from "@/lib/cc-owner";
import { evaluateTransferGate } from "@/services/cc/container-status";
import { prisma } from "@/services/db";
import { assertMailReadable } from "@/services/tenant/access";
type RouteContext = { params: Promise<{ id: string }> };
export async function GET(_req: Request, ctx: RouteContext) {
const guard = await requireSession();
if (guard.response) return guard.response;
const { id } = await ctx.params;
const mailId = parseBigIntId(id);
if (!mailId) return fail("VALIDATION", "Invalid mail id", 400);
const mail = await prisma.mailMessage.findUnique({
where: { id: mailId },
include: { parseResult: true },
});
if (!mail) return fail("NOT_FOUND", "邮件不存在", 404);
if (!(await assertMailReadable(guard.session, mailId))) {
return fail("NOT_FOUND", "邮件不存在", 404);
}
const header = mail.parseResult?.containerHeader as
| { F_ContainerNo?: string }
| undefined;
const cn = (header?.F_ContainerNo || "").trim();
const gate = await runWithMailCcOwner(mailId, () => evaluateTransferGate(cn));
return ok({ container_no: cn, gate });
}