Skip to content

Commit 802d4ea

Browse files
committed
chore: update tsconfig and fix import extensions
1 parent 6e04d33 commit 802d4ea

38 files changed

Lines changed: 1006 additions & 906 deletions

Backend/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# REQUIRED CONFIG
33
# ========================================
44

5-
# MongoDB URI (⚠️ Required — without this the backend won’t run)
5+
# MongoDB URI (Required — without this the backend won’t run)
66
MONGO_DB_URI=mongodb://localhost:27017/cronjob-scheduler
77

88
# REDIS CONFIGURATION

Backend/package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
"name": "backend",
33
"version": "1.0.0",
44
"description": "backend for cronJob Scheduler",
5-
"main": "app.js",
5+
"main": "dist/app.js",
6+
"type": "module",
67
"scripts": {
78
"start": "node ./dist/app.js",
89
"watch": "tsc -w",
910
"build": "tsc",
10-
"dev": "concurrently \"tsc -w\" \"nodemon ./dist/app.js\"",
11+
"dev": "concurrently \"tsc -w\" \"node --watch ./dist/app.js\"",
1112
"bun": "bun ./src/app.ts",
12-
"bun watch": "bun --watch ./src/app.ts"
13+
"bun watch": "bun --watch ./src/app.ts",
14+
"test": "vitest run"
1315
},
1416
"keywords": [],
15-
"author": "sunjay kumar",
17+
"author": "https://github.com/sunjay-dev/",
1618
"license": "MIT",
1719
"packageManager": "pnpm@10.11.0",
1820
"dependencies": {
@@ -45,7 +47,7 @@
4547
"@types/passport-google-oauth20": "^2.0.16",
4648
"@types/validator": "^13.15.2",
4749
"concurrently": "^9.2.0",
48-
"nodemon": "^3.1.10",
49-
"typescript": "^5.9.2"
50+
"typescript": "^5.9.2",
51+
"vitest": "^4.1.0"
5052
}
5153
}

Backend/pnpm-lock.yaml

Lines changed: 712 additions & 199 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Backend/src/agenda/agenda.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

Backend/src/app.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import "dotenv/config";
22
import express from "express";
33
import cookieParser from "cookie-parser";
44
import cors from "cors";
5-
import passport from "./config/passport.config";
6-
import errorHandler from "./middlewares/errorHandler.middlewares";
5+
import passport from "./config/passport.config.js";
6+
import errorHandler from "./middlewares/errorHandler.middlewares.js";
77

88
const app = express();
99

1010
app.use(
1111
cors({
12-
origin: process.env.CLIENT_URL!,
12+
origin: process.env.CLIENT_URL as string,
1313
credentials: true,
1414
}),
1515
);
@@ -18,19 +18,19 @@ app.use(passport.initialize());
1818
app.use(express.json());
1919
app.use(cookieParser());
2020

21-
import userRouter from "./routes/user.routes";
22-
import cronRouter from "./routes/log.routes";
23-
import jobRouter from "./routes/job.routes";
21+
import userRouter from "./routes/user.routes.js";
22+
import cronRouter from "./routes/log.routes.js";
23+
import jobRouter from "./routes/job.routes.js";
2424

2525
app.use("/", userRouter);
2626
app.use("/api/logs", cronRouter);
2727
app.use("/api/jobs", jobRouter);
2828

2929
app.use(errorHandler);
3030

31-
import connectDB from "./config/db.config";
31+
import connectDB from "./config/db.config.js";
3232
connectDB();
3333

34-
import logger from "./utils/logger.utils";
34+
import logger from "./utils/logger.utils.js";
3535
const port = process.env.PORT || 3000;
3636
app.listen(port, () => logger.info(`Server running on Port ${port}`));
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Agenda } from "agenda";
2+
3+
const agenda = new Agenda({
4+
db: {
5+
address: process.env.MONGO_DB_URI as string,
6+
collection: process.env.MONGO_DB_COLLECTION as string,
7+
},
8+
});
9+
10+
export default agenda;

Backend/src/config/db.config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import mongoose from "mongoose";
2-
import logger from "../utils/logger.utils";
2+
import logger from "../utils/logger.utils.js";
33

44
export default async function connectDB() {
55
try {
6-
await mongoose.connect(process.env.MONGO_DB_URI!);
7-
logger.info("MongoDB connected");
8-
} catch (err) {
9-
logger.error(`MongoDB connection error: ${err}`);
6+
await mongoose.connect(process.env.MONGO_DB_URI as string);
7+
logger.info({ message: "MongoDB connected" });
8+
} catch (error) {
9+
logger.error({ message: "Failed to connect to MongoDB", error });
1010
}
1111
}

Backend/src/config/passport.config.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
import passport from "passport";
22
import { Strategy as GoogleStrategy } from "passport-google-oauth20";
3-
import userModels from "../models/user.models";
3+
import userModels from "../models/user.models.js";
44

55
passport.use(
66
new GoogleStrategy(
77
{
8-
clientID: process.env.GOOGLE_CLIENT_ID!,
9-
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
10-
callbackURL: process.env.GOOGLE_CALLBACK_URL!,
8+
clientID: process.env.GOOGLE_CLIENT_ID as string,
9+
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
10+
callbackURL: process.env.GOOGLE_CALLBACK_URL as string,
1111
},
1212
async (_accessToken, _refreshToken, profile, done) => {
1313
const email = profile.emails?.[0]?.value;
1414
if (!email) return done(new Error("No email from Google"), false);
1515

1616
try {
17-
const user = await userModels.findOneAndUpdate(
18-
{ email },
19-
{
20-
$setOnInsert: {
21-
name: profile.displayName,
22-
email,
23-
authProvider: "google",
24-
verified: true,
17+
const user = await userModels
18+
.findOneAndUpdate(
19+
{ email },
20+
{
21+
$setOnInsert: {
22+
name: profile.displayName,
23+
email,
24+
authProvider: "google",
25+
verified: true,
26+
},
2527
},
26-
},
27-
{ new: true, upsert: true },
28-
);
28+
{ new: true, upsert: true },
29+
)
30+
.lean();
2931

3032
return done(null, user);
3133
} catch (err) {

Backend/src/config/redis.config.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import Redis from "ioredis";
2-
import logger from "../utils/logger.utils";
1+
import { Redis } from "ioredis";
2+
import logger from "../utils/logger.utils.js";
33

4-
const redis = new Redis(process.env.REDIS_URL!);
4+
const redis = new Redis(process.env.REDIS_URL as string);
55

66
redis.on("connect", () => {
7-
logger.info("Redis client connected");
7+
logger.info({ message: "Redis client connected" });
88
});
99

1010
redis.on("ready", () => {
11-
logger.info("Redis is ready to use");
11+
logger.info({ message: "Redis is ready to use" });
1212
});
1313

14-
redis.on("error", (err) => {
15-
logger.error(`Redis connection error: ${err}`);
14+
redis.on("error", (error) => {
15+
logger.error({ message: `Redis connection error`, error });
1616
});
1717

1818
redis.on("close", () => {
19-
logger.info("Redis connection closed");
19+
logger.info({ message: "Redis connection closed" });
2020
});
2121

2222
export default redis;

Backend/src/controllers/job.controllers.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import type { Request, Response, NextFunction } from "express";
2-
import agenda from "../agenda/agenda";
3-
import logsModels from "../models/logs.models";
2+
import agenda from "../config/agenda.config.js";
3+
import logsModels from "../models/logs.models.js";
44
import mongoose from "mongoose";
5-
import { BadRequestError, InternalServerError, NotFoundError } from "../utils/appError.utils";
5+
import { BadRequestError, InternalServerError, NotFoundError } from "../utils/appError.utils.js";
66

77
function getHeaderObj(headers: any[]) {
8-
return headers.reduce((acc, { key, value }) => {
9-
const trimmedKey = key?.trim();
10-
const trimmedValue = value?.trim();
11-
12-
if (trimmedKey && trimmedValue) acc[trimmedKey] = trimmedValue;
13-
return acc;
14-
}, {} as Record<string, string>);
8+
return headers.reduce(
9+
(acc, { key, value }) => {
10+
const trimmedKey = key?.trim();
11+
const trimmedValue = value?.trim();
12+
13+
if (trimmedKey && trimmedValue) acc[trimmedKey] = trimmedValue;
14+
return acc;
15+
},
16+
{} as Record<string, string>,
17+
);
1518
}
1619

1720
export const handleNewCronJobs = async (req: Request, res: Response, next: NextFunction): Promise<void> => {

0 commit comments

Comments
 (0)