Fix: ensure admin config is always stored with ID 1 to prevent persistence issues

This commit is contained in:
Quintine committed 2026-05-20 16:46:49 +10:00
1 parent 92792cb2de
commit ab3e36e95f
1 file changed
+15 -11
+15 -11
View File
@@ -237,21 +237,19 @@ app.delete('/api/stock/:id', async (req, res) => {
app.post('/api/config', async (req, res) => { app.post('/api/config', async (req, res) => {
try { try {
const { adminCode, finalDepositDate, cookDay, payIdInfo } = req.body; const { adminCode, finalDepositDate, cookDay, payIdInfo } = req.body;
const config = await prisma.config.findFirst();
const data: any = {}; const data: any = {};
if (adminCode !== undefined) data.adminCode = adminCode; if (adminCode !== undefined) data.adminCode = adminCode;
if (finalDepositDate !== undefined) data.finalDepositDate = finalDepositDate; if (finalDepositDate !== undefined) data.finalDepositDate = finalDepositDate;
if (cookDay !== undefined) data.cookDay = cookDay; if (cookDay !== undefined) data.cookDay = cookDay;
if (payIdInfo !== undefined) data.payIdInfo = payIdInfo; if (payIdInfo !== undefined) data.payIdInfo = payIdInfo;
if (config) { // Use upsert to ensure we always use ID 1
await prisma.config.update({ await prisma.config.upsert({
where: { id: config.id }, where: { id: 1 },
data update: data,
}); create: { ...data, id: 1 }
} else { });
await prisma.config.create({ data });
}
res.sendStatus(200); res.sendStatus(200);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
@@ -266,8 +264,14 @@ app.post('/api/reset', async (req, res) => {
await prisma.stockItem.deleteMany(); await prisma.stockItem.deleteMany();
await prisma.config.deleteMany(); await prisma.config.deleteMany();
// Seed default admin code and limits // Seed default admin code and limits with ID 1
await prisma.config.create({ data: { adminCode: '1234', maxTotalWeight: 100.0, maxItemWeight: 50.0 } }); await prisma.config.create({
data: {
id: 1,
adminCode: '1234',
payIdInfo: 'Your PayID Here'
}
});
// Seed some default stock items // Seed some default stock items
await prisma.stockItem.createMany({ await prisma.stockItem.createMany({