-
Notifications
You must be signed in to change notification settings - Fork 1
/
routes.ts
17 lines (13 loc) · 929 Bytes
/
routes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import {Router} from "oak";
import {addHero, deleteHero, getHero, getHeroes, searchHeroes, updateHero} from "./controller/hero_controller.ts";
import {login} from "./controller/auth_controller.ts";
import {authorityGuard} from "./middleware/authority_guard.ts";
const router = new Router({prefix: "/api"});
router.post("/auth", login);
router.get("/heroes/", (context, next) => authorityGuard(context, next, ["USER"]), searchHeroes)
.get("/heroes", (context, next) => authorityGuard(context, next, ["USER"]), getHeroes)
.get("/heroes/:id", (context, next) => authorityGuard(context, next, ["USER"]), getHero)
.post("/heroes", (context, next) => authorityGuard(context, next, ["ADMIN"]), addHero)
.put("/heroes", (context, next) => authorityGuard(context, next, ["ADMIN"]), updateHero)
.delete("/heroes/:id", (context, next) => authorityGuard(context, next, ["ADMIN"]), deleteHero);
export default router;