diff --git a/web/src/utils.ts b/web/src/utils.ts index 8437925..f932446 100644 --- a/web/src/utils.ts +++ b/web/src/utils.ts @@ -28,7 +28,7 @@ export async function generateCode() { ciffers[Math.floor(Math.random() * 10)] + ciffers[Math.floor(Math.random() * 10)] + ciffers[Math.floor(Math.random() * 10)]; - found = await prisma.opening.findFirst({ where: { code } }); + found = await prisma.opening.findFirst({ where: { code, date: null } }); } while (found); return code; } diff --git a/web/src/webRouter.ts b/web/src/webRouter.ts index 09b6113..82a8023 100644 --- a/web/src/webRouter.ts +++ b/web/src/webRouter.ts @@ -158,6 +158,17 @@ webRouter.get('/legal', async (request: Request, response: Response) => { return response.sendFile(path.join(__dirname, "../www/legal.html")); }); +webRouter.get('/cancel', async (request: Request, response: Response) => { + if (!chestAlive()) return response.redirect('/down'); + const login = authenticate(request); + if (!login) return response.redirect('/login'); + const opening = await getWaitingOpening(login); + if (opening && opening.type === 'borrow') { + await prisma.opening.update({ where: { id: opening.id }, data: { code: null, codeGeneratedAt: null } }); + } + return response.redirect('/'); +}); + webRouter.get('/', async (request: Request, response: Response) => { if (!chestAlive()) return response.redirect('/down'); const login = authenticate(request);