Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Added request body parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoerlitz committed Apr 25, 2023
1 parent 3b32031 commit 5b9affc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# Moodle Course API

The Moodle-Course-API provides a read-only interface to easily
query whether a user has completed a course, or a quiz. This can
be used in other applications (such as the Training-Center) to
determine a member's progress within a specific course.

## API Interface

| Method | Path | Parameters | Response | Description |
|:------:|:-------------------:|:---------------------------------------|:-------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------|
| `GET` | `/course_completed` | `{course_id: number, user_id: number}` | `{course_name: string, completed: bool, completed_at: Date}` | Returns the provided response for the provided parameters. Returns a `400` HTTP Error in the event of missing parameters. |
| `GET` | `/quiz_completed` | `{module_id: number, user_id: number}` | Result of the `SELECT` statement | Returns the result of the `SELECT` statement for the provided parameters. Returns a `400` HTTP Error in the event of missing parameters. |
2 changes: 2 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { initializeApplication } from "./src/core/StartupRoutine";
import { Config } from "./src/core/Config";
import Logger, { LogLevels } from "./src/utility/Logger";
import { apiRouter } from "./src/routes/ApiRouter";
import bodyParser from "body-parser";

const application = express();

Expand All @@ -11,6 +12,7 @@ initializeApplication()
application.listen(Config.APP_PORT, () => {
Logger.log(LogLevels.LOG_SUCCESS, `Server is running on http://localhost:${Config.APP_PORT}`, true);
});
application.use(bodyParser.json());

application.use(apiRouter);
})
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
"author": "VATSIM Germany <[email protected]>",
"license": "GPL3",
"dependencies": {
"@types/body-parser": "^1.19.2",
"@types/express": "^4.17.14",
"@types/sequelize": "^4.28.14",
"body-parser": "^1.20.2",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"mysql2": "^2.3.3",
Expand Down
4 changes: 2 additions & 2 deletions src/routes/ApiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ apiRouter.get("/course_completed", async (req, res) => {
const user_id = req.query.user_id;

if (course_id == null || user_id == null) {
res.status(404).send({ error: "Missing required parameters" });
res.status(400).send({ error: "Missing required parameters" });
return;
}

Expand Down Expand Up @@ -45,7 +45,7 @@ apiRouter.get("/quiz_completed", async (req, res) => {
const user_id = req.query.user_id;

if (module_id == null || user_id == null) {
res.status(404).send({ error: "Missing required parameters" });
res.status(400).send({ error: "Missing required parameters" });
return;
}

Expand Down

0 comments on commit 5b9affc

Please sign in to comment.