forked from journey-ad/Moe-Counter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc1881c
commit 77cac2c
Showing
10 changed files
with
311 additions
and
88 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 @@ | ||
module.exports = { | ||
randomArray: (arr) => { | ||
return arr[Math.floor(Math.random() * arr.length)] | ||
}, | ||
} |
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,50 @@ | ||
function parseError(error) { | ||
const err = JSON.parse(error)[0]; | ||
|
||
return { | ||
code: 400, | ||
message: `The field \`${err.path[0]}\` is invalid. ${err.message}`, | ||
} | ||
} | ||
|
||
module.exports = { | ||
ZodValid: ({ headers, params, query, body }) => { | ||
const handler = (req, res, next) => { | ||
if (headers) { | ||
const result = headers.safeParse(req.headers); | ||
if (!result.success) { | ||
res.status(400).send(parseError(result.error)); | ||
return; | ||
} | ||
} | ||
|
||
if (params) { | ||
const result = params.safeParse(req.params); | ||
if (!result.success) { | ||
res.status(400).send(parseError(result.error)); | ||
return; | ||
} | ||
} | ||
|
||
if (query) { | ||
const result = query.safeParse(req.query); | ||
if (!result.success) { | ||
res.status(400).send(parseError(result.error)); | ||
return; | ||
} | ||
} | ||
|
||
if (body) { | ||
const result = body.safeParse(req.body); | ||
if (!result.success) { | ||
res.status(400).send(parseError(result.error)); | ||
return; | ||
} | ||
} | ||
|
||
next(); | ||
} | ||
|
||
return handler | ||
} | ||
} |
Oops, something went wrong.