Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mess menu v2 #26

Merged
merged 42 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
17af2c8
Added auto sized text
Nailsonseat Feb 16, 2024
b6f53fa
added message for lost and found
Nailsonseat Feb 16, 2024
6e2f66a
remove unused resource
Nailsonseat Feb 16, 2024
4e1337f
added a list Id attribute to track who listed a item
Nailsonseat Feb 16, 2024
7c042d5
Create uploads folder if not exist
Nailsonseat Feb 16, 2024
14e15d1
added occupant name to room schema
Nailsonseat Feb 16, 2024
fc62bc3
Added delete method for lost and found alongwith logic to remove list…
Nailsonseat Feb 16, 2024
286ca1d
Accomodated listerId inn get, post and put method
Nailsonseat Feb 16, 2024
a64333b
occupant name in post and put method
Nailsonseat Feb 16, 2024
3b9585f
Fix imports and add lost-and-found resource
Nailsonseat Feb 16, 2024
54e1d00
Updated dummy entries to add new attribute
Nailsonseat Feb 16, 2024
b976caf
Add textAlign, maxLength, and maxLines properties to MaterialTextForm…
Nailsonseat Feb 16, 2024
0d714d4
Add listerId field to LostAndFoundItem model
Nailsonseat Feb 16, 2024
79769e4
Add models and update provider in LostAndFoundProvider
Nailsonseat Feb 16, 2024
3525383
Add user models and import auth provider
Nailsonseat Feb 16, 2024
7bc0c84
Add logger and implement deleteLostAndFoundItem method
Nailsonseat Feb 16, 2024
57da56d
Add occupant name to reserveRoom method and add vacateRoom method
Nailsonseat Feb 16, 2024
c2b50b8
Updated lost and found listing info card and added delete functionality
Nailsonseat Feb 16, 2024
707df94
Added logic to vaccant room for the occupier only
Nailsonseat Feb 16, 2024
6d16a8b
Merge branch 'main' into room-vacancy-lost-and-found-two
Nailsonseat Feb 16, 2024
b69898e
Post merge cleanup
Nailsonseat Feb 16, 2024
63d7d87
Messages for room resources
Nailsonseat Feb 16, 2024
5d5de50
Added add and get methods in menu repository
Nailsonseat Feb 17, 2024
5c8c971
added update and delete in menu repo
Nailsonseat Feb 17, 2024
9bd8c70
Add mess menu constants
Nailsonseat Feb 17, 2024
153bf62
Refactor mess_menu.js model
Nailsonseat Feb 17, 2024
dd8b789
Assets update
Nailsonseat Feb 17, 2024
36bc381
Scroll to bottom on select menu and added buttons for update, refresh…
Nailsonseat Feb 17, 2024
e918acc
Added json factories to mess menu
Nailsonseat Feb 17, 2024
4b1affe
Scroll to bottom on submit kitchen name
Nailsonseat Feb 17, 2024
96d36a6
Add mess menu loading and CRUD methods
Nailsonseat Feb 17, 2024
0bfb5a9
Add messMenuListResource.js with GET and POST methods
Nailsonseat Feb 17, 2024
22d9bfe
Add messMenuResource.js for PUT and DELETE methods
Nailsonseat Feb 17, 2024
374c3c0
Add mess menu resources
Nailsonseat Feb 17, 2024
cb9adae
Created a mess menu page for the user side
Nailsonseat Feb 17, 2024
64c152c
Added buttons to for update, delete and refresh
Nailsonseat Feb 17, 2024
c84b6e8
Add UserMessMenu screen to routes
Nailsonseat Feb 17, 2024
f7147ed
Update mess menu file paths
Nailsonseat Feb 17, 2024
a90dba1
Mess menu tile in home
Nailsonseat Feb 17, 2024
5cc6c85
Remove unused imports and clear kitchen name controller
Nailsonseat Feb 17, 2024
bce1c9c
Refactor code to improve performance and readability
Nailsonseat Feb 17, 2024
ecd1355
Fixed allowing empty menu item
Nailsonseat Feb 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import roomResource from "./resources/rooms/roomResource.js";
import lostAndFoundListResource from "./resources/lostAndFound/lostAndFoundListResource.js";
import studentListResource from "./resources/student/studentListResource.js";
import facultyListResource from "./resources/faculty/facultyListResource.js";
import messageResource from "./resources/chatroom/messageListResource.js";
import lostAndFoundResource from "./resources/lostAndFound/lostAndFoundResource.js";
import timetableListResource from "./resources/timetable/timetableListResource.js";
import timetableResource from "./resources/timetable/timetableResource.js";
import messageResource from './resources/chatroom/messageListResource.js'
import messMenuListResource from "./resources/messMenu/messMenuListResource.js";
import messMenuResource from "./resources/messMenu/messMenuResource.js";

const PORT = `${process.env.PORT || 3000}`;
const app = express();
Expand All @@ -38,6 +41,8 @@ app.use("/faculty", facultyResource);
app.use("/faculties", facultyListResource);
app.use("/timetable", timetableResource);
app.use("/timetables", timetableListResource);
app.use("/mess-menu", messMenuResource);
app.use("/mess-menus", messMenuListResource);

app.use("/admin-auth", adminAuthResource);
app.use("/general-auth", generalAuthResource);
Expand All @@ -46,7 +51,8 @@ app.use("/", testResource);
app.use("/rooms", roomListResource);
app.use("/room", roomResource);
app.use("/lost-and-found", lostAndFoundListResource);
app.use("/messages",messageResource);
app.use("/lost-and-found-item", lostAndFoundResource);
app.use("/messages", messageResource);

app.get("/protected", tokenRequired, (req, res) => {
res.json({ message: "Access granted" });
Expand Down
17 changes: 16 additions & 1 deletion backend/constants/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@ export const invalidUserType = "Invalid user type";
export const tokenUpdateError = "Error updating token";
export const badRequest = "Bad request";
export const notFound = "Not found";
export const deleted = "Deleted";
export const deleted = "Deleted";

// Lost and Found
export const itemNotFound = "Item not found";
export const itemAdded = "Item added successfully";
export const itemDeleted = "Item deleted successfully";

// Rooom Vacancy
export const roomNotFound = "Room not found";
export const roomUpdated = "Room updated successfully";
export const roomCreated = "Room created successfully";

// Mess Menu
export const messMenuNotFound = "Mess Menu not found";
export const messMenuAdded = "Mess Menu added successfully";
export const messMenuUpdated = "Mess Menu updated successfully";
9 changes: 8 additions & 1 deletion backend/middlewares/multerConfig.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import multer from "multer";
import fs from "fs";

const uploadsFolder = "uploads/";

if (!fs.existsSync(uploadsFolder)) {
fs.mkdirSync(uploadsFolder);
}

// Define storage configuration
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "uploads/");
cb(null, uploadsFolder);
},
filename: function (req, file, cb) {
cb(null, file.originalname);
Expand Down
4 changes: 4 additions & 0 deletions backend/models/lost_and_found.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const lostAndFoundItemSchema = new mongoose.Schema({
type: String,
required: true,
},
listerId: {
type: String,
required: true,
},
isLost: {
type: Boolean,
required: true,
Expand Down
32 changes: 14 additions & 18 deletions backend/models/mess_menu.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
const mongoose = require('mongoose');
import mongoose from "mongoose";

const messMenuSchema = new mongoose.Schema({
id: {
type: String,
required: true
kitchenName: {
type: String,
required: true,
},
messMenu: {
type: Map,
of: {
type: Map,
of: [String],
},
kitchenName: {
type: String,
required: true
},
messMenu: {
type: Map,
of: {
type: Map,
of: [String]
},
required: true
}
required: true,
},
});

const MessMenu = mongoose.model('MessMenu', messMenuSchema);
const MessMenu = mongoose.model("MessMenu", messMenuSchema);

module.exports = MessMenu;
export default MessMenu;
4 changes: 4 additions & 0 deletions backend/models/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const roomSchema = new mongoose.Schema({
type: String,
default: null,
},
occupantName: {
type: String,
default: null,
},
});

const Room = mongoose.model("Room", roomSchema);
Expand Down
42 changes: 23 additions & 19 deletions backend/resources/lostAndFound/lostAndFoundListResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Router } from "express";
import LostAndFoundItem from "../../models/lost_and_found.js";
import fs from "fs/promises";
import uploader from "../../middlewares/multerConfig.js";
import * as messages from "../../constants/messages.js";

const router = Router();

Expand All @@ -13,7 +14,7 @@ router.get("/", async (req, res) => {

// Create an empty array to store items with images
const itemsWithImages = [];
``

// Iterate through each item
for (const item of items) {
// Check if imagePath is null
Expand All @@ -32,43 +33,46 @@ router.get("/", async (req, res) => {
imagePath: imagePathBase64, // Set imagePath to null if null in the database
description: item.description,
contactNumber: item.contactNumber,
listerId: item.listerId,
isLost: item.isLost,
};

// Push the item with image to the array
itemsWithImages.push(itemWithImage);
}

console.log("Retrieved items:", itemsWithImages.length);

// Send the response with the items
res.json(itemsWithImages);
} catch (error) {
// Handle errors
console.error("Error:", error);
res.status(500).send("Error retrieving items");
res.status(500).json({ message: messages.internalServerError });
}
});

// POST method
router.post("/", uploader.single("image"), async (req, res) => {
// Access the uploaded file using req.file
const file = req.file;
try {
// Access the uploaded file using req.file
const file = req.file;

// Construct the LostAndFoundItem object with data from the request
const newItem = new LostAndFoundItem({
name: req.body.name,
lastSeenLocation: req.body.lastSeenLocation,
imagePath: file ? file.path : null,
description: req.body.description,
contactNumber: req.body.contactNumber,
isLost: req.body.isLost,
});
// Construct the LostAndFoundItem object with data from the request
const newItem = new LostAndFoundItem({
name: req.body.name,
lastSeenLocation: req.body.lastSeenLocation,
imagePath: file ? file.path : null,
description: req.body.description,
contactNumber: req.body.contactNumber,
listerId: req.body.listerId,
isLost: req.body.isLost,
});

// Save the new item to the database
await newItem.save();
// Save the new item to the database
await newItem.save();

res.send("Added new item");
res.json({ message: messages.itemAdded });
} catch (error) {
res.status(500).json({ message: messages.internalServerError });
}
});

export default router;
32 changes: 32 additions & 0 deletions backend/resources/lostAndFound/lostAndFoundResource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import express from "express";
import * as messages from "../../constants/messages.js";
import LostAndFoundItem from "../../models/lost_and_found.js";
import fs from "fs";

const lostAndFoundRouter = express.Router();

// DELETE item by id
lostAndFoundRouter.delete("/:id", async (req, res) => {
const itemId = req.params.id;

try {
const item = await LostAndFoundItem.findByIdAndDelete(itemId);

if (!item) {
return res.status(404).json({ message: messages.itemNotFound });
}

// Delete the image file
fs.unlink(item.imagePath, (err) => {
if (err) {
console.error(err);
}
});

res.json(item);
} catch (err) {
res.status(500).json({ message: messages.internalServerError });
}
});

export default lostAndFoundRouter;
29 changes: 29 additions & 0 deletions backend/resources/messMenu/messMenuListResource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import express from "express";
import * as messages from "../../constants/messages.js";
import MessMenu from "../../models/mess_menu.js";

const messMenuListRouter = express.Router();

// GET method
messMenuListRouter.get("/", async (req, res) => {
try {
const messMenuData = await MessMenu.find();
res.json(messMenuData);
} catch (error) {
res.status(500).json({ message: messages.internalServerError });
}
});

// POST method
messMenuListRouter.post("/", async (req, res) => {
try {
const { kitchenName, messMenu } = req.body;
const newMessMenu = new MessMenu({ kitchenName, messMenu });
await newMessMenu.save();
res.json({ message: messages.messMenuAdded, newMessMenu });
} catch (error) {
res.status(500).json({ message: messages.internalServerError });
}
});

export default messMenuListRouter;
39 changes: 39 additions & 0 deletions backend/resources/messMenu/messMenuResource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import express from "express";
import * as messages from "../../constants/messages.js";
import MessMenu from "../../models/mess_menu.js";

const messMenuRouter = express.Router();

// PUT method
messMenuRouter.put("/:id", async (req, res) => {
try {
const { id } = req.params;
const { messMenu } = req.body;
const currentMenu = await MessMenu.findById(id);

if (!currentMenu) {
return res.status(404).json({ message: messages.messMenuNotFound });
}

currentMenu.messMenu = messMenu;
await currentMenu.save();

res.json({ message: messages.messMenuUpdated });
} catch (error) {
res.status(500).json({ message: messages.internalServerError });
}
});

//DELETE method
messMenuRouter.delete("/:id", async (req, res) => {
try {
const { id } = req.params;
await MessMenu.findByIdAndDelete(id);

res.json({ message: messages.deleted });
} catch (error) {
res.status(500).json({ message: messages.internalServerError });
}
});

export default messMenuRouter;
27 changes: 0 additions & 27 deletions backend/resources/rooms/occupantListResource.js

This file was deleted.

12 changes: 5 additions & 7 deletions backend/resources/rooms/roomListResource.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Router } from "express";
import Room from "../../models/room.js";
import * as messages from "../../constants/messages.js";
const router = Router();

// GET method
Expand All @@ -13,27 +14,24 @@ router.get("/", async (req, res) => {
router.post("/", async (req, res) => {
try {
// Extract data from request body
const { name, vacant, occupantId } = req.body;
const { name, vacant, occupantId, occupantName } = req.body;

// Create a new room instance
const newRoom = new Room({
name,
vacant: vacant || true, // Set default value if not provided
occupantId: occupantId || null, // Set default value if not provided
occupantName: occupantName || null, // Set default value if not provided
});

// Save the new room to the database
await newRoom.save();
console.log("Room created successfully");

// Respond with success message
res
.status(201)
.json({ message: "Room created successfully", room: newRoom });
res.status(201).json({ message: messages.roomCreated, room: newRoom });
} catch (error) {
// Handle errors
console.error("Error creating room:", error);
res.status(500).json({ error: "Internal server error" });
res.status(500).json({ message: messages.internalServerError });
}
});

Expand Down
Loading
Loading