deno.land / x / opine@2.3.4 / examples / mvc / controllers / pet / index.ts

نووسراو ببینە
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
35
36
37
38
39
40
41
42
43
44
45
// 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}`);};
opine

Version Info

Tagged at
2 years ago