Skip to content

Commit

Permalink
Add major functionality to admin editor
Browse files Browse the repository at this point in the history
  • Loading branch information
micahlt committed Nov 7, 2024
1 parent 6649a4e commit cd83ba8
Show file tree
Hide file tree
Showing 14 changed files with 684 additions and 60 deletions.
238 changes: 238 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
},
"dependencies": {
"@heroicons/react": "^2.1.5",
"@radix-ui/react-dialog": "^1.1.2",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-tooltip": "^1.1.3",
"@remixicon/react": "^4.5.0",
"@tremor/react": "^3.18.3",
Expand Down
15 changes: 13 additions & 2 deletions pages/api/foods.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,19 @@ export default async function handler(req, res) {
await client.connect();
const db = client.db(dbName);
const collection = db.collection("foods");
const food = await collection.find({ name: { $in: req.body } }).toArray();
const newBody = req.body.map((f) => f.toLowerCase());
const foods = await collection.find({ name: { $in: newBody } }).toArray();
client.close();
return res.status(200).json(food);
req.body.forEach((food) => {
if (foods.findIndex((f) => f.name.toLowerCase() == food.toLowerCase()) == -1) {
foods.push({
_id: `${Math.random() * 10000}`,
name: food.toLowerCase(),
rating: 0,
ratings: 0
})
}
})
return res.status(200).json(foods);
}
}
15 changes: 12 additions & 3 deletions pages/api/meals.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { MongoClient } from "mongodb";
import firebaseAdmin from "firebase-admin";
import { revalidatePath } from "next/cache";
export default async function handler(req, res) {
// Retrieving meals by date
if (req.method == "GET") {
console.log(req.query.date);
const client = new MongoClient(process.env.CAFMONGO);
const dbName = process.env.CAFMONGO_DB;
await client.connect();
const db = client.db(dbName);
const collection = db.collection("menu");
const foods = await collection.findOne({
date: req.query.date,
date: req.query.date
});
client.close();
return res
.setHeader("Cache-Control", "max-age=7200, public")
.setHeader("Cache-Control", "no-cache, no-store, must-revalidate")
.setHeader("Pragma", "no-cache")
.setHeader("Expires", "0")
.status(200)
.json(foods);
} else if (req.method == "POST") {
Expand Down Expand Up @@ -74,7 +78,12 @@ export default async function handler(req, res) {
);
await client.close();
await firebaseApp.delete();
return res.status(200).json(result);
revalidatePath(`/api/meals?date=${req.body.date}`);
return res
.setHeader("Cache-Control", "no-cache, no-store, must-revalidate")
.setHeader("Pragma", "no-cache")
.setHeader("Expires", "0")
.status(200).json(result);
} else {
res.status(401).json({
error: "You are not a Caf App administrator.",
Expand Down
Loading

0 comments on commit cd83ba8

Please sign in to comment.