fix(seed): upsert POs so re-running seed does not fail on duplicate poNumber; currency USD -> INR

This commit is contained in:
Hardik 2026-05-06 00:21:37 +05:30
parent 7c31b0e838
commit 67beccc16d

View file

@ -185,14 +185,16 @@ async function main() {
}, },
}); });
// Sample POs // Sample POs — upsert so re-running seed is safe
const po1 = await db.purchaseOrder.create({ const po1 = await db.purchaseOrder.upsert({
data: { where: { poNumber: "PO-2026-00001" },
update: {},
create: {
poNumber: "PO-2026-00001", poNumber: "PO-2026-00001",
title: "Engine Room Spare Parts — MV Pelagia Star", title: "Engine Room Spare Parts — MV Pelagia Star",
status: "MGR_REVIEW", status: "MGR_REVIEW",
totalAmount: 8450.0, totalAmount: 8450.0,
currency: "USD", currency: "INR",
submittedAt: new Date(), submittedAt: new Date(),
submitterId: technical.id, submitterId: technical.id,
vesselId: mv1.id, vesselId: mv1.id,
@ -214,13 +216,15 @@ async function main() {
}, },
}); });
await db.purchaseOrder.create({ await db.purchaseOrder.upsert({
data: { where: { poNumber: "PO-2026-00002" },
update: {},
create: {
poNumber: "PO-2026-00002", poNumber: "PO-2026-00002",
title: "Crew Safety Equipment — MV Aegean Wind", title: "Crew Safety Equipment — MV Aegean Wind",
status: "DRAFT", status: "DRAFT",
totalAmount: 3200.0, totalAmount: 3200.0,
currency: "USD", currency: "INR",
submitterId: technical.id, submitterId: technical.id,
vesselId: mv2.id, vesselId: mv2.id,
accountId: acc2.id, accountId: acc2.id,
@ -236,13 +240,15 @@ async function main() {
}, },
}); });
await db.purchaseOrder.create({ await db.purchaseOrder.upsert({
data: { where: { poNumber: "PO-2026-00003" },
update: {},
create: {
poNumber: "PO-2026-00003", poNumber: "PO-2026-00003",
title: "Navigation Charts Update — Fleet", title: "Navigation Charts Update — Fleet",
status: "MGR_APPROVED", status: "MGR_APPROVED",
totalAmount: 950.0, totalAmount: 950.0,
currency: "USD", currency: "INR",
submittedAt: new Date(Date.now() - 5 * 86400000), submittedAt: new Date(Date.now() - 5 * 86400000),
approvedAt: new Date(Date.now() - 2 * 86400000), approvedAt: new Date(Date.now() - 2 * 86400000),
submitterId: technical.id, submitterId: technical.id,