How get type of request with context ? #445
Unanswered
CarlosZiegler
asked this question in
Q&A
Replies: 1 comment 3 replies
-
Hello, I asked similar question before. Here is how you can get typed middleware and controller type definition. lSelectral/zodios-express-middleware-test@d25871c export type Middleware<
M extends Method,
Path extends ZodiosPathsByMethod<Api, Method>
> = ZodiosRequestHandler<Api, Context, M, Path>
export const verifyPermissions = <
M extends Method,
Path extends ZodiosPathsByMethod<Api, Method>
>(
...permissions: PermissionType[]
) => {
const middleware: Middleware<M, Path> = async (req, res, next) => {}}
public static create: Middleware<'post', '/booklets'> = async (
req,
res
) => {
try {
const result = await this.getService(req, res).create(req.body)
return res.status(200).json(result)
} catch (error) {
return res.status(500).json(ServerError())
}
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
First I want to say that is a really great library :)
In my case I like to use middlewares and controllers to hanle my request. Then is is great that I can do something like :
my context:
my route schema:
my route implementation:
That is fine if I do something like:
But I want to extract this logic inside a controller:
my controller:
Then will to use like:
The main problem is if I need use the typed request or response on another piece of code, how can I get it ?
Thanks for some tips :)
Beta Was this translation helpful? Give feedback.
All reactions