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.

110 lines
2.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* 仅初始化登录账号。不再写入 M1–M5 / 样例邮件。
* Usage: pnpm db:seed
*/
import { createHash } from "crypto";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
function hashPassword(plain: string): string {
return createHash("sha256").update(plain).digest("hex");
}
async function main() {
const adminUser = process.env.APP_ADMIN_USER || "admin";
const adminPass = process.env.APP_ADMIN_PASS || "admin123";
const opsUser = process.env.APP_OPS_USER || "ops";
const opsPass = process.env.APP_OPS_PASS || "ops123";
await prisma.appUser.upsert({
where: { username: adminUser },
create: {
username: adminUser,
passwordHash: hashPassword(adminPass),
passwordEnc: "",
role: "admin",
},
update: {
passwordHash: hashPassword(adminPass),
role: "admin",
},
});
await prisma.appUser.upsert({
where: { username: opsUser },
create: {
username: opsUser,
passwordHash: hashPassword(opsPass),
passwordEnc: "",
role: "ops",
},
update: {
passwordHash: hashPassword(opsPass),
role: "ops",
},
});
const caps = [
{ id: "save_container", mode: "live", endpoint: "/Container/SaveContainer" },
{ id: "transfer", mode: "mock", endpoint: "/Container/TransferWarehouse" },
{ id: "hold_split", mode: "mock", endpoint: "/Container/HoldSplitInstruction" },
{ id: "label", mode: "mock", endpoint: "/Container/ApplyLabelInstruction" },
{
id: "customer_message",
mode: "live",
endpoint: "/CustomerMessage/SaveForm",
},
{ id: "do_upload", mode: "live", endpoint: "/learun/adms/annexes/upload" },
{
id: "batch_transfer",
mode: "mock",
endpoint: "/Container/SaveStockBatchTransfer",
},
];
for (const c of caps) {
await prisma.ccWriteCapability.upsert({
where: { id: c.id },
create: c,
update:
c.id === "customer_message"
? { mode: "live", endpoint: c.endpoint }
: {},
});
}
const defaultMessageTypes = [
"操作指令",
"货件拦截",
"拆柜时自动转仓",
"客户拆分指令",
"扣货",
"扣货问题",
"收费问题",
"查验柜",
"PO查验报错",
"天灾",
"客户新增集装箱",
];
const msgTypeCount = await prisma.ccMessageTypeDict.count();
if (msgTypeCount === 0) {
await prisma.ccMessageTypeDict.createMany({
data: defaultMessageTypes.map((name, i) => ({
name,
enabled: true,
sortOrder: i,
})),
});
}
console.log(
`Seed users only: ${adminUser} (admin), ${opsUser} (ops); cc_write_capability seeded; message types ensured`,
);
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(() => prisma.$disconnect());