Multiple changes, basic rental CRUD backend implemented.
All responses are now in their own object with context name. Added limit to user based recent results for matches. Moved all code in endpoints inside try and catch. Renamed authentication guard function.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import express from "express";
|
||||
import { authenticationGuard } from "../middleware/authority.js";
|
||||
import { requireAuthenticated } from "../middleware/authority.js";
|
||||
import { needDatabase } from "../middleware/database.js";
|
||||
import userModel from "../schemas/userModel.js";
|
||||
import User from "../schemas/userModel.js";
|
||||
@@ -34,7 +34,7 @@ UserController.post("/login", needDatabase, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
UserController.get("/logout", authenticationGuard, (req, res) => {
|
||||
UserController.get("/logout", requireAuthenticated, (req, res) => {
|
||||
req.session.destroy((err) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
@@ -50,7 +50,7 @@ UserController.get("/logout", authenticationGuard, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
UserController.get("/:id?", needDatabase, authenticationGuard, async (req, res) => {
|
||||
UserController.get("/:id?", needDatabase, requireAuthenticated, async (req, res) => {
|
||||
let user = null;
|
||||
if (req.params.id) {
|
||||
if (req.user.accessLevel > 2) {
|
||||
@@ -66,7 +66,7 @@ UserController.get("/:id?", needDatabase, authenticationGuard, async (req, res)
|
||||
res.status(200).send(user);
|
||||
});
|
||||
|
||||
UserController.patch("/:id?", needDatabase, authenticationGuard, async (req, res) => {
|
||||
UserController.patch("/:id?", needDatabase, requireAuthenticated, async (req, res) => {
|
||||
let user = null;
|
||||
if (req.params.id) {
|
||||
if (req.user.accessLevel > 2) {
|
||||
@@ -114,7 +114,7 @@ UserController.patch("/:id?", needDatabase, authenticationGuard, async (req, res
|
||||
|
||||
/* TODO: Implement middleware for removing users.
|
||||
|
||||
UserController.delete("/:id?", needDatabase, authenticationGuard, async (req, res) => {
|
||||
UserController.delete("/:id?", needDatabase, requireAuthenticated, async (req, res) => {
|
||||
let user = null;
|
||||
if (req.params.id) {
|
||||
if (req.user.accessLevel > 2) {
|
||||
|
||||
Reference in New Issue
Block a user