refactor: rename lockerNumber to safe_nr and update related logic
This commit is contained in:
@@ -30,7 +30,7 @@ const AddItemForm: React.FC<AddItemFormProps> = ({ onClose, alert }) => {
|
|||||||
</Field.Root>
|
</Field.Root>
|
||||||
<Field.Root>
|
<Field.Root>
|
||||||
<Field.Label>Schließfachnummer (immer zwei Zahlen)</Field.Label>
|
<Field.Label>Schließfachnummer (immer zwei Zahlen)</Field.Label>
|
||||||
<Input id="lockerNumber" placeholder="Nummer 01 - 06" />
|
<Input id="safe_nr" placeholder="Nummer 01 - 06" />
|
||||||
</Field.Root>
|
</Field.Root>
|
||||||
<Field.Root>
|
<Field.Root>
|
||||||
<Field.Label>Ausleih-Berechtigung (Rolle)</Field.Label>
|
<Field.Label>Ausleih-Berechtigung (Rolle)</Field.Label>
|
||||||
@@ -57,17 +57,16 @@ const AddItemForm: React.FC<AddItemFormProps> = ({ onClose, alert }) => {
|
|||||||
(document.getElementById("can_borrow_role") as HTMLInputElement)
|
(document.getElementById("can_borrow_role") as HTMLInputElement)
|
||||||
?.value
|
?.value
|
||||||
);
|
);
|
||||||
const lockerValue = (
|
const safeNrValue = (
|
||||||
document.getElementById("lockerNumber") as HTMLInputElement
|
document.getElementById("safe_nr") as HTMLInputElement
|
||||||
)?.value.trim();
|
)?.value.trim();
|
||||||
|
|
||||||
const lockerNumber =
|
const safeNr = safeNrValue === "" ? null : safeNrValue;
|
||||||
lockerValue === "" ? null : Number(lockerValue);
|
|
||||||
|
|
||||||
if (!name || Number.isNaN(role)) return;
|
if (!name || Number.isNaN(role)) return;
|
||||||
if (lockerNumber !== null && Number.isNaN(lockerNumber)) return;
|
if (safeNr !== null && !/^\d{2}$/.test(safeNr)) return;
|
||||||
|
|
||||||
const res = await createItem(name, role, lockerNumber);
|
const res = await createItem(name, role, safeNr);
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
alert(
|
alert(
|
||||||
"success",
|
"success",
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ export const deleteItem = async (itemId: number) => {
|
|||||||
export const createItem = async (
|
export const createItem = async (
|
||||||
item_name: string,
|
item_name: string,
|
||||||
can_borrow_role: number,
|
can_borrow_role: number,
|
||||||
lockerNumber: number | null
|
lockerNumber: string | null
|
||||||
) => {
|
) => {
|
||||||
console.log(JSON.stringify({ item_name, can_borrow_role, lockerNumber }));
|
console.log(JSON.stringify({ item_name, can_borrow_role, lockerNumber }));
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -47,10 +47,6 @@ CREATE TABLE items (
|
|||||||
UNIQUE KEY ux_items_safe_nr (safe_nr)
|
UNIQUE KEY ux_items_safe_nr (safe_nr)
|
||||||
) ENGINE=InnoDB;
|
) ENGINE=InnoDB;
|
||||||
|
|
||||||
CREATE UNIQUE INDEX ux_items_safe_nr_not_null
|
|
||||||
ON items (safe_nr)
|
|
||||||
WHERE safe_nr IS NOT NULL;
|
|
||||||
|
|
||||||
CREATE TABLE apiKeys (
|
CREATE TABLE apiKeys (
|
||||||
id INT NOT NULL AUTO_INCREMENT,
|
id INT NOT NULL AUTO_INCREMENT,
|
||||||
api_key CHAR(8) NOT NULL UNIQUE,
|
api_key CHAR(8) NOT NULL UNIQUE,
|
||||||
|
|||||||
Reference in New Issue
Block a user