Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/vatger/trainingcenter into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhollmann committed May 19, 2024
2 parents 340c8ec + 8744aca commit 095b22e
Show file tree
Hide file tree
Showing 8 changed files with 328 additions and 163 deletions.
2 changes: 2 additions & 0 deletions backend/db/seeders/20221121101837-PermissionSeeder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const allPerms = [
"mentor.view",

"lm.view",
"lm.action_requirements.view",
"lm.course.view",

"atd.view",
"atd.solo.delete",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import { Request, Response } from "express";
import { NextFunction, Request, Response } from "express";
import { ActionRequirement } from "../../models/ActionRequirement";
import { User } from "../../models/User";
import PermissionHelper from "../../utility/helper/PermissionHelper";

async function getAll(request: Request, response: Response) {
const actionRequirements = await ActionRequirement.findAll();
/**
* Get all action requirements stored in the database
* @param _request
* @param response
* @param next
*/
async function getAll(_request: Request, response: Response, next: NextFunction) {
try {
const user: User = response.locals.user;
PermissionHelper.checkUserHasPermission(user, "lm.action_requirements.view");

response.send(actionRequirements);
const actionRequirements: ActionRequirement[] = await ActionRequirement.findAll();

response.send(actionRequirements);
} catch (e) {
next(e);
}
}

export default {
Expand Down
22 changes: 18 additions & 4 deletions backend/src/controllers/admin-logs/JoblogAdminController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { Job } from "../../models/Job";
import Validator, { ValidationTypeEnum } from "../../utility/Validator";
import { HttpStatusCode } from "axios";

async function getAll(request: Request, response: Response, next: NextFunction) {
/**
* Returns all currently stored Job-Logs
* @param _request
* @param response
* @param next
*/
async function getAll(_request: Request, response: Response, next: NextFunction) {
try {
const user = response.locals.user;
PermissionHelper.checkUserHasPermission(user, "tech.joblog.view");
Expand All @@ -16,13 +22,19 @@ async function getAll(request: Request, response: Response, next: NextFunction)
}
}

/**
* Gets information on a single Job-Log
* @param request
* @param response
* @param next
*/
async function getInformationByID(request: Request, response: Response, next: NextFunction) {
try {
const user = response.locals.user;
const params = request.params as { id: string };
PermissionHelper.checkUserHasPermission(user, "tech.joblog.view");

const params = request.params as { id: string };
Validator.validate(params, { id: [ValidationTypeEnum.NON_NULL, ValidationTypeEnum.NUMBER] });
PermissionHelper.checkUserHasPermission(user, "tech.joblog.view");

const job = await Job.findOne({
where: {
Expand All @@ -36,7 +48,9 @@ async function getInformationByID(request: Request, response: Response, next: Ne
}

response.send(job);
} catch (e) {}
} catch (e) {
next(e);
}
}

export default {
Expand Down
10 changes: 5 additions & 5 deletions backend/src/controllers/admin-logs/SyslogAdminController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import Validator, { ValidationTypeEnum } from "../../utility/Validator";

/**
* Gets all system log entries
* @param request
* @param _request
* @param response
* @param next
*/
async function getAll(request: Request, response: Response, next: NextFunction) {
async function getAll(_request: Request, response: Response, next: NextFunction) {
try {
const user: User = response.locals.user;
PermissionHelper.checkUserHasPermission(user, "tech.syslog.view");

const sysLogs = await SysLog.findAll({
const sysLogs: SysLog[] = await SysLog.findAll({
order: [["id", "desc"]],
attributes: ["id", "method", "path", "createdAt"],
});
Expand All @@ -29,14 +29,14 @@ async function getAll(request: Request, response: Response, next: NextFunction)
async function getInformationByID(request: Request, response: Response, next: NextFunction) {
try {
const user: User = response.locals.user;
const params = request.params;
PermissionHelper.checkUserHasPermission(user, "tech.syslog.view");

const params = request.params;
Validator.validate(params, {
id: [ValidationTypeEnum.NON_NULL],
});

const sysLog = await SysLog.findOne({
const sysLog: SysLog | null = await SysLog.findOne({
where: {
id: params.id,
},
Expand Down
Loading

0 comments on commit 095b22e

Please sign in to comment.