allow vorgangPIN to be changed on Vorgang page
includes: - UI and backend logic - adjustment to `NameItemEditor` to disallow deletion
This commit is contained in:
@@ -190,6 +190,34 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function savePIN(newVorgangPIN: string, oldVorgangPIN: string) {
|
||||
open = true;
|
||||
inProgress = true;
|
||||
isError = false;
|
||||
try {
|
||||
const res = await fetch(API_ROUTES.VORGANG(vorgangToken), {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ vorgangToken, oldVorgangPIN, newVorgangPIN,
|
||||
changePIN: true})
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error('Fehler beim Speichern');
|
||||
}
|
||||
await invalidateAll();
|
||||
crimesList = data.crimesList;
|
||||
open = false;
|
||||
} catch (err) {
|
||||
console.error('⚠️ Netzwerkfehler beim Speichern', err);
|
||||
isError = true;
|
||||
} finally {
|
||||
inProgress = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(tatort: string) {
|
||||
open = true;
|
||||
inProgress = true;
|
||||
@@ -251,7 +279,13 @@ Mit freundlichen Grüßen,
|
||||
<h1 class="text-xl">{vorgangName}</h1>
|
||||
|
||||
{#if admin}
|
||||
Zugangs-PIN: {vorgangPIN}
|
||||
Zugangs-PIN:
|
||||
<NameItemEditor
|
||||
list={[]}
|
||||
currentName={vorgangPIN}
|
||||
onSave={savePIN}
|
||||
onDelete={null}
|
||||
/>
|
||||
<a class="pt-2 pb-6" href={constructMailToLink()}
|
||||
><Button disabled={isEmptyList}>Share Link</Button></a
|
||||
>
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
deleteVorgangByToken,
|
||||
getCrimesListByToken,
|
||||
vorgangNameExists,
|
||||
renameVorgangByToken
|
||||
updateVorgangAttrByToken
|
||||
} from '$lib/server/vorgangService';
|
||||
|
||||
export async function DELETE({ params }) {
|
||||
@@ -59,14 +59,26 @@ export async function GET({ params }) {
|
||||
}
|
||||
}
|
||||
|
||||
// rename vorgang
|
||||
// change Vorgang properties
|
||||
export async function PUT({ request }) {
|
||||
const data = await request.json();
|
||||
|
||||
const vorgangToken = data['vorgangToken'];
|
||||
const newVorgangName = data['newName'];
|
||||
|
||||
const changePIN = data['changePIN'];
|
||||
|
||||
let attrChanged;
|
||||
let newValue;
|
||||
|
||||
const res = renameVorgangByToken(vorgangToken, newVorgangName);
|
||||
if (changePIN) {
|
||||
attrChanged = 'pin';
|
||||
newValue = data['newVorgangPIN']
|
||||
} else {
|
||||
attrChanged = 'name';
|
||||
newValue = data['newName']
|
||||
}
|
||||
|
||||
const res = updateVorgangAttrByToken(vorgangToken, newValue, attrChanged);
|
||||
|
||||
if (!res) {
|
||||
return json({ msg: 'Fehler beim Umbenennen' }, { status: 400 });
|
||||
|
||||
Reference in New Issue
Block a user