Skip to content

Commit 49f2322

Browse files
authored
Merge pull request #14 from ubclaunchpad/backend-endpoints
2 parents 1e50c61 + cbdbfde commit 49f2322

18 files changed

+253
-152
lines changed

backend/eslint.config.js

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
1-
import js from '@eslint/js'
2-
import jest from 'eslint-plugin-jest'
3-
import globals from 'globals'
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
43

4+
/** @type {import('eslint').Linter.Config[]} */
55
export default [
6-
{ ignores: ['dist'] },
7-
{
8-
files: ['**/*.{js,ts}'],
9-
languageOptions: {
10-
ecmaVersion: 'latest',
11-
globals: globals.node,
12-
parserOptions: {
13-
ecmaVersion: 'latest',
14-
ecmaFeatures: { jsx: true },
15-
sourceType: 'module',
16-
},
17-
},
18-
rules: {
19-
...js.configs.recommended.rules,
20-
},
21-
},
22-
{
23-
files: ['**/__tests__/**/*.test.{js,ts}'],
24-
plugins: {
25-
jest,
26-
},
27-
languageOptions: {
28-
globals: jest.environments.globals.globals
29-
},
30-
rules: {
31-
...jest.configs.recommended.rules,
32-
}
33-
}
34-
]
6+
{ languageOptions: { globals: { ...globals.node, ...globals.jest } } },
7+
pluginJs.configs.recommended,
8+
{
9+
rules: {
10+
camelcase: ["warn", { properties: "never", ignoreDestructuring: false }],
11+
"max-len": ["warn", { code: 140 }],
12+
},
13+
},
14+
];

backend/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import cors from "cors";
22
import dotenv from "dotenv";
33
import express from "express";
4-
import authRoutes from "./src/routes/authRoutes.js";
5-
import logRoutes from "./src/routes/logRoutes.js";
6-
import transcriptionRoutes from "./src/routes/transcriptionRoutes.js";
4+
import authRoutes from "./src/routes/auth-route.js";
5+
import logbookRoutes from "./src/routes/logbooks-route.js";
6+
import transcriptionRoutes from "./src/routes/transcription-route.js";
77
import fileUpload from "express-fileupload";
88

99
dotenv.config();
@@ -20,7 +20,7 @@ app.use(fileUpload());
2020

2121
//Routes
2222
app.use("/api/auth", authRoutes);
23-
app.use("/api/log", logRoutes);
23+
app.use("/api/logbooks", logbookRoutes);
2424
app.use("/api/transcriptions", transcriptionRoutes);
2525

2626
app.listen(PORT, () => {

backend/package-lock.json

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"build": "babel index.js -d dist",
88
"dev": "nodemon server",
9-
"lint": "eslint .",
9+
"lint": "eslint",
1010
"start": "node index.js",
1111
"test": "jest"
1212
},
@@ -20,6 +20,7 @@
2020
"dotenv": "^16.4.5",
2121
"express": "^4.21.0",
2222
"express-fileupload": "^1.5.1",
23+
"form-data": "^4.0.1",
2324
"jsonwebtoken": "^9.0.2",
2425
"supabase": "^1.207.9"
2526
},

backend/src/middlewares/__tests__/auth.test.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

backend/src/middlewares/auth.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@ const auth = async (req, res, next) => {
1616
})
1717
req.supabase = supabase;
1818
} else {
19-
console.error("No token: Authentication Denied");
2019
return res.status(401).json({ message: "No token: Authentication Denied" });
2120
}
2221
next();
2322
} catch (err) {
24-
console.error("Invalid token, authentication denied:", err.message);
2523
return res.status(400).json({ message: `Invalid token, authentication denied: ${err.message}`});
2624
}
2725
};
2826

29-
export default auth;
30-
27+
export default auth;

backend/src/routes/authRoutes.js renamed to backend/src/routes/auth-route.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import auth from "../middlewares/auth.js";
33

44
const router = express.Router();
55

6-
//auth test
76
router.post("/check", auth, async (req, res) => {
87
res.json({ message: "Auth Check Ok"});
98
})

backend/src/routes/logRoutes.js

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import express from "express";
2+
import auth from "../middlewares/auth.js";
3+
import { createLogbook, getUserLogbooks, getLogbook, createLog, getLogbookLogs, getLog } from "../services/logbooks-service.js";
4+
5+
const router = express.Router();
6+
7+
router.post("", auth, async (req, res) => {
8+
const logbook = await createLogbook(req);
9+
if (logbook.error) {
10+
res.status(500).json({ error: logbook.error });
11+
} else {
12+
res.status(201).json({ data: logbook });
13+
}
14+
});
15+
16+
router.get("", auth, async (req, res) => {
17+
const userLogbooks = await getUserLogbooks(req);
18+
if (userLogbooks.error) {
19+
res.status(500).json({ error: userLogbooks.error });
20+
} else {
21+
res.status(200).json({ data: userLogbooks });
22+
}
23+
});
24+
25+
router.get("/:logbookID", auth, async (req, res) => {
26+
const logbook = await getLogbook(req);
27+
if (logbook.error) {
28+
res.status(500).json({ error: logbook.error });
29+
} else {
30+
res.status(200).json({ data: logbook });
31+
}
32+
});
33+
34+
router.post("/:logbookID/logs", auth, async (req, res) => {
35+
const log = await createLog(req);
36+
if (log.error) {
37+
res.status(500).json({ error: log.error });
38+
} else {
39+
res.status(201).json({ data: log });
40+
}
41+
});
42+
43+
router.get("/:logbookID/logs", auth, async (req, res) => {
44+
const logbookLogs = await getLogbookLogs(req);
45+
if (logbookLogs.error) {
46+
res.status(500).json({ error: logbookLogs.error });
47+
} else {
48+
res.status(200).json({ data: logbookLogs });
49+
}
50+
});
51+
52+
router.get("/:logbookID/logs/:logID", auth, async (req, res) => {
53+
const log = await getLog(req);
54+
if (log.error) {
55+
res.status(500).json({ error: log.error });
56+
} else {
57+
res.status(200).json({ data: log });
58+
}
59+
});
60+
61+
export default router;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test("empty test", () => {
2+
expect(true).toBe(true);
3+
});

0 commit comments

Comments
 (0)