This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class User { | |
| constructor( | |
| public name:string, | |
| public birthDate:Date, | |
| public role: "User" | "Admin" | |
| ){} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @domain() | |
| export class User { | |
| constructor( | |
| public name:string, | |
| public birthDate:Date, | |
| public role: "User" | "Admin" | |
| ){} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.use((req, res, next) => { | |
| // do something with request | |
| // proceed next middleware | |
| next() | |
| }) | |
| app.use((req, res) => { | |
| res.json({}) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ErrorMiddleare implements Middleware { | |
| async execute(next: Readonly<Invocation>): Promise<ActionResult> { | |
| try{ | |
| return await next.proceed() | |
| } | |
| catch(e){ | |
| // process the error or return ActionResult with status code | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ResponseTimeMiddleware implements Middleware { | |
| async execute(next: Readonly<Invocation>): Promise<ActionResult> { | |
| console.time("Response Time") | |
| const result = await next.execute() | |
| console.timeEnd("Response Time") | |
| return result | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class SimpleMiddleware implements Middleware { | |
| async execute(next: Readonly<Invocation>): Promise<ActionResult> { | |
| //do something before execution | |
| const result = await next.proceed() | |
| //do something after execution | |
| //return result or throw HttpStatusError | |
| return result; | |
| } | |
| } |