Skip to content

Commit 1644b03

Browse files
Refactor routes and services to use ES module syntax; update imports and exports for consistency.
- Changed require statements to import statements in routes: questions, staging, stocks, subscription, tags, taskRequests, tasks, trading, userStatus, users, wallets. - Updated service imports to use ES module syntax in contributions, discordService, githubService, onboardingExtension, tasks, and users. - Adjusted logger configuration and removed unnecessary comments. - Replaced NotFound errors with httpError.NotFound in various utility functions for better error handling. - Refactored task-related functions to use taskModel for fetching and updating tasks.
1 parent ffce1c7 commit 1644b03

File tree

150 files changed

+1592
-1469
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+1592
-1469
lines changed

app.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import createError from 'http-errors';
2-
import express from 'express';
3-
import { isMulterError, multerErrorHandling } from './utils/multer.js';
1+
import createError from "http-errors";
2+
import express from "express";
3+
import { isMulterError, multerErrorHandling } from "./utils/multer.js";
44

55
// Attach response headers
6-
import { responseHeaders } from './middlewares/responseHeaders.js';
6+
import { responseHeaders } from "./middlewares/responseHeaders.js";
77

88
// import app middlewares
9-
import { middleware } from './middlewares/index.js';
9+
import { middleware } from "./middlewares/index.js";
1010

1111
// import routes
12-
import { appRoutes } from './routes/index.js';
12+
import { appRoutes } from "./routes/index.js";
13+
import logger from "./utils/logger.js";
1314

1415
const app = express();
1516

@@ -27,6 +28,7 @@ app.use(function (err, req, res, next) {
2728
if (isMulterError(err)) {
2829
return multerErrorHandling(err, req, res, next);
2930
}
31+
logger.error(err);
3032
return res.boom.boomify(err, {
3133
statusCode: err.statusCode,
3234
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
const IMAGE_VERIFICATION_TYPES = ["profile", "discord"];
22

3-
export default { IMAGE_VERIFICATION_TYPES };
3+
export { IMAGE_VERIFICATION_TYPES };

constants/logs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { REQUEST_LOG_TYPE } from "./requests";
1+
import { REQUEST_LOG_TYPE } from "./requests.js";
22

33
export const logType = {
44
PROFILE_DIFF_APPROVED: "PROFILE_DIFF_APPROVED",

controllers/answers.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Request } from "express";
22
import crypto from "crypto";
33

4-
import { Answer, AnswerClient, AnswerFieldsToUpdate, AnswerStatus } from "../typeDefinitions/answers";
5-
import { CustomRequest, CustomResponse } from "../typeDefinitions/global";
4+
import { Answer, AnswerClient, AnswerFieldsToUpdate, AnswerStatus } from "../typeDefinitions/answers.js";
5+
import { CustomRequest, CustomResponse } from "../typeDefinitions/global.js";
66

7-
import * as answerQuery from "../models/answers";
7+
import * as answerQuery from "../models/answers.js";
88

9-
import { ANSWER_STATUS } from "../constants/answers";
10-
import { HEADERS_FOR_SSE } from "../constants/constants";
11-
import { INTERNAL_SERVER_ERROR } from "../constants/errorMessages";
9+
import { ANSWER_STATUS } from "../constants/answers.js";
10+
import { HEADERS_FOR_SSE } from "../constants/constants.js";
11+
import { INTERNAL_SERVER_ERROR } from "../constants/errorMessages.js";
1212
import logger from "../utils/logger.js";
1313

1414
/* Refer to limitation of this clients array here(in the limitations section of doc) - https://github.com/Real-Dev-Squad/website-www/wiki/%5BFeature%5D-%E2%80%90-Realtime-Word-Cloud-Questions-Answers-Feature*/

controllers/applications.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { logType } from "../constants/logs.js";
21
import type { Request, Response } from "express";
2+
import admin from "firebase-admin";
3+
4+
import { logType } from "../constants/logs.js";
35
import { INTERNAL_SERVER_ERROR } from "../constants/errorMessages.js";
4-
import {
6+
import {
57
getAllApplications,
68
getUserApplications,
79
addApplication,
@@ -10,7 +12,6 @@ import {
1012
getApplicationById
1113
} from "../models/applications.js";
1214
import { API_RESPONSE_MESSAGES } from "../constants/application.js";
13-
import admin from "firebase-admin";
1415
import logger from "../utils/logger.js";
1516
import { addLog } from "../services/logService.js";
1617

controllers/arts.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { SOMETHING_WENT_WRONG } from "../constants/errorMessages.js";
22
import artsQuery from "../models/arts.js";
3+
import logger from "../utils/logger.js";
4+
35
/**
46
* Adds art
57
*

controllers/auction.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import auctions from "../models/auctions.js";
2-
import wallet from "../models/wallets.js";
2+
import { fetchWallet } from "../models/wallets.js";
33
import { INTERNAL_SERVER_ERROR } from "../constants/errorMessages.js";
4+
import logger from "../utils/logger.js";
45

56
/**
67
* Fetches all the active (ongoing) auctions
@@ -52,7 +53,7 @@ const createNewAuction = async (req, res) => {
5253
const { id: seller } = req.userData;
5354
const { initial_price: initialPrice, item_type: itemType, end_time: endTime, quantity } = req.body;
5455

55-
const { currencies } = await wallet.fetchWallet(seller);
56+
const { currencies } = await fetchWallet(seller);
5657
const itemQuantity = parseInt(currencies[`${itemType}`]);
5758
if (!itemQuantity || itemQuantity < quantity) return res.boom.forbidden(`You do not have enough of ${itemType}s!`);
5859

controllers/auth.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import config from "config";
22
import passport from "passport";
3+
34
import { DATA_ADDED_SUCCESSFULLY, SOMETHING_WENT_WRONG } from "../constants/errorMessages.js";
45
import QrCodeAuthModel from "../models/qrCodeAuth.js";
5-
import users from "../models/users.js";
6-
import authService from "../services/authService.js";
6+
import { addOrUpdate, fetchUser } from "../models/users.js";
7+
import { generateAuthToken } from "../services/authService.js";
78
import logger from "../utils/logger.js";
89

910
const googleAuthLogin = (req, res, next) => {
@@ -80,7 +81,7 @@ async function handleGoogleLogin(req, res, user, authRedirectionUrl) {
8081
updated_at: null,
8182
};
8283

83-
const userDataFromDB = await users.fetchUser({ email: userData.email });
84+
const userDataFromDB = await fetchUser({ email: userData.email });
8485

8586
if (userDataFromDB.userExists) {
8687
if (userDataFromDB.user.roles?.developer) {
@@ -90,9 +91,9 @@ async function handleGoogleLogin(req, res, user, authRedirectionUrl) {
9091
}
9192
}
9293

93-
const { userId, incompleteUserDetails } = await users.addOrUpdate(userData);
94+
const { userId, incompleteUserDetails } = await addOrUpdate(userData);
9495

95-
const token = authService.generateAuthToken({ userId });
96+
const token = generateAuthToken({ userId });
9697

9798
const cookieOptions = getAuthCookieOptions();
9899

@@ -184,17 +185,17 @@ const githubAuthCallback = (req, res, next) => {
184185
}
185186
}
186187

187-
const { userId, incompleteUserDetails, role } = await users.addOrUpdate(userData);
188+
const { userId, incompleteUserDetails, role } = await addOrUpdate(userData);
188189

189-
const token = authService.generateAuthToken({ userId });
190+
const token = generateAuthToken({ userId });
190191

191192
const cookieOptions = getAuthCookieOptions();
192193
// respond with a cookie
193194
res.cookie(config.get("userToken.cookieName"), token, cookieOptions);
194195

195196
/* redirectUrl woud be like https://realdevsquad.com?v2=true */
196197
if (isV2FlagPresent) {
197-
const tokenV2 = authService.generateAuthToken({ userId, role });
198+
const tokenV2 = generateAuthToken({ userId, role });
198199
res.cookie(config.get("userToken.cookieV2Name"), tokenV2, cookieOptions);
199200
}
200201

@@ -264,7 +265,7 @@ const updateAuthStatus = async (req, res) => {
264265
const authStatus = req.params.authorization_status;
265266
let token;
266267
if (authStatus === "AUTHORIZED") {
267-
token = authService.generateAuthToken({ userId });
268+
token = generateAuthToken({ userId });
268269
}
269270
const result = await QrCodeAuthModel.updateStatus(userId, authStatus, token);
270271

controllers/awsAccess.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { PROFILE_SVC_GITHUB_URL } from "../constants/urls";
1+
import { PROFILE_SVC_GITHUB_URL } from "../constants/urls.js";
22
import logger from "../utils/logger.js";
3-
import {addUserToGroup, createUser, fetchAwsUserIdByUsername} from "../utils/awsFunctions";
3+
import {addUserToGroup, createUser, fetchAwsUserIdByUsername} from "../utils/awsFunctions.js";
44

5-
import * as dataAccess from "../services/dataAccessLayer";
6-
import * as userDataLevels from '../constants/userDataLevels';
5+
import * as dataAccess from "../services/dataAccessLayer.js";
6+
import * as userDataLevels from '../constants/userDataLevels.js';
77

88
export const addUserToAWSGroup = async (req, res) => {
99
const { groupId, userId } = req.body;
@@ -15,15 +15,15 @@ export const addUserToAWSGroup = async (req, res) => {
1515
} else if(!userInfoData.user.email) {
1616
return res.status(400).json({ error: `User email is required to create an AWS user. Please update your email by setting up Profile service, url : ${PROFILE_SVC_GITHUB_URL}` });
1717
}
18-
18+
1919
let awsUserId = await fetchAwsUserIdByUsername(userInfoData.user.username);
20-
20+
2121
let userCreationResponse = null;
22-
22+
2323
if (awsUserId === null){
2424
// We need to create the user in AWS before and then fetch its Id
2525
userCreationResponse = await createUser(userInfoData.user.username, userInfoData.user.email);
26-
26+
2727
if (userCreationResponse.conflict){
2828
return res.status(400).json({
2929
error: `Username or Email is already being used, please use another email / username for creating account in AWS`

controllers/badges.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const getBadges = async (req, res, next) => {
2626
* @param res {Object} - Express response object
2727
* @returns {Object}: <badges: Array<badge>, message: string> - Return user badges
2828
*/
29-
async function getUserBadges(req, res) {
29+
export async function getUserBadges(req, res) {
3030
try {
3131
const userId = req.params.id;
3232
const { badges } = await badgeQuery.fetchUserBadges(userId);

0 commit comments

Comments
 (0)