Skip to content

Commit be052ec

Browse files
committed
fixed syntax according to eslint
1 parent 044cc1a commit be052ec

File tree

15 files changed

+144
-133
lines changed

15 files changed

+144
-133
lines changed

controller/auth.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import OTPStore from "#models/otpStore";
2-
import util, {logger} from "#util";
2+
import util, { logger } from "#util";
33
import { authenticateUser, userExists, updatePassword } from "#services/user";
44

55
async function login(req, res) {
@@ -16,7 +16,7 @@ async function login(req, res) {
1616
userDetails.token = token;
1717
res.json({ res: "welcome", user: userDetails });
1818
} catch (error) {
19-
logger.error("Error while login", error)
19+
logger.error("Error while login", error);
2020
if (error.name === "UserDoesNotExist") {
2121
res.status(403);
2222
res.json({ err: "Incorrect ID password" });
@@ -35,7 +35,7 @@ async function sendOTP(req, res) {
3535
const { uid, emailId } = req.body;
3636
if (await userExists(uid, emailId)) {
3737
const otp = Math.floor(1000 + Math.random() * 9000);
38-
await OTPStore.update({uid: uid}, {otp: otp});
38+
await OTPStore.update({ uid }, { otp });
3939
util.sendOTP(emailId, otp);
4040
res.json({ res: "otp sent to emailID" });
4141
} else {
@@ -45,13 +45,13 @@ async function sendOTP(req, res) {
4545

4646
async function resetPassword(req, res) {
4747
const { uid, otp, password } = req.body;
48-
const storedOtp = await OTPStore.read({uid: uid});
48+
const storedOtp = await OTPStore.read({ uid });
4949
if (storedOtp[0].otp === `${otp}`) {
5050
try {
5151
await updatePassword(uid, password);
5252
res.json({ res: "successfully updated password" });
5353
} catch (error) {
54-
logger.log("Error while updating", error)
54+
logger.log("Error while updating", error);
5555
res.status(500);
5656
if (error.name === "UpdateError") res.json({ err: "Something went wrong while updating password" });
5757
else res.json({ err: "something went wrong" });
@@ -60,7 +60,6 @@ async function resetPassword(req, res) {
6060
res.json({ err: "incorrect otp" });
6161
}
6262
}
63-
6463

6564
export default {
6665
validateUser, sendOTP, resetPassword, login,

controller/user.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ async function addUser(req, res) {
99
const newUser = await createUser(name, password, emailId, uid, userType);
1010
res.json({ res: `added user ${newUser.id}` });
1111
} catch (error) {
12-
logger.error("Error while inserting", error)
13-
res.status(500)
12+
logger.error("Error while inserting", error);
13+
res.status(500);
1414
res.json({ err: "Error while inserting in DB" });
1515
}
1616
}

middleware/auth.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import jwt from "jsonwebtoken";
2-
import util, {logger} from "#util";
2+
import util from "#util";
33

44
async function authenticateToken(req, res, next) {
55
const authHeader = req.headers.authorization;
@@ -9,15 +9,17 @@ async function authenticateToken(req, res, next) {
99
const payload = jwt.verify(token, process.env.TOKEN_SECRET);
1010
const decryptedIP = util.decrypt(payload.ip);
1111
if (decryptedIP !== req.ip) {
12-
res.status(403)
13-
res.send({err:"Unauthorized"});
12+
res.status(403);
13+
res.send({ err: "Unauthorized" });
1414
}
1515

1616
req.user = payload.data;
1717
next();
18+
return true;
1819
} catch (error) {
19-
res.status(403)
20-
res.send({err:"Unauthorized"});
20+
res.status(403);
21+
res.send({ err: "Unauthorized" });
22+
return false;
2123
}
2224
}
2325

models/accreditation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const accreditationSchema = {
88
dateofExpiry: { type: Date, required: true },
99
};
1010

11-
const Accreditation = new connector.model("Accreditation", accreditationSchema);
11+
const Accreditation = connector.model("Accreditation", accreditationSchema);
1212

1313
async function remove(filter) {
1414
const res = await Accreditation.findOneAndDelete(filter);

models/attendance.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import connector from "./databaseUtil";
2-
import Infrastructure from "./infrastructure";
32

43
connector.set("debug", true);
54

65
const attendanceSchema = {
76
date: { type: Date, required: true },
87
time: { type: String, required: true },
98
absentees: { type: Array },
10-
class: Infrastructure,
119
};
1210

1311
const Attendance = connector.model("Attendance", attendanceSchema);
@@ -28,10 +26,14 @@ async function remove(filter) {
2826
}
2927

3028
async function grantAttendance(roll, date) {
31-
const res = await Attendance.findOneAndUpdate(date, {$pull: { absentees: roll } }, { new: true });
29+
const res = await Attendance.findOneAndUpdate(
30+
date,
31+
{ $pull: { absentees: roll } },
32+
{ new: true },
33+
);
3234
return res;
3335
}
3436

3537
export default {
3638
create, remove, grantAttendance,
37-
};
39+
};

models/faculty.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const { connector } = require('./databaseUtil');
1+
const { connector } = require("./databaseUtil");
22

3-
const facultySchema = new mongoose.Schema({
3+
const facultySchema = {
44
name: {
55
type: String,
66
required: true,
77
},
88
department: {
9-
type: mongoose.Schema.Types.ObjectId,
10-
ref: 'Department',
9+
type: connector.Schema.Types.ObjectId,
10+
ref: "Department",
1111
required: true,
1212
},
1313
empType: {
@@ -19,7 +19,7 @@ const facultySchema = new mongoose.Schema({
1919
required: true,
2020
},
2121
preferredSubjects: {
22-
type: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Subject' }],
22+
type: [{ type: connector.Schema.Types.ObjectId, ref: "Subject" }],
2323
required: true,
2424
},
2525
profileLink: {
@@ -87,8 +87,8 @@ const facultySchema = new mongoose.Schema({
8787
type: Date,
8888
default: Date.now,
8989
},
90-
});
90+
};
9191

92-
const Faculty = connector.model('Faculty', facultySchema);
92+
const Faculty = connector.model("Faculty", facultySchema);
9393

9494
module.exports = Faculty;

models/group.js

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,55 @@
11
import connector from "#models/databaseUtil";
2+
23
const groupSchema = {
3-
groupName: { type: String, required: true },
4-
studentIds: { type: [Number], required: true },
4+
groupName: { type: String, required: true },
5+
studentIds: { type: [Number], required: true },
56
};
67

7-
const groupModel = new connector.model("group", groupSchema);
8+
const groupModel = connector.model("group", groupSchema);
89

910
async function createGroup(groupData) {
10-
try {
11-
const newGroup = await groupModel.create(groupData);
12-
return newGroup;
13-
} catch (error) {
14-
console.error("Error creating group:", error);
15-
return null;
16-
}
11+
try {
12+
const newGroup = await groupModel.create(groupData);
13+
return newGroup;
14+
} catch (error) {
15+
console.error("Error creating group:", error);
16+
return null;
17+
}
1718
}
1819

1920
async function getGroupById(groupId) {
20-
try {
21-
const group = await groupModel.findById(groupId);
22-
return group;
23-
} catch (error) {
24-
console.error("Error retrieving group:", error);
25-
return null;
26-
}
21+
try {
22+
const group = await groupModel.findById(groupId);
23+
return group;
24+
} catch (error) {
25+
console.error("Error retrieving group:", error);
26+
return null;
27+
}
2728
}
2829

2930
async function updateGroup(groupId, updateData) {
30-
try {
31-
const updatedGroup = await groupModel.findByIdAndUpdate(groupId, updateData, { new: true });
32-
return updatedGroup;
33-
} catch (error) {
34-
console.error("Error updating group:", error);
35-
return null;
36-
}
31+
try {
32+
const updatedGroup = await groupModel.findByIdAndUpdate(groupId, updateData, { new: true });
33+
return updatedGroup;
34+
} catch (error) {
35+
console.error("Error updating group:", error);
36+
return null;
37+
}
3738
}
3839

3940
async function deleteGroup(groupId) {
40-
try {
41-
const deletedGroup = await groupModel.findByIdAndDelete(groupId);
42-
return deletedGroup;
43-
} catch (error) {
44-
console.error("Error deleting group:", error);
45-
return null;
46-
}
41+
try {
42+
const deletedGroup = await groupModel.findByIdAndDelete(groupId);
43+
return deletedGroup;
44+
} catch (error) {
45+
console.error("Error deleting group:", error);
46+
return null;
47+
}
4748
}
4849

49-
module.exports = {
50-
createGroup,
51-
getGroupById,
52-
updateGroup,
53-
deleteGroup,
50+
export default {
51+
createGroup,
52+
getGroupById,
53+
updateGroup,
54+
deleteGroup,
5455
};

models/infra.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const infrastructureSchema = {
88
capacity: { type: Number, required: true },
99
};
1010

11-
const Infrastructure = new connector.model("Infrastructure", infrastructureSchema);
11+
const Infrastructure = connector.model("Infrastructure", infrastructureSchema);
1212

1313
async function remove(filter) {
1414
const res = await Infrastructure.findOneAndDelete(filter);

models/module.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import connector from '#models/databaseUtil';
1+
import connector from "#models/databaseUtil";
22

33
const moduleSchema = {
44
moduleNo: { type: Number, required: true },
@@ -9,7 +9,7 @@ const moduleSchema = {
99
cognitiveLevels: [{ type: String, required: true }],
1010
};
1111

12-
const Module = new connector.model('Module', moduleSchema);
12+
const Module = connector.model("Module", moduleSchema);
1313

1414
async function remove(filter) {
1515
const res = await Module.findOneAndDelete(filter);
@@ -22,7 +22,7 @@ async function create(
2222
moduleOutcome,
2323
moduleContents,
2424
hrsPerModule,
25-
cognitiveLevels
25+
cognitiveLevels,
2626
) {
2727
const module = new Module({
2828
moduleNo,

models/organization.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ const organizationSchema = {
1111
employees: [{ type: connector.Schema.Types.ObjectId, ref: "Faculty", required: "true" }],
1212

1313
};
14-
const Organization = new connector.model("Organization", organizationSchema);
14+
15+
// eslint-disable-next-line no-unused-vars
16+
const Organization = connector.model("Organization", organizationSchema);

0 commit comments

Comments
 (0)