generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add feature to update request before approval or rejection
- Loading branch information
Showing
5 changed files
with
111 additions
and
2 deletions.
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
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
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,31 @@ | ||
import { NextFunction, Request } from "express"; | ||
import joi from "joi"; | ||
import { CustomResponse } from "../../types/global"; | ||
|
||
export const updateRequestValidator = async ( | ||
req: Request, | ||
res: CustomResponse, | ||
next: NextFunction | ||
) => { | ||
|
||
const schema = joi | ||
.object() | ||
.strict() | ||
.keys({ | ||
reason: joi.string().optional(), | ||
newEndsOn: joi.number().positive().min(Date.now()).required().messages({ | ||
'number.any': 'newEndsOn is required', | ||
'number.base': 'newEndsOn must be a number', | ||
'number.positive': 'newEndsOn must be positive', | ||
'number.greater': 'newEndsOn must be greater than current date', | ||
})}) | ||
|
||
try { | ||
await schema.validateAsync(req.body, { abortEarly: false }); | ||
next(); | ||
} catch (error) { | ||
const errorMessages = error.details.map((detail:{message: string}) => detail.message); | ||
logger.error(`Error while validating request payload : ${errorMessages}`); | ||
return res.boom.badRequest(errorMessages); | ||
} | ||
}; |
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
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