feat: Implement the tracker
This commit is contained in:
@@ -19,6 +19,8 @@ import UserRouter from "./api/user";
|
||||
import ClassRouter from "./api/class";
|
||||
import LevelRouter from "./api/level";
|
||||
|
||||
import { ITrackerDBModel } from "./models/tracker";
|
||||
|
||||
const baseRouter = express.Router();
|
||||
const authRouter = express.Router();
|
||||
|
||||
@@ -66,6 +68,40 @@ const password = encodeURIComponent(env["LATEINICUS_USER_PW"]);
|
||||
app.use("/api/level", LevelRouter);
|
||||
app.use("/api/class", ClassRouter);
|
||||
app.use("/api/user", UserRouter);
|
||||
app.post("/api/tracker", async (req, res) => {
|
||||
// Did we get any data
|
||||
if (!req.body) {
|
||||
res.send({
|
||||
error: "403",
|
||||
data: {
|
||||
msg: "No request body provided",
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Did we get all arguments?
|
||||
if (!("session" in req.body) || !("event" in req.body)) {
|
||||
res.send({
|
||||
error: "403",
|
||||
data: {
|
||||
msg: "Invalid request",
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Insert it into the database
|
||||
const tracker: ITrackerDBModel = Object.assign({}, req.body, {
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
await db.collection("tracker").insertOne(tracker);
|
||||
|
||||
res.send({
|
||||
error: "200",
|
||||
data: {},
|
||||
});
|
||||
});
|
||||
app.get("/api/levels", async (req, res) => {
|
||||
// TODO: if (levels)
|
||||
const levels = (await db.collection("levels").find({}, {
|
||||
|
||||
16
backend/src/models/tracker.ts
Normal file
16
backend/src/models/tracker.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export enum TrackerEvent {
|
||||
LOG_IN = "LOG_IN",
|
||||
LOG_OUT = "LOG_OUT",
|
||||
START_LEARNING = "START_LEARNING",
|
||||
CANCEL_LEARNING = "CANCEL_LEARNING",
|
||||
FINISH_LEARNING = "FINISH_LEARNING",
|
||||
};
|
||||
|
||||
export interface ITrackerRequest {
|
||||
session: string;
|
||||
event: TrackerEvent;
|
||||
};
|
||||
|
||||
export type ITrackerDBModel = ITrackerRequest & {
|
||||
timestamp: number;
|
||||
};
|
||||
Reference in New Issue
Block a user