0% found this document useful (0 votes)
10 views5 pages

Quizquest Backend Code

Uploaded by

hasini.thota.04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Quizquest Backend Code

Uploaded by

hasini.thota.04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

C:\Users\hasin\Desktop\prog\MERN\quiz\FINAL\finalest\QuizQuest backend\backend\controllers

Controllers:
getAll

getQuiz

postQuiz

[Link]
import Quizes from "../models/[Link]";

const getAll = async (req, res) => {

try {

const quizes = await [Link]({});

[Link]();

[Link](quizes);

catch(e) {

[Link]({

status: 404,

success: false,

message: "objects not found"

});

export default getAll;

[Link]
import Quizes from "../models/[Link]";
const getQuiz = async (req, res) => {

const id = [Link];

try {

const quiz = await [Link]({_id:id});

[Link](quiz);

catch(e) {

[Link]({

status: 404,

success: false,

message: "object not found"

});

export default getQuiz;

[Link]
import { __dirname } from "../[Link]";

import Quiz from "../models/[Link]"

const postQuiz = async (req, res) => {

const entry = [Link];

const quiz = new Quiz({title: [Link], duration: [Link]});


[Link](({description, options, correctOption}) => {

[Link]({description, options, correctOption});

});

try {

await [Link]();

[Link]({

status: 201,

success: true

});

catch(e) {

[Link](e);

[Link]({

status: 406,

success: false,

message: "Internal Server error or the data sent was invalid"

});

export default postQuiz;

[Link]
import mongoose from "mongoose";

const quizSchema = [Link]({

title: String,

duration: Number,
questions: [{

description: String,

options: [{ type: String }],

correctOption: Number

}],

});

const Quizes = [Link]("quiz_db", quizSchema);

export default Quizes;

C:\Users\hasin\Desktop\prog\MERN\quiz\FINAL\finalest\QuizQuest backend\backend\routes

[Link]
import express from "express";

import getAll from "../controllers/[Link]";

import getQuiz from "../controllers/[Link]";

import postQuiz from "../controllers/[Link]";

const router = [Link]();

[Link]('/get-all', getAll);

[Link]('/get-quiz/:id', getQuiz);

[Link]('/post-quiz', postQuiz);

//[Link]('/delete/:id',delete);

//[Link]('/update/:id',update);

export default router;


[Link]
import express from "express";

import dotenv from "dotenv";

import router from "./routes/[Link]";

import mongoose from "mongoose";

import { fileURLToPath } from 'url';

import { dirname } from "path";

import cors from "cors";

const __filename = fileURLToPath([Link]);

export const __dirname = dirname(__filename);

[Link]();

const PORT = [Link] || 5500;

const DB_PWD = [Link].DB_PWD || "Honey@2004";

const server = express();

// middlewares

[Link](cors());

[Link]([Link]());

[Link]("/api", router); // router middleware should be placed at the last

const URI = "mongodb+srv://hasini21bce8857:"+DB_PWD+"@[Link]/?


retryWrites=true&w=majority";

[Link](URI, {dbName: "main"}).then(() => [Link]("db connected


sucessfully!")).catch((e) => [Link](e));

[Link](PORT, () => [Link]("server started successfully on port:", PORT));

You might also like