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.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.Label>Ausleih-Berechtigung (Rolle)</Field.Label>
|
||||
@@ -57,17 +57,16 @@ const AddItemForm: React.FC<AddItemFormProps> = ({ onClose, alert }) => {
|
||||
(document.getElementById("can_borrow_role") as HTMLInputElement)
|
||||
?.value
|
||||
);
|
||||
const lockerValue = (
|
||||
document.getElementById("lockerNumber") as HTMLInputElement
|
||||
const safeNrValue = (
|
||||
document.getElementById("safe_nr") as HTMLInputElement
|
||||
)?.value.trim();
|
||||
|
||||
const lockerNumber =
|
||||
lockerValue === "" ? null : Number(lockerValue);
|
||||
const safeNr = safeNrValue === "" ? null : safeNrValue;
|
||||
|
||||
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) {
|
||||
alert(
|
||||
"success",
|
||||
|
||||
@@ -165,7 +165,7 @@ export const deleteItem = async (itemId: number) => {
|
||||
export const createItem = async (
|
||||
item_name: string,
|
||||
can_borrow_role: number,
|
||||
lockerNumber: number | null
|
||||
lockerNumber: string | null
|
||||
) => {
|
||||
console.log(JSON.stringify({ item_name, can_borrow_role, lockerNumber }));
|
||||
try {
|
||||
|
||||
@@ -47,10 +47,6 @@ CREATE TABLE items (
|
||||
UNIQUE KEY ux_items_safe_nr (safe_nr)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
CREATE UNIQUE INDEX ux_items_safe_nr_not_null
|
||||
ON items (safe_nr)
|
||||
WHERE safe_nr IS NOT NULL;
|
||||
|
||||
CREATE TABLE apiKeys (
|
||||
id INT NOT NULL AUTO_INCREMENT,
|
||||
api_key CHAR(8) NOT NULL UNIQUE,
|
||||
|
||||
Reference in New Issue
Block a user