SudoSOS Back-end API / internal/middleware / AsyncValidatorMiddleware
Class: AsyncValidatorMiddleware ​
Middleware that runs async (potentially DB-hitting) validation specs against the request body before passing to the handler. Runs after RequestValidatorMiddleware (structural Swagger check) and returns the same { valid, errors[] } shape on failure, ensuring a consistent 400 response regardless of which layer caught the error.
If no spec is registered in the registry for the given model name, the middleware is a no-op and calls next() immediately.
Constructors ​
Constructor ​
ts
new AsyncValidatorMiddleware(registry, validator): AsyncValidatorMiddleware;Creates a new async validator middleware instance.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
registry | AsyncValidatorRegistry | The registry to look up specs from. |
validator | BodyValidator | The BodyValidator containing the model name to look up. |
Returns ​
AsyncValidatorMiddleware
Methods ​
getMiddleware() ​
ts
getMiddleware(): RequestHandler;Returns ​
RequestHandler
a middleware handler to be used by express.
handle() ​
ts
handle(
req,
res,
next): Promise<void>;Middleware handler. Looks up the spec for the model name and runs it against req.body.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
req | RequestWithToken | the express request to handle. |
res | Response | the express response object. |
next | Function | the express next function to continue processing of the request. |
Returns ​
Promise<void>