Skip to content

Commit

Permalink
small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoerlitz committed Mar 17, 2024
1 parent 74ebec4 commit 685dd46
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ router.use(
r.get("/log-template/:uuid", TrainingSessionAdminController.getLogTemplate);
r.get("/participants/:uuid", TrainingSessionAdminController.getParticipants);

r.put("/log/:uuid", TrainingSessionAdminController.createTrainingLogs);
r.post("/log/:uuid", TrainingSessionAdminController.createTrainingLogs);
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { HttpStatusCode } from "axios";
import NotificationLibrary from "../../libraries/notification/NotificationLibrary";
import { Config } from "../../core/Config";
import { TrainingType } from "../../models/TrainingType";
import { Op } from "sequelize";
import { TrainingLog } from "../../models/TrainingLog";
import { UsersBelongsToCourses } from "../../models/through/UsersBelongsToCourses";
import { sequelize } from "../../core/Sequelize";
Expand Down Expand Up @@ -395,6 +394,8 @@ async function getCourseTrainingTypes(request: Request, response: Response) {
}

async function createTrainingLogs(request: Request, response: Response, next: NextFunction) {
// TODO: Rewrite slightly :) - especially add validation :D

// All of these steps MUST complete, else we are left in an undefined state
const t = await sequelize.transaction();

Expand Down
11 changes: 9 additions & 2 deletions src/controllers/user/UserStatisticsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@ import { NextFunction, Request, Response } from "express";
import axios, { AxiosError, HttpStatusCode } from "axios";
import { User } from "../../models/User";
import Logger, { LogLevels } from "../../utility/Logger";
import { Config } from "../../core/Config";

// TODO: The entire statistics controller should ideally cache the data for at least a day (the hours really don't change that much).
// That way we can drastically reduce load times and the chance of getting blocked by VATSIM (again).

async function getUserRatingTimes(request: Request, response: Response, next: NextFunction) {
const user: User = response.locals.user;
let userID = user.id;

if (Config.APP_DEBUG) {
userID = 1373921;
}

try {
const res = await axios.get(`https://api.vatsim.net/v2/members/${user.id}/stats`);
const res = await axios.get(`https://api.vatsim.net/v2/members/${userID}/stats`);
response.send(res.data);
} catch (e: any) {
Logger.log(LogLevels.LOG_WARN, `Failed to retrieve API Statistics for ${user.id}: ${e.message}`);
Logger.log(LogLevels.LOG_WARN, `Failed to retrieve API Statistics for ${userID}: ${e.message}`);
response.sendStatus(HttpStatusCode.InternalServerError);
}
}
Expand Down

0 comments on commit 685dd46

Please sign in to comment.