deno.land / x / opine@2.3.4 / examples / mvc / controllers / user / 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// 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 id = req.params.user_id; if (!id) return next(); // Pretend to query a database... setTimeout(function () { (req as any).user = db.users[parseInt(id)]; // cant find that user if (!(req as any).user) return next("route"); // found it, move on to the routes next(); });};
export const list = function ( _req: OpineRequest, res: OpineResponse, _next: NextFunction,) { res.render("list", { users: db.users });};
export const edit = function ( req: OpineRequest, res: OpineResponse, _next: NextFunction,) { res.render("edit", { user: (req as any).user });};
export const show = function ( req: OpineRequest, res: OpineResponse, _next: NextFunction,) { res.render("show", { user: (req as any).user });};
export const update = function ( req: OpineRequest, res: OpineResponse, _next: NextFunction,) { const body = req.body; (req as any).user.name = body.user.name; res.redirect("/user/" + (req as any).user.id);};
opine

Version Info

Tagged at
2 years ago