generated from Archit404Error/MERN-webapp
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into email-notifications-setting
- Loading branch information
Showing
26 changed files
with
775 additions
and
199 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
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,23 +1,40 @@ | ||
import { Router, RequestHandler, Request, Response } from "express"; | ||
import { auth, NoAuth } from "../middleware/auth"; | ||
import { | ||
auth, | ||
NoAuth, | ||
authIfAdmin, | ||
authIfSupervisor, | ||
} from "../middleware/auth"; | ||
import { attempt } from "../utils/helpers"; | ||
import aboutController from "./controllers"; | ||
|
||
const aboutRouter = Router(); | ||
|
||
let useAuth: RequestHandler; | ||
let useAdminAuth: RequestHandler; | ||
let useSupervisorAuth: RequestHandler; | ||
|
||
process.env.NODE_ENV === "test" | ||
? (useAuth = NoAuth as RequestHandler) | ||
: (useAuth = auth as RequestHandler); | ||
? ((useAuth = NoAuth as RequestHandler), | ||
(useAdminAuth = NoAuth as RequestHandler), | ||
(useSupervisorAuth = NoAuth as RequestHandler)) | ||
: ((useAuth = auth as RequestHandler), | ||
(useAdminAuth = authIfAdmin as RequestHandler), | ||
(useSupervisorAuth = authIfSupervisor as RequestHandler)); | ||
|
||
aboutRouter.get("/", useAuth, async (req: Request, res: Response) => { | ||
attempt(res, 200, () => aboutController.getAboutPageContent()); | ||
}); | ||
|
||
aboutRouter.patch("/:pageid", useAuth, async (req: Request, res: Response) => { | ||
const { newContent } = req.body; | ||
attempt(res, 200, () => aboutController.updateAboutPageContent(req.params.pageid, newContent)); | ||
}); | ||
aboutRouter.patch( | ||
"/:pageid", | ||
useAdminAuth, | ||
async (req: Request, res: Response) => { | ||
const { newContent } = req.body; | ||
attempt(res, 200, () => | ||
aboutController.updateAboutPageContent(req.params.pageid, newContent) | ||
); | ||
} | ||
); | ||
|
||
export default aboutRouter; | ||
export default aboutRouter; |
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.