generated from Ruler45/Next-Template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changes in routes and schema files and add verify (validate file)
- Loading branch information
1 parent
1250412
commit de3a84d
Showing
9 changed files
with
123 additions
and
10,815 deletions.
There are no files selected for viewing
This file was deleted.
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
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
File renamed without changes.
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,29 @@ | ||
const mongoose = require("mongoose"); | ||
|
||
const teamMemberSchema = new mongoose.Schema({ | ||
type: "object", | ||
properties: { | ||
name: { | ||
type: String, | ||
required: true, | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
unique: true, | ||
lowercase: true, | ||
}, | ||
role: { | ||
type: String, | ||
required: true, | ||
enum: ["admin", "developer", "designer", "manager", "other"], | ||
default: "admin", | ||
}, | ||
required: ["id", "name", "email", "role"], | ||
additionalProperties: false, | ||
}, | ||
}); | ||
|
||
const TeamMember = mongoose.model("TeamMember", teamMemberSchema); | ||
|
||
module.exports = TeamMember; |
This file was deleted.
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,20 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
const Ajv = require("ajv"); | ||
const ajv = new Ajv({ allErrors: true }); | ||
|
||
const schema = require("../schema/teamMemberSchema"); | ||
|
||
const validate = ajv.compile(schema); | ||
|
||
// eslint-disable-next-line consistent-return | ||
export default async function handler(req, res) { | ||
if (req.method !== "POST") { | ||
return res.status(405).json({ error: "Method Not Allowed" }); | ||
} | ||
const valid = validate(req.body); | ||
if (!valid) { | ||
return res.status(400).json({ errors: validate.errors }); | ||
} | ||
|
||
res.status(200).json({ message: "TeamMember data is valid!" }); | ||
} |
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