Skip to content

Commit

Permalink
Merge pull request #61 from Code-Hammers/CHE-57/subtask/Create-Databa…
Browse files Browse the repository at this point in the history
…se-Models

[CHE-57] Create Database Models
  • Loading branch information
brok3turtl3 authored Apr 4, 2024
2 parents 7bbdcf6 + c1fbe91 commit 63fdecd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
12 changes: 12 additions & 0 deletions server/models/forumModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import mongoose from "mongoose";

const forumSchema = new mongoose.Schema({
title: { type: String, required: true },
description: { type: String, required: true },
createdAt: { type: Date, default: Date.now },
updatedAt: { type: Date, default: Date.now },
});

const Forum = mongoose.model("Forum", forumSchema);

export default Forum;
17 changes: 17 additions & 0 deletions server/models/postModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import mongoose from "mongoose";

const postSchema = new mongoose.Schema({
thread: {
type: mongoose.Schema.Types.ObjectId,
ref: "Thread",
required: true,
},
user: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true },
content: { type: String, required: true },
createdAt: { type: Date, default: Date.now },
updatedAt: { type: Date, default: Date.now },
});

const Post = mongoose.model("Post", postSchema);

export default Post;
14 changes: 14 additions & 0 deletions server/models/threadModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import mongoose from "mongoose";

const threadSchema = new mongoose.Schema({
user: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true },
forum: { type: mongoose.Schema.Types.ObjectId, ref: "Forum", required: true },
title: { type: String, required: true },
content: { type: String, required: true },
createdAt: { type: Date, default: Date.now },
updatedAt: { type: Date, default: Date.now },
});

const Thread = mongoose.model("Thread", threadSchema);

export default Thread;

0 comments on commit 63fdecd

Please sign in to comment.