fix(my-orders): correct closed PO filters for manager and submitter

Managers and superusers were silently filtered to only their own
submitted POs because submitterId: userId was applied unconditionally.
Submitters were also shown MGR_APPROVED, SENT_FOR_PAYMENT,
PAID_DELIVERED and REJECTED orders alongside CLOSED ones.

Fix: managers/superusers see all CLOSED POs (no submitterId filter);
submitters see only their own CLOSED POs.

Fixes #6
This commit is contained in:
Claude (auto-fix) 2026-06-19 03:34:21 +05:30
parent b19ab695eb
commit a37ca068c2

View file

@ -15,11 +15,12 @@ export default async function MyOrdersPage() {
const { role, id: userId } = session.user;
if (!["TECHNICAL", "MANNING", "MANAGER", "SUPERUSER"].includes(role)) redirect("/dashboard");
const isManager = role === "MANAGER" || role === "SUPERUSER";
const closed = await db.purchaseOrder.findMany({
where: {
submitterId: userId,
status: { in: ["MGR_APPROVED", "SENT_FOR_PAYMENT", "PAID_DELIVERED", "CLOSED", "REJECTED"] },
},
where: isManager
? { status: "CLOSED" }
: { submitterId: userId, status: "CLOSED" },
orderBy: { updatedAt: "desc" },
include: {
vessel: { select: { name: true } },