forked from TomDoesTech/Testing-Express-REST-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.ts
More file actions
64 lines (54 loc) · 1.66 KB
/
Copy pathroutes.ts
File metadata and controls
64 lines (54 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Express, Request, Response } from "express";
import {
createProductHandler,
getProductHandler,
updateProductHandler,
} from "./controller/product.controller";
import {
createUserSessionHandler,
getUserSessionsHandler,
deleteSessionHandler,
} from "./controller/session.controller";
import { createUserHandler } from "./controller/user.controller";
import requireUser from "./middleware/requireUser";
import validateResource from "./middleware/validateResource";
import {
createProductSchema,
deleteProductSchema,
getProductSchema,
updateProductSchema,
} from "./schema/product.schema";
import { createSessionSchema } from "./schema/session.schema";
import { createUserSchema } from "./schema/user.schema";
function routes(app: Express) {
app.get("/healthcheck", (req: Request, res: Response) => res.sendStatus(200));
app.post("/api/users", validateResource(createUserSchema), createUserHandler);
app.post(
"/api/sessions",
validateResource(createSessionSchema),
createUserSessionHandler
);
app.get("/api/sessions", requireUser, getUserSessionsHandler);
app.delete("/api/sessions", requireUser, deleteSessionHandler);
app.post(
"/api/products",
[requireUser, validateResource(createProductSchema)],
createProductHandler
);
app.put(
"/api/products/:productId",
[requireUser, validateResource(updateProductSchema)],
updateProductHandler
);
app.get(
"/api/products/:productId",
validateResource(getProductSchema),
getProductHandler
);
app.delete(
"/api/products/:productId",
[requireUser, validateResource(deleteProductSchema)],
getProductHandler
);
}
export default routes;