Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 37x 1x 2x 4x 4x 4x 4x 4x 2x 2x 2x 2x | import { Request, Response, NextFunction } from "express"; import guard from "@cooper/backend/src/middleware/guard"; export async function validateTransaction(req: Request, res: Response, next: NextFunction) { const db = req.app.locals.database; // parseInt because we don't want to include "truthy" numbers // e.g. hello10 = 10 > this should be NaN const transactionId = parseInt(req.params.transactionId, 10); Iif (Number.isNaN(transactionId)) { return res.status(401).json({ error: "Unauthorised" }); } const transaction = db.budgeting.transactions.getTransaction(transactionId); // Transaction does not exist if (transaction == null) { return res.status(404).json({ error: "Transaction does not exist", }); } // Check that transaction being accessed belongs to the workspace Iif (transaction.workspace !== guard(res.workspace).workspaceId) { return res.status(401).json({ error: "Unauthorised", }); } res.transaction = transaction; return next(); } |