-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |