Compare commits
10 Commits
bcf3cc08bb
...
dev_v1
Author | SHA1 | Date | |
---|---|---|---|
478f03452d | |||
7faf95188d | |||
79df00a17e | |||
d1625d7e47 | |||
a8377e5ec3 | |||
8f1d401aa1 | |||
226a267ccb | |||
fd9496645a | |||
33bb64f44b | |||
2cf82c8dcb |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -111,4 +111,6 @@ backend/public/uploads/
|
||||
# API keys and secrets (additional protection)
|
||||
config/
|
||||
secrets/
|
||||
keys/
|
||||
keys/
|
||||
|
||||
ToDo.txt
|
11
Docs/HELP.md
Normal file
11
Docs/HELP.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Hilfe Seite
|
||||
|
||||
Hier finden Sie Informationen zur Verwendung des Systems.
|
||||
|
||||
## Unerwartete Probleme
|
||||
|
||||
Falls unerwartetet Probleme im Web oder im Safe auftreten sollten, können Sie den Support via Teams kontaktieren.
|
||||
|
||||
**Kontaktpersonen:**
|
||||
- Theis Gaedigk (Web & Safe)
|
||||
- Niklas Brunke (Safe)
|
@@ -8,7 +8,7 @@ On this page you will learn how my API works.
|
||||
|
||||
When you look at my backend folder and file structure, you can see that I have two files called `API`. The first file called `api.js` is for my web frontend, because this file works together with my JWT token service.
|
||||
|
||||
But I have built a second API. You can see the second API file in the same directory, the file is called `apiV2.js`.
|
||||
**\*But I have built a second API. You can see the second API file in the same directory, the file is called `apiV2.js`.**
|
||||
|
||||
This is the file that you can use to build an API.
|
||||
|
||||
@@ -45,21 +45,114 @@ Returns a list of all items and their details.
|
||||
#### Example Request
|
||||
|
||||
```
|
||||
GET /apiV2/items/your_admin_key
|
||||
GET https://backend.insta.the1s.de/apiV2/items/your_admin_key
|
||||
```
|
||||
|
||||
#### Example Response
|
||||
|
||||
```
|
||||
[
|
||||
{
|
||||
"id": 1,
|
||||
"item_name": "DJI 1er Mikro",
|
||||
"can_borrow_role": "4",
|
||||
"inSafe": 1
|
||||
},
|
||||
...
|
||||
]
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"id": 1,
|
||||
"item_name": "DJI 1er Mikro",
|
||||
"can_borrow_role": 4,
|
||||
"inSafe": 1,
|
||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"item_name": "DJI 2er Mikro 1",
|
||||
"can_borrow_role": 4,
|
||||
"inSafe": 1,
|
||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"item_name": "DJI 2er Mikro 2",
|
||||
"can_borrow_role": 4,
|
||||
"inSafe": 1,
|
||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"item_name": "Rode Richt Mikrofon",
|
||||
"can_borrow_role": 2,
|
||||
"inSafe": 1,
|
||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"item_name": "Kamera Stativ",
|
||||
"can_borrow_role": 1,
|
||||
"inSafe": 1,
|
||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
"item_name": "SONY Kamera - inkl. Akkus und Objektiv",
|
||||
"can_borrow_role": 1,
|
||||
"inSafe": 1,
|
||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
"item_name": "MacBook inkl. Adapter",
|
||||
"can_borrow_role": 2,
|
||||
"inSafe": 1,
|
||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"item_name": "SD Karten",
|
||||
"can_borrow_role": 3,
|
||||
"inSafe": 1,
|
||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"item_name": "Kameragimbal",
|
||||
"can_borrow_role": 1,
|
||||
"inSafe": 1,
|
||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"item_name": "ATEM MINI PRO",
|
||||
"can_borrow_role": 1,
|
||||
"inSafe": 1,
|
||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"item_name": "Handygimbal",
|
||||
"can_borrow_role": 4,
|
||||
"inSafe": 1,
|
||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
||||
},
|
||||
{
|
||||
"id": 12,
|
||||
"item_name": "Kameralfter",
|
||||
"can_borrow_role": 1,
|
||||
"inSafe": 1,
|
||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"item_name": "Kleine Kamera 1 - inkl. Objektiv",
|
||||
"can_borrow_role": 2,
|
||||
"inSafe": 1,
|
||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
||||
},
|
||||
{
|
||||
"id": 14,
|
||||
"item_name": "Kleine Kamera 2 - inkl. Objektiv",
|
||||
"can_borrow_role": 2,
|
||||
"inSafe": 1,
|
||||
"entry_created_at": "2025-08-19T22:02:16.000Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Each item has the following properties:
|
||||
@@ -69,6 +162,8 @@ Each item has the following properties:
|
||||
- `can_borrow_role`: The role ID that is allowed to borrow the item.
|
||||
- `inSafe`: Indicates whether the item is currently in the locker (1) or not (0). This variable/state can change over time.
|
||||
|
||||
_You also get an http 200 status code._
|
||||
|
||||
---
|
||||
|
||||
### 2. Change Item Safe State
|
||||
@@ -82,7 +177,7 @@ Updates the `inSafe` state of an item (whether it is in the locker).
|
||||
#### Example Request
|
||||
|
||||
```
|
||||
POST /apiV2/controlInSafe/your_admin_key/5/0
|
||||
POST https://backend.insta.the1s.de/apiV2/controlInSafe/your_admin_key/item_id/new_item_state
|
||||
```
|
||||
|
||||
#### Example Response
|
||||
@@ -93,7 +188,7 @@ POST /apiV2/controlInSafe/your_admin_key/5/0
|
||||
|
||||
_An empty object means, that the operation was successful and no further information is returned._
|
||||
|
||||
_You also get an http 2xx status code._
|
||||
_You also get an http 200 status code._
|
||||
|
||||
---
|
||||
|
||||
@@ -108,7 +203,7 @@ Sets the `returned_date` of a loan to the current server time.
|
||||
#### Example Request
|
||||
|
||||
```
|
||||
POST /apiV2/setReturnDate/your_admin_key/123456
|
||||
POST https://backend.insta.the1s.de/apiV2/setReturnDate/your_admin_key/your_loan_code
|
||||
```
|
||||
|
||||
#### Example Response
|
||||
@@ -119,7 +214,7 @@ POST /apiV2/setReturnDate/your_admin_key/123456
|
||||
|
||||
_An empty object means, that the operation was successful and no further information is returned._
|
||||
|
||||
_You also get an http 2xx status code._
|
||||
_You also get an http 200 status code._
|
||||
|
||||
---
|
||||
|
||||
@@ -134,7 +229,7 @@ Sets the `take_date` of a loan to the current server time.
|
||||
#### Example Request
|
||||
|
||||
```
|
||||
POST /apiV2/setTakeDate/your_admin_key/123456
|
||||
POST https://backend.insta.the1s.de/apiV2/setTakeDate/your_admin_key/your_loan_code
|
||||
```
|
||||
|
||||
#### Example Response
|
||||
@@ -149,6 +244,57 @@ _You also get an http 2xx status code._
|
||||
|
||||
---
|
||||
|
||||
### 5. Get whole loan by loan code
|
||||
|
||||
**POST** `/getLoanByCode/:key/:loan_code`
|
||||
|
||||
Retrieves the details of a specific loan by its unique code.
|
||||
|
||||
- `loan_code`: The unique code of the loan.
|
||||
|
||||
#### Example Request
|
||||
|
||||
```
|
||||
GET https://backend.insta.the1s.de/getLoanByCode/your_admin_key/your_loan_code
|
||||
```
|
||||
|
||||
#### Example Response
|
||||
|
||||
```
|
||||
{
|
||||
"data": {
|
||||
"id": 6,
|
||||
"username": "theis",
|
||||
"loan_code": 646473,
|
||||
"start_date": "2025-08-25T13:23:00.000Z",
|
||||
"end_date": "2025-08-26T13:23:00.000Z",
|
||||
"take_date": null,
|
||||
"returned_date": null,
|
||||
"created_at": "2025-08-20T11:23:40.000Z",
|
||||
"loaned_items_id": [
|
||||
8,
|
||||
9
|
||||
],
|
||||
"loaned_items_name": [
|
||||
"SD Karten",
|
||||
"Kameragimbal"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
_You also get an http 200 status code._
|
||||
|
||||
If the loan id does not exist, you will receive a 404 status code and an error message.
|
||||
|
||||
```
|
||||
{
|
||||
"message": "Loan not found"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Error Handling
|
||||
|
||||
- `403 Forbidden`: Invalid or missing API key.
|
||||
|
@@ -7,6 +7,8 @@ import {
|
||||
deleteLoanFromDatabase,
|
||||
getBorrowableItemsFromDatabase,
|
||||
createLoanInDatabase,
|
||||
onTake,
|
||||
onReturn,
|
||||
} from "../services/database.js";
|
||||
import { authenticate, generateToken } from "../services/tokenService.js";
|
||||
const router = express.Router();
|
||||
@@ -85,6 +87,26 @@ router.post("/borrowableItems", authenticate, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/takeLoan/:id", authenticate, async (req, res) => {
|
||||
const loanId = req.params.id;
|
||||
const result = await onTake(loanId);
|
||||
if (result.success) {
|
||||
res.status(200).json({ message: "Loan taken successfully" });
|
||||
} else {
|
||||
res.status(500).json({ message: "Failed to take loan" });
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/returnLoan/:id", authenticate, async (req, res) => {
|
||||
const loanId = req.params.id;
|
||||
const result = await onReturn(loanId);
|
||||
if (result.success) {
|
||||
res.status(200).json({ message: "Loan returned successfully" });
|
||||
} else {
|
||||
res.status(500).json({ message: "Failed to return loan" });
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/createLoan", authenticate, async (req, res) => {
|
||||
try {
|
||||
const { items, startDate, endDate } = req.body || {};
|
||||
|
@@ -293,3 +293,29 @@ export const createLoanInDatabase = async (
|
||||
conn.release();
|
||||
}
|
||||
};
|
||||
|
||||
// These functions are only temporary, and will be deleted when the full bin is set up.
|
||||
|
||||
export const onTake = async (loanId) => {
|
||||
const [result] = await pool.query(
|
||||
"UPDATE loans SET take_date = NOW() WHERE id = ?",
|
||||
[loanId]
|
||||
);
|
||||
|
||||
if (result.affectedRows > 0) {
|
||||
return { success: true };
|
||||
}
|
||||
return { success: false };
|
||||
};
|
||||
|
||||
export const onReturn = async (loanId) => {
|
||||
const [result] = await pool.query(
|
||||
"UPDATE loans SET returned_date = NOW() WHERE id = ?",
|
||||
[loanId]
|
||||
);
|
||||
|
||||
if (result.affectedRows > 0) {
|
||||
return { success: true };
|
||||
}
|
||||
return { success: false };
|
||||
};
|
||||
|
12
frontend/src/components/Footer.tsx
Normal file
12
frontend/src/components/Footer.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
import React from "react";
|
||||
|
||||
const Footer: React.FC = () => {
|
||||
return (
|
||||
<footer className="fixed bottom-0 left-0 text-sm w-full bg-slate-100 text-center py-2 border-t border-slate-200 z-50">
|
||||
<p>Made with ❤️ by Theis Gaedigk - Jahrgang 2019</p>
|
||||
<p>v1.1</p>
|
||||
</footer>
|
||||
);
|
||||
};
|
||||
|
||||
export default Footer;
|
@@ -4,6 +4,7 @@ import { handleDeleteLoan } from "../utils/userHandler";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import Cookies from "js-cookie";
|
||||
import { queryClient } from "../utils/queryClient";
|
||||
import { onTake, onReturn } from "../utils/userHandler";
|
||||
|
||||
type Loan = {
|
||||
id: number;
|
||||
@@ -49,6 +50,20 @@ const Form4: React.FC = () => {
|
||||
},
|
||||
});
|
||||
|
||||
const takeMutation = useMutation({
|
||||
mutationFn: (loanID: number) => onTake(loanID),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["userLoans"] });
|
||||
},
|
||||
});
|
||||
|
||||
const returnMutation = useMutation({
|
||||
mutationFn: (loanID: number) => onReturn(loanID),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["userLoans"] });
|
||||
},
|
||||
});
|
||||
|
||||
const onDelete = (loanID: number) => deleteMutation.mutate(loanID);
|
||||
|
||||
if (isFetching) {
|
||||
@@ -99,11 +114,32 @@ const Form4: React.FC = () => {
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-slate-500">Abgeholt:</span>{" "}
|
||||
{formatDate(loan.take_date)}
|
||||
{loan.take_date ? (
|
||||
formatDate(loan.take_date)
|
||||
) : (
|
||||
<button
|
||||
className="inline-flex items-center rounded-md border border-blue-200 bg-blue-50 px-2 py-0.5 text-[11px] font-medium text-blue-700 hover:bg-blue-100 focus:outline-none focus:ring-2 focus:ring-blue-500/40 disabled:opacity-50"
|
||||
onClick={() => takeMutation.mutate(loan.id)}
|
||||
disabled={takeMutation.isPending}
|
||||
>
|
||||
{takeMutation.isPending ? "..." : "Abholen"}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-slate-500">Zurück:</span>{" "}
|
||||
{formatDate(loan.returned_date)}
|
||||
{loan.returned_date ? (
|
||||
formatDate(loan.returned_date)
|
||||
) : (
|
||||
<button
|
||||
className="inline-flex items-center rounded-md border border-emerald-200 bg-emerald-50 px-2 py-0.5 text-[11px] font-medium text-emerald-700 hover:bg-emerald-100 focus:outline-none focus:ring-2 focus:ring-emerald-500/40 disabled:opacity-50"
|
||||
onClick={() => returnMutation.mutate(loan.id)}
|
||||
disabled={returnMutation.isPending || !loan.take_date}
|
||||
title={!loan.take_date ? "Erst abholen" : ""}
|
||||
>
|
||||
{returnMutation.isPending ? "..." : "Zurückgeben"}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-2 text-xs text-slate-700">
|
||||
@@ -170,10 +206,31 @@ const Form4: React.FC = () => {
|
||||
{formatDate(loan.end_date)}
|
||||
</td>
|
||||
<td className="px-4 py-3 whitespace-nowrap font-mono tabular-nums text-slate-900">
|
||||
{formatDate(loan.take_date)}
|
||||
{loan.take_date ? (
|
||||
formatDate(loan.take_date)
|
||||
) : (
|
||||
<button
|
||||
className="inline-flex items-center rounded-md border border-blue-200 bg-blue-50 px-2 py-1 text-xs font-medium text-blue-700 hover:bg-blue-100 focus:outline-none focus:ring-2 focus:ring-blue-500/40 disabled:opacity-50"
|
||||
onClick={() => takeMutation.mutate(loan.id)}
|
||||
disabled={takeMutation.isPending}
|
||||
>
|
||||
{takeMutation.isPending ? "..." : "Abholen"}
|
||||
</button>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-4 py-3 whitespace-nowrap font-mono tabular-nums text-slate-900">
|
||||
{formatDate(loan.returned_date)}
|
||||
{loan.returned_date ? (
|
||||
formatDate(loan.returned_date)
|
||||
) : (
|
||||
<button
|
||||
className="inline-flex items-center rounded-md border border-emerald-200 bg-emerald-50 px-2 py-1 text-xs font-medium text-emerald-700 hover:bg-emerald-100 focus:outline-none focus:ring-2 focus:ring-emerald-500/40 disabled:opacity-50"
|
||||
onClick={() => returnMutation.mutate(loan.id)}
|
||||
disabled={returnMutation.isPending || !loan.take_date}
|
||||
title={!loan.take_date ? "Erst abholen" : ""}
|
||||
>
|
||||
{returnMutation.isPending ? "..." : "Zurückgeben"}
|
||||
</button>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-4 py-3 whitespace-nowrap font-mono tabular-nums text-slate-900">
|
||||
{formatDate(loan.created_at)}
|
||||
@@ -182,7 +239,7 @@ const Form4: React.FC = () => {
|
||||
<div className="text-slate-900">
|
||||
{Array.isArray(loan.loaned_items_name)
|
||||
? loan.loaned_items_name.join(", ")
|
||||
: "-"}
|
||||
: ""}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-4 py-3 text-right">
|
||||
|
@@ -23,6 +23,16 @@ const Header: React.FC<HeaderProps> = ({ onLogout }) => {
|
||||
>
|
||||
Logout
|
||||
</button>
|
||||
<a href="https://git.the1s.de/Matthias-Claudius-Schule/borrow-system/src/branch/dev/Docs/HELP.md">
|
||||
<button className="h-9 px-3 rounded-md border border-slate-300 text-slate-700 hover:bg-slate-100 transition">
|
||||
Hilfe
|
||||
</button>
|
||||
</a>
|
||||
<a href="https://git.the1s.de/Matthias-Claudius-Schule/borrow-system">
|
||||
<button className="h-9 px-3 rounded-md border border-slate-300 text-slate-700 hover:bg-slate-100 transition">
|
||||
Source Code
|
||||
</button>
|
||||
</a>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import React from "react";
|
||||
import Footer from "./Footer";
|
||||
import { useState } from "react";
|
||||
import { loginUser } from "../utils/fetchData";
|
||||
import { myToast } from "../utils/toastify";
|
||||
@@ -66,6 +67,7 @@ const LoginForm: React.FC<LoginFormProps> = ({ onLogin }) => {
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@@ -70,7 +70,9 @@ const Sidebar: React.FC = () => {
|
||||
<Object
|
||||
title={item.item_name}
|
||||
description={
|
||||
item.inSafe ? "Im Schließfach" : "Nicht im Schließfach"
|
||||
item.inSafe
|
||||
? "Aktuell im Schließfach"
|
||||
: "Aktuell nicht im Schließfach"
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
@@ -81,7 +83,7 @@ const Sidebar: React.FC = () => {
|
||||
<div className="mt-4 pt-3 border-t border-slate-200/70 text-[10px] sm:text-xs text-slate-500 items-center gap-4 hidden md:flex">
|
||||
<span className="inline-flex items-center gap-1">
|
||||
<span className="inline-block w-3 h-3 bg-emerald-500 rounded-full ring-2 ring-white shadow-sm"></span>
|
||||
Verfügbar
|
||||
Im Schließfach
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-1">
|
||||
<span className="inline-block w-3 h-3 bg-red-500 rounded-full ring-2 ring-white shadow-sm"></span>
|
||||
|
@@ -2,6 +2,7 @@ import React from "react";
|
||||
import "../App.css";
|
||||
import Header from "../components/Header";
|
||||
import Sidebar from "../components/Sidebar";
|
||||
import Footer from "../components/Footer";
|
||||
|
||||
type LayoutProps = {
|
||||
children: React.ReactNode;
|
||||
@@ -10,15 +11,13 @@ type LayoutProps = {
|
||||
|
||||
const Layout: React.FC<LayoutProps> = ({ children, onLogout }) => {
|
||||
return (
|
||||
<div className="h-screen overflow-hidden flex bg-slate-50 text-slate-800">
|
||||
<div className="h-screen flex flex-col bg-slate-50 text-slate-800">
|
||||
{/* Main */}
|
||||
<main className="flex-1 min-h-0 overflow-hidden flex flex-col items-center px-3 sm:px-5 py-4 sm:py-8">
|
||||
{/* Sidebar on mobile appears inline on top; on desktop it's a sticky column */}
|
||||
<main className="flex-1 min-h-0 overflow-hidden flex flex-col items-center px-3 sm:px-5 py-4 sm:py-8 pb-12">
|
||||
<div className="w-full max-w-5xl flex flex-col gap-3 md:flex-row md:gap-6 md:items-stretch min-h-0 h-full">
|
||||
<div className="hidden md:flex md:flex-col md:shrink-0 md:w-72 md:min-h-0 md:h-full">
|
||||
<Sidebar />
|
||||
</div>
|
||||
|
||||
<div className="flex-1 min-w-0 min-h-0 h-full flex flex-col overflow-hidden">
|
||||
<div className="w-full">
|
||||
<Header onLogout={onLogout} />
|
||||
@@ -29,6 +28,7 @@ const Layout: React.FC<LayoutProps> = ({ children, onLogout }) => {
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@@ -32,7 +32,7 @@ export const fetchAllData = async (token: string | undefined) => {
|
||||
},
|
||||
});
|
||||
|
||||
if (response.status === 401) {
|
||||
if (response.status === 500) {
|
||||
if (!sendError) {
|
||||
sendError = true;
|
||||
myToast("Session expired. Please log in again.", "error");
|
||||
@@ -64,7 +64,7 @@ export const fetchAllData = async (token: string | undefined) => {
|
||||
},
|
||||
});
|
||||
|
||||
if (response.status === 401) {
|
||||
if (response.status === 500) {
|
||||
if (!sendError) {
|
||||
sendError = true;
|
||||
myToast("Session expired. Please log in again.", "error");
|
||||
@@ -96,7 +96,7 @@ export const fetchAllData = async (token: string | undefined) => {
|
||||
},
|
||||
});
|
||||
|
||||
if (response.status === 401) {
|
||||
if (response.status === 500) {
|
||||
if (!sendError) {
|
||||
sendError = true;
|
||||
myToast("Session expired. Please log in again.", "error");
|
||||
@@ -168,7 +168,7 @@ export const getBorrowableItems = async () => {
|
||||
body: JSON.stringify({ startDate, endDate }),
|
||||
});
|
||||
|
||||
if (response.status === 401) {
|
||||
if (response.status === 500) {
|
||||
if (!sendError) {
|
||||
sendError = true;
|
||||
myToast("Session expired. Please log in again.", "error");
|
||||
|
@@ -100,3 +100,40 @@ export const createLoan = async (startDate: string, endDate: string) => {
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export const onReturn = async (loanID: number) => {
|
||||
const response = await fetch(
|
||||
`http://localhost:8002/api/returnLoan/${loanID}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${Cookies.get("token") || ""}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
myToast("Fehler beim Zurückgeben der Ausleihe", "error");
|
||||
return false;
|
||||
}
|
||||
|
||||
myToast("Ausleihe erfolgreich zurückgegeben!", "success");
|
||||
return true;
|
||||
};
|
||||
|
||||
export const onTake = async (loanID: number) => {
|
||||
const response = await fetch(`http://localhost:8002/api/takeLoan/${loanID}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${Cookies.get("token") || ""}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
myToast("Fehler beim Ausleihen der Ausleihe", "error");
|
||||
return false;
|
||||
}
|
||||
|
||||
myToast("Ausleihe erfolgreich ausgeliehen!", "success");
|
||||
return true;
|
||||
};
|
||||
|
Reference in New Issue
Block a user