Skip to content

Commit

Permalink
πŸ€ Changed the module type (#838)
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Owais Warsi authored Feb 11, 2024
1 parent fd4f33d commit 38831a0
Show file tree
Hide file tree
Showing 94 changed files with 490 additions and 430 deletions.
14 changes: 7 additions & 7 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const express = require('express');
const cors = require('cors');
const helmet = require('helmet');
const responseTime = require('response-time');
const routes = require('./app/routes');
const { errorHandler } = require('./helpers/error');
import express from "express";
import cors from "cors";
import helmet from "helmet"
import responseTime from "response-time";
import routes from "./app/routes"
import {errorHandler} from "./helpers/error"
require('colors');
require('./helpers/dbConnection');

Expand Down Expand Up @@ -43,4 +43,4 @@ process.on('uncaughtException', (err) => {
console.log(err);
});

module.exports = app;
export default app;
2 changes: 1 addition & 1 deletion backend/app/models/Admin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose');
import mongoose from "mongoose";

const { Schema } = mongoose;

Expand Down
2 changes: 1 addition & 1 deletion backend/app/models/Broadcast.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose');
import mongoose from "mongoose";

const { Schema } = mongoose;
const broadcastSchema = new Schema(
Expand Down
2 changes: 1 addition & 1 deletion backend/app/models/TeamMember.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose');
import mongoose from "mongoose";

const { Schema } = mongoose;

Expand Down
2 changes: 1 addition & 1 deletion backend/app/models/answers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose');
import mongoose from "mongoose";

const { Schema } = mongoose;

Expand Down
2 changes: 1 addition & 1 deletion backend/app/models/contactUs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose');
import mongoose from "mongoose";

const { Schema } = mongoose;

Expand Down
2 changes: 1 addition & 1 deletion backend/app/models/faq.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose');
import mongoose from "mongoose";

const { Schema } = mongoose;

Expand Down
2 changes: 1 addition & 1 deletion backend/app/models/joinUs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose');
import mongoose from "mongoose";

const { Schema } = mongoose;

Expand Down
2 changes: 1 addition & 1 deletion backend/app/models/question.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose');
import mongoose from "mongoose";

const { Schema } = mongoose;

Expand Down
2 changes: 1 addition & 1 deletion backend/app/models/resource.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose');
import mongoose from "mongoose";

const resourceSchema = new mongoose.Schema(
{
Expand Down
2 changes: 1 addition & 1 deletion backend/app/models/tinyURL.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose');
import mongoose from "mongoose";

const { Schema } = mongoose;
const tinyURLSchema = new Schema({
Expand Down
4 changes: 2 additions & 2 deletions backend/app/routes/Q&A/answers/@validationSchema/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Joi = require('joi');
import Joi from "joi";

const answerValidationSchema = Joi.object().keys({
question_id: Joi.string().trim().required().max(24).min(24),
Expand All @@ -16,7 +16,7 @@ const updateAnswerStatusSchema = Joi.object().keys({
status : Joi.boolean().required()
});

module.exports = {
export {
answerValidationSchema,
getAnswerValidationSchema,
updateAnswerStatusSchema
Expand Down
11 changes: 6 additions & 5 deletions backend/app/routes/Q&A/answers/downvoteAnswer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const to = require('await-to-js').default;
const answer = require('../../../models/answers');
const { ErrorHandler } = require('../../../../helpers/error');
const constants = require('../../../../constants');
import to from "await-to-js";
import answer from '../../../models/answers';
import { ErrorHandler } from "../../../../helpers/error";
import constants from "../../../../constants";

module.exports = async (req, res, next) => {

export default async (req, res, next) => {
const { answerId } = req.body;
const [err] = await to(
answer.updateOne({ _id: answerId }, [
Expand Down
13 changes: 7 additions & 6 deletions backend/app/routes/Q&A/answers/getAnswers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const to = require('await-to-js').default;
const mongoose = require('mongoose');
const Answer = require('../../../models/answers');
const { ErrorHandler } = require('../../../../helpers/error');
const constants = require('../../../../constants');
import to from "await-to-js"
import mongoose from "mongoose";
import Answer from '../../../models/answers'
import { ErrorHandler } from "../../../../helpers/error";
import constants from "../../../../constants";

module.exports = async (req, res, next) => {

export default async (req, res, next) => {
const qId = req.body.question_id;

const [err, answers] = await to(
Expand Down
20 changes: 10 additions & 10 deletions backend/app/routes/Q&A/answers/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const router = require('express').Router({ mergeParams: true });
const { answerValidationSchema, getAnswerValidationSchema, updateAnswerStatusSchema } = require('./@validationSchema');
const validation = require('../../../../helpers/middlewares/validation');

const postAnswer = require('./post');
const getAnswers = require('./getAnswers');
const upvoteAnswer = require('./upvoteAnswer');
const downvoteAnswer = require('./downvoteAnswer');
const updateAnswerStatus = require('./updateAnswerStatus');
import express from "express";
import {answerValidationSchema, getAnswerValidationSchema, updateAnswerStatus} from './@validationSchema'
import validation from '../../../../helpers/middlewares/validation'
import postAnswer from "./post";
import getAnswers from "./getAnswers"
import upvoteAnswer from "./upvoteAnswer";
import downvoteAnswer from "./downvoteAnswer"
import updateAnswerStatus from "./updateAnswerStatus";
const router = express.Router({mergeParams:true});

// POST API FOR ANSWER
router.post('/', validation(answerValidationSchema), postAnswer);
Expand All @@ -23,4 +23,4 @@ router.patch('/downvote', downvoteAnswer);
// Update Answer Status
router.patch('/updateStatus', validation(updateAnswerStatusSchema), updateAnswerStatus);

module.exports = router;
export default router;
11 changes: 6 additions & 5 deletions backend/app/routes/Q&A/answers/post.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const to = require('await-to-js').default;
const answer = require('../../../models/answers');
const { ErrorHandler } = require('../../../../helpers/error');
const constants = require('../../../../constants');
import to from "await-to-js"
import answer from '../../../models/answers'
import { ErrorHandler } from "../../../../helpers/error";
import constants from "../../../../constants";

module.exports = async (req, res, next) => {

export default async (req, res, next) => {
const [err, body] = await to(answer.create({ ...req.body }));

if (err) {
Expand Down
11 changes: 5 additions & 6 deletions backend/app/routes/Q&A/answers/updateAnswerStatus.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const to = require("await-to-js").default;
import to from "await-to-js";
import constants from "../../../../constants";
import { ErrorHandler } from "../../../../helpers/error";
import answers from "../../../models/answers"

const constants = require("../../../../constants");
const { ErrorHandler } = require("../../../../helpers/error");

const answers = require("../../../models/answers");

module.exports = async (req, res, next) => {
export default async (req, res, next) => {
// getting id and status from body
const id = req.body.id;
const status = req.body.status
Expand Down
11 changes: 6 additions & 5 deletions backend/app/routes/Q&A/answers/upvoteAnswer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const to = require('await-to-js').default;
const answer = require('../../../models/answers');
const { ErrorHandler } = require('../../../../helpers/error');
const constants = require('../../../../constants');
import to from "await-to-js"
import answer from '../../../models/answers'
import { ErrorHandler } from "../../../../helpers/error";
import constants from "../../../../constants";

module.exports = async (req, res, next) => {

export default async (req, res, next) => {
const { answerId } = req.body;
const [err] = await to(answer.updateOne({ _id: answerId }, { $inc: { upvotes: 1 } }));
if (err) {
Expand Down
4 changes: 2 additions & 2 deletions backend/app/routes/Q&A/question/@validationSchema/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Joi = require('joi');
import Joi from "joi"

const QuestionValidationSchema = Joi.object().keys({
title: Joi.string().trim().required().min(5),
Expand All @@ -11,4 +11,4 @@ const updateQuestionStatusSchema = Joi.object().keys({
status : Joi.boolean().required()
});

module.exports = { QuestionValidationSchema, updateQuestionStatusSchema };
export { QuestionValidationSchema, updateQuestionStatusSchema };
11 changes: 6 additions & 5 deletions backend/app/routes/Q&A/question/downvoteQuestion.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const to = require('await-to-js').default;
const question = require('../../../models/question');
const { ErrorHandler } = require('../../../../helpers/error');
const constants = require('../../../../constants');
import to from "await-to-js"
import question from '../../../models/question';
import { ErrorHandler } from "../../../../helpers/error";
import constants from "../../../../constants";

module.exports = async (req, res, next) => {

export default async (req, res, next) => {
const { questionId } = req.body;
const [err] = await to(
question.updateOne({ _id: questionId }, [
Expand Down
4 changes: 2 additions & 2 deletions backend/app/routes/Q&A/question/getAllQuestion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const question = require('../../../models/question');
import question from '../../../models/question'

module.exports = async (req, res) => {
export default async (req, res) => {
try {
const questions = {}; // Empty object filter which matches all the documents

Expand Down
4 changes: 2 additions & 2 deletions backend/app/routes/Q&A/question/getQuestionById.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const question = require('../../../models/question');
import question from '../../../models/question';

module.exports = async (req, res) => {
export default async (req, res) => {
try {
const { questionId } = req.body; // Getting question id from body
const result = await question.findOne({ _id: questionId }); // Find the question corresponding to the given id
Expand Down
22 changes: 12 additions & 10 deletions backend/app/routes/Q&A/question/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const router = require('express').Router({ mergeParams: true });
const postQuestion = require('./post');
const { QuestionValidationSchema, updateQuestionStatusSchema } = require('./@validationSchema');
const getAllQuestion = require('./getAllQuestion');
const getQuestionById = require('./getQuestionById');
const validation = require('../../../../helpers/middlewares/validation');
const upvoteQuestion = require('./upvoteQuestion');
const downvoteQuestion = require('./downvoteQuestion');
const updateQuestionStatus = require('./updateQuestionStatus');

import express from "express";
import postQuestion from "./post";
import {QuestionValidationSchema , updateQuestionStatusSchema} from './@validationSchema'
import getAllQuestion from './getAllQuestion'
import getQuestionById from "./getQuestionById"
import validation from '../../../../helpers/middlewares/validation'
import upvoteQuestion from "./upvoteQuestion"
import downvoteQuestion from "./downvoteQuestion"
import updateQuestionStatus from "./updateQuestionStatus"
const router = express.Router({mergeParams:true})

router.post('/', validation(QuestionValidationSchema), postQuestion);

Expand All @@ -25,4 +27,4 @@ router.patch('/downvote', downvoteQuestion);
// route for updating the question status
router.patch('/updateStatus', validation(updateQuestionStatusSchema), updateQuestionStatus);

module.exports = router;
export default router;
12 changes: 7 additions & 5 deletions backend/app/routes/Q&A/question/post.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const to = require('await-to-js').default;
const question = require('../../../models/question');
const { ErrorHandler } = require('../../../../helpers/error');
const constants = require('../../../../constants');

module.exports = async (req, res, next) => {
import to from "await-to-js"
import question from '../../../models/question'
import { ErrorHandler } from "../../../../helpers/error";
import constants from "../../../../constants";


export default async (req, res, next) => {
const [err, body] = await to(question.create({ ...req.body }));

if (err) {
Expand Down
11 changes: 6 additions & 5 deletions backend/app/routes/Q&A/question/updateQuestionStatus.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const to = require("await-to-js").default;

const constants = require("../../../../constants");
const { ErrorHandler } = require("../../../../helpers/error");
import to from "await-to-js"
import constants from "../../../../constants";
import { ErrorHandler } from "../../../../helpers/error";
import question from "../../../models/question"

const question = require("../../../models/question");

module.exports = async (req, res, next) => {

export default async (req, res, next) => {
// getting id and status from body
const id = req.body.id;
const status = req.body.status
Expand Down
12 changes: 7 additions & 5 deletions backend/app/routes/Q&A/question/upvoteQuestion.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const to = require('await-to-js').default;
const question = require('../../../models/question');
const { ErrorHandler } = require('../../../../helpers/error');
const constants = require('../../../../constants');

module.exports = async (req, res, next) => {
import to from "await-to-js"
import question from '../../../models/question'
import { ErrorHandler } from "../../../../helpers/error";
import constants from "../../../../constants";


export default async (req, res, next) => {
const { questionId } = req.body;
const [err] = await to(question.updateOne({ _id: questionId }, { $inc: { upvotes: 1 } }));
if (err) {
Expand Down
4 changes: 2 additions & 2 deletions backend/app/routes/admin/@validationSchema/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Joi = require('joi');
import Joi from "joi"

const postSuperAdminSchema = Joi.object({
firstName: Joi.string()
Expand Down Expand Up @@ -53,7 +53,7 @@ const deleteAdminSchema = Joi.object({
id : Joi.string().min(24).max(24).required()
})

module.exports = {
export {
postSuperAdminSchema,
getAdminsSchema,
passwordChangeSchema,
Expand Down
13 changes: 7 additions & 6 deletions backend/app/routes/admin/changePassword.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const to = require('await-to-js').default;
const argon2 = require('argon2');
const Admin = require('../../models/Admin');
const { ErrorHandler } = require('../../../helpers/error');
const constants = require('../../../constants');
import to from "await-to-js"
import argon2 from "argon2"
import Admin from '../../models/Admin';
import { ErrorHandler } from '../../../helpers/error';
import constants from '../../../constants';

module.exports = async (req, res, next) => {

export default async (req, res, next) => {
const { oldPassword, newPassword } = req.body;

if (oldPassword === newPassword) {
Expand Down
11 changes: 6 additions & 5 deletions backend/app/routes/admin/createSuperAdmin.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const to = require('await-to-js').default;
const Admin = require('../../models/Admin');
const { ErrorHandler } = require('../../../helpers/error');
const constants = require('../../../constants');
import to from "await-to-js"
import Admin from '../../models/Admin';
import {ErrorHandler} from '../../../helpers/error';
import constants from "../../../constants";

module.exports = async (req, res, next) => {

export default async (req, res, next) => {
const options = { upsert: true, new: true, setDefaultsOnInsert: true };
const adminData = {
firstName: 'Root',
Expand Down
10 changes: 5 additions & 5 deletions backend/app/routes/admin/deleteAdmin.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { default: to } = require("await-to-js");
const constants = require("../../../constants");
const { ErrorHandler } = require("../../../helpers/error");
const Admin = require("../../models/Admin");
import to from "await-to-js"
import constants from "../../../constants";
import {ErrorHandler} from "../../../helpers/error";
import Admin from "../../models/Admin";

module.exports = async (req, res, next) => {
export default async (req, res, next) => {
const { isSuperAdmin } = res.locals.decode;

if(!isSuperAdmin) {
Expand Down
Loading

0 comments on commit 38831a0

Please sign in to comment.