Skip to content

Commit

Permalink
Merge pull request #26 from skartik-sk/schema-branch
Browse files Browse the repository at this point in the history
Add Poll, Vote, Admin Model
  • Loading branch information
namansharma3007 authored Oct 3, 2024
2 parents d46ed0c + a44a3d0 commit 83f0d99
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import authRoutes from './Routes/auth.js'
const app = express();


const PORT = process.env.PORT || 5000;
const PORT = process.env.PORT || 5001;

dotenv.config();

Expand Down
22 changes: 22 additions & 0 deletions backend-server/src/models/AdminModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const mongoose = require('mongoose');
const { Schema } = mongoose;

const adminSchema = new Schema({
user: {
type: Schema.Types.ObjectId,
ref: 'User',
required: true,
},
role: {
type: String,
enum: ['admin'],
default: 'admin',
},
actions: [{
type: String,
}],
}, {
timestamps: true,
});

module.exports = mongoose.model('Admin', adminSchema);
43 changes: 43 additions & 0 deletions backend-server/src/models/PollModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const mongoose = require('mongoose');
const { Schema } = mongoose;

const pollSchema = new Schema({
title: {
type: String,
required: true,
maxLength: 100,
},
description: {
type: String,
maxLength: 500,
},
options: [{
type: String,
required: true,
}],
startDate: {
type: Date,
required: true,
},
endDate: {
type: Date,
required: true,
},
allowMultipleVotes: {
type: Boolean,
default: false,
},
createdBy: {
type: Schema.Types.ObjectId,
ref: 'User',
required: true,
},
votes: [{
type: Schema.Types.ObjectId,
ref: 'Vote',
}],
}, {
timestamps: true,
});

module.exports = mongoose.model('Poll', pollSchema);
25 changes: 25 additions & 0 deletions backend-server/src/models/VoteModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const mongoose = require('mongoose');
const { Schema } = mongoose;

const voteSchema = new Schema({
poll: {
type: Schema.Types.ObjectId,
ref: 'Poll',
required: true,
},
user: {
type: Schema.Types.ObjectId,
ref: 'User',
required: true,
},
option: {
type: Boolean,
required: true,
},
createdAt: {
type: Date,
default: Date.now,
},
});

module.exports = mongoose.model('Vote', voteSchema);

0 comments on commit 83f0d99

Please sign in to comment.