-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a default value for the ctx.validatedData (#287)
* feat: update regex validations * feat: add default value for the validatedData * refactor: add empty line
- Loading branch information
Showing
3 changed files
with
12 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
9 changes: 9 additions & 0 deletions
9
template/apps/api/src/routes/middlewares/attach-custom-properties.middleware.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { AppKoaContext, Next } from 'types'; | ||
|
||
const attachCustomProperties = async (ctx: AppKoaContext, next: Next) => { | ||
ctx.validatedData = {}; | ||
|
||
await next(); | ||
}; | ||
|
||
export default attachCustomProperties; |
This file contains 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
ce5b07e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR fixes problems when we need to pass some value from a validator to a handler in a controller. Without this fix, if
validateMiddleware
is not used in a controller, when trying to do the following:we'll get an error that
ctx.validatedData
is undefined.