From e53a629a4a7243c6b7b736c68e01c1587d3afc58 Mon Sep 17 00:00:00 2001 From: Luxshan2000 Date: Thu, 12 Oct 2023 10:31:43 +0530 Subject: [PATCH] database schema added --- backend/config/database.js | 39 +++++++++++++++- backend/src/models/topic.js | 60 +++++++++++++++++++++++++ backend/src/models/user.js | 90 ++++++++++++++++++++++++++++++++++++- 3 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 backend/src/models/topic.js diff --git a/backend/config/database.js b/backend/config/database.js index 516bbb9..c5b4dd0 100644 --- a/backend/config/database.js +++ b/backend/config/database.js @@ -1,5 +1,6 @@ require('dotenv').config(); -const mongoose = require("mongoose") +const mongoose = require("mongoose"); +const Topic = require('../src/models/topic'); const connectMongoDb = ()=>{ @@ -10,6 +11,42 @@ const connectMongoDb = ()=>{ console.log('===================================='); console.log("mongoDB is sucessfully connected!"); console.log('===================================='); + + /*Debugging Purpose*/ + // const sample = async ()=>{ + // const title = "Overview" + // const no = 1 + // const videoUrl = "videourl" + // const script = '

This is an script

' + // const questions = [ + // { + // ques: "Question 1", + // answer: "Answer 1", + // posFeedback: "Correct!", + // negativeFeedback: "Sorry, wrong answer.", + // options: ["Option A", "Option B", "Option C"], + // correctOption: "Option B" + // }, + // { + // ques: "Question 2", + // answer: "Answer 2", + // posFeedback: "Good job!", + // negativeFeedback: "Try again.", + // options: ["Option X", "Option Y", "Option Z"], + // correctOption:"Option X" + // } + // // Add more questions as needed + // ] + + + // const topic = new Topic({title,no,videoUrl, script, questions }) + + // await topic.save() + // } + + // sample() + + }).catch((error)=>{ console.log('===================================='); console.log("mongoDB configration error\n",error); diff --git a/backend/src/models/topic.js b/backend/src/models/topic.js new file mode 100644 index 0000000..912644e --- /dev/null +++ b/backend/src/models/topic.js @@ -0,0 +1,60 @@ +const mongoose = require("mongoose") + +const Topic= mongoose.model("topics",{ + title:{ + type:String, + required:true, + unique:true + }, + no:{ + type:String, + required:true, + unique: true + }, + videoUrl: { + type:String + }, + popQuiz:[ + { + quizId: { + type: Number, + required: true + }, + popTime:{ + type: Number, //in seconds + required: true + } + } + ], + script:{ + type: String, + }, + questions: [ + { + ques: { + type: String, + required: true, + trim: true + }, + answer: { + type: String, + required: true, + trim: true + }, + posFeedback: { + type: String, + trim: true + }, + negativeFeedback: { + type: String, + trim: true + }, + options: [{ + type: String, + trim: true + }], + } + ] +}) + +module.exports = Topic \ No newline at end of file diff --git a/backend/src/models/user.js b/backend/src/models/user.js index 43aa74c..255dd09 100644 --- a/backend/src/models/user.js +++ b/backend/src/models/user.js @@ -18,10 +18,98 @@ const User= mongoose.model("users",{ type:Boolean, default:false }, + preLanguage:{ + type:Strig, + default:"English", + required: true, + enum :["Sinhala", "Tamil", "English"] + }, otp: { type : String, default:null - } + }, + payments:[ + { + amount:{ + type: Number, + required: true, + default: 400 + }, + subcriDate:{ + type: Date, + required: true, + default: Date.now + } + } + ], + refundRequests:[ + { + reqDate:{ + type: Date, + trim : true, + required : true + }, + resDate:{ + type: Date, + trim : true + }, + Status: { + type: String, + trim : true, + default: "Open", + enum :["Opened", "Accepted", "Rejected"] + } + } + ], + isAdmin:{ + type: Boolean, + required: true + }, + query:[ + { + req:{ + type: String, + required: true, + trim: true + }, + res:{ + type: String, + trim: true + }, + reqDate:{ + type: Date, + required: true + }, + resDate:{ + type: Date, + required: true + }, + status:{ + type: String, + default: "Open", + required: true, + enum:["Open","Closed"] + } + } + ], + completed:[ + { + topicId:{ + type: Number, + required: true + }, + isVideoFinished:{ + type: Boolean, + required: true, + default: false + }, + isQuizFinished:{ + type: Boolean, + required: true, + default: false + } + } + ] }) module.exports = User \ No newline at end of file