Skip to content

Commit 840de5b

Browse files
committed
fix: update lock file, routes, controllers and add public assets
1 parent fd8dbe0 commit 840de5b

15 files changed

+119
-92
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
<img src="https://img.shields.io/badge/WebSocket-ws-010101?style=flat-square&logo=socket.io&logoColor=white" alt="WebSocket" />
1212
</p>
1313

14+
<p align="center">
15+
<img src="public/assets/images/museum%20management%20api.png" alt="Museum Management API" width="100%" />
16+
</p>
17+
1418
Production-ready REST API for a digital museum platform: content, auth, bookings, forum, and real-time features. Built with a **modular, microservice-friendly** design and standard Web API practices.
1519

1620
## Key features
2.3 MB
Loading

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
background: var(--accent-soft);
140140
transform: translateY(-1px);
141141
box-shadow: 0 8px 24px rgba(184, 134, 11, 0.35);
142+
color: #fff;
142143
}
143144

144145
.btn--outline {

server/controllers/post_like.controller.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,38 @@ import { postLikeService } from "../services";
44
export class PostLikesController {
55
async likePost(req: Request, res: Response) {
66
try {
7-
const data = req.body;
7+
// Use authenticated user (required by route); ignore body userId for security
8+
const userId = req.user?.id ?? req.body.userId;
9+
const postId = req.body.postId;
810

9-
if (!data.userId || !data.postId)
10-
return res.status(400).send({
11+
if (!userId || !postId)
12+
return res.status(400).json({
1113
error: true,
12-
message: "Missing required fields post id and author id",
14+
message: "Missing required fields: postId (and authentication for userId)",
1315
});
1416

15-
const content = await postLikeService.postLike(data);
17+
const content = await postLikeService.postLike({ userId, postId });
1618
res.json(content);
1719
} catch (error) {
18-
res.status(500).json({ error: "Failed like a post with id: " + req.body.postId });
20+
res.status(500).json({ error: "Failed to like post with id: " + req.body?.postId });
1921
}
2022
}
2123

2224
async unlikePost(req: Request, res: Response) {
23-
const data = req.body;
25+
try {
26+
const userId = req.user?.id ?? req.body.userId;
27+
const postId = req.body.postId;
2428

25-
if (!data.userId || !data.postId)
26-
return res.status(400).send({
27-
error: true,
28-
message: "Missing required fields post id and author id",
29-
});
29+
if (!userId || !postId)
30+
return res.status(400).json({
31+
error: true,
32+
message: "Missing required fields: postId (and authentication for userId)",
33+
});
3034

31-
try {
32-
const content = await postLikeService.unlikePost(data);
35+
const content = await postLikeService.unlikePost({ userId, postId });
3336
res.json(content);
3437
} catch (error) {
35-
res.status(500).json({ error: "Failed to unlike a post with id: " + req.body.postId });
38+
res.status(500).json({ error: "Failed to unlike post with id: " + req.body?.postId });
3639
}
3740
}
3841
}

server/controllers/user.controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class UserController {
8686
try {
8787
const { email } = req.params;
8888
await userService.deleteUserByEmail(email);
89-
res.sendStatus(204).send({ message: "User deleted successfully" });
89+
res.sendStatus(204);
9090
} catch (error) {
9191
res.status(500).json({ error: "Failed to delete user" });
9292
}
@@ -97,9 +97,9 @@ export class UserController {
9797
try {
9898
const { id } = req.params;
9999
await userService.deleteUserById(id);
100-
res.sendStatus(204).send({ message: "User deleted successfully" });
100+
res.sendStatus(204);
101101
} catch (error) {
102-
console.error("\n\n 💥💥💥💥💥💥💥💥💥 rror deleting user:", error);
102+
console.error("Error deleting user:", error);
103103
res.status(500).json({ error: "Failed to delete user" });
104104
}
105105
}

server/routes/admin-route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { requireAdmin } from "../../config/auth/auth-config";
44

55
const router = Router();
66

7-
// router.use(requireAdmin);
7+
// All admin routes require admin role
8+
router.use(requireAdmin);
89

910
// Get all contact messages (admin only)
1011
router.get("/admin/contact-messages", adminController.getAllContactMessages);

server/routes/auth-routes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Router } from "express";
22
import passport from "passport";
33
import { userService } from "../services";
4-
import { hashPassword } from "../../config/auth/auth-config";
4+
import { hashPassword, requireAuth } from "../../config/auth/auth-config";
55

66
const authRoute = Router();
77

@@ -57,8 +57,8 @@ authRoute.post("/login", (req, res, next) => {
5757
)(req, res, next);
5858
});
5959

60-
// Logout endpoint
61-
authRoute.post("/logout", (req, res, next) => {
60+
// Logout endpoint (authenticated only per API spec)
61+
authRoute.post("/logout", requireAuth, (req, res, next) => {
6262
req.logout((err) => {
6363
if (err) {
6464
console.log("\n\n Logging out user:", err);

server/routes/bookings-route.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,29 @@ import { Router } from "express";
22
import { WebSocketServer } from "ws";
33

44
import { bookingController } from "../controllers";
5+
import { requireAuth, requireAttendant } from "../../config/auth/auth-config";
56

67
export default function bookingRoutes(wss: WebSocketServer) {
78
const router = Router();
89

9-
// Create a booking
10+
// Create a booking (optional auth: session sets userId if present)
1011
router.post("/bookings", async (req, res) =>
1112
(await bookingController.createBooking(req, res))(wss)
1213
);
1314

14-
// Get bookings (user-specific or all based on user type)
15-
router.get("/bookings", bookingController.getAllBookings);
15+
// Get bookings (authenticated; visitors see own, attendants/admins see all)
16+
router.get("/bookings", requireAuth, bookingController.getAllBookings);
1617

17-
// Get booking by ID
18-
router.get("/bookings/:id", bookingController.getBookingById);
19-
20-
// Update booking status (attendant-specific)
21-
router.patch("/bookings/attendant/:id/status", bookingController.updateBookingStatus);
22-
23-
// get specific booking for a user by id
24-
router.get("/bookings/users/:userId", bookingController.getBookingsByUserId);
25-
26-
// get booking by id
27-
router.get("/bookings/:id", bookingController.getBookingById);
18+
// More specific paths before /bookings/:id (RESTful route order)
19+
router.get("/bookings/users/:userId", requireAuth, bookingController.getBookingsByUserId);
20+
router.patch(
21+
"/bookings/attendant/:id/status",
22+
requireAttendant,
23+
bookingController.updateBookingStatus
24+
);
2825

29-
// delete booking
30-
// router.delete("/bookings/:id", bookingController.deleteBooking);
26+
// Get booking by ID (authenticated)
27+
router.get("/bookings/:id", requireAuth, bookingController.getBookingById);
3128

3229
return router;
3330
}

server/routes/contact-route.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
import { Router } from "express";
2-
import { contactService } from "../services";
3-
import {
4-
ContactMessage,
5-
insertContactMessageSchema,
6-
} from "../../config/database/schema/schema-types";
7-
import { z } from "zod";
82
import { contactController } from "../controllers";
3+
import { requireAuth } from "../../config/auth/auth-config";
94

105
const router = Router();
116

12-
// Submit contact form
7+
// Submit contact form (public per API spec)
138
router.post("/contact_messages", contactController.createContactMessage);
149

15-
// Get all contact messages
16-
router.get("/contact_messages", contactController.getAllContactMessages);
17-
18-
// Mark a contact message as read
19-
router.patch("/contact_messages/:id/read", contactController.markContactMessageAsRead);
20-
21-
// Get unread contact messages count
22-
router.get("/contact_messages/unread_count", contactController.getUnreadContactMessagesCount);
10+
// Authenticated contact message operations (list, unread count, mark read)
11+
router.get("/contact_messages", requireAuth, contactController.getAllContactMessages);
12+
router.get(
13+
"/contact_messages/unread_count",
14+
requireAuth,
15+
contactController.getUnreadContactMessagesCount
16+
);
17+
router.patch(
18+
"/contact_messages/:id/read",
19+
requireAuth,
20+
contactController.markContactMessageAsRead
21+
);
2322

2423
export default router;

server/routes/forum-route.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,32 @@ import { Router } from "express";
22
import { WebSocketServer } from "ws";
33

44
import { forumController } from "../controllers";
5+
import { requireAuth } from "../../config/auth/auth-config";
56

67
export default function forumRoutes(wss: WebSocketServer) {
78
const router = Router();
89

9-
// Get all posts
10+
// Get all posts (public; attendantOnly filter requires auth in controller)
1011
router.get("/posts", forumController.getAllPosts);
1112

12-
// Get post by ID
13+
// Get post by ID (public; attendant-only access enforced in controller)
1314
router.get("/posts/:id", forumController.getPostById);
1415

15-
// Create a new post
16-
router.post("/posts", async (req, res) => (await forumController.createPost(req, res))(wss));
16+
// Create a new post (authenticated per API spec)
17+
router.post(
18+
"/posts",
19+
requireAuth,
20+
async (req, res) => (await forumController.createPost(req, res))(wss)
21+
);
1722

18-
// Add comment to a post
19-
router.post("/posts/:id/comments", async (req, res) =>
20-
(await forumController.createComment(req, res))(wss)
23+
// Add comment to a post (authenticated per API spec)
24+
router.post(
25+
"/posts/:id/comments",
26+
requireAuth,
27+
async (req, res) => (await forumController.createComment(req, res))(wss)
2128
);
2229

23-
// get comment by id
30+
// Get comments by post ID
2431
router.get("/posts/:id/comments", forumController.getCommentsByPostId);
2532

2633
return router;

0 commit comments

Comments
 (0)