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

Fix alot of linting errors #67

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ services:
app:
container_name: app
build:
context: ./app
context: .
dockerfile: Dockerfile
env_file:
- app/.env
- ./.env
ports:
- "6000:3000"
networks:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"dependencies": {
"@yudiel/react-qr-scanner": "^2.0.4",
"caniuse-lite": "^1.0.30001689",
"moment": "^2.30.1",
"moment-timezone": "^0.5.45",
"mongoose": "^8.4.3",
Expand Down
4 changes: 4 additions & 0 deletions public/icons/add-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/icons/remove-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 14 additions & 14 deletions src/app/admin/manage/order/[[...orderId]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { useEffect, useState } from "react";
import { IDetectedBarcode, Scanner } from "@yudiel/react-qr-scanner";
import { getFromLocalStorage } from "@/lib/localStorage";
import WithAuth from "@/app/admin/WithAuth";
import { ORDER_STATES, OrderDocument, OrderStatus, OrderWithId } from "@/model/order";
import { Order, ORDER_STATES, OrderDocument, OrderStatus } from "@/model/order";
import { formatDateTime, getDateFromTimeSlot } from "@/lib/time";
import SearchInput from "@/app/components/SearchInput";
import ErrorMessage from "@/app/components/ErrorMessage";

const Page = ({ params }: { params: { orderId: string } }) => {
const [error, setError] = useState('');

const [orders, setOrders] = useState<OrderWithId[]>([]);
const [filteredOrders, setFilteredOrders] = useState([] as OrderWithId[]); // state to hold order status]
const [orders, setOrders] = useState<OrderDocument[]>([]);
const [filteredOrders, setFilteredOrders] = useState([] as OrderDocument[]); // state to hold order status]
const [filter, setFilter] = useState(''); // state to hold order status

const [noFinished, setNoFinished] = useState(true);
Expand Down Expand Up @@ -41,7 +41,7 @@ const Page = ({ params }: { params: { orderId: string } }) => {
}
return data;
})
.then(data => setOrders(data))
.then(data => setOrders(data as OrderDocument[]))
.catch(error => {
console.error('Error fetching orders', error);
setError(error.message)
Expand All @@ -63,11 +63,11 @@ const Page = ({ params }: { params: { orderId: string } }) => {
// Filter the orders
useEffect(() => {
if (filter) {
setFilteredOrders(orders.filter((order: OrderWithId) => {
setFilteredOrders(orders.filter((order) => {
if (order.name.toLowerCase().includes(filter.toLowerCase())) {
return true;
}
if (order._id.toLowerCase().includes(filter.toLowerCase())) {
if (order._id.toString().toLowerCase().includes(filter.toLowerCase())) {
return true;
}
if (order.status.toLowerCase().includes(filter.toLowerCase())) {
Expand All @@ -86,7 +86,7 @@ const Page = ({ params }: { params: { orderId: string } }) => {
* @param status
*/
const updateOrderStatus = (_id: string, status: OrderStatus) => {
const order = orders.find(order => order._id === _id);
const order = orders.find(order => order._id.toString() === _id);
if (!order) {
setError('Order not found');
return;
Expand All @@ -108,7 +108,7 @@ const Page = ({ params }: { params: { orderId: string } }) => {
return data;
})
.then(() => {
setOrders(orders.map(order => order._id === _id ? newOrder : order));
setOrders(orders.map(order => order._id.toString() === _id ? newOrder as OrderDocument : order));
})
.catch(error => setError(error.message));
}
Expand All @@ -130,7 +130,7 @@ const Page = ({ params }: { params: { orderId: string } }) => {
.then(() => {
// Update the order by id
const newOrders = orders.map((order) => {
if (order._id === _id) {
if (order._id.toString() === _id) {
order.isPaid = isPaid;
}
return order;
Expand Down Expand Up @@ -205,12 +205,12 @@ const Page = ({ params }: { params: { orderId: string } }) => {
.filter(order => noFinished ? !['delivered', 'cancelled'].includes(order.status) : true) // Filter by finished
.toSorted((a, b) => getDateFromTimeSlot(a.timeslot).toDate().getTime() - getDateFromTimeSlot(b.timeslot).toDate().getTime()) // Sort by date
.map((order, index) => ( // Map the orders
<div key={order._id + index} className="w-full px-4 py-4 bg-white rounded-lg shadow-sm">
<div key={order._id.toString() + index} className="w-full px-4 py-4 bg-white rounded-lg shadow-sm">
<div className="mb-4 p-4 bg-white rounded-lg shadow-sm">
<div className="flex justify-between items-center mb-2">
<span className="text-lg font-semibold text-gray-800">{order.name}</span>
<a className="text-xs font-light text-gray-500" href={order_url(order._id)}>
{order._id}
<a className="text-xs font-light text-gray-500" href={order_url(order._id.toString())}>
{order._id.toString()}
</a>
</div>

Expand Down Expand Up @@ -275,7 +275,7 @@ const Page = ({ params }: { params: { orderId: string } }) => {
key={state}
disabled={state === order.status}
className={`rounded-full px-4 py-2 text-sm font-medium transition duration-200 ${state === order.status ? 'bg-green-500 text-white' : 'bg-gray-300 text-gray-700 hover:bg-gray-400'} focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed`}
onClick={() => updateOrderStatus(order._id, state)}
onClick={() => updateOrderStatus(order._id.toString(), state)}
>
{state}
</button>
Expand All @@ -284,7 +284,7 @@ const Page = ({ params }: { params: { orderId: string } }) => {
className={`rounded-full px-4 py-2 text-sm font-medium transition duration-200
${order.isPaid ? 'bg-green-300 text-green-700 hover:bg-green-400' : 'bg-red-300 text-red-700 hover:bg-red-400'}
focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed`}
onClick={() => setOrderAsPaid(order._id, !order.isPaid)}
onClick={() => setOrderAsPaid(order._id.toString(), !order.isPaid)}
>
{order.isPaid ? 'Paid' : 'Not Paid'}
</button>
Expand Down
4 changes: 2 additions & 2 deletions src/app/admin/manage/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const Page = () => {
.then(data => setStatus(data.status))
.catch((error) => {
console.error('There was an error!', error);
setMessage(error)
setMessage('Error getting system status')
})
}

Expand Down Expand Up @@ -135,4 +135,4 @@ const Page = () => {
);
}

export default WithAuth(Page);
export default Page;
27 changes: 14 additions & 13 deletions src/app/admin/prepare/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { useEffect, useState } from "react";
import { getFromLocalStorage } from "@/lib/localStorage";
import ErrorMessage from "@/app/components/ErrorMessage.jsx";
import { getDateFromTimeSlot } from "@/lib/time";
import { ItemStatus, Order, OrderWithId } from "@/model/order";
import { ItemStatus } from "@/model/order";
import type { OrderDocument, OrderModel } from "@/model/order";
import WithAuth from "@/app/admin/WithAuth";
import SearchInput from "@/app/components/SearchInput";
import './Prepare.css';
Expand All @@ -14,9 +15,9 @@ const Page = () => {
const [error, setError] = useState('');

const [filter, setFilter] = useState('')
const [orders, setOrders] = useState<OrderWithId[]>([]);
const [filteredOrders, setFilteredOrders] = useState<OrderWithId[]>([]);
const [ordersByTimeslot, setOrdersByTimeslot] = useState(new Map<string, OrderWithId[]>)
const [orders, setOrders] = useState<OrderDocument[]>([]);
const [filteredOrders, setFilteredOrders] = useState<OrderDocument[]>([]);
const [ordersByTimeslot, setOrdersByTimeslot] = useState(new Map<string, OrderDocument[]>)

const [currentTime, setCurrentTime] = useState(new Date());
const [isClient, setIsClient] = useState(false);
Expand Down Expand Up @@ -59,9 +60,9 @@ const Page = () => {
// Filter the orders
useEffect(() => {
if (filter) {
setFilteredOrders(orders.filter((order: OrderWithId) =>
setFilteredOrders(orders.filter((order) =>
order.name.toLowerCase().includes(filter.toLowerCase()) ||
order._id.toLowerCase().includes(filter.toLowerCase()) ||
order._id.toString().toLowerCase().includes(filter.toLowerCase()) ||
order.status.toLowerCase().includes(filter.toLowerCase()) ||
order.totalPrice.toString().includes(filter) ||
order.timeslot.includes(filter) ||
Expand All @@ -72,7 +73,7 @@ const Page = () => {
}, [filter, orders]);

useEffect(() => {
const ordersByTimeslot = new Map<string, OrderWithId[]>
const ordersByTimeslot = new Map<string, OrderDocument[]>
filteredOrders.forEach(order => {
const timeslot = order.timeslot
// Add order to list at the respective timeslot
Expand All @@ -94,10 +95,10 @@ const Page = () => {
setOrdersByTimeslot(sortedOrdersByTimeslots)
}, [filteredOrders])

const setFoodStatusFromLocalStorage = (orders: OrderWithId[]) => {
const setFoodStatusFromLocalStorage = (orders: OrderDocument[]) => {
// Get from local storage
orders.map(order => {
let foodItems = getFromLocalStorage(`foodItems.${order._id}`, []);
let foodItems = getFromLocalStorage(`foodItems.${order._id.toString()}`, []);
if (!foodItems || foodItems.length === 0) {
return;
}
Expand All @@ -123,7 +124,7 @@ const Page = () => {
* @param status
*/
const updateItemStatus = (_id: string, itemIndex: number, status: ItemStatus) => {
const order = orders.find(order => order._id === _id);
const order = orders.find(order => order._id.toString() === _id);
if (!order) {
console.error('Order not found');
return;
Expand All @@ -148,7 +149,7 @@ const Page = () => {
})
.then(() => {
// Update the order by id
setOrders(orders.map(order => order._id === _id ? newOrder : order));
setOrders(orders.map(order => order._id.toString() === _id ? newOrder as OrderDocument : order));
})
.catch(error => setError(error.message));
};
Expand All @@ -164,7 +165,7 @@ const Page = () => {
* Check if the order has a comment
* @param order
*/
const hasComment = (order: Order) => {
const hasComment = (order: OrderDocument) => {
return (
typeof order.comment === "string" &&
order.comment != "" &&
Expand Down Expand Up @@ -259,7 +260,7 @@ const Page = () => {
<td className={`px-4 py-2 text-xs md:text-sm font-medium w-1/6`}>
<button
className="p-1 rounded-md border border-gray-300 bg-white text-xs md:text-sm font-medium text-gray-600 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
onClick={() => updateItemStatus(order._id, itemIndex, item.status === 'readyToCook' ? 'prepping' : 'readyToCook')}>
onClick={() => updateItemStatus(order._id.toString(), itemIndex, item.status === 'readyToCook' ? 'prepping' : 'readyToCook')}>
{item.status === 'readyToCook' ? '✅ Done' : item.status}
</button>
</td>
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/auth/login/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function POST(req: Request): Promise<Response> {

try {
// Validate token
const correct_token: string = process.env.PAYMENT_ADMIN_TOKEN || tokens.PAYMENT_ADMIN_TOKEN || '';
const correct_token = process.env.PAYMENT_ADMIN_TOKEN;
if (!correct_token || correct_token.length === 0) {
return NextResponse.json({
message: 'Token not set'
Expand Down
10 changes: 6 additions & 4 deletions src/app/api/manage/db/delete/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Fill the database
import { Food } from "@/model/food";
import { FoodModel } from "@/model/food";
import { headers } from "next/headers";
import { extractBearerFromHeaders, validateToken } from "@/lib/auth";
import dbConnect from "@/lib/dbConnect";
import { Order } from "@/model/order";
import { OrderModel } from "@/model/order";
import { NextResponse } from "next/server";
import { System } from "@/model/system";
import { constants } from "@/config";

// Thanks to https://medium.com/phantom3/next-js-14-build-prerender-error-fix-f3c51de2fe1d
export const dynamic = "force-dynamic";
Expand All @@ -25,8 +27,8 @@ export async function POST() {
}, { status: 401 });
}

await Food.deleteMany({})
await Order.deleteMany({})
await FoodModel.deleteMany({})
await OrderModel.deleteMany({})

return Response.json({ message: 'Successfully deleted database' })
}
Loading
Loading