From 38831a0b8dd79fd394e1b65a603abf404175ef4e Mon Sep 17 00:00:00 2001 From: Muhammad Owais Warsi Date: Sun, 11 Feb 2024 15:19:28 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=80=20Changed=20the=20module=20type=20?= =?UTF-8?q?(#838)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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, 490 insertions(+), 430 deletions(-) diff --git a/backend/app.js b/backend/app.js index 28fb8e6f..cd6571cd 100644 --- a/backend/app.js +++ b/backend/app.js @@ -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'); @@ -43,4 +43,4 @@ process.on('uncaughtException', (err) => { console.log(err); }); -module.exports = app; +export default app; diff --git a/backend/app/models/Admin.js b/backend/app/models/Admin.js index 18b68209..901aa55e 100644 --- a/backend/app/models/Admin.js +++ b/backend/app/models/Admin.js @@ -1,4 +1,4 @@ -const mongoose = require('mongoose'); +import mongoose from "mongoose"; const { Schema } = mongoose; diff --git a/backend/app/models/Broadcast.js b/backend/app/models/Broadcast.js index 26568d1d..b5cf771c 100644 --- a/backend/app/models/Broadcast.js +++ b/backend/app/models/Broadcast.js @@ -1,4 +1,4 @@ -const mongoose = require('mongoose'); +import mongoose from "mongoose"; const { Schema } = mongoose; const broadcastSchema = new Schema( diff --git a/backend/app/models/TeamMember.js b/backend/app/models/TeamMember.js index a0fdaa4c..3bd8b11d 100644 --- a/backend/app/models/TeamMember.js +++ b/backend/app/models/TeamMember.js @@ -1,4 +1,4 @@ -const mongoose = require('mongoose'); +import mongoose from "mongoose"; const { Schema } = mongoose; diff --git a/backend/app/models/answers.js b/backend/app/models/answers.js index 90d85036..93cc4872 100644 --- a/backend/app/models/answers.js +++ b/backend/app/models/answers.js @@ -1,4 +1,4 @@ -const mongoose = require('mongoose'); +import mongoose from "mongoose"; const { Schema } = mongoose; diff --git a/backend/app/models/contactUs.js b/backend/app/models/contactUs.js index 5e34adb9..83521648 100644 --- a/backend/app/models/contactUs.js +++ b/backend/app/models/contactUs.js @@ -1,4 +1,4 @@ -const mongoose = require('mongoose'); +import mongoose from "mongoose"; const { Schema } = mongoose; diff --git a/backend/app/models/faq.js b/backend/app/models/faq.js index c3a3943b..3614896d 100644 --- a/backend/app/models/faq.js +++ b/backend/app/models/faq.js @@ -1,4 +1,4 @@ -const mongoose = require('mongoose'); +import mongoose from "mongoose"; const { Schema } = mongoose; diff --git a/backend/app/models/joinUs.js b/backend/app/models/joinUs.js index 63a2b6ec..94c45721 100644 --- a/backend/app/models/joinUs.js +++ b/backend/app/models/joinUs.js @@ -1,4 +1,4 @@ -const mongoose = require('mongoose'); +import mongoose from "mongoose"; const { Schema } = mongoose; diff --git a/backend/app/models/question.js b/backend/app/models/question.js index 43051a07..d0bdc720 100644 --- a/backend/app/models/question.js +++ b/backend/app/models/question.js @@ -1,4 +1,4 @@ -const mongoose = require('mongoose'); +import mongoose from "mongoose"; const { Schema } = mongoose; diff --git a/backend/app/models/resource.js b/backend/app/models/resource.js index 32556e0e..870424e1 100644 --- a/backend/app/models/resource.js +++ b/backend/app/models/resource.js @@ -1,4 +1,4 @@ -const mongoose = require('mongoose'); +import mongoose from "mongoose"; const resourceSchema = new mongoose.Schema( { diff --git a/backend/app/models/tinyURL.js b/backend/app/models/tinyURL.js index 254b9725..7c93df67 100644 --- a/backend/app/models/tinyURL.js +++ b/backend/app/models/tinyURL.js @@ -1,4 +1,4 @@ -const mongoose = require('mongoose'); +import mongoose from "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 51098c62..3577d78d 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 @@ -const Joi = require('joi'); +import Joi from "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() }); -module.exports = { +export { answerValidationSchema, getAnswerValidationSchema, updateAnswerStatusSchema diff --git a/backend/app/routes/Q&A/answers/downvoteAnswer.js b/backend/app/routes/Q&A/answers/downvoteAnswer.js index b4608d80..15367be7 100644 --- a/backend/app/routes/Q&A/answers/downvoteAnswer.js +++ b/backend/app/routes/Q&A/answers/downvoteAnswer.js @@ -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 }, [ diff --git a/backend/app/routes/Q&A/answers/getAnswers.js b/backend/app/routes/Q&A/answers/getAnswers.js index e58a4793..d9a3a354 100644 --- a/backend/app/routes/Q&A/answers/getAnswers.js +++ b/backend/app/routes/Q&A/answers/getAnswers.js @@ -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( diff --git a/backend/app/routes/Q&A/answers/index.js b/backend/app/routes/Q&A/answers/index.js index 06c724b1..4aaea410 100644 --- a/backend/app/routes/Q&A/answers/index.js +++ b/backend/app/routes/Q&A/answers/index.js @@ -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); @@ -23,4 +23,4 @@ router.patch('/downvote', downvoteAnswer); // Update Answer Status router.patch('/updateStatus', validation(updateAnswerStatusSchema), updateAnswerStatus); -module.exports = router; +export default router; diff --git a/backend/app/routes/Q&A/answers/post.js b/backend/app/routes/Q&A/answers/post.js index 62e86cdf..1ff87899 100644 --- a/backend/app/routes/Q&A/answers/post.js +++ b/backend/app/routes/Q&A/answers/post.js @@ -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) { diff --git a/backend/app/routes/Q&A/answers/updateAnswerStatus.js b/backend/app/routes/Q&A/answers/updateAnswerStatus.js index 7822a123..701580c1 100644 --- a/backend/app/routes/Q&A/answers/updateAnswerStatus.js +++ b/backend/app/routes/Q&A/answers/updateAnswerStatus.js @@ -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 diff --git a/backend/app/routes/Q&A/answers/upvoteAnswer.js b/backend/app/routes/Q&A/answers/upvoteAnswer.js index 38ce0678..b48416eb 100644 --- a/backend/app/routes/Q&A/answers/upvoteAnswer.js +++ b/backend/app/routes/Q&A/answers/upvoteAnswer.js @@ -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) { diff --git a/backend/app/routes/Q&A/question/@validationSchema/index.js b/backend/app/routes/Q&A/question/@validationSchema/index.js index 10bfee90..73c12d08 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 @@ -const Joi = require('joi'); +import Joi from "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() }); -module.exports = { QuestionValidationSchema, updateQuestionStatusSchema }; +export { QuestionValidationSchema, updateQuestionStatusSchema }; diff --git a/backend/app/routes/Q&A/question/downvoteQuestion.js b/backend/app/routes/Q&A/question/downvoteQuestion.js index 4fbb3731..c41e0212 100644 --- a/backend/app/routes/Q&A/question/downvoteQuestion.js +++ b/backend/app/routes/Q&A/question/downvoteQuestion.js @@ -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 }, [ diff --git a/backend/app/routes/Q&A/question/getAllQuestion.js b/backend/app/routes/Q&A/question/getAllQuestion.js index 79ed187f..b34af952 100644 --- a/backend/app/routes/Q&A/question/getAllQuestion.js +++ b/backend/app/routes/Q&A/question/getAllQuestion.js @@ -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 diff --git a/backend/app/routes/Q&A/question/getQuestionById.js b/backend/app/routes/Q&A/question/getQuestionById.js index 825ee212..e57e4231 100644 --- a/backend/app/routes/Q&A/question/getQuestionById.js +++ b/backend/app/routes/Q&A/question/getQuestionById.js @@ -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 diff --git a/backend/app/routes/Q&A/question/index.js b/backend/app/routes/Q&A/question/index.js index b2421e3a..2075c710 100644 --- a/backend/app/routes/Q&A/question/index.js +++ b/backend/app/routes/Q&A/question/index.js @@ -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); @@ -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; diff --git a/backend/app/routes/Q&A/question/post.js b/backend/app/routes/Q&A/question/post.js index 44b6160e..c1620e56 100644 --- a/backend/app/routes/Q&A/question/post.js +++ b/backend/app/routes/Q&A/question/post.js @@ -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) { diff --git a/backend/app/routes/Q&A/question/updateQuestionStatus.js b/backend/app/routes/Q&A/question/updateQuestionStatus.js index 97700534..c3bb92eb 100644 --- a/backend/app/routes/Q&A/question/updateQuestionStatus.js +++ b/backend/app/routes/Q&A/question/updateQuestionStatus.js @@ -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 diff --git a/backend/app/routes/Q&A/question/upvoteQuestion.js b/backend/app/routes/Q&A/question/upvoteQuestion.js index 63b28fd6..10bf46d5 100644 --- a/backend/app/routes/Q&A/question/upvoteQuestion.js +++ b/backend/app/routes/Q&A/question/upvoteQuestion.js @@ -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) { diff --git a/backend/app/routes/admin/@validationSchema/index.js b/backend/app/routes/admin/@validationSchema/index.js index a4329f5f..71cc6285 100644 --- a/backend/app/routes/admin/@validationSchema/index.js +++ b/backend/app/routes/admin/@validationSchema/index.js @@ -1,4 +1,4 @@ -const Joi = require('joi'); +import Joi from "joi" const postSuperAdminSchema = Joi.object({ firstName: Joi.string() @@ -53,7 +53,7 @@ const deleteAdminSchema = Joi.object({ id : Joi.string().min(24).max(24).required() }) -module.exports = { +export { postSuperAdminSchema, getAdminsSchema, passwordChangeSchema, diff --git a/backend/app/routes/admin/changePassword.js b/backend/app/routes/admin/changePassword.js index 02735c5f..f4c9c9e4 100644 --- a/backend/app/routes/admin/changePassword.js +++ b/backend/app/routes/admin/changePassword.js @@ -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) { diff --git a/backend/app/routes/admin/createSuperAdmin.js b/backend/app/routes/admin/createSuperAdmin.js index 8f6ed2ae..00e343f5 100644 --- a/backend/app/routes/admin/createSuperAdmin.js +++ b/backend/app/routes/admin/createSuperAdmin.js @@ -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', diff --git a/backend/app/routes/admin/deleteAdmin.js b/backend/app/routes/admin/deleteAdmin.js index cbab67aa..fab3a028 100644 --- a/backend/app/routes/admin/deleteAdmin.js +++ b/backend/app/routes/admin/deleteAdmin.js @@ -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) { diff --git a/backend/app/routes/admin/forgotPassword.js b/backend/app/routes/admin/forgotPassword.js index a3e8c04f..7f60f39a 100644 --- a/backend/app/routes/admin/forgotPassword.js +++ b/backend/app/routes/admin/forgotPassword.js @@ -1,10 +1,10 @@ -const Admin = require('../../models/Admin'); -const config = require('../../../config'); -const { ErrorHandler } = require('../../../helpers/error'); -const constants = require('../../../constants'); -const { generateJWT } = require('../../../helpers/middlewares/auth'); +import Admin from '../../models/Admin' +import config from '../../../config'; +import { ErrorHandler } from '../../../helpers/error'; +import constants from '../../../constants'; +import { generateJWT } from '../../../helpers/middlewares/auth'; -module.exports = async (req, res, next) => { +export default 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 bfeac15b..fd092611 100644 --- a/backend/app/routes/admin/getAdmins.js +++ b/backend/app/routes/admin/getAdmins.js @@ -1,7 +1,7 @@ -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"; const getAdminsAggregate = (match, page) => { const pipeline = [ @@ -23,7 +23,7 @@ const getAdminsAggregate = (match, page) => { return pipeline; }; -module.exports = async (req, res, next) => { +export default 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 35ff2d0f..2048c401 100644 --- a/backend/app/routes/admin/index.js +++ b/backend/app/routes/admin/index.js @@ -1,6 +1,7 @@ -const router = require('express').Router({ mergeParams: true }); -const validationMiddleware = require('../../../helpers/middlewares/validation'); -const { authMiddleware } = require('../../../helpers/middlewares/auth'); +import express from "expresss"; +import validationMiddleware from '../../../helpers/middlewares/validation' +import { authMiddleware } from "../../../helpers/middlewares/auth"; +const router = express.Router({ mergeParams: true }); const { postSuperAdminSchema, @@ -37,4 +38,4 @@ router.put('/:id/:token', validationMiddleware(updateAdminSchema), updateAdmin); router.delete('/deleteAdmin', validationMiddleware(deleteAdminSchema), authMiddleware, deleteAdmin); -module.exports = router; \ No newline at end of file +export default router; \ No newline at end of file diff --git a/backend/app/routes/admin/inviteAdmin.js b/backend/app/routes/admin/inviteAdmin.js index 34413e01..5353b270 100644 --- a/backend/app/routes/admin/inviteAdmin.js +++ b/backend/app/routes/admin/inviteAdmin.js @@ -1,9 +1,9 @@ -const to = require('await-to-js').default; -const { ErrorHandler } = require('../../../helpers/error'); -const { sendEmail } = require('../../../helpers/emailService'); -const constants = require('../../../constants'); +import to from "await-to-js"; +import { ErrorHandler } from "../../../helpers/error"; +import { sendEmail } from "../../../helpers/emailService"; +import constants from "../../../constants"; -module.exports = async (req, res, next) => { +export default 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 baae1166..b8beda6c 100644 --- a/backend/app/routes/admin/postAdmin.js +++ b/backend/app/routes/admin/postAdmin.js @@ -1,10 +1,10 @@ -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 adminData = { ...req.body, isSuperAdmin: false, diff --git a/backend/app/routes/admin/postSuperAdmin.js b/backend/app/routes/admin/postSuperAdmin.js index ac507489..a4c18f80 100644 --- a/backend/app/routes/admin/postSuperAdmin.js +++ b/backend/app/routes/admin/postSuperAdmin.js @@ -1,10 +1,10 @@ -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 adminData = { ...req.body, isSuperAdmin: true, diff --git a/backend/app/routes/admin/resetPassword.js b/backend/app/routes/admin/resetPassword.js index 2ff7673c..04cbfc66 100644 --- a/backend/app/routes/admin/resetPassword.js +++ b/backend/app/routes/admin/resetPassword.js @@ -1,11 +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'); -const { verifyToken } = require('../../../helpers/middlewares/auth'); - -module.exports = async (req, res, next) => { +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) => { // 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 9984d1e8..c4c44f6b 100644 --- a/backend/app/routes/admin/updateAdmin.js +++ b/backend/app/routes/admin/updateAdmin.js @@ -1,6 +1,6 @@ -const Admin = require('../../models/Admin'); +import Admin from '../../models/Admin' -module.exports =async (req, res) => { +export default 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 b2106529..63085c8b 100644 --- a/backend/app/routes/auth/@validationSchema/index.js +++ b/backend/app/routes/auth/@validationSchema/index.js @@ -1,8 +1,8 @@ -const Joi = require('joi'); +import Joi from "joi"; const loginSchema = Joi.object().keys({ email: Joi.string().required(), password: Joi.string().required(), }); -module.exports = loginSchema; +export default loginSchema; diff --git a/backend/app/routes/auth/index.js b/backend/app/routes/auth/index.js index 5d9a5a28..e3f78070 100644 --- a/backend/app/routes/auth/index.js +++ b/backend/app/routes/auth/index.js @@ -1,8 +1,9 @@ -const router = require('express').Router({ mergeParams: true }); -const login = require('./login'); -const loginSchema = require('./@validationSchema'); -const validation = require('../../../helpers/middlewares/validation'); +import express from "express"; +import login from "./login"; +import loginSchema from './@validationSchema' +import validation from '../../../helpers/middlewares/validation' +const router = express.Router({ mergeParams: true }); router.post('/login', validation(loginSchema), login); -module.exports = router; +export default router; diff --git a/backend/app/routes/auth/login.js b/backend/app/routes/auth/login.js index 3a8d8513..c66d21d6 100644 --- a/backend/app/routes/auth/login.js +++ b/backend/app/routes/auth/login.js @@ -1,10 +1,10 @@ -const argon2 = require('argon2'); -const Admin = require('../../models/Admin'); -const { ErrorHandler } = require('../../../helpers/error'); -const constants = require('../../../constants'); -const { generateJWT } = require('../../../helpers/middlewares/auth'); +import argon2 from "argon2" +import Admin from '../../models/Admin' +import { ErrorHandler } from "../../../helpers/error"; +import constants from "../../../constants"; +import { generateJWT } from "../../../helpers/middlewares/auth"; -module.exports = async (req, res, next) => { +export default 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 0a954a23..5278a92e 100644 --- a/backend/app/routes/broadcast/@validationSchema/index.js +++ b/backend/app/routes/broadcast/@validationSchema/index.js @@ -1,4 +1,4 @@ -const Joi = require('joi'); +import Joi from "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(), }); -module.exports = { +export { postBroadcastValidationSchema, getBroadcastsValidationSchema, updateBroadcastValidationSchema diff --git a/backend/app/routes/broadcast/deleteBroadcast.js b/backend/app/routes/broadcast/deleteBroadcast.js index fdc23823..96192cf7 100644 --- a/backend/app/routes/broadcast/deleteBroadcast.js +++ b/backend/app/routes/broadcast/deleteBroadcast.js @@ -1,9 +1,9 @@ -const to = require('await-to-js').default; -const Broadcast = require('../../models/Broadcast'); -const { ErrorHandler } = require('../../../helpers/error'); -const constants = require('../../../constants'); +import to from "await-to-js" +import Broadcast from '../../models/Broadcast' +import { ErrorHandler } from "../../../helpers/error"; +import constants from "../../../constants"; -module.exports = async (req, res, next) => { +export default 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 26e97c10..08f80eb4 100644 --- a/backend/app/routes/broadcast/getBroadcasts.js +++ b/backend/app/routes/broadcast/getBroadcasts.js @@ -1,7 +1,7 @@ -const to = require('await-to-js').default; -const Broadcast = require('../../models/Broadcast'); -const { ErrorHandler } = require('../../../helpers/error'); -const constants = require('../../../constants'); +import to from "await-to-js" +import Broadcast from '../../models/Broadcast' +import { ErrorHandler } from "../../../helpers/error"; +import constants from "../../../constants"; const limit = constants.PAGINATION_LIMIT.GET_BROADCASTS; @@ -30,7 +30,7 @@ const getBroadcastsAggregate = (startIndex, match) => { ]; return pipeline; }; -module.exports = async (req, res, next) => { +export default 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 46bddc7b..8f6232a3 100644 --- a/backend/app/routes/broadcast/getallbroadcasts.js +++ b/backend/app/routes/broadcast/getallbroadcasts.js @@ -1,9 +1,9 @@ -const to = require('await-to-js').default; -const Broadcast = require('../../models/Broadcast'); -const constants = require('../../../constants'); -const { ErrorHandler } = require('../../../helpers/error'); +import to from "await-to-js" +import Broadcast from '../../models/Broadcast' +import constants from "../../../constants"; +import { ErrorHandler } from "../../../helpers/error"; -module.exports = async (req, res, next) => { +export default 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 0b538a1f..2e055ba1 100644 --- a/backend/app/routes/broadcast/index.js +++ b/backend/app/routes/broadcast/index.js @@ -1,17 +1,20 @@ -const router = require('express').Router({ mergeParams: true }); -const validationMiddleware = require('../../../helpers/middlewares/validation'); -const { authMiddleware } = require('../../../helpers/middlewares/auth'); +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 { 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); -module.exports = router; +export default router; diff --git a/backend/app/routes/broadcast/postBroadcast.js b/backend/app/routes/broadcast/postBroadcast.js index 7b2bcec1..ae5b10de 100644 --- a/backend/app/routes/broadcast/postBroadcast.js +++ b/backend/app/routes/broadcast/postBroadcast.js @@ -1,9 +1,9 @@ -const to = require('await-to-js').default; -const Broadcast = require('../../models/Broadcast'); -const { ErrorHandler } = require('../../../helpers/error'); -const constants = require('../../../constants'); +import to from "await-to-js" +import Broadcast from '../../models/Broadcast' +import { ErrorHandler } from "../../../helpers/error"; +import constants from "../../../constants"; -module.exports = async (req, res, next) => { +export default 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 be508474..594451ab 100644 --- a/backend/app/routes/broadcast/updateBroadcast.js +++ b/backend/app/routes/broadcast/updateBroadcast.js @@ -1,9 +1,9 @@ -const to = require('await-to-js').default; -const Broadcast = require('../../models/Broadcast'); -const { ErrorHandler } = require('../../../helpers/error'); -const constants = require('../../../constants'); +import to from "await-to-js" +import Broadcast from '../../models/Broadcast'; +import { ErrorHandler } from "../../../helpers/error"; +import constants from "../../../constants"; -module.exports = async (req, res, next) => { +export default 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 61f722f0..207689d4 100644 --- a/backend/app/routes/contactUs/@validationSchema/index.js +++ b/backend/app/routes/contactUs/@validationSchema/index.js @@ -1,4 +1,4 @@ -const Joi = require('joi'); +import Joi from "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), }); -module.exports = contactValidationSchema; +export default contactValidationSchema; diff --git a/backend/app/routes/contactUs/get.js b/backend/app/routes/contactUs/get.js index 6f1ec323..b377584b 100644 --- a/backend/app/routes/contactUs/get.js +++ b/backend/app/routes/contactUs/get.js @@ -1,9 +1,9 @@ -const to = require('await-to-js').default; -const contactUs = require('../../models/contactUs'); -const { ErrorHandler } = require('../../../helpers/error'); -const constants = require('../../../constants'); +import to from "await-to-js" +import contactUs from '../../models/contactUs' +import { ErrorHandler } from "../../../helpers/error"; +import constants from "../../../constants"; -module.exports = async (req, res, next) => { +export default 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 60701905..100f847e 100644 --- a/backend/app/routes/contactUs/index.js +++ b/backend/app/routes/contactUs/index.js @@ -1,11 +1,12 @@ -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'); +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}) router.get('/getcontactus', authMiddleware, getContact); router.post('/contactus', validation(contactValidationSchema), postContact); -module.exports = router; +export default router; diff --git a/backend/app/routes/contactUs/post.js b/backend/app/routes/contactUs/post.js index 6a327573..d2e14829 100644 --- a/backend/app/routes/contactUs/post.js +++ b/backend/app/routes/contactUs/post.js @@ -1,12 +1,13 @@ -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'); +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"; -module.exports = async (req, res, next) => { + +export default 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 7922b5f0..bbfcd2fd 100644 --- a/backend/app/routes/faq/@validationSchema/index.js +++ b/backend/app/routes/faq/@validationSchema/index.js @@ -1,4 +1,4 @@ -const Joi = require('joi'); +import Joi from "joi"; const FAQValidationSchema = Joi.object().keys({ question: Joi.string().required(), @@ -6,4 +6,4 @@ const FAQValidationSchema = Joi.object().keys({ tags: Joi.array().required(), }); -module.exports = FAQValidationSchema; +export default FAQValidationSchema; diff --git a/backend/app/routes/faq/deleteFaq.js b/backend/app/routes/faq/deleteFaq.js index d0a762ba..cdcab102 100644 --- a/backend/app/routes/faq/deleteFaq.js +++ b/backend/app/routes/faq/deleteFaq.js @@ -1,10 +1,10 @@ -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'); +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' -module.exports = async (req, res, next) => { +export default 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 0a86dd53..d4f718ad 100644 --- a/backend/app/routes/faq/getFaq.js +++ b/backend/app/routes/faq/getFaq.js @@ -1,9 +1,10 @@ -const to = require('await-to-js').default; -const FAQ = require('../../models/faq'); -const { ErrorHandler } = require('../../../helpers/error'); -const constants = require('../../../constants'); +import to from "await-to-js" +import FAQ from '../../models/faq' +import { ErrorHandler } from "../../../helpers/error"; +import constants from "../../../constants"; -module.exports = async (req, res, next) => { + +export default 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 6fc56a61..bc5e94cb 100644 --- a/backend/app/routes/faq/index.js +++ b/backend/app/routes/faq/index.js @@ -1,14 +1,15 @@ -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'); +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}) router.post('/faq', validation(FAQValidationSchema), faq); router.get('/getFaq', getfaq); router.put('/deleteFaq', deleteFaq); router.patch('/updateFaq',updateFaq); -module.exports = router; +export default router; diff --git a/backend/app/routes/faq/post.js b/backend/app/routes/faq/post.js index 805aa958..9838a93e 100644 --- a/backend/app/routes/faq/post.js +++ b/backend/app/routes/faq/post.js @@ -1,9 +1,10 @@ -const to = require('await-to-js').default; -const FAQ = require('../../models/faq'); -const { ErrorHandler } = require('../../../helpers/error'); -const constants = require('../../../constants'); +import to from "await-to-js" +import FAQ from '../../models/faq' +import { ErrorHandler } from "../../../helpers/error"; +import constants from "../../../constants"; -module.exports = async (req, res, next) => { + +export default 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 6cd027a0..2adf3590 100644 --- a/backend/app/routes/faq/updateFaq.js +++ b/backend/app/routes/faq/updateFaq.js @@ -1,6 +1,6 @@ -const FAQ = require('../../models/faq'); +import FAQ from '../../models/faq'; -module.exports = async(req,res,next) => { +export default 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 1a209920..d30d2088 100644 --- a/backend/app/routes/index.js +++ b/backend/app/routes/index.js @@ -1,24 +1,26 @@ -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'); +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 getContactUs = require('./contactUs/get'); -const contactValidationSchema = require('./contactUs/@validationSchema'); -const validation = require('../../helpers/middlewares/validation'); -const question = require('./Q&A/question'); -const answer = require('./Q&A/answers'); -const teamMember = require('./teamMember'); -const resource = require('./resources'); +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}); router.use('/admin', admin); router.use('/auth', auth); @@ -36,4 +38,4 @@ router.use('/joinUs', joinUs); router.use('/teamMember', teamMember); router.use('/', tinyURL); router.use('/resources', resource); -module.exports = router; +export default router; diff --git a/backend/app/routes/joinUs/@validationSchema/index.js b/backend/app/routes/joinUs/@validationSchema/index.js index 23b9e96b..5decc87b 100644 --- a/backend/app/routes/joinUs/@validationSchema/index.js +++ b/backend/app/routes/joinUs/@validationSchema/index.js @@ -1,4 +1,4 @@ -const Joi = require('joi'); +import Joi from "joi"; const JoinUsValidationSchema = Joi.object().keys({ name: Joi.string().required(), @@ -13,4 +13,4 @@ const JoinUsValidationSchema = Joi.object().keys({ department: Joi.string(), }); -module.exports = JoinUsValidationSchema; +export default JoinUsValidationSchema; diff --git a/backend/app/routes/joinUs/deleteJoinUs.js b/backend/app/routes/joinUs/deleteJoinUs.js index 3433e4f1..ca7ba825 100644 --- a/backend/app/routes/joinUs/deleteJoinUs.js +++ b/backend/app/routes/joinUs/deleteJoinUs.js @@ -1,5 +1,6 @@ -const joinUsModel = require('../../models/joinUs'); -module.exports = async(req,res,next) => { +import joinUsModel from '../../models/joinUs'; + +export default 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 52805aa6..d4dc0e3c 100644 --- a/backend/app/routes/joinUs/get.js +++ b/backend/app/routes/joinUs/get.js @@ -1,6 +1,6 @@ -const joinUsModel = require('../../models/joinUs'); +import joinUsModel from '../../models/joinUs'; -module.exports = async (req, res, next) => { +export default 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 8e20ee46..a61110e5 100644 --- a/backend/app/routes/joinUs/index.js +++ b/backend/app/routes/joinUs/index.js @@ -1,13 +1,14 @@ -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") +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}) router.post('/', validation(JoinUsValidationSchema), postJoinUs); router.get('/', authMiddleware, getJoinUs); router.delete('/deleteJoinUs',deleteJoinUs) -module.exports = router; +export default router; diff --git a/backend/app/routes/joinUs/post.js b/backend/app/routes/joinUs/post.js index 47c198e5..832c7f7f 100644 --- a/backend/app/routes/joinUs/post.js +++ b/backend/app/routes/joinUs/post.js @@ -1,12 +1,13 @@ -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'); +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"; -module.exports = async (req, res, next) => { + +export default 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 3aa64195..e5967964 100644 --- a/backend/app/routes/resources/@validationSchema/index.js +++ b/backend/app/routes/resources/@validationSchema/index.js @@ -1,4 +1,4 @@ -const Joi = require('joi'); +import Joi from "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), }); -module.exports = ResourcesValidationSchema; +export default ResourcesValidationSchema; diff --git a/backend/app/routes/resources/addResource.js b/backend/app/routes/resources/addResource.js index 4ce78724..d51abfe2 100644 --- a/backend/app/routes/resources/addResource.js +++ b/backend/app/routes/resources/addResource.js @@ -1,12 +1,13 @@ -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'); +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"; -module.exports = async (req, res, next) => { + +export default 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 19b706aa..f165418c 100644 --- a/backend/app/routes/resources/deleteResource.js +++ b/backend/app/routes/resources/deleteResource.js @@ -1,6 +1,7 @@ -const Resource = require('../../models/resource'); -module.exports = async (req, res) => { +import Resource from "../../models/resource" + +export default 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 eb11250c..bb7dce29 100644 --- a/backend/app/routes/resources/getResource.js +++ b/backend/app/routes/resources/getResource.js @@ -1,6 +1,7 @@ -const Resource = require('../../models/resource'); -module.exports = async (req, res, next) => { +import Resource from '../../models/resource' + +export default 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 075fccc6..4f0733ed 100644 --- a/backend/app/routes/resources/index.js +++ b/backend/app/routes/resources/index.js @@ -1,14 +1,15 @@ -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'); +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}) router.post('/', validation(ResourcesValidationSchema), addaResource); // Route for deleting a resource router.delete('/deleteResource', deleteResource); router.get('/getresources', authMiddleware, getResource); -module.exports = router; +export default router; diff --git a/backend/app/routes/teamMember/addTeam.js b/backend/app/routes/teamMember/addTeam.js index 0ba89a54..49464f72 100644 --- a/backend/app/routes/teamMember/addTeam.js +++ b/backend/app/routes/teamMember/addTeam.js @@ -1,9 +1,10 @@ -const to = require('await-to-js').default; -const { ErrorHandler } = require('../../../helpers/error'); -const constants = require('../../../constants'); -const TeamMemberModel = require('../../models/TeamMember'); +import to from "await-to-js" +import { ErrorHandler } from "../../../helpers/error"; +import constants from "../../../constants"; +import TeamMemberModel from '../../models/TeamMember' -module.exports = async (req, res, next) => { + +export default 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 b6c3aac2..b06bedd5 100644 --- a/backend/app/routes/teamMember/deleteTeamMember.js +++ b/backend/app/routes/teamMember/deleteTeamMember.js @@ -1,5 +1,6 @@ -const teamMemberModel = require('../../models/TeamMember'); -module.exports = async(req,res,next) => { +import teamMemberModel from '../../models/TeamMember'; + +export default 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 ed0012f7..5069aab8 100644 --- a/backend/app/routes/teamMember/getTeamMemberById.js +++ b/backend/app/routes/teamMember/getTeamMemberById.js @@ -1,10 +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"; -module.exports = async (req, res, next) => { +export default 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 9f1b3fc3..f427edbf 100644 --- a/backend/app/routes/teamMember/getTeamMembers.js +++ b/backend/app/routes/teamMember/getTeamMembers.js @@ -1,10 +1,12 @@ -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"; -module.exports = async (req, res, next) => { + + +export default 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 065f81f6..90d8f63a 100644 --- a/backend/app/routes/teamMember/index.js +++ b/backend/app/routes/teamMember/index.js @@ -1,17 +1,19 @@ -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'); +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 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); -module.exports = router; +export default router; diff --git a/backend/app/routes/teamMember/updateTeamMember.js b/backend/app/routes/teamMember/updateTeamMember.js index c9492699..e86f60a7 100644 --- a/backend/app/routes/teamMember/updateTeamMember.js +++ b/backend/app/routes/teamMember/updateTeamMember.js @@ -1,6 +1,6 @@ -const TeamMemberModel = require('../../models/TeamMember'); +import TeamMemberModel from '../../models/TeamMember' -module.exports = async(req,res) => { +export default 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 53468ac0..5823c359 100644 --- a/backend/app/routes/testRoutes/emailTest.js +++ b/backend/app/routes/testRoutes/emailTest.js @@ -1,9 +1,10 @@ -const to = require('await-to-js').default; -const { ErrorHandler } = require('../../../helpers/error'); -const { sendEmail } = require('../../../helpers/emailService'); -const constants = require('../../../constants'); +import to from "await-to-js"; +import { ErrorHandler } from "../../../helpers/error"; +import { sendEmail } from "../../../helpers/emailService"; +import constants from "../../../constants"; -module.exports.emailTest = async (req, res, next) => { + +export default 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 a563b005..4d7177db 100644 --- a/backend/app/routes/tinyURL/@validationSchema/index.js +++ b/backend/app/routes/tinyURL/@validationSchema/index.js @@ -1,7 +1,7 @@ -const Joi = require('joi'); +import Joi from "joi" const tinyURLSchema = Joi.object().keys({ longURL: Joi.string().required().uri(), }); -module.exports = tinyURLSchema; +export default tinyURLSchema; diff --git a/backend/app/routes/tinyURL/index.js b/backend/app/routes/tinyURL/index.js index 420a83ba..0a85e2df 100644 --- a/backend/app/routes/tinyURL/index.js +++ b/backend/app/routes/tinyURL/index.js @@ -1,8 +1,9 @@ -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'); +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}) // GET /:code -> Redirect to long/original URL router.get('/:code', redirectURL); @@ -10,4 +11,4 @@ router.get('/:code', redirectURL); // POST /shorten -> creates short url router.post('/shorten', validationMiddleware(tinyURLSchema), shortenURL); -module.exports = router; +export default router; diff --git a/backend/app/routes/tinyURL/redirectURL.js b/backend/app/routes/tinyURL/redirectURL.js index abcaba8f..655521dc 100644 --- a/backend/app/routes/tinyURL/redirectURL.js +++ b/backend/app/routes/tinyURL/redirectURL.js @@ -1,9 +1,10 @@ -const to = require('await-to-js').default; -const tinyURL = require('../../models/tinyURL'); -const { ErrorHandler } = require('../../../helpers/error'); -const constants = require('../../../constants'); +import to from "await-to-js" +import tinyURL from '../../models/tinyURL' +import { ErrorHandler } from "../../../helpers/error"; +import constants from "../../../constants"; -module.exports = async (req, res, next) => { + +export default 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 d5d5781f..2e83a262 100644 --- a/backend/app/routes/tinyURL/shortenURL.js +++ b/backend/app/routes/tinyURL/shortenURL.js @@ -1,13 +1,14 @@ // const urlExists = require('url-exists'); -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'); +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"; -module.exports = async (req, res, next) => { + +export default 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 7599e845..85e4afa2 100644 --- a/backend/config/index.js +++ b/backend/config/index.js @@ -1,4 +1,5 @@ -require('dotenv').config(); +import dotenv from "dotenv"; +dotenv.config(); const config = { MONGO_DB_URL: process.env.MONGO_DB_URL, @@ -13,4 +14,4 @@ const config = { LOCAL_DEV_ENV: process.env.LOCAL_DEV_ENV, }; -module.exports = config; +export default config; diff --git a/backend/constants/index.js b/backend/constants/index.js index ff246410..31a922c9 100644 --- a/backend/constants/index.js +++ b/backend/constants/index.js @@ -1,3 +1,3 @@ -const constants = require('./constants.json'); +import constants from "./constants.json" -module.exports = constants; +export default constants; diff --git a/backend/helpers/cluster.js b/backend/helpers/cluster.js index 159d4321..9cbb468e 100644 --- a/backend/helpers/cluster.js +++ b/backend/helpers/cluster.js @@ -1,7 +1,8 @@ -const cluster = require('cluster'); -const os = require('os'); -module.exports = () => { +import cluster from 'cluster'; +import os from "os"; + +export default () => { if (process.env.CLUSTER === 'yes') { const numCPUs = os.cpus().length; diff --git a/backend/helpers/dbConnection.js b/backend/helpers/dbConnection.js index 78cd6cec..7f817c0f 100644 --- a/backend/helpers/dbConnection.js +++ b/backend/helpers/dbConnection.js @@ -1,5 +1,6 @@ -const mongoose = require('mongoose'); -const config = require('../config'); + +import mongoose from 'mongoose'; +import config from "../config" function connect() { mongoose.connect(config.MONGO_DB_URL, { @@ -37,4 +38,4 @@ function connect() { }); } -module.exports = connect(); +export default connect(); diff --git a/backend/helpers/emailService.js b/backend/helpers/emailService.js index 8f817c74..23f014d1 100644 --- a/backend/helpers/emailService.js +++ b/backend/helpers/emailService.js @@ -1,10 +1,11 @@ -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'); +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 transporter = nodemailer.createTransport({ type: 'SMTP', @@ -18,7 +19,7 @@ const transporter = nodemailer.createTransport({ }, }); -module.exports.sendEmail = async (email, data, type) => { +export default 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 269cb296..102cfe89 100644 --- a/backend/helpers/error.js +++ b/backend/helpers/error.js @@ -1,4 +1,5 @@ -const utils = require('./utils'); + +import utils from "./utils" class ErrorHandler extends Error { constructor(errorType, error) { @@ -15,4 +16,4 @@ const errorHandler = (err, _req, res, _next) => { res.status(err.statusCode).json(err); }; -module.exports = { ErrorHandler, errorHandler }; +export { ErrorHandler, errorHandler }; diff --git a/backend/helpers/middlewares/auth.js b/backend/helpers/middlewares/auth.js index fa38cfc3..45d50c32 100644 --- a/backend/helpers/middlewares/auth.js +++ b/backend/helpers/middlewares/auth.js @@ -1,8 +1,9 @@ -const to = require('await-to-js').default; -const { sign, verify } = require('jsonwebtoken'); -const { ErrorHandler } = require('../error'); -const config = require('../../config'); -const constants = require('../../constants'); +import to from "await-to-js" +import {sign , verify} from "jsonwebtoken" +import { ErrorHandler } from "../error"; +import config from "../../config" +import constants from "../../constants" + const generateJWT = (payload, expiry = config.JWT_EXPIRES_IN) => sign(payload, config.JWT_SECRET_KEY, { expiresIn: expiry }); @@ -38,4 +39,4 @@ const authMiddleware = async (req, res, next) => { next(); }; -module.exports = { authMiddleware, generateJWT, verifyToken }; +export { authMiddleware, generateJWT, verifyToken }; diff --git a/backend/helpers/middlewares/validation.js b/backend/helpers/middlewares/validation.js index 0d129081..e56684d0 100644 --- a/backend/helpers/middlewares/validation.js +++ b/backend/helpers/middlewares/validation.js @@ -1,5 +1,7 @@ -const { ErrorHandler } = require('../error'); -const constants = require('../../constants'); + +import { ErrorHandler } from '../error'; +import constants from "../../constants" + const middleware = (schema, type = 'body') => (req, res, next) => { const { error, value } = schema.validate(type === 'body' ? req.body : req[type], { abortEarly: false }); @@ -17,4 +19,4 @@ const middleware = (schema, type = 'body') => (req, res, next) => { res.locals[type] = value; return next(); }; -module.exports = middleware; +export default middleware; diff --git a/backend/helpers/utils.js b/backend/helpers/utils.js index a68d8586..cb79b487 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, ''); -module.exports = { replaceWithBlankStrInObj, replaceWithStrInObj }; +export{ replaceWithBlankStrInObj, replaceWithStrInObj }; diff --git a/backend/index.js b/backend/index.js index 0a9d661f..1ee3adde 100644 --- a/backend/index.js +++ b/backend/index.js @@ -1,20 +1,17 @@ -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'); +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(); // Cron job to delete all resource data for 2months cronJob('0 0 2 * *', async (req, res, next) => { @@ -203,4 +200,4 @@ server.listen(port); server.on('error', onError); server.on('listening', onListening); -module.exports = app; +export default app; diff --git a/backend/package.json b/backend/package.json index e470d723..242c17f8 100644 --- a/backend/package.json +++ b/backend/package.json @@ -2,6 +2,7 @@ "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 e9658355..995a7ec7 100644 --- a/backend/utility/cronJob.js +++ b/backend/utility/cronJob.js @@ -1,7 +1,8 @@ -const cron = require('node-cron'); + +import cron from "node-cron" const cronJob = (time, fnc) => { cron.schedule(time, fnc); }; -module.exports = cronJob; +export default cronJob; diff --git a/backend/utility/emailTemplates.js b/backend/utility/emailTemplates.js index caa5cbca..00421769 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){}; -module.exports.getMailTemplate = (type) => { +const 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]; }; -module.exports.JoinUsMailTemplate = (adminName, req) => { +const JoinUsMailTemplate = (adminName, req) => { const emailContent = `

Hi ${adminName},

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