Skip to content

Commit 2e112bb

Browse files
committed
add returns on responses
1 parent 5fbb376 commit 2e112bb

File tree

7 files changed

+34
-43
lines changed

7 files changed

+34
-43
lines changed

src/admin-routes/router.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@ router.use(async (req, res, next) => {
2525
let user = await getUserInfo(req);
2626

2727
if (!user) {
28-
res.status(401).json({
28+
return res.status(401).json({
2929
error: "Unauthorized",
3030
});
31-
return;
3231
}
3332

3433
if (user.permissionLevel < permissionLevel.enumValues[2]) {
35-
res.status(403).json({
34+
return res.status(403).json({
3635
error: "You do not have permission to access this endpoint",
3736
});
38-
return;
3937
} else {
4038
next();
4139
}
@@ -138,7 +136,7 @@ router.get("/metrics", logRequest, async (req, res) => {
138136

139137
let environment = process.env.NODE_ENV;
140138

141-
res.status(200).json({
139+
return res.status(200).json({
142140
status: "up",
143141
environment: environment,
144142
uptime: uptimeString,

src/admin-routes/routes/domain.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const router = express.Router();
2020
*/
2121
router.get("/", async (req: Request, res: Response) => {
2222
let alldomains = await db.select().from(domains);
23-
res.status(200).json(alldomains);
23+
return res.status(200).json(alldomains);
2424
});
2525

2626
/**
@@ -45,9 +45,9 @@ router.get("/:id", async (req: Request, res: Response) => {
4545
return res.status(400).json("Domain not found");
4646
}
4747

48-
res.status(200).json(dbDomain);
48+
return res.status(200).json(dbDomain);
4949
} catch (error) {
50-
res
50+
return res
5151
.status(500)
5252
.json({ error: "An error occurred while fetching the domain." });
5353
}

src/admin-routes/routes/user.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const router = express.Router();
3535
router.get("/", async (req, res) => {
3636
// metrics.increment("endpoint.admin.users.get");
3737
const dbUsers = await db.query.users.findMany();
38-
res.status(200).json(dbUsers);
38+
return res.status(200).json(dbUsers);
3939
});
4040

4141
/**
@@ -83,7 +83,7 @@ router.get("/user/:id", async (req, res) => {
8383
});
8484
}
8585

86-
res.status(200).json(dbUser);
86+
return res.status(200).json(dbUser);
8787
} catch (error) {
8888
logger.error(error as string);
8989

@@ -132,11 +132,11 @@ router.patch("/user/:id", async (req, res) => {
132132
.set(updateData)
133133
.where(eq(users.id, parseInt(id)));
134134

135-
res.status(200).json({
135+
return res.status(200).json({
136136
message: "User updated successfully.",
137137
});
138138
} catch (error) {
139-
res.status(500).json({
139+
return res.status(500).json({
140140
message: "An error occurred.",
141141
});
142142
}
@@ -167,10 +167,9 @@ router.post("/user/new", async (req, res) => {
167167
const { name, email, password } = body;
168168

169169
if (!name || !email || !password) {
170-
res
170+
return res
171171
.status(400)
172172
.json("Invalid arguments. Please provide name, email, and password");
173-
return;
174173
}
175174

176175
// Check if the user already exists
@@ -179,8 +178,7 @@ router.post("/user/new", async (req, res) => {
179178
});
180179

181180
if (user) {
182-
res.status(400).json("User with that email already exists");
183-
return;
181+
return res.status(400).json("User with that email already exists");
184182
}
185183

186184
const salt = bcrypt.genSaltSync(saltRounds);
@@ -197,7 +195,7 @@ router.post("/user/new", async (req, res) => {
197195
})
198196
.returning();
199197

200-
res.status(200).json({
198+
return res.status(200).json({
201199
message: "User created successfully, please login.",
202200
uuid: newUser.uuid,
203201
});
@@ -228,11 +226,11 @@ router.delete("/user/:id", async (req, res) => {
228226
})
229227
.where(eq(users.id, parseInt(id)));
230228

231-
res.status(200).json({
229+
return res.status(200).json({
232230
message: "User deleted successfully.",
233231
});
234232
} catch (error) {
235-
res.status(500).json({
233+
return res.status(500).json({
236234
message: "An error occurred.",
237235
});
238236
}
@@ -319,11 +317,11 @@ router.patch("/role/:id/:role", async (req, res) => {
319317
})
320318
.where(eq(users.id, parseInt(id)));
321319

322-
res.status(200).json({
320+
return res.status(200).json({
323321
message: `User role updated to ${permission} successfully.`,
324322
});
325323
} catch (error) {
326-
res.status(500).json({
324+
return res.status(500).json({
327325
message: "An error occurred.",
328326
});
329327
}
@@ -382,11 +380,11 @@ router.patch("/useExtended/:id/:useExtended", async (req, res) => {
382380
})
383381
.where(eq(users.id, parseInt(id)));
384382

385-
res.status(200).json({
383+
return res.status(200).json({
386384
message: `User useExtended data updated to ${useExtended} successfully.`,
387385
});
388386
} catch (error) {
389-
res.status(500).json({
387+
return res.status(500).json({
390388
message: "An error occurred.",
391389
});
392390
}

src/routes/domain/adblock.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import { eq } from "drizzle-orm";
12
import express from "express";
23
import { db } from "src/utils/db";
34
const router = express.Router();
4-
import { domains } from "src/db/schema";
5-
import { eq } from "drizzle-orm";
65

76
async function getAllDomains() {
87
const dbDomains = await db.query.domains.findMany({
@@ -34,7 +33,7 @@ router.get("/adgaurd", async (req, res) => {
3433
const filters = domains.map((domain) => `||${domain}^`).join("\n");
3534
// Set content type for filter list
3635
res.setHeader("Content-Type", "text/plain");
37-
res.send(`${header}\n${filters}`);
36+
return res.status(200).send(`${header}\n${filters}`);
3837
});
3938

4039
/**
@@ -58,7 +57,7 @@ router.get("/ublock", async (req, res) => {
5857
const filters = domains.map((domain) => `||${domain}^`).join("\n");
5958
// Set content type for filter list
6059
res.setHeader("Content-Type", "text/plain");
61-
res.send(`${header}\n${filters}`);
60+
return res.status(200).send(`${header}\n${filters}`);
6261
});
6362

6463
/**
@@ -79,7 +78,7 @@ router.get("/pihole", async (req, res) => {
7978
"#",
8079
].join("\n");
8180
res.setHeader("Content-Type", "text/plain");
82-
res.send(`${header}\n${domains.join("\n")}`);
81+
return res.status(200).send(`${header}\n${domains.join("\n")}`);
8382
});
8483

8584
export default router;

src/routes/email.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ router.get("/check", authenticateToken, async (req, res) => {
5959
}
6060

6161
const result = await ipQualityScoreService.email.check(email);
62-
res.status(200).json(result);
62+
return res.status(200).json(result);
6363
});
6464

6565
export default router;

src/routes/misc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ router.get("/metrics", async (req, res) => {
3838
let dateStartedFormatted = moment(dateStarted).format("MM-DD-YY H:m:s A Z");
3939
let environment = process.env.NODE_ENV;
4040

41-
res.status(200).json({
41+
return res.status(200).json({
4242
status: "up",
4343
environment: environment,
4444
uptime: uptimeString,

src/routes/user.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ router.post("/signup", async (req, res) => {
5050
const { firstName, lastName, email, password } = body;
5151

5252
if (!firstName || !lastName || !email || !password) {
53-
res
53+
return res
5454
.status(400)
5555
.json(
5656
"Invalid arguments. Please provide firstName, lastName, email, and password"
5757
);
58-
return;
5958
}
6059

6160
let isDisposable = await disposableEmailDetector(email as string);
@@ -68,8 +67,7 @@ router.post("/signup", async (req, res) => {
6867
// use regex to validate email
6968
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
7069
if (!emailRegex.test(email)) {
71-
res.status(400).json("Invalid email address");
72-
return;
70+
return res.status(400).json("Invalid email address");
7371
}
7472

7573
// Check if the user already exists
@@ -78,8 +76,7 @@ router.post("/signup", async (req, res) => {
7876
});
7977

8078
if (user) {
81-
res.status(400).json("User with that email already exists");
82-
return;
79+
return res.status(400).json("User with that email already exists");
8380
}
8481

8582
const salt = bcrypt.genSaltSync(saltRounds);
@@ -155,12 +152,12 @@ router.post("/signup", async (req, res) => {
155152
}
156153

157154
// Send success response with the user's uuid
158-
res.status(200).json({
155+
return res.status(200).json({
159156
message: "User created successfully, please login.",
160157
uuid: newUser.uuid,
161158
});
162159
} catch (error: any) {
163-
res.status(500).json({
160+
return res.status(500).json({
164161
message: "Error creating user",
165162
error: error.message,
166163
});
@@ -196,8 +193,7 @@ router.post("/login", async (req, res) => {
196193
const { email, password } = body;
197194

198195
if (!email || !password) {
199-
res.status(400).json("Missing email or password");
200-
return;
196+
return res.status(400).json("Missing email or password");
201197
}
202198

203199
// Get IP address from the request
@@ -317,7 +313,7 @@ router.post("/login", async (req, res) => {
317313
};
318314
}
319315

320-
res.status(200).json(jsonresponsebody);
316+
return res.status(200).json(jsonresponsebody);
321317
});
322318

323319
/**
@@ -413,7 +409,7 @@ router.get("/me", authenticateToken, async (req, res) => {
413409
count: methodGroup.count,
414410
}));
415411

416-
res.status(200).json({
412+
return res.status(200).json({
417413
name: userInfo.firstName + " " + userInfo.lastName,
418414
email: userInfo.email,
419415
uuid: userInfo.uuid,
@@ -493,7 +489,7 @@ router.patch("/me", authenticateToken, async (req, res) => {
493489
.where(eq(users.id, userInfo.id));
494490
}
495491

496-
res.status(200).json("User updated successfully");
492+
return res.status(200).json("User updated successfully");
497493
});
498494

499495
export default router;

0 commit comments

Comments
 (0)