Closed CarlosZiegler closed 1 year ago
Hello, I asked similar question before.
Here is how you can get typed middleware and controller type definition.
export type Middleware<
M extends Method,
Path extends ZodiosPathsByMethod<Api, Method>
> = ZodiosRequestHandler<Api, Context, M, Path>
Sample
export const verifyPermissions = <
M extends Method,
Path extends ZodiosPathsByMethod<Api, Method>
>(
...permissions: PermissionType[]
) => {
const middleware: Middleware<M, Path> = async (req, res, next) => {}}
Controller Sample
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())
}
}
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 :)