Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoerlitz committed Mar 8, 2024
1 parent c1ea026 commit 2c57d5c
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import { Job } from "./models/Job";
import JobLibrary from "./libraries/JobLibrary";
import dayjs from "dayjs";
import { Config } from "./core/Config";
import SyslogAdminController from "./controllers/logs/SyslogAdminController";
import JoblogAdminController from "./controllers/logs/JoblogAdminController";
import SyslogAdminController from "./controllers/admin-logs/SyslogAdminController";
import JoblogAdminController from "./controllers/admin-logs/JoblogAdminController";

const routerGroup = (callback: (router: Router) => void) => {
const router = Router();
Expand Down
45 changes: 45 additions & 0 deletions src/controllers/admin-logs/JoblogAdminController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { NextFunction, Request, Response } from "express";
import PermissionHelper from "../../utility/helper/PermissionHelper";
import { Job } from "../../models/Job";
import Validator, { ValidationTypeEnum } from "../../utility/Validator";
import { HttpStatusCode } from "axios";

async function getAll(request: Request, response: Response, next: NextFunction) {
try {
const user = response.locals.user;
PermissionHelper.checkUserHasPermission(user, "tech.joblog.view");

const jobs = await Job.findAll();
response.send(jobs);
} catch (e) {
next(e);
}
}

async function getInformationByID(request: Request, response: Response, next: NextFunction) {
try {
const user = response.locals.user;
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: {
id: params.id,
},
});

if (job == null) {
response.sendStatus(HttpStatusCode.NotFound);
return;
}

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

export default {
getAll,
getInformationByID,
};
54 changes: 54 additions & 0 deletions src/controllers/admin-logs/SyslogAdminController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { NextFunction, Request, Response } from "express";
import PermissionHelper from "../../utility/helper/PermissionHelper";
import { SysLog } from "../../models/SysLog";
import { User } from "../../models/User";
import Validator, { ValidationTypeEnum } from "../../utility/Validator";

/**
* Gets all system log entries
* @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, "tech.syslog.view");

const sysLogs = await SysLog.findAll({
order: [["id", "desc"]],
attributes: ["id", "method", "path", "createdAt"],
});

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

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");

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

const sysLog = await SysLog.findOne({
where: {
id: params.id,
},
});

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

export default {
getAll,
getInformationByID,
};

0 comments on commit 2c57d5c

Please sign in to comment.