Skip to content

Commit f4ec5bc

Browse files
committed
add comment in code
1 parent 723bfdb commit f4ec5bc

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

src/controllers/transaction.controller.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const update = async (req, res) => {
6363
const userId = req.user.id;
6464
const { content, amount, service } = req.body;
6565

66+
// Check if ServiceProvider exists
6667
const serviceProvider = await ServiceProvider.findOne({
6768
where: { name: service },
6869
});
@@ -86,6 +87,7 @@ const update = async (req, res) => {
8687
// Update transaction
8788
transaction.amount = amount;
8889
await transaction.save();
90+
8991
res.status(200).json({
9092
msg: "Transaction updated successfully.",
9193
transaction,
@@ -101,12 +103,14 @@ const deleteTrans = async (req, res) => {
101103
const userId = req.user.id;
102104
const { service } = req.body;
103105

106+
// Check if ServiceProvider exists
104107
const serviceProvider = await ServiceProvider.findOne({
105108
where: { name: service },
106109
});
107110
if (!serviceProvider) {
108111
return res.status(404).json({ msg: "ServiceProvider not found." });
109112
}
113+
110114
const serviceId = serviceProvider.id;
111115

112116
// Check if transaction exists

src/controllers/user.controller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ const search = async (req, res) => {
227227
try {
228228
const { key } = req.query;
229229

230+
// Check if the service exists
230231
const searchedService = await ServiceProvider.findAll({
231232
where: {
232233
servicesProvided: {

src/controllers/verify.controller.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ const sendCode = async (req, res) => {
1010
try {
1111
const { email } = req.body;
1212

13-
const userAccount = await UserAccount.findOne({ where: { email } });
14-
1513
// Check if the user exists
14+
const userAccount = await UserAccount.findOne({ where: { email } });
1615
if (!userAccount) {
1716
return res.status(404).json({ msg: "User did not signup. Please signup." });
1817
}
@@ -37,6 +36,8 @@ const sendCode = async (req, res) => {
3736
pass: process.env.SMTP_PASSWORD,
3837
},
3938
});
39+
40+
// Defined transport object
4041
const mailOptions = {
4142
from: `${process.env.APP_NAME} <${process.env.EMAIL_FROM}>`,
4243
to: email,
@@ -47,6 +48,8 @@ const sendCode = async (req, res) => {
4748
<h1 style="padding: 12px; border-left: 4px solid #d0d0d0; font-style: italic;">${code}</h1>
4849
<p>Best wishes,<br>Scope Inc.</p>`,
4950
};
51+
52+
// send mail with defined transport object
5053
transporter.sendMail(mailOptions, (error, info) => {
5154
if (error) {
5255
res.status(500).json({ msg: error.message });

src/middlewares/requiredAuth.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,34 @@ const secretOrKey = process.env.JWT_ACCESS_TOKEN_SECRET_PRIVATE;
88

99
module.exports = async (req, res, next) => {
1010
try {
11+
// Check if the user is authenticated
1112
if (!req.headers.authorization) {
1213
return res.status(401).json({ msg: "No authentication." });
1314
}
15+
16+
// Check if the token is existed.
1417
const token = req.headers.authorization;
1518
if (!token) {
1619
return res
1720
.status(401)
1821
.json({ msg: "No token, authentication denied." });
1922
}
23+
24+
// Verify token
2025
jwt.verify(token, secretOrKey, async (error, decoded) => {
2126
if (error) {
2227
return res.status(401).json({ msg: "Token is not valid." });
2328
}
2429

30+
// Check if the user exists
2531
const userAccount = await UserAccount.findOne({
2632
where: { email: decoded.email },
2733
});
28-
2934
if (!userAccount) {
3035
return res.status(404).json({ msg: "User does not exist." });
3136
}
3237

38+
// Add user to request
3339
req.user = userAccount;
3440
await next();
3541
});

0 commit comments

Comments
 (0)