You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dick/src/routes/route.user.ts

37 lines
1010 B

3 years ago
import { Request, Response, Router } from "express"
import { adminCheck, authCheck, wrap } from "../utils/utils"
import { TEMPLATE } from "../CONSTANTS"
import { Pager } from "../Pager"
import { parseAuthFile } from "../utils/assJSONStructure"
export const userRoutes = (app: Router) => {
// User Profile
app.get(
"/",
authCheck,
wrap,
async (req: Request, res: Response) => {
await Pager.render(res, req, TEMPLATE.USER, {})
}
)
// External Viewing Of Other User Profiles (Admin Only)
app.get(
"/:userID",
authCheck,
adminCheck,
wrap,
async (req: Request, res: Response) => {
const allUsers = parseAuthFile()
const User = allUsers.find((user) => user.username === req.params.userID)
if (!User) {
// TODO ADD USER NOT FOUND PAGE FOR THIS ERROR INSTEAD OF SENDING A 404
return Pager.render(res, req, TEMPLATE.ERRORS[404])
}
return Pager.render(res, req, TEMPLATE.USER, {
params: req.params,
})
}
)
}