Skip to content

Commit a5f1367

Browse files
committed
style: format code
1 parent 1a641ff commit a5f1367

16 files changed

+203
-156
lines changed

src/config/db.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import mongoose from 'mongoose'
2-
import { logger } from '../middleware/logger.js'
1+
import mongoose from 'mongoose';
2+
import { logger } from '../middleware/logger.js';
33

44
const connectDB = async () => {
55
try {
6-
const conn = await mongoose.connect(process.env.MONGODB_URI)
7-
logger.info(`DB Connected: ${conn.connection.host}`)
6+
const conn = await mongoose.connect(process.env.MONGODB_URI);
7+
logger.info(`DB Connected: ${conn.connection.host}`);
88
} catch (error) {
9-
logger.error(`Error connecting to MongoDB: ${error.message}`)
10-
process.exit(1)
9+
logger.error(`Error connecting to MongoDB: ${error.message}`);
10+
process.exit(1);
1111
}
12-
}
12+
};
1313

14-
export default connectDB
14+
export default connectDB;

src/config/redis.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import Redis from "ioredis";
2-
import { logger } from "../middleware/logger.js"; // Assuming you have a logger setup
1+
import Redis from 'ioredis';
2+
import { logger } from '../middleware/logger.js'; // Assuming you have a logger setup
33

44
const redis = new Redis({
5-
host: process.env.REDIS_HOST || "localhost",
5+
host: process.env.REDIS_HOST || 'localhost',
66
port: process.env.REDIS_PORT || 6379,
77
});
88

9-
redis.on("connect", () => {
10-
logger.info("Connected to Redis successfully");
9+
redis.on('connect', () => {
10+
logger.info('Connected to Redis successfully');
1111
});
1212

13-
redis.on("error", (err) => {
13+
redis.on('error', (err) => {
1414
logger.error(`Redis Error: ${err.message}`);
1515
});
1616

src/controllers/goalController.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,15 @@ export const addGoal = async (req, res, next) => {
2121
const userId = req.user.id;
2222

2323
if (!title || !targetAmount || !currency) {
24-
return res
25-
.status(StatusCodes.BAD_REQUEST)
26-
.json({
27-
message: 'Title, targetAmount, and currency are required.',
28-
});
24+
return res.status(StatusCodes.BAD_REQUEST).json({
25+
message: 'Title, targetAmount, and currency are required.',
26+
});
2927
}
3028

3129
if (allocationPercentage < 0 || allocationPercentage > 100) {
32-
return res
33-
.status(StatusCodes.BAD_REQUEST)
34-
.json({
35-
message: 'Allocation percentage must be between 0 and 100.',
36-
});
30+
return res.status(StatusCodes.BAD_REQUEST).json({
31+
message: 'Allocation percentage must be between 0 and 100.',
32+
});
3733
}
3834

3935
// Convert goal target amount to base currency
@@ -102,12 +98,9 @@ export const updateGoal = async (req, res, next) => {
10298
goal.allocationCategories = allocationCategories;
10399
if (allocationPercentage !== undefined) {
104100
if (allocationPercentage < 0 || allocationPercentage > 100) {
105-
return res
106-
.status(StatusCodes.BAD_REQUEST)
107-
.json({
108-
message:
109-
'Allocation percentage must be between 0 and 100.',
110-
});
101+
return res.status(StatusCodes.BAD_REQUEST).json({
102+
message: 'Allocation percentage must be between 0 and 100.',
103+
});
111104
}
112105
goal.allocationPercentage = allocationPercentage;
113106
}

src/jobs/transactionScheduler.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { Cron } from "croner";
2-
import { Transaction } from "../models/transactionModel.js";
3-
import { Notification } from "../models/notificationModel.js";
4-
import { logger } from "../middleware/logger.js";
5-
import dayjs from "dayjs";
1+
import { Cron } from 'croner';
2+
import { Transaction } from '../models/transactionModel.js';
3+
import { Notification } from '../models/notificationModel.js';
4+
import { logger } from '../middleware/logger.js';
5+
import dayjs from 'dayjs';
66

77
// Function to check and notify users
88
const checkRecurringTransactions = async () => {
99
try {
1010
const now = dayjs();
11-
const upcomingThreshold = now.add(1, "day").toDate(); // Look ahead 1 day
12-
const missedThreshold = now.subtract(1, "day").toDate(); // Look back 1 day
11+
const upcomingThreshold = now.add(1, 'day').toDate(); // Look ahead 1 day
12+
const missedThreshold = now.subtract(1, 'day').toDate(); // Look back 1 day
1313

1414
// Find upcoming transactions
1515
const upcomingTransactions = await Transaction.find({
@@ -41,21 +41,22 @@ const checkRecurringTransactions = async () => {
4141
});
4242
}
4343

44-
logger.info("Recurring transaction check completed.");
44+
logger.info('Recurring transaction check completed.');
4545
} catch (error) {
4646
logger.error(`Error checking recurring transactions: ${error.message}`);
4747
}
4848
};
4949

5050
// Schedule job to run every day at midnight
5151

52-
new Cron("0 0 * * *", { timezone: "Asia/Colombo" }, async () => {
53-
52+
new Cron('0 0 * * *', { timezone: 'Asia/Colombo' }, async () => {
5453
try {
55-
logger.info("Running scheduled job: Checking recurring transactions...");
54+
logger.info(
55+
'Running scheduled job: Checking recurring transactions...'
56+
);
5657
await checkRecurringTransactions();
57-
logger.info("Scheduled job completed successfully.");
58+
logger.info('Scheduled job completed successfully.');
5859
} catch (error) {
5960
logger.error(`Error in scheduled job: ${error.message}`);
6061
}
61-
});
62+
});

src/middleware/errorMiddleware.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ const errorHandler = (err, req, res, next) => {
1515
statusCode = 404;
1616
}
1717

18-
req.log.error(`ERROR: ${message} - Status: ${statusCode} - Path: ${req.originalUrl}`);
18+
req.log.error(
19+
`ERROR: ${message} - Status: ${statusCode} - Path: ${req.originalUrl}`
20+
);
1921

2022
res.status(statusCode).json({
2123
message,

src/middleware/logger.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import pino from "pino";
2-
import pinoHttp from "pino-http";
1+
import pino from 'pino';
2+
import pinoHttp from 'pino-http';
33

44
const logger = pino({
5-
level: process.env.LOG_LEVEL || "info",
5+
level: process.env.LOG_LEVEL || 'info',
66
transport: {
7-
target: "pino-pretty",
7+
target: 'pino-pretty',
88
options: {
99
colorize: true,
1010
},
@@ -24,21 +24,21 @@ const httpLogger = pinoHttp({
2424
method: req.method,
2525
url: req.url,
2626
query: req.query,
27-
params: req.params
27+
params: req.params,
2828
};
2929
},
3030
res(res) {
3131
return {
32-
statusCode: res.statusCode
32+
statusCode: res.statusCode,
3333
};
34-
}
34+
},
3535
},
3636

3737
autoLogging: {
3838
ignore(req) {
3939
return false; // Do not ignore any requests by default
40-
}
41-
}
40+
},
41+
},
4242
});
4343

4444
export { logger, httpLogger };

src/middleware/notification.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Notification } from "../models/notificationModel.js";
2-
import { logger } from "./logger.js";
1+
import { Notification } from '../models/notificationModel.js';
2+
import { logger } from './logger.js';
33

44
/**
55
* Middleware to create a notification

src/models/configModel.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import mongoose from "mongoose";
1+
import mongoose from 'mongoose';
22

3-
const configSchema = new mongoose.Schema({
4-
defaultCurrency: { type: String, required: true },
5-
budgetLimit: { type: Number, required: true },
6-
transactionCategories: { type: [String], required: true },
7-
}, { timestamps: true });
3+
const configSchema = new mongoose.Schema(
4+
{
5+
defaultCurrency: { type: String, required: true },
6+
budgetLimit: { type: Number, required: true },
7+
transactionCategories: { type: [String], required: true },
8+
},
9+
{ timestamps: true }
10+
);
811

9-
export const Config = mongoose.model("Config", configSchema);
12+
export const Config = mongoose.model('Config', configSchema);

src/models/goalModel.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import mongoose from "mongoose";
1+
import mongoose from 'mongoose';
22

33
const goalSchema = new mongoose.Schema(
44
{
55
userId: {
66
type: mongoose.Schema.Types.ObjectId,
7-
ref: "User",
7+
ref: 'User',
88
required: true,
99
},
1010
title: {
@@ -24,9 +24,9 @@ const goalSchema = new mongoose.Schema(
2424
min: 0,
2525
validate: {
2626
validator: function (value) {
27-
return typeof value === "number" && !isNaN(value);
27+
return typeof value === 'number' && !isNaN(value);
2828
},
29-
message: "Saved amount must be a valid number.",
29+
message: 'Saved amount must be a valid number.',
3030
},
3131
},
3232
currency: {
@@ -62,4 +62,4 @@ const goalSchema = new mongoose.Schema(
6262
{ timestamps: true }
6363
);
6464

65-
export const Goal = mongoose.model("Goal", goalSchema);
65+
export const Goal = mongoose.model('Goal', goalSchema);

src/models/notificationModel.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1-
import mongoose from "mongoose";
1+
import mongoose from 'mongoose';
22

33
const notificationSchema = new mongoose.Schema(
44
{
5-
userId: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true },
6-
type: { type: String, required: true, enum: ["transaction_alert", "bill_reminder", "goal_reminder", "recurrence_alert", "missed_payment", "budget_alert", "other"] },
5+
userId: {
6+
type: mongoose.Schema.Types.ObjectId,
7+
ref: 'User',
8+
required: true,
9+
},
10+
type: {
11+
type: String,
12+
required: true,
13+
enum: [
14+
'transaction_alert',
15+
'bill_reminder',
16+
'goal_reminder',
17+
'recurrence_alert',
18+
'missed_payment',
19+
'budget_alert',
20+
'other',
21+
],
22+
},
723
message: { type: String, required: true },
824
isRead: { type: Boolean, default: false },
925
createdAt: { type: Date, default: Date.now },
1026
},
1127
{ timestamps: true }
1228
);
1329

14-
export const Notification = mongoose.model("Notification", notificationSchema);
30+
export const Notification = mongoose.model('Notification', notificationSchema);
1531

16-
//FIXME Remove hardcoded notification types
32+
//FIXME Remove hardcoded notification types

0 commit comments

Comments
 (0)