Skip to content

Commit 3745099

Browse files
committed
Merge branch 'development' of https://github.com/tcet-opensource/erp-backend into 54-update-the-documentation-for-the-project
2 parents 88a2027 + 05572c4 commit 3745099

24 files changed

+2662
-700
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
apidoc

.github/pull_request_template.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Description
2+
Briefly describe the changes made in this pull request.
3+
4+
## Fixes
5+
Specify the related issues or tickets that this pull request fixes (e.g., Fixes #123).
6+
7+
## Checklist
8+
<!-- add x inside brackets for ticking the checkbox eg - [x] -->
9+
- [ ] Code follows project's style guidelines.
10+
- [ ] Changes are documented appropriately.
11+
12+
## Notes
13+
Add any additional notes or context that might be useful for reviewers.
14+
15+
16+
17+
#### (PS → Make Sure Pull request title is meaningful.)

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,5 @@ dist
129129
.yarn/install-state.gz
130130
.pnp.*
131131

132+
# ingore genrated APIdocs
133+
apidoc

_apidoc.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// ------------------------------------------------------------------------------------------
2+
// General apiDoc documentation blocks and old history blocks.
3+
// ------------------------------------------------------------------------------------------
4+
5+
// ------------------------------------------------------------------------------------------
6+
// Current Success.
7+
// ------------------------------------------------------------------------------------------
8+
9+
// ------------------------------------------------------------------------------------------
10+
// Current Errors.
11+
// ------------------------------------------------------------------------------------------
12+
13+
// ------------------------------------------------------------------------------------------
14+
// Current Permissions.
15+
// ------------------------------------------------------------------------------------------
16+
17+
// ------------------------------------------------------------------------------------------
18+
// History.
19+
// ------------------------------------------------------------------------------------------

apidoc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "ERP-backend",
3+
"version": "0.1.0",
4+
"description": "TCET ERP System is a project that aims to simplify and automate daily operation in TCET."
5+
}

controller/auth.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import util, {logger} from "#util";
1+
import OTPStore from "#models/otpStore";
2+
import util, { logger } from "#util";
23
import { authenticateUser, userExists, updatePassword } from "#services/user";
34

4-
const otpStore = {};
5-
65
async function login(req, res) {
76
const { id, password } = req.body;
87
try {
@@ -17,7 +16,7 @@ async function login(req, res) {
1716
userDetails.token = token;
1817
res.json({ res: "welcome", user: userDetails });
1918
} catch (error) {
20-
logger.error("Error while login", error)
19+
logger.error("Error while login", error);
2120
if (error.name === "UserDoesNotExist") {
2221
res.status(403);
2322
res.json({ err: "Incorrect ID password" });
@@ -36,7 +35,7 @@ async function sendOTP(req, res) {
3635
const { uid, emailId } = req.body;
3736
if (await userExists(uid, emailId)) {
3837
const otp = Math.floor(1000 + Math.random() * 9000);
39-
otpStore[uid] = otp;
38+
await OTPStore.update({ uid }, { otp });
4039
util.sendOTP(emailId, otp);
4140
res.json({ res: "otp sent to emailID" });
4241
} else {
@@ -46,12 +45,13 @@ async function sendOTP(req, res) {
4645

4746
async function resetPassword(req, res) {
4847
const { uid, otp, password } = req.body;
49-
if (otpStore[uid] === otp) {
48+
const storedOtp = await OTPStore.read({ uid });
49+
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" });

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
}

hooks/pre-commit

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
for file in $(git diff --diff-filter=d --cached --name-only | grep -E '\.(js|jsx)$')
4+
do
5+
git show ":$file" | npm run eslint --stdin --stdin-filename "$file"
6+
if [ $? -ne 0 ]; then
7+
echo "ESLint failed on staged file '$file'. Please check your code and try again. You can run ESLint manually via npm run eslint."
8+
exit 1
9+
fi
10+
done

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: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import connector from "#models/databaseUtil";
22

33
const accreditationSchema = {
4-
uid: { type: String, unique: true, required: true },
5-
accreditationName: { type: String, required: true },
4+
name: { type: String, required: true },
65
agencyName: { type: String, required: true },
76
dateofAccreditation: { type: Date, required: true },
87
dateofExpiry: { type: Date, required: true },
98
};
109

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

1312
async function remove(filter) {
1413
const res = await Accreditation.findOneAndDelete(filter);
1514
return res;
1615
}
1716

18-
async function create(uid, accreditationName, agencyName, dateofAccreditation, dateofExpiry) {
17+
async function create(name, agencyName, dateofAccreditation, dateofExpiry) {
1918
const accreditation = new Accreditation({
20-
accreditationName,
19+
name,
2120
agencyName,
22-
uid,
2321
dateofAccreditation,
2422
dateofExpiry,
2523
});

0 commit comments

Comments
 (0)