Skip to content

Commit ee63d77

Browse files
committed
feat: changed the imported file extension to .js
1 parent 00a1887 commit ee63d77

26 files changed

+69
-66
lines changed

Diff for: backend/api/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import app from '../app';
1+
import app from '../app.js';
22
export default app;

Diff for: backend/app.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import compression from 'compression';
22
import cookieParser from 'cookie-parser';
33
import cors from 'cors';
44
import express from 'express';
5-
import authRouter from './routes/auth';
6-
import postsRouter from './routes/posts';
7-
import userRouter from './routes/user';
8-
import errorMiddleware from './middlewares/error-middleware';
9-
import passport from './config/passport';
5+
import authRouter from './routes/auth.js';
6+
import postsRouter from './routes/posts.js';
7+
import userRouter from './routes/user.js';
8+
import errorMiddleware from './middlewares/error-middleware.js';
9+
import passport from './config/passport.js';
1010
import session from 'express-session';
11-
import { FRONTEND_URL } from './config/utils';
11+
import { FRONTEND_URL } from './config/utils.js';
1212

1313
const app = express();
1414

Diff for: backend/config/db.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mongoose, { AnyArray } from 'mongoose';
2-
import { MONGODB_URI } from './utils';
2+
import { MONGODB_URI } from './utils.js';
33

44
export default async function connectDB() {
55
try {

Diff for: backend/config/passport.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import passport from 'passport';
22
import { Strategy as GoogleStrategy } from 'passport-google-oauth20';
3-
import User from '../models/user';
3+
import User from '../models/user.js';
44
passport.use(
55
new GoogleStrategy(
66
{

Diff for: backend/controllers/auth-controller.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import User from '../models/user';
1+
import User from '../models/user.js';
22
import jwt from 'jsonwebtoken';
3-
import { HTTP_STATUS, RESPONSE_MESSAGES } from '../utils/constants';
4-
import { cookieOptions } from '../utils/cookie_options';
5-
import { JWT_SECRET } from '../config/utils';
6-
import { ApiError } from '../utils/api-error';
7-
import { ApiResponse } from '../utils/api-response';
8-
import { asyncHandler } from '../utils/async-handler';
3+
import { HTTP_STATUS, RESPONSE_MESSAGES } from '../utils/constants.js';
4+
import { cookieOptions } from '../utils/cookie_options.js';
5+
import { JWT_SECRET } from '../config/utils.js';
6+
import { ApiError } from '../utils/api-error.js';
7+
import { ApiResponse } from '../utils/api-response.js';
8+
import { asyncHandler } from '../utils/async-handler.js';
99
import { NextFunction, Request, Response } from 'express';
1010

1111
//REGULAR EMAIL PASSWORD STRATEGY

Diff for: backend/controllers/posts-controller.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import Post from '../models/post';
2-
import User from '../models/user';
3-
import { deleteDataFromCache, storeDataInCache } from '../utils/cache-posts';
4-
import { HTTP_STATUS, REDIS_KEYS, RESPONSE_MESSAGES, validCategories } from '../utils/constants';
1+
import Post from '../models/post.js';
2+
import User from '../models/user.js';
3+
import { deleteDataFromCache, storeDataInCache } from '../utils/cache-posts.js';
4+
import { HTTP_STATUS, REDIS_KEYS, RESPONSE_MESSAGES, validCategories } from '../utils/constants.js';
55
import { Request, Response, NextFunction } from 'express';
66
export const createPostHandler = async (req: Request, res: Response) => {
77
try {

Diff for: backend/controllers/user-controller.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { HTTP_STATUS, RESPONSE_MESSAGES } from '../utils/constants';
2-
import User from '../models/user';
3-
import { Role } from '../types/role-type';
1+
import { HTTP_STATUS, RESPONSE_MESSAGES } from '../utils/constants.js';
2+
import User from '../models/user.js';
3+
import { Role } from '../types/role-type.js';
44
import { Request, Response } from 'express';
55

66
export const getAllUserHandler = async (req: Request, res: Response) => {

Diff for: backend/middlewares/auth-middleware.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { JWT_SECRET } from '../config/utils';
2-
import { ApiError } from '../utils/api-error';
3-
import { HTTP_STATUS, RESPONSE_MESSAGES } from '../utils/constants';
1+
import { JWT_SECRET } from '../config/utils.js';
2+
import { ApiError } from '../utils/api-error.js';
3+
import { HTTP_STATUS, RESPONSE_MESSAGES } from '../utils/constants.js';
44
import jwt from 'jsonwebtoken';
5-
import { Role } from '../types/role-type';
6-
import User from '../models/user';
5+
import { Role } from '../types/role-type.js';
6+
import User from '../models/user.js';
77

88
import { Request, Response, NextFunction } from 'express';
99
import { ObjectId } from 'mongoose';

Diff for: backend/middlewares/error-middleware.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HTTP_STATUS, RESPONSE_MESSAGES } from '../utils/constants';
1+
import { HTTP_STATUS, RESPONSE_MESSAGES } from '../utils/constants.js';
22
import { Request, Response, NextFunction } from 'express';
33

44
const errorMiddleware = (err: any, req: Request, res: Response, next: NextFunction) => {

Diff for: backend/middlewares/post-middleware.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Post from '../models/post';
2-
import { HTTP_STATUS, RESPONSE_MESSAGES } from '../utils/constants';
1+
import Post from '../models/post.js';
2+
import { HTTP_STATUS, RESPONSE_MESSAGES } from '../utils/constants.js';
33
import { Request, Response, NextFunction } from 'express';
44

55
export const isAuthorMiddleware = async (req: Request, res: Response, next: NextFunction) => {

Diff for: backend/models/user.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Schema, model, Document } from 'mongoose';
22
import JWT from 'jsonwebtoken';
33
import bcrypt from 'bcryptjs';
44
import crypto from 'crypto';
5-
import { ACCESS_TOKEN_EXPIRES_IN, JWT_SECRET, REFRESH_TOKEN_EXPIRES_IN } from '../config/utils';
6-
import { Role } from '../types/role-type';
5+
import { ACCESS_TOKEN_EXPIRES_IN, JWT_SECRET, REFRESH_TOKEN_EXPIRES_IN } from '../config/utils.js';
6+
import { Role } from '../types/role-type.js';
77

88
interface UserObject extends Document {
99
userName: string;

Diff for: backend/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"type": "commonjs",
2+
"type": "module",
33
"dependencies": {
44
"@types/bcrypt": "^5.0.2",
55
"@types/bcryptjs": "^2.4.6",
@@ -10,6 +10,7 @@
1010
"@types/express-session": "^1.18.0",
1111
"@types/ioredis": "^5.0.0",
1212
"@types/jsonwebtoken": "^9.0.6",
13+
"@types/mongoose": "^5.11.97",
1314
"@types/passport": "^1.0.16",
1415
"@types/passport-google-oauth20": "^2.0.16",
1516
"@types/redis": "^4.0.11",
@@ -44,16 +45,18 @@
4445
"vercel-build": "echo yay"
4546
},
4647
"jest": {
47-
"globalTeardown": "./tests/teardown.js",
48+
"globalTeardown": "./tests/teardown",
4849
"transform": {
4950
"^.+\\.js?$": "babel-jest"
5051
}
5152
},
5253
"devDependencies": {
5354
"@babel/preset-env": "^7.23.2",
5455
"@eslint/js": "^9.9.0",
56+
"@jest/globals": "^29.7.0",
5557
"@stylistic/eslint-plugin-js": "^2.1.0",
5658
"@types/eslint": "^9.6.0",
59+
"@types/jest": "^29.5.12",
5760
"@typescript-eslint/eslint-plugin": "^8.1.0",
5861
"@typescript-eslint/parser": "^8.1.0",
5962
"babel-jest": "^29.7.0",

Diff for: backend/routes/auth.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Router } from 'express';
2-
import { authMiddleware } from '../middlewares/auth-middleware';
3-
import passport from '../config/passport';
2+
import { authMiddleware } from '../middlewares/auth-middleware.js';
3+
import passport from '../config/passport.js';
44
import jwt from 'jsonwebtoken';
55
import { Request, Response } from 'express';
66
import {
77
signUpWithEmail,
88
signInWithEmailOrUsername,
99
signOutUser,
1010
isLoggedIn,
11-
} from '../controllers/auth-controller';
11+
} from '../controllers/auth-controller.js';
1212

1313
const router = Router();
1414

Diff for: backend/routes/posts.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
getRelatedPostsByCategories,
1111
updatePostHandler,
1212
} from '../controllers/posts-controller.js';
13-
import { REDIS_KEYS } from '../utils/constants';
14-
import { cacheHandler } from '../utils/middleware';
15-
import { isAdminMiddleware, authMiddleware } from '../middlewares/auth-middleware';
13+
import { REDIS_KEYS } from '../utils/constants.js';
14+
import { cacheHandler } from '../utils/middleware.js';
15+
import { isAdminMiddleware, authMiddleware } from '../middlewares/auth-middleware.js';
1616
import { isAuthorMiddleware } from '../middlewares/post-middleware.js';
1717
const router = Router();
1818

Diff for: backend/routes/user.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Router } from 'express';
2-
import { isAdminMiddleware, authMiddleware } from '../middlewares/auth-middleware';
2+
import { isAdminMiddleware, authMiddleware } from '../middlewares/auth-middleware.js';
33
import {
44
changeUserRoleHandler,
55
deleteUserHandler,
66
getAllUserHandler,
7-
} from '../controllers/user-controller';
7+
} from '../controllers/user-controller.js';
88

99
const router = Router();
1010

Diff for: backend/server.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import app from './app';
2-
import connectDB from './config/db';
3-
import { PORT } from './config/utils';
1+
import app from './app.js';
2+
import connectDB from './config/db.js';
3+
import { PORT } from './config/utils.js';
44
import { connectToRedis } from './services/redis.js';
55

66
const server = () => {
77
const port = PORT || 8080;
88

9-
// Redis connection
9+
// Redis connections
1010
connectToRedis();
1111
// mongodb connection
1212
connectDB()

Diff for: backend/services/redis.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createClient } from 'redis';
2-
import { REDIS_URL } from '../config/utils';
2+
import { REDIS_URL } from '../config/utils.js';
33

44
let redis: any = null;
55
export async function connectToRedis() {

Diff for: backend/tests/integration/controllers/posts-controller.test.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import mongoose from 'mongoose';
22
import request from 'supertest';
3-
import Post from '../../../models/post';
3+
import Post from '../../../models/post.js';
44
import server from '../../../server';
5-
import { validCategories, HTTP_STATUS, RESPONSE_MESSAGES } from '../../../utils/constants';
6-
import { createPostObject } from '../../utils/helper-objects';
5+
import { validCategories, HTTP_STATUS, RESPONSE_MESSAGES } from '../../../utils/constants.js';
6+
import { createPostObject } from '../../utils/helper-objects.js';
77
import { expect, jest, it, afterAll, describe } from '@jest/globals';
8-
98
afterAll(async () => {
109
await mongoose.disconnect();
1110
});

Diff for: backend/tests/unit/controllers/posts-controller.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import {
77
getPostByCategoryHandler,
88
getPostByIdHandler,
99
updatePostHandler,
10-
} from '../../../controllers/posts-controller';
11-
import Post from '../../../models/post';
10+
} from '../../../controllers/posts-controller.js';
11+
import Post from '../../../models/post.js';
1212
import { expect, jest, it, describe } from '@jest/globals';
13-
import { validCategories, HTTP_STATUS, RESPONSE_MESSAGES } from '../../../utils/constants';
14-
import { createPostObject, createRequestObject, res } from '../../utils/helper-objects';
13+
import { validCategories, HTTP_STATUS, RESPONSE_MESSAGES } from '../../../utils/constants.js';
14+
import { createPostObject, createRequestObject, res } from '../../utils/helper-objects.js';
1515

1616
jest.mock('../../../models/post.js', () => ({
1717
__esModule: true,

Diff for: backend/tests/utils/helper-objects.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { validCategories } from '../../utils/constants';
1+
import { validCategories } from '../../utils/constants.js';
22
import { jest } from '@jest/globals';
33

44
import { Response } from 'express';

Diff for: backend/tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"compilerOptions": {
33
"target": "es2016",
4-
"module": "commonjs",
4+
"module": "ESNext",
5+
"moduleResolution": "Node",
56
"allowArbitraryExtensions": true,
67
"outDir": "./dist",
78
"esModuleInterop": true,
89
"forceConsistentCasingInFileNames": true,
910
"strict": true,
10-
"skipLibCheck": true
11+
"skipLibCheck": true,
1112
}
1213
}

Diff for: backend/utils/api-error.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Error as MongooseError } from 'mongoose';
2-
import { RESPONSE_MESSAGES } from './constants';
2+
import { RESPONSE_MESSAGES } from './constants.js';
33

44
interface ApiErrorParams {
55
status: number;

Diff for: backend/utils/api-response.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HTTP_STATUS } from './constants';
1+
import { HTTP_STATUS } from './constants.js';
22

33
class ApiResponse {
44
public status: number;

Diff for: backend/utils/cache-posts.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { getRedisClient } from '../services/redis';
2-
import { REDIS_PREFIX } from './constants';
1+
import { getRedisClient } from '../services/redis.js';
2+
import { REDIS_PREFIX } from './constants.js';
33

44
// Helper function to check if Redis is available
55
function isRedisEnabled() {

Diff for: backend/utils/cookie_options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ACCESS_COOKIE_MAXAGE, NODE_ENV } from '../config/utils';
1+
import { ACCESS_COOKIE_MAXAGE, NODE_ENV } from '../config/utils.js';
22
const defaultMaxAge = 3600000;
33
interface CookieObject {
44
httpOnly: boolean;

Diff for: backend/utils/middleware.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { retrieveDataFromCache } from './cache-posts';
2-
import { HTTP_STATUS } from './constants';
1+
import { retrieveDataFromCache } from './cache-posts.js';
2+
import { HTTP_STATUS } from './constants.js';
33
import { Request, Response, NextFunction } from 'express';
44

55
export const cacheHandler =

0 commit comments

Comments
 (0)