From ab3e36e95fb4fc35df77a3513e5c6923bd209035 Mon Sep 17 00:00:00 2001 From: Quintine Date: Wed, 20 May 2026 16:46:49 +1000 Subject: [PATCH] Fix: ensure admin config is always stored with ID 1 to prevent persistence issues --- backend/src/server.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/backend/src/server.ts b/backend/src/server.ts index 57f7298..5dadc15 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -237,21 +237,19 @@ app.delete('/api/stock/:id', async (req, res) => { app.post('/api/config', async (req, res) => { try { const { adminCode, finalDepositDate, cookDay, payIdInfo } = req.body; - const config = await prisma.config.findFirst(); const data: any = {}; if (adminCode !== undefined) data.adminCode = adminCode; if (finalDepositDate !== undefined) data.finalDepositDate = finalDepositDate; if (cookDay !== undefined) data.cookDay = cookDay; if (payIdInfo !== undefined) data.payIdInfo = payIdInfo; - if (config) { - await prisma.config.update({ - where: { id: config.id }, - data - }); - } else { - await prisma.config.create({ data }); - } + // Use upsert to ensure we always use ID 1 + await prisma.config.upsert({ + where: { id: 1 }, + update: data, + create: { ...data, id: 1 } + }); + res.sendStatus(200); } catch (error) { console.error(error); @@ -266,8 +264,14 @@ app.post('/api/reset', async (req, res) => { await prisma.stockItem.deleteMany(); await prisma.config.deleteMany(); - // Seed default admin code and limits - await prisma.config.create({ data: { adminCode: '1234', maxTotalWeight: 100.0, maxItemWeight: 50.0 } }); + // Seed default admin code and limits with ID 1 + await prisma.config.create({ + data: { + id: 1, + adminCode: '1234', + payIdInfo: 'Your PayID Here' + } + }); // Seed some default stock items await prisma.stockItem.createMany({