deno.land / x / opine@2.3.4 / examples / mvc / controllers / pet / index.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445// deno-lint-ignore-file no-explicit-anyimport * as db from "../../db.ts";import type { NextFunction, OpineRequest, OpineResponse,} from "../../../../src/types.ts";
export const before = function ( req: OpineRequest, _res: OpineResponse, next: NextFunction,) { const pet = db.pets[parseInt(req.params.pet_id)]; if (!pet) return next("route"); (req as any).pet = pet; next();};
export const show = function ( req: OpineRequest, res: OpineResponse, _next: NextFunction,) { res.render("show", { pet: (req as any).pet });};
export const edit = function ( req: OpineRequest, res: OpineResponse, _next: NextFunction,) { res.render("edit", { pet: (req as any).pet });};
export const update = function ( req: OpineRequest, res: OpineResponse, _next: NextFunction,) { const body = req.body; (req as any).pet.name = body.pet.name; res.redirect(`/pet/${(req as any).pet.id}`);};
Version Info