From d7f1a050ca34fa854936c9f7d60245ccc2e5cfbf Mon Sep 17 00:00:00 2001 From: kajol Date: Sun, 11 Feb 2024 15:38:24 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20Revert=20"=F0=9F=8D=80=20Changed?= =?UTF-8?q?=20the=20module=20type=20(#838)"=20(#843)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 38831a0b8dd79fd394e1b65a603abf404175ef4e. --- backend/app.js | 14 +++---- backend/app/models/Admin.js | 2 +- backend/app/models/Broadcast.js | 2 +- backend/app/models/TeamMember.js | 2 +- backend/app/models/answers.js | 2 +- backend/app/models/contactUs.js | 2 +- backend/app/models/faq.js | 2 +- backend/app/models/joinUs.js | 2 +- backend/app/models/question.js | 2 +- backend/app/models/resource.js | 2 +- backend/app/models/tinyURL.js | 2 +- .../Q&A/answers/@validationSchema/index.js | 4 +- .../app/routes/Q&A/answers/downvoteAnswer.js | 11 +++-- backend/app/routes/Q&A/answers/getAnswers.js | 13 +++--- backend/app/routes/Q&A/answers/index.js | 20 ++++----- backend/app/routes/Q&A/answers/post.js | 11 +++-- .../routes/Q&A/answers/updateAnswerStatus.js | 11 ++--- .../app/routes/Q&A/answers/upvoteAnswer.js | 11 +++-- .../Q&A/question/@validationSchema/index.js | 4 +- .../routes/Q&A/question/downvoteQuestion.js | 11 +++-- .../app/routes/Q&A/question/getAllQuestion.js | 4 +- .../routes/Q&A/question/getQuestionById.js | 4 +- backend/app/routes/Q&A/question/index.js | 22 +++++----- backend/app/routes/Q&A/question/post.js | 12 +++--- .../Q&A/question/updateQuestionStatus.js | 11 +++-- .../app/routes/Q&A/question/upvoteQuestion.js | 12 +++--- .../routes/admin/@validationSchema/index.js | 4 +- backend/app/routes/admin/changePassword.js | 13 +++--- backend/app/routes/admin/createSuperAdmin.js | 11 +++-- backend/app/routes/admin/deleteAdmin.js | 10 ++--- backend/app/routes/admin/forgotPassword.js | 12 +++--- backend/app/routes/admin/getAdmins.js | 10 ++--- backend/app/routes/admin/index.js | 9 ++-- backend/app/routes/admin/inviteAdmin.js | 10 ++--- backend/app/routes/admin/postAdmin.js | 12 +++--- backend/app/routes/admin/postSuperAdmin.js | 12 +++--- backend/app/routes/admin/resetPassword.js | 16 +++---- backend/app/routes/admin/updateAdmin.js | 4 +- .../routes/auth/@validationSchema/index.js | 4 +- backend/app/routes/auth/index.js | 11 +++-- backend/app/routes/auth/login.js | 12 +++--- .../broadcast/@validationSchema/index.js | 4 +- .../app/routes/broadcast/deleteBroadcast.js | 10 ++--- backend/app/routes/broadcast/getBroadcasts.js | 10 ++--- .../app/routes/broadcast/getallbroadcasts.js | 10 ++--- backend/app/routes/broadcast/index.js | 23 +++++----- backend/app/routes/broadcast/postBroadcast.js | 10 ++--- .../app/routes/broadcast/updateBroadcast.js | 10 ++--- .../contactUs/@validationSchema/index.js | 4 +- backend/app/routes/contactUs/get.js | 10 ++--- backend/app/routes/contactUs/index.js | 15 ++++--- backend/app/routes/contactUs/post.js | 17 ++++---- .../app/routes/faq/@validationSchema/index.js | 4 +- backend/app/routes/faq/deleteFaq.js | 12 +++--- backend/app/routes/faq/getFaq.js | 11 +++-- backend/app/routes/faq/index.js | 17 ++++---- backend/app/routes/faq/post.js | 11 +++-- backend/app/routes/faq/updateFaq.js | 4 +- backend/app/routes/index.js | 42 +++++++++---------- .../routes/joinUs/@validationSchema/index.js | 4 +- backend/app/routes/joinUs/deleteJoinUs.js | 5 +-- backend/app/routes/joinUs/get.js | 4 +- backend/app/routes/joinUs/index.js | 17 ++++---- backend/app/routes/joinUs/post.js | 17 ++++---- .../resources/@validationSchema/index.js | 4 +- backend/app/routes/resources/addResource.js | 17 ++++---- .../app/routes/resources/deleteResource.js | 5 +-- backend/app/routes/resources/getResource.js | 5 +-- backend/app/routes/resources/index.js | 17 ++++---- backend/app/routes/teamMember/addTeam.js | 11 +++-- .../app/routes/teamMember/deleteTeamMember.js | 5 +-- .../routes/teamMember/getTeamMemberById.js | 10 ++--- .../app/routes/teamMember/getTeamMembers.js | 12 +++--- backend/app/routes/teamMember/index.js | 20 ++++----- .../app/routes/teamMember/updateTeamMember.js | 4 +- backend/app/routes/testRoutes/emailTest.js | 11 +++-- .../routes/tinyURL/@validationSchema/index.js | 4 +- backend/app/routes/tinyURL/index.js | 13 +++--- backend/app/routes/tinyURL/redirectURL.js | 11 +++-- backend/app/routes/tinyURL/shortenURL.js | 17 ++++---- backend/config/index.js | 5 +-- backend/constants/index.js | 4 +- backend/helpers/cluster.js | 7 ++-- backend/helpers/dbConnection.js | 7 ++-- backend/helpers/emailService.js | 17 ++++---- backend/helpers/error.js | 5 +-- backend/helpers/middlewares/auth.js | 13 +++--- backend/helpers/middlewares/validation.js | 8 ++-- backend/helpers/utils.js | 2 +- backend/index.js | 33 ++++++++------- backend/package.json | 1 - backend/utility/cronJob.js | 5 +-- backend/utility/emailTemplates.js | 26 ++++-------- backend/utility/sendEmail.js | 5 +-- 94 files changed, 430 insertions(+), 490 deletions(-) diff --git a/backend/app.js b/backend/app.js index cd6571cd..28fb8e6f 100644 --- a/backend/app.js +++ b/backend/app.js @@ -1,9 +1,9 @@ -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" +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'); require('colors'); require('./helpers/dbConnection'); @@ -43,4 +43,4 @@ process.on('uncaughtException', (err) => { console.log(err); }); -export default app; +module.exports = app; diff --git a/backend/app/models/Admin.js b/backend/app/models/Admin.js index 901aa55e..18b68209 100644 --- a/backend/app/models/Admin.js +++ b/backend/app/models/Admin.js @@ -1,4 +1,4 @@ -import mongoose from "mongoose"; +const mongoose = require('mongoose'); const { Schema } = mongoose; diff --git a/backend/app/models/Broadcast.js b/backend/app/models/Broadcast.js index b5cf771c..26568d1d 100644 --- a/backend/app/models/Broadcast.js +++ b/backend/app/models/Broadcast.js @@ -1,4 +1,4 @@ -import mongoose from "mongoose"; +const mongoose = require('mongoose'); const { Schema } = mongoose; const broadcastSchema = new Schema( diff --git a/backend/app/models/TeamMember.js b/backend/app/models/TeamMember.js index 3bd8b11d..a0fdaa4c 100644 --- a/backend/app/models/TeamMember.js +++ b/backend/app/models/TeamMember.js @@ -1,4 +1,4 @@ -import mongoose from "mongoose"; +const mongoose = require('mongoose'); const { Schema } = mongoose; diff --git a/backend/app/models/answers.js b/backend/app/models/answers.js index 93cc4872..90d85036 100644 --- a/backend/app/models/answers.js +++ b/backend/app/models/answers.js @@ -1,4 +1,4 @@ -import mongoose from "mongoose"; +const mongoose = require('mongoose'); const { Schema } = mongoose; diff --git a/backend/app/models/contactUs.js b/backend/app/models/contactUs.js index 83521648..5e34adb9 100644 --- a/backend/app/models/contactUs.js +++ b/backend/app/models/contactUs.js @@ -1,4 +1,4 @@ -import mongoose from "mongoose"; +const mongoose = require('mongoose'); const { Schema } = mongoose; diff --git a/backend/app/models/faq.js b/backend/app/models/faq.js index 3614896d..c3a3943b 100644 --- a/backend/app/models/faq.js +++ b/backend/app/models/faq.js @@ -1,4 +1,4 @@ -import mongoose from "mongoose"; +const mongoose = require('mongoose'); const { Schema } = mongoose; diff --git a/backend/app/models/joinUs.js b/backend/app/models/joinUs.js index 94c45721..63a2b6ec 100644 --- a/backend/app/models/joinUs.js +++ b/backend/app/models/joinUs.js @@ -1,4 +1,4 @@ -import mongoose from "mongoose"; +const mongoose = require('mongoose'); const { Schema } = mongoose; diff --git a/backend/app/models/question.js b/backend/app/models/question.js index d0bdc720..43051a07 100644 --- a/backend/app/models/question.js +++ b/backend/app/models/question.js @@ -1,4 +1,4 @@ -import mongoose from "mongoose"; +const mongoose = require('mongoose'); const { Schema } = mongoose; diff --git a/backend/app/models/resource.js b/backend/app/models/resource.js index 870424e1..32556e0e 100644 --- a/backend/app/models/resource.js +++ b/backend/app/models/resource.js @@ -1,4 +1,4 @@ -import mongoose from "mongoose"; +const mongoose = require('mongoose'); const resourceSchema = new mongoose.Schema( { diff --git a/backend/app/models/tinyURL.js b/backend/app/models/tinyURL.js index 7c93df67..254b9725 100644 --- a/backend/app/models/tinyURL.js +++ b/backend/app/models/tinyURL.js @@ -1,4 +1,4 @@ -import mongoose from "mongoose"; +const mongoose = require('mongoose'); const { Schema } = mongoose; const tinyURLSchema = new Schema({ diff --git a/backend/app/routes/Q&A/answers/@validationSchema/index.js b/backend/app/routes/Q&A/answers/@validationSchema/index.js index 3577d78d..51098c62 100644 --- a/backend/app/routes/Q&A/answers/@validationSchema/index.js +++ b/backend/app/routes/Q&A/answers/@validationSchema/index.js @@ -1,4 +1,4 @@ -import Joi from "joi"; +const Joi = require('joi'); const answerValidationSchema = Joi.object().keys({ question_id: Joi.string().trim().required().max(24).min(24), @@ -16,7 +16,7 @@ const updateAnswerStatusSchema = Joi.object().keys({ status : Joi.boolean().required() }); -export { +module.exports = { answerValidationSchema, getAnswerValidationSchema, updateAnswerStatusSchema diff --git a/backend/app/routes/Q&A/answers/downvoteAnswer.js b/backend/app/routes/Q&A/answers/downvoteAnswer.js index 15367be7..b4608d80 100644 --- a/backend/app/routes/Q&A/answers/downvoteAnswer.js +++ b/backend/app/routes/Q&A/answers/downvoteAnswer.js @@ -1,10 +1,9 @@ -import to from "await-to-js"; -import answer from '../../../models/answers'; -import { ErrorHandler } from "../../../../helpers/error"; -import constants from "../../../../constants"; +const to = require('await-to-js').default; +const answer = require('../../../models/answers'); +const { ErrorHandler } = require('../../../../helpers/error'); +const constants = require('../../../../constants'); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const { answerId } = req.body; const [err] = await to( answer.updateOne({ _id: answerId }, [ diff --git a/backend/app/routes/Q&A/answers/getAnswers.js b/backend/app/routes/Q&A/answers/getAnswers.js index d9a3a354..e58a4793 100644 --- a/backend/app/routes/Q&A/answers/getAnswers.js +++ b/backend/app/routes/Q&A/answers/getAnswers.js @@ -1,11 +1,10 @@ -import to from "await-to-js" -import mongoose from "mongoose"; -import Answer from '../../../models/answers' -import { ErrorHandler } from "../../../../helpers/error"; -import constants from "../../../../constants"; +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'); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const qId = req.body.question_id; const [err, answers] = await to( diff --git a/backend/app/routes/Q&A/answers/index.js b/backend/app/routes/Q&A/answers/index.js index 4aaea410..06c724b1 100644 --- a/backend/app/routes/Q&A/answers/index.js +++ b/backend/app/routes/Q&A/answers/index.js @@ -1,12 +1,12 @@ -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}); +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'); // POST API FOR ANSWER router.post('/', validation(answerValidationSchema), postAnswer); @@ -23,4 +23,4 @@ router.patch('/downvote', downvoteAnswer); // Update Answer Status router.patch('/updateStatus', validation(updateAnswerStatusSchema), updateAnswerStatus); -export default router; +module.exports = router; diff --git a/backend/app/routes/Q&A/answers/post.js b/backend/app/routes/Q&A/answers/post.js index 1ff87899..62e86cdf 100644 --- a/backend/app/routes/Q&A/answers/post.js +++ b/backend/app/routes/Q&A/answers/post.js @@ -1,10 +1,9 @@ -import to from "await-to-js" -import answer from '../../../models/answers' -import { ErrorHandler } from "../../../../helpers/error"; -import constants from "../../../../constants"; +const to = require('await-to-js').default; +const answer = require('../../../models/answers'); +const { ErrorHandler } = require('../../../../helpers/error'); +const constants = require('../../../../constants'); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const [err, body] = await to(answer.create({ ...req.body })); if (err) { diff --git a/backend/app/routes/Q&A/answers/updateAnswerStatus.js b/backend/app/routes/Q&A/answers/updateAnswerStatus.js index 701580c1..7822a123 100644 --- a/backend/app/routes/Q&A/answers/updateAnswerStatus.js +++ b/backend/app/routes/Q&A/answers/updateAnswerStatus.js @@ -1,10 +1,11 @@ -import to from "await-to-js"; -import constants from "../../../../constants"; -import { ErrorHandler } from "../../../../helpers/error"; -import answers from "../../../models/answers" +const to = require("await-to-js").default; +const constants = require("../../../../constants"); +const { ErrorHandler } = require("../../../../helpers/error"); -export default async (req, res, next) => { +const answers = require("../../../models/answers"); + +module.exports = async (req, res, next) => { // getting id and status from body const id = req.body.id; const status = req.body.status diff --git a/backend/app/routes/Q&A/answers/upvoteAnswer.js b/backend/app/routes/Q&A/answers/upvoteAnswer.js index b48416eb..38ce0678 100644 --- a/backend/app/routes/Q&A/answers/upvoteAnswer.js +++ b/backend/app/routes/Q&A/answers/upvoteAnswer.js @@ -1,10 +1,9 @@ -import to from "await-to-js" -import answer from '../../../models/answers' -import { ErrorHandler } from "../../../../helpers/error"; -import constants from "../../../../constants"; +const to = require('await-to-js').default; +const answer = require('../../../models/answers'); +const { ErrorHandler } = require('../../../../helpers/error'); +const constants = require('../../../../constants'); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const { answerId } = req.body; const [err] = await to(answer.updateOne({ _id: answerId }, { $inc: { upvotes: 1 } })); if (err) { diff --git a/backend/app/routes/Q&A/question/@validationSchema/index.js b/backend/app/routes/Q&A/question/@validationSchema/index.js index 73c12d08..10bfee90 100644 --- a/backend/app/routes/Q&A/question/@validationSchema/index.js +++ b/backend/app/routes/Q&A/question/@validationSchema/index.js @@ -1,4 +1,4 @@ -import Joi from "joi" +const Joi = require('joi'); const QuestionValidationSchema = Joi.object().keys({ title: Joi.string().trim().required().min(5), @@ -11,4 +11,4 @@ const updateQuestionStatusSchema = Joi.object().keys({ status : Joi.boolean().required() }); -export { QuestionValidationSchema, updateQuestionStatusSchema }; +module.exports = { QuestionValidationSchema, updateQuestionStatusSchema }; diff --git a/backend/app/routes/Q&A/question/downvoteQuestion.js b/backend/app/routes/Q&A/question/downvoteQuestion.js index c41e0212..4fbb3731 100644 --- a/backend/app/routes/Q&A/question/downvoteQuestion.js +++ b/backend/app/routes/Q&A/question/downvoteQuestion.js @@ -1,10 +1,9 @@ -import to from "await-to-js" -import question from '../../../models/question'; -import { ErrorHandler } from "../../../../helpers/error"; -import constants from "../../../../constants"; +const to = require('await-to-js').default; +const question = require('../../../models/question'); +const { ErrorHandler } = require('../../../../helpers/error'); +const constants = require('../../../../constants'); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const { questionId } = req.body; const [err] = await to( question.updateOne({ _id: questionId }, [ diff --git a/backend/app/routes/Q&A/question/getAllQuestion.js b/backend/app/routes/Q&A/question/getAllQuestion.js index b34af952..79ed187f 100644 --- a/backend/app/routes/Q&A/question/getAllQuestion.js +++ b/backend/app/routes/Q&A/question/getAllQuestion.js @@ -1,6 +1,6 @@ -import question from '../../../models/question' +const question = require('../../../models/question'); -export default async (req, res) => { +module.exports = async (req, res) => { try { const questions = {}; // Empty object filter which matches all the documents diff --git a/backend/app/routes/Q&A/question/getQuestionById.js b/backend/app/routes/Q&A/question/getQuestionById.js index e57e4231..825ee212 100644 --- a/backend/app/routes/Q&A/question/getQuestionById.js +++ b/backend/app/routes/Q&A/question/getQuestionById.js @@ -1,6 +1,6 @@ -import question from '../../../models/question'; +const question = require('../../../models/question'); -export default async (req, res) => { +module.exports = 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 diff --git a/backend/app/routes/Q&A/question/index.js b/backend/app/routes/Q&A/question/index.js index 2075c710..b2421e3a 100644 --- a/backend/app/routes/Q&A/question/index.js +++ b/backend/app/routes/Q&A/question/index.js @@ -1,14 +1,12 @@ - -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}) +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'); router.post('/', validation(QuestionValidationSchema), postQuestion); @@ -27,4 +25,4 @@ router.patch('/downvote', downvoteQuestion); // route for updating the question status router.patch('/updateStatus', validation(updateQuestionStatusSchema), updateQuestionStatus); -export default router; +module.exports = router; diff --git a/backend/app/routes/Q&A/question/post.js b/backend/app/routes/Q&A/question/post.js index c1620e56..44b6160e 100644 --- a/backend/app/routes/Q&A/question/post.js +++ b/backend/app/routes/Q&A/question/post.js @@ -1,11 +1,9 @@ +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"; - - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const [err, body] = await to(question.create({ ...req.body })); if (err) { diff --git a/backend/app/routes/Q&A/question/updateQuestionStatus.js b/backend/app/routes/Q&A/question/updateQuestionStatus.js index c3bb92eb..97700534 100644 --- a/backend/app/routes/Q&A/question/updateQuestionStatus.js +++ b/backend/app/routes/Q&A/question/updateQuestionStatus.js @@ -1,12 +1,11 @@ +const to = require("await-to-js").default; -import to from "await-to-js" -import constants from "../../../../constants"; -import { ErrorHandler } from "../../../../helpers/error"; -import question from "../../../models/question" +const constants = require("../../../../constants"); +const { ErrorHandler } = require("../../../../helpers/error"); +const question = require("../../../models/question"); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { // getting id and status from body const id = req.body.id; const status = req.body.status diff --git a/backend/app/routes/Q&A/question/upvoteQuestion.js b/backend/app/routes/Q&A/question/upvoteQuestion.js index 10bf46d5..63b28fd6 100644 --- a/backend/app/routes/Q&A/question/upvoteQuestion.js +++ b/backend/app/routes/Q&A/question/upvoteQuestion.js @@ -1,11 +1,9 @@ +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"; - - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const { questionId } = req.body; const [err] = await to(question.updateOne({ _id: questionId }, { $inc: { upvotes: 1 } })); if (err) { diff --git a/backend/app/routes/admin/@validationSchema/index.js b/backend/app/routes/admin/@validationSchema/index.js index 71cc6285..a4329f5f 100644 --- a/backend/app/routes/admin/@validationSchema/index.js +++ b/backend/app/routes/admin/@validationSchema/index.js @@ -1,4 +1,4 @@ -import Joi from "joi" +const Joi = require('joi'); const postSuperAdminSchema = Joi.object({ firstName: Joi.string() @@ -53,7 +53,7 @@ const deleteAdminSchema = Joi.object({ id : Joi.string().min(24).max(24).required() }) -export { +module.exports = { postSuperAdminSchema, getAdminsSchema, passwordChangeSchema, diff --git a/backend/app/routes/admin/changePassword.js b/backend/app/routes/admin/changePassword.js index f4c9c9e4..02735c5f 100644 --- a/backend/app/routes/admin/changePassword.js +++ b/backend/app/routes/admin/changePassword.js @@ -1,11 +1,10 @@ -import to from "await-to-js" -import argon2 from "argon2" -import Admin from '../../models/Admin'; -import { ErrorHandler } from '../../../helpers/error'; -import constants from '../../../constants'; +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'); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const { oldPassword, newPassword } = req.body; if (oldPassword === newPassword) { diff --git a/backend/app/routes/admin/createSuperAdmin.js b/backend/app/routes/admin/createSuperAdmin.js index 00e343f5..8f6ed2ae 100644 --- a/backend/app/routes/admin/createSuperAdmin.js +++ b/backend/app/routes/admin/createSuperAdmin.js @@ -1,10 +1,9 @@ -import to from "await-to-js" -import Admin from '../../models/Admin'; -import {ErrorHandler} from '../../../helpers/error'; -import constants from "../../../constants"; +const to = require('await-to-js').default; +const Admin = require('../../models/Admin'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const options = { upsert: true, new: true, setDefaultsOnInsert: true }; const adminData = { firstName: 'Root', diff --git a/backend/app/routes/admin/deleteAdmin.js b/backend/app/routes/admin/deleteAdmin.js index fab3a028..cbab67aa 100644 --- a/backend/app/routes/admin/deleteAdmin.js +++ b/backend/app/routes/admin/deleteAdmin.js @@ -1,9 +1,9 @@ -import to from "await-to-js" -import constants from "../../../constants"; -import {ErrorHandler} from "../../../helpers/error"; -import Admin from "../../models/Admin"; +const { default: to } = require("await-to-js"); +const constants = require("../../../constants"); +const { ErrorHandler } = require("../../../helpers/error"); +const Admin = require("../../models/Admin"); -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const { isSuperAdmin } = res.locals.decode; if(!isSuperAdmin) { diff --git a/backend/app/routes/admin/forgotPassword.js b/backend/app/routes/admin/forgotPassword.js index 7f60f39a..a3e8c04f 100644 --- a/backend/app/routes/admin/forgotPassword.js +++ b/backend/app/routes/admin/forgotPassword.js @@ -1,10 +1,10 @@ -import Admin from '../../models/Admin' -import config from '../../../config'; -import { ErrorHandler } from '../../../helpers/error'; -import constants from '../../../constants'; -import { generateJWT } from '../../../helpers/middlewares/auth'; +const Admin = require('../../models/Admin'); +const config = require('../../../config'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); +const { generateJWT } = require('../../../helpers/middlewares/auth'); -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const { email } = req.body; const userRecord = await Admin.findOne({ email }); if (!userRecord) { diff --git a/backend/app/routes/admin/getAdmins.js b/backend/app/routes/admin/getAdmins.js index fd092611..bfeac15b 100644 --- a/backend/app/routes/admin/getAdmins.js +++ b/backend/app/routes/admin/getAdmins.js @@ -1,7 +1,7 @@ -import to from "await-to-js"; -import Admin from '../../models/Admin' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; +const to = require('await-to-js').default; +const Admin = require('../../models/Admin'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); const getAdminsAggregate = (match, page) => { const pipeline = [ @@ -23,7 +23,7 @@ const getAdminsAggregate = (match, page) => { return pipeline; }; -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const page = req.query.page || 1; const adminType = req.query.type; let match = {}; diff --git a/backend/app/routes/admin/index.js b/backend/app/routes/admin/index.js index 2048c401..35ff2d0f 100644 --- a/backend/app/routes/admin/index.js +++ b/backend/app/routes/admin/index.js @@ -1,7 +1,6 @@ -import express from "expresss"; -import validationMiddleware from '../../../helpers/middlewares/validation' -import { authMiddleware } from "../../../helpers/middlewares/auth"; -const router = express.Router({ mergeParams: true }); +const router = require('express').Router({ mergeParams: true }); +const validationMiddleware = require('../../../helpers/middlewares/validation'); +const { authMiddleware } = require('../../../helpers/middlewares/auth'); const { postSuperAdminSchema, @@ -38,4 +37,4 @@ router.put('/:id/:token', validationMiddleware(updateAdminSchema), updateAdmin); router.delete('/deleteAdmin', validationMiddleware(deleteAdminSchema), authMiddleware, deleteAdmin); -export default router; \ No newline at end of file +module.exports = router; \ No newline at end of file diff --git a/backend/app/routes/admin/inviteAdmin.js b/backend/app/routes/admin/inviteAdmin.js index 5353b270..34413e01 100644 --- a/backend/app/routes/admin/inviteAdmin.js +++ b/backend/app/routes/admin/inviteAdmin.js @@ -1,9 +1,9 @@ -import to from "await-to-js"; -import { ErrorHandler } from "../../../helpers/error"; -import { sendEmail } from "../../../helpers/emailService"; -import constants from "../../../constants"; +const to = require('await-to-js').default; +const { ErrorHandler } = require('../../../helpers/error'); +const { sendEmail } = require('../../../helpers/emailService'); +const constants = require('../../../constants'); -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const { email, data } = req.body; const type = 'INVITE-ADMIN'; diff --git a/backend/app/routes/admin/postAdmin.js b/backend/app/routes/admin/postAdmin.js index b8beda6c..baae1166 100644 --- a/backend/app/routes/admin/postAdmin.js +++ b/backend/app/routes/admin/postAdmin.js @@ -1,10 +1,10 @@ -import to from "await-to-js" -import argon2 from "argon2"; -import Admin from '../../models/Admin' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; +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'); -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const adminData = { ...req.body, isSuperAdmin: false, diff --git a/backend/app/routes/admin/postSuperAdmin.js b/backend/app/routes/admin/postSuperAdmin.js index a4c18f80..ac507489 100644 --- a/backend/app/routes/admin/postSuperAdmin.js +++ b/backend/app/routes/admin/postSuperAdmin.js @@ -1,10 +1,10 @@ -import to from "await-to-js" -import argon2 from "argon2" -import Admin from '../../models/Admin' -import {ErrorHandler} from '../../../helpers/error' -import constants from "../../../constants"; +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'); -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const adminData = { ...req.body, isSuperAdmin: true, diff --git a/backend/app/routes/admin/resetPassword.js b/backend/app/routes/admin/resetPassword.js index 04cbfc66..2ff7673c 100644 --- a/backend/app/routes/admin/resetPassword.js +++ b/backend/app/routes/admin/resetPassword.js @@ -1,11 +1,11 @@ -import to from "await-to-js" -import argon2 from "argon2" -import Admin from '../../models/Admin' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; -import { verifyToken } from "../../../helpers/middlewares/auth"; - -export default async (req, res, next) => { +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'); +const { verifyToken } = require('../../../helpers/middlewares/auth'); + +module.exports = async (req, res, next) => { // Extracting the new password from the request const { newPassword } = req.body; // Extracting the TOKEN from URl /resetpassword/:token diff --git a/backend/app/routes/admin/updateAdmin.js b/backend/app/routes/admin/updateAdmin.js index c4c44f6b..9984d1e8 100644 --- a/backend/app/routes/admin/updateAdmin.js +++ b/backend/app/routes/admin/updateAdmin.js @@ -1,6 +1,6 @@ -import Admin from '../../models/Admin' +const Admin = require('../../models/Admin'); -export default async (req, res) => { +module.exports =async (req, res) => { try { const updatedAdmin = await Admin.findByIdAndUpdate( diff --git a/backend/app/routes/auth/@validationSchema/index.js b/backend/app/routes/auth/@validationSchema/index.js index 63085c8b..b2106529 100644 --- a/backend/app/routes/auth/@validationSchema/index.js +++ b/backend/app/routes/auth/@validationSchema/index.js @@ -1,8 +1,8 @@ -import Joi from "joi"; +const Joi = require('joi'); const loginSchema = Joi.object().keys({ email: Joi.string().required(), password: Joi.string().required(), }); -export default loginSchema; +module.exports = loginSchema; diff --git a/backend/app/routes/auth/index.js b/backend/app/routes/auth/index.js index e3f78070..5d9a5a28 100644 --- a/backend/app/routes/auth/index.js +++ b/backend/app/routes/auth/index.js @@ -1,9 +1,8 @@ -import express from "express"; -import login from "./login"; -import loginSchema from './@validationSchema' -import validation from '../../../helpers/middlewares/validation' -const router = express.Router({ mergeParams: true }); +const router = require('express').Router({ mergeParams: true }); +const login = require('./login'); +const loginSchema = require('./@validationSchema'); +const validation = require('../../../helpers/middlewares/validation'); router.post('/login', validation(loginSchema), login); -export default router; +module.exports = router; diff --git a/backend/app/routes/auth/login.js b/backend/app/routes/auth/login.js index c66d21d6..3a8d8513 100644 --- a/backend/app/routes/auth/login.js +++ b/backend/app/routes/auth/login.js @@ -1,10 +1,10 @@ -import argon2 from "argon2" -import Admin from '../../models/Admin' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; -import { generateJWT } from "../../../helpers/middlewares/auth"; +const argon2 = require('argon2'); +const Admin = require('../../models/Admin'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); +const { generateJWT } = require('../../../helpers/middlewares/auth'); -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const { email, password } = req.body; const userRecord = await Admin.findOne({ email }); if (!userRecord) { diff --git a/backend/app/routes/broadcast/@validationSchema/index.js b/backend/app/routes/broadcast/@validationSchema/index.js index 5278a92e..0a954a23 100644 --- a/backend/app/routes/broadcast/@validationSchema/index.js +++ b/backend/app/routes/broadcast/@validationSchema/index.js @@ -1,4 +1,4 @@ -import Joi from "joi"; +const Joi = require('joi'); const postBroadcastValidationSchema = Joi.object().keys({ title: Joi.string().required(), @@ -29,7 +29,7 @@ const getBroadcastsValidationSchema = Joi.object().keys({ month: Joi.number().min(1).max(12).optional(), }); -export { +module.exports = { postBroadcastValidationSchema, getBroadcastsValidationSchema, updateBroadcastValidationSchema diff --git a/backend/app/routes/broadcast/deleteBroadcast.js b/backend/app/routes/broadcast/deleteBroadcast.js index 96192cf7..fdc23823 100644 --- a/backend/app/routes/broadcast/deleteBroadcast.js +++ b/backend/app/routes/broadcast/deleteBroadcast.js @@ -1,9 +1,9 @@ -import to from "await-to-js" -import Broadcast from '../../models/Broadcast' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; +const to = require('await-to-js').default; +const Broadcast = require('../../models/Broadcast'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const [err, broadcast] = await to(Broadcast.findByIdAndDelete(req.params.id)); if (!broadcast) { const error = new ErrorHandler(constants.ERRORS.INPUT, { diff --git a/backend/app/routes/broadcast/getBroadcasts.js b/backend/app/routes/broadcast/getBroadcasts.js index 08f80eb4..26e97c10 100644 --- a/backend/app/routes/broadcast/getBroadcasts.js +++ b/backend/app/routes/broadcast/getBroadcasts.js @@ -1,7 +1,7 @@ -import to from "await-to-js" -import Broadcast from '../../models/Broadcast' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; +const to = require('await-to-js').default; +const Broadcast = require('../../models/Broadcast'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); const limit = constants.PAGINATION_LIMIT.GET_BROADCASTS; @@ -30,7 +30,7 @@ const getBroadcastsAggregate = (startIndex, match) => { ]; return pipeline; }; -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const page = parseInt(req.query.page, 10) || 1; const tags = req.query.tags?.split(','); const year = parseInt(req.query.year, 10); diff --git a/backend/app/routes/broadcast/getallbroadcasts.js b/backend/app/routes/broadcast/getallbroadcasts.js index 8f6232a3..46bddc7b 100644 --- a/backend/app/routes/broadcast/getallbroadcasts.js +++ b/backend/app/routes/broadcast/getallbroadcasts.js @@ -1,9 +1,9 @@ -import to from "await-to-js" -import Broadcast from '../../models/Broadcast' -import constants from "../../../constants"; -import { ErrorHandler } from "../../../helpers/error"; +const to = require('await-to-js').default; +const Broadcast = require('../../models/Broadcast'); +const constants = require('../../../constants'); +const { ErrorHandler } = require('../../../helpers/error'); -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const [err, response] = await to(Broadcast.find()); if (err) { const error = new ErrorHandler(constants.ERRORS.DATABASE, { diff --git a/backend/app/routes/broadcast/index.js b/backend/app/routes/broadcast/index.js index 2e055ba1..0b538a1f 100644 --- a/backend/app/routes/broadcast/index.js +++ b/backend/app/routes/broadcast/index.js @@ -1,20 +1,17 @@ -import express from "express"; -import validationMiddleware from '../../../helpers/middlewares/validation' -import { authMiddleware } from "../../../helpers/middlewares/auth"; -const router = express.Router({mergeParams:true}) - - -import { postBroadcastValidationSchema,getBroadcastsValidationSchema,updateBroadcastValidationSchema } from "./@validationSchema"; -import postBroadcast from "./postBroadcast" -import deleteBroadcast from "./deleteBroadcast"; -import getBroadcasts from "./getBroadcasts"; -import getallbroadcast from "./getallbroadcasts"; -import updateBroadcast from "./updateBroadcast" +const router = require('express').Router({ mergeParams: true }); +const validationMiddleware = require('../../../helpers/middlewares/validation'); +const { authMiddleware } = require('../../../helpers/middlewares/auth'); +const { postBroadcastValidationSchema, getBroadcastsValidationSchema, updateBroadcastValidationSchema } = require('./@validationSchema'); +const postBroadcast = require('./postBroadcast'); +const deleteBroadcast = require('./deleteBroadcast'); +const getBroadcasts = require('./getBroadcasts'); +const getallbroadcast = require('./getallbroadcasts'); +const updateBroadcast = require('./updateBroadcast'); router.get('/', validationMiddleware(getBroadcastsValidationSchema, 'query'), getBroadcasts); router.post('/', validationMiddleware(postBroadcastValidationSchema), authMiddleware, postBroadcast); router.delete('/:id', authMiddleware, deleteBroadcast); router.get('/all', getallbroadcast); router.patch('/update', validationMiddleware(updateBroadcastValidationSchema), authMiddleware, updateBroadcast); -export default router; +module.exports = router; diff --git a/backend/app/routes/broadcast/postBroadcast.js b/backend/app/routes/broadcast/postBroadcast.js index ae5b10de..7b2bcec1 100644 --- a/backend/app/routes/broadcast/postBroadcast.js +++ b/backend/app/routes/broadcast/postBroadcast.js @@ -1,9 +1,9 @@ -import to from "await-to-js" -import Broadcast from '../../models/Broadcast' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; +const to = require('await-to-js').default; +const Broadcast = require('../../models/Broadcast'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const [err, { _id }] = await to(Broadcast.create({ ...req.body })); if (err) { const error = new ErrorHandler(constants.ERRORS.DATABASE, { diff --git a/backend/app/routes/broadcast/updateBroadcast.js b/backend/app/routes/broadcast/updateBroadcast.js index 594451ab..be508474 100644 --- a/backend/app/routes/broadcast/updateBroadcast.js +++ b/backend/app/routes/broadcast/updateBroadcast.js @@ -1,9 +1,9 @@ -import to from "await-to-js" -import Broadcast from '../../models/Broadcast'; -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; +const to = require('await-to-js').default; +const Broadcast = require('../../models/Broadcast'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); -export default async (req, res, next) => { +module.exports = async (req, res, next) => { if(Object.keys(req.body).length <= 1) { return res.status(200).send({ message : "Not Sufficient Data" diff --git a/backend/app/routes/contactUs/@validationSchema/index.js b/backend/app/routes/contactUs/@validationSchema/index.js index 207689d4..61f722f0 100644 --- a/backend/app/routes/contactUs/@validationSchema/index.js +++ b/backend/app/routes/contactUs/@validationSchema/index.js @@ -1,4 +1,4 @@ -import Joi from "joi" +const Joi = require('joi'); const contactValidationSchema = Joi.object().keys({ name: Joi.string().trim().required().min(3), @@ -7,4 +7,4 @@ const contactValidationSchema = Joi.object().keys({ message: Joi.string().trim().required().min(8), }); -export default contactValidationSchema; +module.exports = contactValidationSchema; diff --git a/backend/app/routes/contactUs/get.js b/backend/app/routes/contactUs/get.js index b377584b..6f1ec323 100644 --- a/backend/app/routes/contactUs/get.js +++ b/backend/app/routes/contactUs/get.js @@ -1,9 +1,9 @@ -import to from "await-to-js" -import contactUs from '../../models/contactUs' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; +const to = require('await-to-js').default; +const contactUs = require('../../models/contactUs'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const [err, response] = await to(contactUs.find()); if (err) { const error = new ErrorHandler(constants.ERRORS.DATABASE, { diff --git a/backend/app/routes/contactUs/index.js b/backend/app/routes/contactUs/index.js index 100f847e..60701905 100644 --- a/backend/app/routes/contactUs/index.js +++ b/backend/app/routes/contactUs/index.js @@ -1,12 +1,11 @@ -import express from "express"; -import contactValidationSchema from './@validationSchema' -import validation from '../../../helpers/middlewares/validation' -import postContact from "./post"; -import getContact from "./get" -import { authMiddleware } from "../../../helpers/middlewares/auth"; -const router = express.Router({mergeParams:true}) +const router = require('express').Router({ mergeParams: true }); +const contactValidationSchema = require('./@validationSchema'); +const validation = require('../../../helpers/middlewares/validation'); +const postContact = require('./post'); +const getContact = require('./get'); +const { authMiddleware } = require('../../../helpers/middlewares/auth'); router.get('/getcontactus', authMiddleware, getContact); router.post('/contactus', validation(contactValidationSchema), postContact); -export default router; +module.exports = router; diff --git a/backend/app/routes/contactUs/post.js b/backend/app/routes/contactUs/post.js index d2e14829..6a327573 100644 --- a/backend/app/routes/contactUs/post.js +++ b/backend/app/routes/contactUs/post.js @@ -1,13 +1,12 @@ -import to from "await-to-js" -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; -import contactUs from '../../models/contactUs' -import Admin from '../../models/Admin' -import sendEmail from "../../../utility/sendEmail"; -import { ContactUsMailTemplate } from "../../../utility/emailTemplates"; +const to = require('await-to-js').default; +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); +const contactUs = require('../../models/contactUs'); +const Admin = require('../../models/Admin'); +const sendEmail = require('../../../utility/sendEmail'); +const { ContactUsMailTemplate } = require('../../../utility/emailTemplates'); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const [err] = await to(contactUs.create({ ...req.body })); if (err) { const error = new ErrorHandler(constants.ERRORS.DATABASE, { diff --git a/backend/app/routes/faq/@validationSchema/index.js b/backend/app/routes/faq/@validationSchema/index.js index bbfcd2fd..7922b5f0 100644 --- a/backend/app/routes/faq/@validationSchema/index.js +++ b/backend/app/routes/faq/@validationSchema/index.js @@ -1,4 +1,4 @@ -import Joi from "joi"; +const Joi = require('joi'); const FAQValidationSchema = Joi.object().keys({ question: Joi.string().required(), @@ -6,4 +6,4 @@ const FAQValidationSchema = Joi.object().keys({ tags: Joi.array().required(), }); -export default FAQValidationSchema; +module.exports = FAQValidationSchema; diff --git a/backend/app/routes/faq/deleteFaq.js b/backend/app/routes/faq/deleteFaq.js index cdcab102..d0a762ba 100644 --- a/backend/app/routes/faq/deleteFaq.js +++ b/backend/app/routes/faq/deleteFaq.js @@ -1,10 +1,10 @@ -import to from "await-to-js" -import faq from '../../models/faq' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; -import Admin from '../../models/Admin' +const to = require('await-to-js').default; +const faq = require('../../models/faq'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); +const Admin = require('../../models/Admin'); -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const { userId } = req.body; const { faqId } = req.body; if (!userId || !faqId) { diff --git a/backend/app/routes/faq/getFaq.js b/backend/app/routes/faq/getFaq.js index d4f718ad..0a86dd53 100644 --- a/backend/app/routes/faq/getFaq.js +++ b/backend/app/routes/faq/getFaq.js @@ -1,10 +1,9 @@ -import to from "await-to-js" -import FAQ from '../../models/faq' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; +const to = require('await-to-js').default; +const FAQ = require('../../models/faq'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const [err, response] = await to(FAQ.find()); if (err) { const error = new ErrorHandler(constants.ERRORS.DATABASE, { diff --git a/backend/app/routes/faq/index.js b/backend/app/routes/faq/index.js index bc5e94cb..6fc56a61 100644 --- a/backend/app/routes/faq/index.js +++ b/backend/app/routes/faq/index.js @@ -1,15 +1,14 @@ -import express from "express"; -import faq from "./post" -import getfaq from "./getFaq" -import FAQValidationSchema from './@validationSchema' -import validation from '../../../helpers/middlewares/validation'; -import deleteFaq from "./deleteFaq" -import updateFaq from "./updateFaq"; -const router = express.Router({mergeParams:true}) +const router = require('express').Router({ mergeParams: true }); +const faq = require('./post'); +const getfaq = require('./getFaq'); +const FAQValidationSchema = require('./@validationSchema'); +const validation = require('../../../helpers/middlewares/validation'); +const deleteFaq = require('./deleteFaq'); +const updateFaq = require('./updateFaq'); router.post('/faq', validation(FAQValidationSchema), faq); router.get('/getFaq', getfaq); router.put('/deleteFaq', deleteFaq); router.patch('/updateFaq',updateFaq); -export default router; +module.exports = router; diff --git a/backend/app/routes/faq/post.js b/backend/app/routes/faq/post.js index 9838a93e..805aa958 100644 --- a/backend/app/routes/faq/post.js +++ b/backend/app/routes/faq/post.js @@ -1,10 +1,9 @@ -import to from "await-to-js" -import FAQ from '../../models/faq' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; +const to = require('await-to-js').default; +const FAQ = require('../../models/faq'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const [err,response] = await to(FAQ.create({ ...req.body })); if (err) { const error = new ErrorHandler(constants.ERRORS.DATABASE, { diff --git a/backend/app/routes/faq/updateFaq.js b/backend/app/routes/faq/updateFaq.js index 2adf3590..6cd027a0 100644 --- a/backend/app/routes/faq/updateFaq.js +++ b/backend/app/routes/faq/updateFaq.js @@ -1,6 +1,6 @@ -import FAQ from '../../models/faq'; +const FAQ = require('../../models/faq'); -export default async(req,res,next) => { +module.exports = async(req,res,next) => { try { let faqId = req.body.faqId; let faq = await FAQ.findById(faqId); diff --git a/backend/app/routes/index.js b/backend/app/routes/index.js index d30d2088..1a209920 100644 --- a/backend/app/routes/index.js +++ b/backend/app/routes/index.js @@ -1,26 +1,24 @@ -import express from "express"; -import admin from "./admin" -import auth from "./auth" -import {emailTest} from './testRoutes/emailTest' -import tinyURL from "./tinyURL" -import broadcast from "./broadcast" -import faq from "./faq/post" -import getFaq from "./faq/getFaq" -import deleteFaq from "./faq/deleteFaq" -import updateFaq from "./faq/updateFaq" -import joinUs from "./joinUs" -import contactUs from "./contactUs" +const router = require('express').Router({ mergeParams: true }); +const admin = require('./admin'); +const auth = require('./auth'); +const { emailTest } = require('./testRoutes/emailTest'); +const tinyURL = require('./tinyURL'); +const broadcast = require('./broadcast'); +const faq = require('./faq/post'); +const getFaq = require('./faq/getFaq'); +const deleteFaq = require('./faq/deleteFaq'); +const updateFaq = require('./faq/updateFaq') +const joinUs = require('./joinUs'); +const contactUs = require('./contactUs/post'); +const getContactUs = require('./contactUs/get'); +const contactValidationSchema = require('./contactUs/@validationSchema'); +const validation = require('../../helpers/middlewares/validation'); -import getContactUs from "./contactUs/get" -import contactValidationSchema from "./contactUs/@validationSchema" -import validation from '../../helpers/middlewares/validation' - -import question from "./Q&A/question" -import answer from "./Q&A/answers" -import teamMember from "./teamMember" -import resource from "./resources" -const router = express.Router({mergeParams:true}); +const question = require('./Q&A/question'); +const answer = require('./Q&A/answers'); +const teamMember = require('./teamMember'); +const resource = require('./resources'); router.use('/admin', admin); router.use('/auth', auth); @@ -38,4 +36,4 @@ router.use('/joinUs', joinUs); router.use('/teamMember', teamMember); router.use('/', tinyURL); router.use('/resources', resource); -export default router; +module.exports = router; diff --git a/backend/app/routes/joinUs/@validationSchema/index.js b/backend/app/routes/joinUs/@validationSchema/index.js index 5decc87b..23b9e96b 100644 --- a/backend/app/routes/joinUs/@validationSchema/index.js +++ b/backend/app/routes/joinUs/@validationSchema/index.js @@ -1,4 +1,4 @@ -import Joi from "joi"; +const Joi = require('joi'); const JoinUsValidationSchema = Joi.object().keys({ name: Joi.string().required(), @@ -13,4 +13,4 @@ const JoinUsValidationSchema = Joi.object().keys({ department: Joi.string(), }); -export default JoinUsValidationSchema; +module.exports = JoinUsValidationSchema; diff --git a/backend/app/routes/joinUs/deleteJoinUs.js b/backend/app/routes/joinUs/deleteJoinUs.js index ca7ba825..3433e4f1 100644 --- a/backend/app/routes/joinUs/deleteJoinUs.js +++ b/backend/app/routes/joinUs/deleteJoinUs.js @@ -1,6 +1,5 @@ -import joinUsModel from '../../models/joinUs'; - -export default async(req,res,next) => { +const joinUsModel = require('../../models/joinUs'); +module.exports = async(req,res,next) => { try { const id = req.body.itemId const result = await joinUsModel.findByIdAndDelete(id); diff --git a/backend/app/routes/joinUs/get.js b/backend/app/routes/joinUs/get.js index d4dc0e3c..52805aa6 100644 --- a/backend/app/routes/joinUs/get.js +++ b/backend/app/routes/joinUs/get.js @@ -1,6 +1,6 @@ -import joinUsModel from '../../models/joinUs'; +const joinUsModel = require('../../models/joinUs'); -export default async (req, res, next) => { +module.exports = async (req, res, next) => { try { const joinRequests = await joinUsModel.find(); res.status(200).json(joinRequests); diff --git a/backend/app/routes/joinUs/index.js b/backend/app/routes/joinUs/index.js index a61110e5..8e20ee46 100644 --- a/backend/app/routes/joinUs/index.js +++ b/backend/app/routes/joinUs/index.js @@ -1,14 +1,13 @@ -import express from "express"; -import postJoinUs from "./post" -import getJoinUs from "./get"; -import JoinUsValidationSchema from './@validationSchema' -import validation from '../../../helpers/middlewares/validation' -import { authMiddleware } from "../../../helpers/middlewares/auth"; -import deleteJoinUs from "./deleteJoinUs" -const router = express.Router({mergeParams:true}) +const router = require('express').Router({ mergeParams: true }); +const postJoinUs = require('./post'); +const getJoinUs = require('./get'); +const JoinUsValidationSchema = require('./@validationSchema'); +const validation = require('../../../helpers/middlewares/validation'); +const {authMiddleware} = require('../../../helpers/middlewares/auth') +const deleteJoinUs = require("./deleteJoinUs") router.post('/', validation(JoinUsValidationSchema), postJoinUs); router.get('/', authMiddleware, getJoinUs); router.delete('/deleteJoinUs',deleteJoinUs) -export default router; +module.exports = router; diff --git a/backend/app/routes/joinUs/post.js b/backend/app/routes/joinUs/post.js index 832c7f7f..47c198e5 100644 --- a/backend/app/routes/joinUs/post.js +++ b/backend/app/routes/joinUs/post.js @@ -1,13 +1,12 @@ -import to from "await-to-js" -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; -import JoinUs from '../../models/joinUs' -import Admin from '../../models/Admin' -import sendEmail from "../../../utility/sendEmail"; -import { JoinUsMailTemplate } from "../../../utility/emailTemplates"; +const to = require('await-to-js').default; +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); +const JoinUs = require('../../models/joinUs'); +const Admin = require('../../models/Admin'); +const sendEmail = require('../../../utility/sendEmail'); +const { JoinUsMailTemplate } = require('../../../utility/emailTemplates'); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const [err,createdResponse] = await to(JoinUs.create({ ...req.body })); if (err) { const error = new ErrorHandler(constants.ERRORS.DATABASE, { diff --git a/backend/app/routes/resources/@validationSchema/index.js b/backend/app/routes/resources/@validationSchema/index.js index e5967964..3aa64195 100644 --- a/backend/app/routes/resources/@validationSchema/index.js +++ b/backend/app/routes/resources/@validationSchema/index.js @@ -1,4 +1,4 @@ -import Joi from "joi" +const Joi = require('joi'); const ResourcesValidationSchema = Joi.object().keys({ name: Joi.string().trim().required().min(3), @@ -10,4 +10,4 @@ const ResourcesValidationSchema = Joi.object().keys({ additionalInfo: Joi.string().trim().min(5), }); -export default ResourcesValidationSchema; +module.exports = ResourcesValidationSchema; diff --git a/backend/app/routes/resources/addResource.js b/backend/app/routes/resources/addResource.js index d51abfe2..4ce78724 100644 --- a/backend/app/routes/resources/addResource.js +++ b/backend/app/routes/resources/addResource.js @@ -1,13 +1,12 @@ -import to from "await-to-js" -import Resource from '../../models/resource' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; -import Admin from '../../models/Admin' -import sendEmail from "../../../utility/sendEmail"; -import { ResourceAddedInformingMailTemplate } from "../../../utility/emailTemplates"; +const to = require('await-to-js').default; +const Resource = require('../../models/resource'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); +const Admin = require('../../models/Admin'); +const sendEmail = require('../../../utility/sendEmail'); +const { ResourceAddedInformingMailTemplate } = require('../../../utility/emailTemplates'); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const [err] = await to(Resource.create({ ...req.body })); if (err) { const error = new ErrorHandler(constants.ERRORS.DATABASE, { diff --git a/backend/app/routes/resources/deleteResource.js b/backend/app/routes/resources/deleteResource.js index f165418c..19b706aa 100644 --- a/backend/app/routes/resources/deleteResource.js +++ b/backend/app/routes/resources/deleteResource.js @@ -1,7 +1,6 @@ +const Resource = require('../../models/resource'); -import Resource from "../../models/resource" - -export default async (req, res) => { +module.exports = async (req, res) => { try { const { resourceId } = req.body; // Getting resource id from the body const result = await Resource.findByIdAndDelete(resourceId); // Deleting the resource corresponding to reosource id diff --git a/backend/app/routes/resources/getResource.js b/backend/app/routes/resources/getResource.js index bb7dce29..eb11250c 100644 --- a/backend/app/routes/resources/getResource.js +++ b/backend/app/routes/resources/getResource.js @@ -1,7 +1,6 @@ +const Resource = require('../../models/resource'); -import Resource from '../../models/resource' - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { try { const AllResources = await Resource.find(); res.status(200).json(AllResources); diff --git a/backend/app/routes/resources/index.js b/backend/app/routes/resources/index.js index 4f0733ed..075fccc6 100644 --- a/backend/app/routes/resources/index.js +++ b/backend/app/routes/resources/index.js @@ -1,15 +1,14 @@ -import express from "express"; -import addaResource from './addResource' -import deleteResource from "./deleteResource" -import getResource from "./getResource" -import validation from '../../../helpers/middlewares/validation' -import ResourcesValidationSchema from './@validationSchema' -import { authMiddleware } from "../../../helpers/middlewares/auth"; -const router = express.Router({mergeParams:true}) +const router = require('express').Router({ mergeParams: true }); +const addaResource = require('./addResource'); +const deleteResource = require('./deleteResource'); +const getResource = require('./getResource'); +const validation = require('../../../helpers/middlewares/validation'); +const ResourcesValidationSchema = require('./@validationSchema'); +const { authMiddleware } = require('../../../helpers/middlewares/auth'); router.post('/', validation(ResourcesValidationSchema), addaResource); // Route for deleting a resource router.delete('/deleteResource', deleteResource); router.get('/getresources', authMiddleware, getResource); -export default router; +module.exports = router; diff --git a/backend/app/routes/teamMember/addTeam.js b/backend/app/routes/teamMember/addTeam.js index 49464f72..0ba89a54 100644 --- a/backend/app/routes/teamMember/addTeam.js +++ b/backend/app/routes/teamMember/addTeam.js @@ -1,10 +1,9 @@ -import to from "await-to-js" -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; -import TeamMemberModel from '../../models/TeamMember' +const to = require('await-to-js').default; +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); +const TeamMemberModel = require('../../models/TeamMember'); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const payload = res.locals.decode; if (payload.isSuperAdmin === false) { res.status(401).json({ error: 'You are not an admin' }); diff --git a/backend/app/routes/teamMember/deleteTeamMember.js b/backend/app/routes/teamMember/deleteTeamMember.js index b06bedd5..b6c3aac2 100644 --- a/backend/app/routes/teamMember/deleteTeamMember.js +++ b/backend/app/routes/teamMember/deleteTeamMember.js @@ -1,6 +1,5 @@ -import teamMemberModel from '../../models/TeamMember'; - -export default async(req,res,next) => { +const teamMemberModel = require('../../models/TeamMember'); +module.exports = async(req,res,next) => { try { const payload = res.locals.decode; const memberId = req.body.memberId; diff --git a/backend/app/routes/teamMember/getTeamMemberById.js b/backend/app/routes/teamMember/getTeamMemberById.js index 5069aab8..ed0012f7 100644 --- a/backend/app/routes/teamMember/getTeamMemberById.js +++ b/backend/app/routes/teamMember/getTeamMemberById.js @@ -1,10 +1,10 @@ -import to from "await-to-js"; -import TeamMemberModel from '../../models/TeamMember' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; +const to = require('await-to-js').default; +const TeamMemberModel = require('../../models/TeamMember'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const memberId = req.params.id; const [err, member] = await to(TeamMemberModel.findById(memberId)); diff --git a/backend/app/routes/teamMember/getTeamMembers.js b/backend/app/routes/teamMember/getTeamMembers.js index f427edbf..9f1b3fc3 100644 --- a/backend/app/routes/teamMember/getTeamMembers.js +++ b/backend/app/routes/teamMember/getTeamMembers.js @@ -1,12 +1,10 @@ +const to = require('await-to-js').default; +const TeamMemberModel = require('../../models/TeamMember'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); -import to from "await-to-js" -import TeamMemberModel from '../../models/TeamMember' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; - - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const [err, members] = await to(TeamMemberModel.find()); if (err) { diff --git a/backend/app/routes/teamMember/index.js b/backend/app/routes/teamMember/index.js index 90d8f63a..065f81f6 100644 --- a/backend/app/routes/teamMember/index.js +++ b/backend/app/routes/teamMember/index.js @@ -1,19 +1,17 @@ -import express from "express" -import multer from "multer"; -import getTeamMembers from "./getTeamMembers" -import getTeamMemberById from "./getTeamMemberById" -import updateTeamMember from "./updateTeamMember"; -import addTeam from "./addTeam" -import deleteTeamMember from "./deleteTeamMember" -import { authMiddleware } from "../../../helpers/middlewares/auth"; -const router = express.Router({mergeParams:true}) +const router = require('express').Router({ mergeParams: true }); +const multer = require('multer'); +const getTeamMembers = require('./getTeamMembers'); +const getTeamMemberById = require('./getTeamMemberById'); +const updateTeamMember = require('./updateTeamMember'); +const addTeam = require('./addTeam'); +const deleteTeamMember = require('./deleteTeamMember'); +const { authMiddleware } = require('../../../helpers/middlewares/auth'); const upload = multer({ dest: 'uploads/teamMembersProfile' }); - router.get('/getTeamMembers/', getTeamMembers); router.get('/getTeamMember/:id', getTeamMemberById); router.post('/addTeamMember', authMiddleware, upload.single('image'), addTeam); router.put('/updateTeamMember',authMiddleware,upload.single('image'),updateTeamMember); router.delete("/deleteTeamMember",authMiddleware,deleteTeamMember); -export default router; +module.exports = router; diff --git a/backend/app/routes/teamMember/updateTeamMember.js b/backend/app/routes/teamMember/updateTeamMember.js index e86f60a7..c9492699 100644 --- a/backend/app/routes/teamMember/updateTeamMember.js +++ b/backend/app/routes/teamMember/updateTeamMember.js @@ -1,6 +1,6 @@ -import TeamMemberModel from '../../models/TeamMember' +const TeamMemberModel = require('../../models/TeamMember'); -export default async(req,res) => { +module.exports = async(req,res) => { try { const payload = res.locals.decode; let teamMember = await TeamMemberModel.findById(req.body.teamMemberId) diff --git a/backend/app/routes/testRoutes/emailTest.js b/backend/app/routes/testRoutes/emailTest.js index 5823c359..53468ac0 100644 --- a/backend/app/routes/testRoutes/emailTest.js +++ b/backend/app/routes/testRoutes/emailTest.js @@ -1,10 +1,9 @@ -import to from "await-to-js"; -import { ErrorHandler } from "../../../helpers/error"; -import { sendEmail } from "../../../helpers/emailService"; -import constants from "../../../constants"; +const to = require('await-to-js').default; +const { ErrorHandler } = require('../../../helpers/error'); +const { sendEmail } = require('../../../helpers/emailService'); +const constants = require('../../../constants'); - -export default emailTest = async (req, res, next) => { +module.exports.emailTest = async (req, res, next) => { const { email, data, type } = req.body; const [err, response] = await to(sendEmail(email, data, type)); diff --git a/backend/app/routes/tinyURL/@validationSchema/index.js b/backend/app/routes/tinyURL/@validationSchema/index.js index 4d7177db..a563b005 100644 --- a/backend/app/routes/tinyURL/@validationSchema/index.js +++ b/backend/app/routes/tinyURL/@validationSchema/index.js @@ -1,7 +1,7 @@ -import Joi from "joi" +const Joi = require('joi'); const tinyURLSchema = Joi.object().keys({ longURL: Joi.string().required().uri(), }); -export default tinyURLSchema; +module.exports = tinyURLSchema; diff --git a/backend/app/routes/tinyURL/index.js b/backend/app/routes/tinyURL/index.js index 0a85e2df..420a83ba 100644 --- a/backend/app/routes/tinyURL/index.js +++ b/backend/app/routes/tinyURL/index.js @@ -1,9 +1,8 @@ -import express from "express"; -import shortenURL from "./shortenURL" -import redirectURL from "./redirectURL"; -import validationMiddleware from '../../../helpers/middlewares/validation' -import tinyURLSchema from './@validationSchema' -const router = express.Router({mergeParams:true}) +const router = require('express').Router({ mergeParams: true }); +const shortenURL = require('./shortenURL'); +const redirectURL = require('./redirectURL'); +const validationMiddleware = require('../../../helpers/middlewares/validation'); +const tinyURLSchema = require('./@validationSchema'); // GET /:code -> Redirect to long/original URL router.get('/:code', redirectURL); @@ -11,4 +10,4 @@ router.get('/:code', redirectURL); // POST /shorten -> creates short url router.post('/shorten', validationMiddleware(tinyURLSchema), shortenURL); -export default router; +module.exports = router; diff --git a/backend/app/routes/tinyURL/redirectURL.js b/backend/app/routes/tinyURL/redirectURL.js index 655521dc..abcaba8f 100644 --- a/backend/app/routes/tinyURL/redirectURL.js +++ b/backend/app/routes/tinyURL/redirectURL.js @@ -1,10 +1,9 @@ -import to from "await-to-js" -import tinyURL from '../../models/tinyURL' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; +const to = require('await-to-js').default; +const tinyURL = require('../../models/tinyURL'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const [err, url] = await to(tinyURL.findOne({ urlCode: req.params.code })); if (err) { const error = new ErrorHandler(constants.ERRORS.DATABASE, { diff --git a/backend/app/routes/tinyURL/shortenURL.js b/backend/app/routes/tinyURL/shortenURL.js index 2e83a262..d5d5781f 100644 --- a/backend/app/routes/tinyURL/shortenURL.js +++ b/backend/app/routes/tinyURL/shortenURL.js @@ -1,14 +1,13 @@ // const urlExists = require('url-exists'); -import nanoid from "nanoid" -import to from "await-to-js" -import urlExists from "url-exists" -import config from "../../../config"; -import Url from '../../models/tinyURL' -import { ErrorHandler } from "../../../helpers/error"; -import constants from "../../../constants"; +const { nanoid } = require('nanoid'); +const to = require('await-to-js').default; +const urlExists = require('url-exists'); +const config = require('../../../config'); +const Url = require('../../models/tinyURL'); +const { ErrorHandler } = require('../../../helpers/error'); +const constants = require('../../../constants'); - -export default async (req, res, next) => { +module.exports = async (req, res, next) => { const { longURL } = req.body; const { BASE_URL } = config; urlExists(longURL, (_err, exists) => { diff --git a/backend/config/index.js b/backend/config/index.js index 85e4afa2..7599e845 100644 --- a/backend/config/index.js +++ b/backend/config/index.js @@ -1,5 +1,4 @@ -import dotenv from "dotenv"; -dotenv.config(); +require('dotenv').config(); const config = { MONGO_DB_URL: process.env.MONGO_DB_URL, @@ -14,4 +13,4 @@ const config = { LOCAL_DEV_ENV: process.env.LOCAL_DEV_ENV, }; -export default config; +module.exports = config; diff --git a/backend/constants/index.js b/backend/constants/index.js index 31a922c9..ff246410 100644 --- a/backend/constants/index.js +++ b/backend/constants/index.js @@ -1,3 +1,3 @@ -import constants from "./constants.json" +const constants = require('./constants.json'); -export default constants; +module.exports = constants; diff --git a/backend/helpers/cluster.js b/backend/helpers/cluster.js index 9cbb468e..159d4321 100644 --- a/backend/helpers/cluster.js +++ b/backend/helpers/cluster.js @@ -1,8 +1,7 @@ +const cluster = require('cluster'); +const os = require('os'); -import cluster from 'cluster'; -import os from "os"; - -export default () => { +module.exports = () => { if (process.env.CLUSTER === 'yes') { const numCPUs = os.cpus().length; diff --git a/backend/helpers/dbConnection.js b/backend/helpers/dbConnection.js index 7f817c0f..78cd6cec 100644 --- a/backend/helpers/dbConnection.js +++ b/backend/helpers/dbConnection.js @@ -1,6 +1,5 @@ - -import mongoose from 'mongoose'; -import config from "../config" +const mongoose = require('mongoose'); +const config = require('../config'); function connect() { mongoose.connect(config.MONGO_DB_URL, { @@ -38,4 +37,4 @@ function connect() { }); } -export default connect(); +module.exports = connect(); diff --git a/backend/helpers/emailService.js b/backend/helpers/emailService.js index 23f014d1..8f817c74 100644 --- a/backend/helpers/emailService.js +++ b/backend/helpers/emailService.js @@ -1,11 +1,10 @@ -import nodemailer from "nodemailer" -import to from "await-to-js" -import ejs from "ejs" -import { ErrorHandler } from "./error"; -import constants from "../constants" -import {EMAIL_HOST,EMAIL_PASS,EMAIL_USER} from "../config/index" -import { getMailTemplate } from "../utility/emailTemplates"; - +const nodemailer = require('nodemailer'); +const to = require('await-to-js').default; +const ejs = require('ejs'); +const { ErrorHandler } = require('./error'); +const constants = require('../constants'); +const { EMAIL_USER, EMAIL_PASS, EMAIL_HOST } = require('../config/index'); +const { getMailTemplate } = require('../utility/emailTemplates'); const transporter = nodemailer.createTransport({ type: 'SMTP', @@ -19,7 +18,7 @@ const transporter = nodemailer.createTransport({ }, }); -export default sendEmail = async (email, data, type) => { +module.exports.sendEmail = async (email, data, type) => { const template = getMailTemplate(type); const { subject } = template; let { text } = template; diff --git a/backend/helpers/error.js b/backend/helpers/error.js index 102cfe89..269cb296 100644 --- a/backend/helpers/error.js +++ b/backend/helpers/error.js @@ -1,5 +1,4 @@ - -import utils from "./utils" +const utils = require('./utils'); class ErrorHandler extends Error { constructor(errorType, error) { @@ -16,4 +15,4 @@ const errorHandler = (err, _req, res, _next) => { res.status(err.statusCode).json(err); }; -export { ErrorHandler, errorHandler }; +module.exports = { ErrorHandler, errorHandler }; diff --git a/backend/helpers/middlewares/auth.js b/backend/helpers/middlewares/auth.js index 45d50c32..fa38cfc3 100644 --- a/backend/helpers/middlewares/auth.js +++ b/backend/helpers/middlewares/auth.js @@ -1,9 +1,8 @@ -import to from "await-to-js" -import {sign , verify} from "jsonwebtoken" -import { ErrorHandler } from "../error"; -import config from "../../config" -import constants from "../../constants" - +const to = require('await-to-js').default; +const { sign, verify } = require('jsonwebtoken'); +const { ErrorHandler } = require('../error'); +const config = require('../../config'); +const constants = require('../../constants'); const generateJWT = (payload, expiry = config.JWT_EXPIRES_IN) => sign(payload, config.JWT_SECRET_KEY, { expiresIn: expiry }); @@ -39,4 +38,4 @@ const authMiddleware = async (req, res, next) => { next(); }; -export { authMiddleware, generateJWT, verifyToken }; +module.exports = { authMiddleware, generateJWT, verifyToken }; diff --git a/backend/helpers/middlewares/validation.js b/backend/helpers/middlewares/validation.js index e56684d0..0d129081 100644 --- a/backend/helpers/middlewares/validation.js +++ b/backend/helpers/middlewares/validation.js @@ -1,7 +1,5 @@ - -import { ErrorHandler } from '../error'; -import constants from "../../constants" - +const { ErrorHandler } = require('../error'); +const constants = require('../../constants'); const middleware = (schema, type = 'body') => (req, res, next) => { const { error, value } = schema.validate(type === 'body' ? req.body : req[type], { abortEarly: false }); @@ -19,4 +17,4 @@ const middleware = (schema, type = 'body') => (req, res, next) => { res.locals[type] = value; return next(); }; -export default middleware; +module.exports = middleware; diff --git a/backend/helpers/utils.js b/backend/helpers/utils.js index cb79b487..a68d8586 100644 --- a/backend/helpers/utils.js +++ b/backend/helpers/utils.js @@ -13,4 +13,4 @@ const replaceWithStrInObj = (obj, key, defaultString) => (obj[key] ? obj[key] : */ const replaceWithBlankStrInObj = (obj, key) => replaceWithStrInObj(obj, key, ''); -export{ replaceWithBlankStrInObj, replaceWithStrInObj }; +module.exports = { replaceWithBlankStrInObj, replaceWithStrInObj }; diff --git a/backend/index.js b/backend/index.js index 1ee3adde..0a9d661f 100644 --- a/backend/index.js +++ b/backend/index.js @@ -1,17 +1,20 @@ -import dotenv from "dotenv"; -import to from "await-to-js" -import http from "http"; -import {ErrorHandler} from "./helpers/error" -import constants from "./constants" -import cronJob from "./utility/cronJob" -import cluster from "./helpers/cluster"; -import joinUs from "./app/models/joinUs" -import contactUs from "./app/models/contactUs" -import sendEmail from "./utility/sendEmail" -import Resource from "./app/models/resource" -import { JoinUsCronJobMailTemplate,ContactUsCronJobMailTemplate,ResourceDeletedMailTemplate } from "./utility/emailTemplates"; -import Admin from "./app/models/Admin" -dotenv.config(); +require('dotenv').config(); +const to = require('await-to-js').default; +const http = require('http'); +const { ErrorHandler } = require('./helpers/error'); +const constants = require('./constants'); +const cronJob = require('./utility/cronJob'); +const cluster = require('./helpers/cluster'); +const joinUs = require('./app/models/joinUs'); +const contactUs = require('./app/models/contactUs'); +const sendEmail = require('./utility/sendEmail'); +const Resource = require('./app/models/resource'); +const { + JoinUsCronJobMailTemplate, + ContactUsCronJobMailTemplate, + ResourceDeletedMailTemplate, +} = require('./utility/emailTemplates'); +const Admin = require('./app/models/Admin'); // Cron job to delete all resource data for 2months cronJob('0 0 2 * *', async (req, res, next) => { @@ -200,4 +203,4 @@ server.listen(port); server.on('error', onError); server.on('listening', onListening); -export default app; +module.exports = app; diff --git a/backend/package.json b/backend/package.json index 242c17f8..e470d723 100644 --- a/backend/package.json +++ b/backend/package.json @@ -2,7 +2,6 @@ "name": "community-website", "version": "1.0.0", "description": "HITK Community Website", - "type": "module", "main": "index.js", "scripts": { "dev": "nodemon index.js", diff --git a/backend/utility/cronJob.js b/backend/utility/cronJob.js index 995a7ec7..e9658355 100644 --- a/backend/utility/cronJob.js +++ b/backend/utility/cronJob.js @@ -1,8 +1,7 @@ - -import cron from "node-cron" +const cron = require('node-cron'); const cronJob = (time, fnc) => { cron.schedule(time, fnc); }; -export default cronJob; +module.exports = cronJob; diff --git a/backend/utility/emailTemplates.js b/backend/utility/emailTemplates.js index 00421769..caa5cbca 100644 --- a/backend/utility/emailTemplates.js +++ b/backend/utility/emailTemplates.js @@ -1,19 +1,19 @@ // This function will be used to generate a template which will be utilized in all email types // module.exports.generateHtml(data){}; -const getMailTemplate = (type) => { +module.exports.getMailTemplate = (type) => { const templates = { 'INVITE-ADMIN': { // html:"", subject: '[INVITATION] Invited to become an admin', text: - `Hi <%= name %> \n We would love for you to join us at HITK Tech Community as an admin.\n\tHITK Tech Community is a platform built by the students and for the students with the main intent of increasing awareness towards plethora of opportunities and internships in tech all around/over the year. This will not only give practical work experience/exposure to students, but will also help everyone to know and grab their required opportunities in time!\nClick on <%= link %> for further action`, + 'Hi <%= name %> \n We would love for you to join us at HITK Tech Community as an admin.\n\tHITK Tech Community is a platform built by the students and for the students with the main intent of increasing awareness towards plethora of opportunities and internships in tech all around/over the year. This will not only give practical work experience/exposure to students, but will also help everyone to know and grab their required opportunities in time!\nClick on <%= link %> for further action', }, }; return templates[type]; }; -const JoinUsMailTemplate = (adminName, req) => { +module.exports.JoinUsMailTemplate = (adminName, req) => { const emailContent = `

Hi ${adminName},

There is new Join Us Request at Community Website with following details :