Skip to content

Commit 5dde58d

Browse files
authored
Merge pull request #39 from call-0f-code/health-endpoint
Refactor routes and improve error handling; added health check endpoint; and removed comments
2 parents f77737a + 9bf6f5e commit 5dde58d

5 files changed

Lines changed: 17 additions & 25 deletions

File tree

src/app.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// src/app.ts
21
import express from "express";
32
import cors from "cors";
43
import multer from "multer";
@@ -17,39 +16,40 @@ export const supabase = createClient(
1716

1817
const app = express();
1918

20-
// 1) Enable CORS for your domains
19+
2120
app.use(
2221
cors({
23-
origin: config.ALLOWED_ORIGINS || "*", // e.g. 'https://club.example.com'
22+
origin: config.ALLOWED_ORIGINS || "*",
2423
methods: ["GET", "POST", "PATCH", "DELETE", "OPTIONS"],
2524
credentials: true,
2625
}),
2726
);
2827

29-
// 2) Parse JSON and form data
28+
3029
app.use(json());
3130
app.use(urlencoded({ extended: true }));
3231

33-
// 3) Handle file uploads (in-memory)
32+
3433
const upload = multer({ storage: multer.memoryStorage(),
3534
limits: { fileSize: 2 * 1024 * 1024 }
3635
});
3736

38-
// 4) Mount your routes, injecting `upload` middleware where needed
39-
// For endpoints that accept file uploads, you can do e.g.:
40-
// router.post('/members/:memberId/photo', upload.single('photo'), ...)
37+
38+
app.use("/health",(req,res)=>{
39+
res.status(200).json({ message: "OK" });
40+
})
4141

4242
app.use("/api/v1", routes(upload, supabase));
4343

44-
// 5) 404 handler
44+
// 404 handler
4545
app.use((req, res) => {
4646
res.status(404).json({ message: "Not Found" });
4747
});
4848

49-
// 6) Global error handler
49+
50+
// Global error handler
5051
app.use(errorHandler);
5152

52-
// 7) do 'npm run apidoc to generate the documentation, I have added it in the scripts
53-
// then you can go to localhost:3000/docs to see the docs
53+
// Serve API documentation
5454
app.use("/docs", express.static(path.join(__dirname, "..", "docs/apidoc")));
5555
export default app;

src/routes/achievements.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function parseCreateAchievementData(req: Request, res: Response, next: Ne
2020

2121
export default function acheivementsRouter(upload: Multer, supabase: SupabaseClient) {
2222
const router = express.Router();
23-
23+
2424

2525
/**
2626
* @api {get} /achievements Get all achievements

src/routes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function routes(upload: Multer, supabase: SupabaseClient) {
1717

1818
router.use('/achievements' ,acheivementsRouter(upload, supabase));
1919

20-
router.use('/interviews', interviewRouter(upload, supabase));
20+
router.use('/interviews', interviewRouter());
2121

2222
router.use('/topics',topicRouter());
2323

src/routes/interviews.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import express from 'express';
22
import * as interviewCtrl from '../controllers/interview.controller';
3-
import { supabase } from '../app';
4-
import { Multer } from 'multer';
5-
import { NextFunction } from 'express-serve-static-core';
6-
import { SupabaseClient } from '@supabase/supabase-js';
73

84

9-
10-
export default function interviewRouter(upload: Multer, supabase: SupabaseClient) {
5+
export default function interviewRouter() {
116
const router = express.Router();
127

138
/**
@@ -106,7 +101,7 @@ export default function interviewRouter(upload: Multer, supabase: SupabaseClient
106101
* @apiParam (Path Params) {Number} id Interview ID to delete
107102
*
108103
* @apiSuccess {String} message Deletion confirmation
109-
*
104+
* @apiBody (Request Body) {UUID} memberId Member ID of the owner
110105
* @apiError (400) BadRequest Invalid interview ID
111106
* @apiError (404) NotFound Interview not found
112107
* @apiError (500) InternalServerError Internal server error

src/utils/apiError.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// src/utils/apiError.ts
21
import { Request, Response, NextFunction } from "express";
32

43
/**
@@ -17,9 +16,7 @@ export class ApiError extends Error {
1716
}
1817
}
1918

20-
/**
21-
* Standard structure for API error responses
22-
*/
19+
2320
interface ErrorResponse {
2421
error: boolean;
2522
message: string;

0 commit comments

Comments
 (0)