Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the parameter of express req object to custom validate function
- Loading branch information
1 parent
de1fdc7
commit 1d0dc48
Showing
9 changed files
with
94 additions
and
14 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
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
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 |
---|---|---|
@@ -1,6 +1,19 @@ | ||
module.exports = Object.freeze({ | ||
begin_time : { | ||
required:[true,{code:1,msg:'The begin_time is empty'}], | ||
type:[Date,{code:2,msg:'the begin_time should be a Date'}] | ||
type:[Date,{code:2,msg:'the begin_time should be a Date'}], | ||
custom:function(value,req) { | ||
const session = req.session; | ||
if (!session) { | ||
return {code:3,msg:'session invalid'} | ||
} | ||
const user = session.user; | ||
if (!user) { | ||
return {code:4,msg:'invalid user'}; | ||
} | ||
if (user.role !== 1) { | ||
return {code:5,msg:'you have no right to do this query'}; | ||
} | ||
} | ||
} | ||
}); |