Skip to content

Commit

Permalink
Merge pull request #14 from ubclaunchpad/backend-endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
parkrafael authored Dec 4, 2024
2 parents 1e50c61 + cbdbfde commit 49f2322
Show file tree
Hide file tree
Showing 18 changed files with 253 additions and 152 deletions.
44 changes: 12 additions & 32 deletions backend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
import js from '@eslint/js'
import jest from 'eslint-plugin-jest'
import globals from 'globals'
import globals from "globals";
import pluginJs from "@eslint/js";

/** @type {import('eslint').Linter.Config[]} */
export default [
{ ignores: ['dist'] },
{
files: ['**/*.{js,ts}'],
languageOptions: {
ecmaVersion: 'latest',
globals: globals.node,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
rules: {
...js.configs.recommended.rules,
},
},
{
files: ['**/__tests__/**/*.test.{js,ts}'],
plugins: {
jest,
},
languageOptions: {
globals: jest.environments.globals.globals
},
rules: {
...jest.configs.recommended.rules,
}
}
]
{ languageOptions: { globals: { ...globals.node, ...globals.jest } } },
pluginJs.configs.recommended,
{
rules: {
camelcase: ["warn", { properties: "never", ignoreDestructuring: false }],
"max-len": ["warn", { code: 140 }],
},
},
];
8 changes: 4 additions & 4 deletions backend/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import cors from "cors";
import dotenv from "dotenv";
import express from "express";
import authRoutes from "./src/routes/authRoutes.js";
import logRoutes from "./src/routes/logRoutes.js";
import transcriptionRoutes from "./src/routes/transcriptionRoutes.js";
import authRoutes from "./src/routes/auth-route.js";
import logbookRoutes from "./src/routes/logbooks-route.js";
import transcriptionRoutes from "./src/routes/transcription-route.js";
import fileUpload from "express-fileupload";

dotenv.config();
Expand All @@ -20,7 +20,7 @@ app.use(fileUpload());

//Routes
app.use("/api/auth", authRoutes);
app.use("/api/log", logRoutes);
app.use("/api/logbooks", logbookRoutes);
app.use("/api/transcriptions", transcriptionRoutes);

app.listen(PORT, () => {
Expand Down
28 changes: 14 additions & 14 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "babel index.js -d dist",
"dev": "nodemon server",
"lint": "eslint .",
"lint": "eslint",
"start": "node index.js",
"test": "jest"
},
Expand All @@ -20,6 +20,7 @@
"dotenv": "^16.4.5",
"express": "^4.21.0",
"express-fileupload": "^1.5.1",
"form-data": "^4.0.1",
"jsonwebtoken": "^9.0.2",
"supabase": "^1.207.9"
},
Expand Down
3 changes: 0 additions & 3 deletions backend/src/middlewares/__tests__/auth.test.js

This file was deleted.

5 changes: 1 addition & 4 deletions backend/src/middlewares/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ const auth = async (req, res, next) => {
})
req.supabase = supabase;
} else {
console.error("No token: Authentication Denied");
return res.status(401).json({ message: "No token: Authentication Denied" });
}
next();
} catch (err) {
console.error("Invalid token, authentication denied:", err.message);
return res.status(400).json({ message: `Invalid token, authentication denied: ${err.message}`});
}
};

export default auth;

export default auth;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import auth from "../middlewares/auth.js";

const router = express.Router();

//auth test
router.post("/check", auth, async (req, res) => {
res.json({ message: "Auth Check Ok"});
})
Expand Down
17 changes: 0 additions & 17 deletions backend/src/routes/logRoutes.js

This file was deleted.

61 changes: 61 additions & 0 deletions backend/src/routes/logbooks-route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import express from "express";
import auth from "../middlewares/auth.js";
import { createLogbook, getUserLogbooks, getLogbook, createLog, getLogbookLogs, getLog } from "../services/logbooks-service.js";

const router = express.Router();

router.post("", auth, async (req, res) => {
const logbook = await createLogbook(req);
if (logbook.error) {
res.status(500).json({ error: logbook.error });
} else {
res.status(201).json({ data: logbook });
}
});

router.get("", auth, async (req, res) => {
const userLogbooks = await getUserLogbooks(req);
if (userLogbooks.error) {
res.status(500).json({ error: userLogbooks.error });
} else {
res.status(200).json({ data: userLogbooks });
}
});

router.get("/:logbookID", auth, async (req, res) => {
const logbook = await getLogbook(req);
if (logbook.error) {
res.status(500).json({ error: logbook.error });
} else {
res.status(200).json({ data: logbook });
}
});

router.post("/:logbookID/logs", auth, async (req, res) => {
const log = await createLog(req);
if (log.error) {
res.status(500).json({ error: log.error });
} else {
res.status(201).json({ data: log });
}
});

router.get("/:logbookID/logs", auth, async (req, res) => {
const logbookLogs = await getLogbookLogs(req);
if (logbookLogs.error) {
res.status(500).json({ error: logbookLogs.error });
} else {
res.status(200).json({ data: logbookLogs });
}
});

router.get("/:logbookID/logs/:logID", auth, async (req, res) => {
const log = await getLog(req);
if (log.error) {
res.status(500).json({ error: log.error });
} else {
res.status(200).json({ data: log });
}
});

export default router;
3 changes: 3 additions & 0 deletions backend/src/routes/test/auth-route.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test("empty test", () => {
expect(true).toBe(true);
});
3 changes: 3 additions & 0 deletions backend/src/routes/test/logbooks-route.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test("empty test", () => {
expect(true).toBe(true);
});
File renamed without changes.
76 changes: 0 additions & 76 deletions backend/src/services/cardiacSurgeryAdultService.js

This file was deleted.

Loading

0 comments on commit 49f2322

Please sign in to comment.