-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from icefoganalytics/main
Updates
- Loading branch information
Showing
22 changed files
with
854 additions
and
161 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
import { NextFunction, Request, Response } from "express"; | ||
import { validationResult } from "express-validator"; | ||
import { isNil } from "lodash"; | ||
import { UserRole } from "../data/models"; | ||
|
||
export async function ReturnValidationErrors(req: Request, res: Response, next: NextFunction) { | ||
const errors = validationResult(req); | ||
const errors = validationResult(req); | ||
|
||
if (!errors.isEmpty()) { | ||
return res.status(400).json({ errors: errors.array() }); | ||
} | ||
if (!errors.isEmpty()) { | ||
return res.status(400).json({ errors: errors.array() }); | ||
} | ||
|
||
next(); | ||
next(); | ||
} | ||
|
||
export async function RequireAdmin(req: Request, res: Response, next: NextFunction) { | ||
if (isNil(req.user.roles || req.user.roles.length == 0)) { | ||
return res.status(403).json({ error: "Unauthorized" }); | ||
} | ||
|
||
if (!req.user.roles.filter((role: UserRole) => role.name === "System Admin").length) { | ||
return res.status(403).json({ error: "Unauthorized" }); | ||
} | ||
|
||
next(); | ||
} |
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 |
---|---|---|
@@ -1,10 +1,36 @@ | ||
import express, { Request, Response } from "express"; | ||
|
||
import { db as knex } from "../data"; | ||
import { RequireAdmin } from "../middleware"; | ||
import { checkJwt, loadUser } from "../middleware/authz.middleware"; | ||
|
||
export const locationRouter = express.Router(); | ||
|
||
locationRouter.get("/", async (_req: Request, res: Response) => { | ||
const list = await knex("locations"); | ||
const list = await knex("locations").orderBy("name", "asc"); | ||
res.json({ data: list }); | ||
}); | ||
|
||
locationRouter.post("/", checkJwt, loadUser, RequireAdmin, async (req: Request, res: Response) => { | ||
const { code, name, description } = req.body; | ||
|
||
try { | ||
const list = await knex("locations").insert({ code, name, description }); | ||
|
||
res.json({ data: list }); | ||
} catch (err) { | ||
return res.status(400).json({ error: err }); | ||
} | ||
}); | ||
|
||
locationRouter.put("/:code", async (req: Request, res: Response) => { | ||
const { code } = req.params; | ||
const { name, description } = req.body; | ||
|
||
try { | ||
const list = await knex("locations").where({ code }).update({ name, description }); | ||
res.json({ data: list }); | ||
} catch (err) { | ||
return res.status(400).json({ error: err }); | ||
} | ||
}); |
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
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,8 @@ | ||
<p style="margin: 0; margin-bottom: 12px; line-height: 24px; font-size: 16px"> | ||
This email is to notify you that the investigation and resolution of an incident you reported has been completed. The | ||
incident has been marked as closed. | ||
</p> | ||
|
||
<p style="margin: 0; margin-bottom: 12px; line-height: 24px; font-size: 16px"> | ||
To view the details of the incident, please visit <a href="``INCIDENT_URL``">``INCIDENT_URL``</a>. | ||
</p> |
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,8 @@ | ||
<p style="margin: 0; margin-bottom: 12px; line-height: 24px; font-size: 16px"> | ||
This email is to notify you that you have been invited to view or contribute to a reported incident in the YG Safety | ||
Portal. | ||
</p> | ||
|
||
<p style="margin: 0; margin-bottom: 12px; line-height: 24px; font-size: 16px"> | ||
To view the details of the incident, please visit <a href="``INCIDENT_URL``">``INCIDENT_URL``</a>. | ||
</p> |
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
Oops, something went wrong.