Skip to content

Commit

Permalink
added new report schema
Browse files Browse the repository at this point in the history
  • Loading branch information
KovacevicAleksa committed Feb 17, 2025
1 parent 4bcdf15 commit f131803
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions backend/models/report.js
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;

0 comments on commit f131803

Please # to comment.