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
+14 -10
+14 -10
View File
@@ -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
// Use upsert to ensure we always use ID 1
await prisma.config.upsert({
where: { id: 1 },
update: data,
create: { ...data, id: 1 }
});
} else {
await prisma.config.create({ data });
}
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({