-
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
4bcdf15
commit f131803
Showing
1 changed file
with
41 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import mongoose from "mongoose"; | ||
|
||
// Define the schema for the 'Report' collection | ||
const ReportSchema = new mongoose.Schema( | ||
{ | ||
email: { | ||
type: String, | ||
required: true, // Ensures email is always provided | ||
match: [/^\S+@\S+\.\S+$/, "Please enter a valid email address"], | ||
}, | ||
reportText: { | ||
type: String, | ||
required: true, // Ensures report text is always provided | ||
minlength: [10, "Report text must be at least 10 characters long"], | ||
}, | ||
category: { | ||
type: String, | ||
required: true, // Ensures category is always provided | ||
enum: [ | ||
"Sexual Harassment", | ||
"False Information", | ||
"Spam", | ||
"Hate Speech", | ||
"Other", | ||
], | ||
}, | ||
}, | ||
{ | ||
timestamps: true, // Automatically adds createdAt and updatedAt fields | ||
collection: "reports", // Specify the collection name in the database | ||
} | ||
); | ||
|
||
// Ensure virtual fields are not included in JSON or object conversion | ||
ReportSchema.set("toJSON", { virtuals: false }); | ||
ReportSchema.set("toObject", { virtuals: false }); | ||
|
||
// Compile the model from the schema | ||
const Report = mongoose.model("Report", ReportSchema); | ||
|
||
export default Report; |