implemented deletion of new documents
This commit is contained in:
@@ -48,6 +48,38 @@ public class DocumentApi extends BaseHandler {
|
||||
users = companyService.userService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doDelete(Path path, HttpExchange ex) throws IOException {
|
||||
addCors(ex);
|
||||
try {
|
||||
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
||||
var user = users.loadUser(token);
|
||||
if (user.isEmpty()) return unauthorized(ex);
|
||||
var head = path.pop();
|
||||
return switch (head){
|
||||
default -> {
|
||||
try {
|
||||
yield deleteDocument(ex,Long.parseLong(head),user.get());
|
||||
} catch (NumberFormatException ignored) {}
|
||||
yield super.doDelete(path,ex);
|
||||
}
|
||||
};
|
||||
} catch (UmbrellaException e) {
|
||||
return send(ex,e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean deleteDocument(HttpExchange ex, long docId, UmbrellaUser user) throws IOException, UmbrellaException {
|
||||
var doc = db.loadDoc(docId);
|
||||
var companyId = doc.companyId();
|
||||
var company = companies.get(companyId);
|
||||
var members = companies.getMembers(companyId);
|
||||
var isMember = false;
|
||||
for (var member : members) isMember |= user.equals(member);
|
||||
if (!isMember) return sendContent(ex,HTTP_FORBIDDEN,"You are mot a member of company "+doc.companyId());
|
||||
return sendContent(ex,db.deleteDoc(docId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
||||
addCors(ex);
|
||||
@@ -73,6 +105,11 @@ public class DocumentApi extends BaseHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doOptions(Path path, HttpExchange ex) throws IOException {
|
||||
return sendEmptyResponse(HTTP_OK,addCors(ex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doPost(Path path, HttpExchange ex) throws IOException {
|
||||
addCors(ex);
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
document.sender.name = '';
|
||||
if (company.name) document.sender.name += company.name+"\n";
|
||||
if (company.address) document.sender.name += company.address+"\n";
|
||||
if (company.tax_number) document.sender.tax_id = company.tax_number;
|
||||
if (company.tax_number) document.sender.tax_id = company.tax_number;
|
||||
if (company.bank_account) document.sender.bank_account = company.bank_account;
|
||||
if (company.court) document.sender.court = company.court;
|
||||
} else {
|
||||
|
||||
@@ -44,6 +44,21 @@
|
||||
router.navigate(`/document/${id}/view`);
|
||||
}
|
||||
|
||||
async function deleteDoc(ev,doc){
|
||||
if (confirm(t('document.really_delete',doc.number))){
|
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${doc.id}`;
|
||||
const resp = await fetch(url,{
|
||||
credentials: 'include',
|
||||
method: 'DELETE'
|
||||
});
|
||||
if (resp.ok){
|
||||
load(selected_company); // relaod docs
|
||||
} else {
|
||||
error = await resp.text();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMount(loadCompanies);
|
||||
</script>
|
||||
|
||||
@@ -77,13 +92,18 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each Object.entries(documents).reverse() as [id,document]}
|
||||
<tr onclick={() => show(id)}>
|
||||
<td>{document.number}</td>
|
||||
<td>{document.date}</td>
|
||||
<td>{document.customer.name.split('\n')[0]}</td>
|
||||
<td>{document.sum/100 + document.currency}</td>
|
||||
<td>{t('document.type_'+document.type)}</td>
|
||||
<td>{t('document.state_'+document.state.name)}</td>
|
||||
<tr>
|
||||
<td onclick={() => show(id)}>{document.number}</td>
|
||||
<td onclick={() => show(id)}>{document.date}</td>
|
||||
<td onclick={() => show(id)}>{document.customer.name.split('\n')[0]}</td>
|
||||
<td onclick={() => show(id)}>{document.sum/100 + document.currency}</td>
|
||||
<td onclick={() => show(id)}>{t('document.type_'+document.type)}</td>
|
||||
<td onclick={() => show(id)}>{t('document.state_'+document.state.name)}</td>
|
||||
<td>
|
||||
{#if document.state.id == 1}
|
||||
<button onclick={(ev) => deleteDoc(ev,document)}>{t('document.delete')}</button>
|
||||
{/if}
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
{
|
||||
"contacts": {
|
||||
"loading": "lade…"
|
||||
},
|
||||
"document": {
|
||||
"actions": "Aktionen",
|
||||
"add_new": "{0} anlegen",
|
||||
@@ -6,8 +9,10 @@
|
||||
"court": "Amtsgericht: {0}",
|
||||
"create_new": "neues Dokument",
|
||||
"customer": "Kunde",
|
||||
"customer_number": "Kundennummer: {0}",
|
||||
"customer_address": "Adresse",
|
||||
"customer_id": "Kundennummer",
|
||||
"date": "Datum",
|
||||
"delete": "löschen",
|
||||
"email": "E-Mail: {0}",
|
||||
"gross_sum": "Brutto-Summe",
|
||||
"list": "Dokumente",
|
||||
@@ -16,6 +21,10 @@
|
||||
"select_company" : "Wählen Sie eine ihrer Firmen:",
|
||||
"select_customer": "Kunde auswählen",
|
||||
"sender": "Absender",
|
||||
"sender_bank_account": "Bankverbindung",
|
||||
"sender_local_court": "Amtsgericht",
|
||||
"sender_name": "Name",
|
||||
"sender_tax_id": "Steuernummer",
|
||||
"state": "Status",
|
||||
"state_declined": "abgelehnt",
|
||||
"state_new":"neu",
|
||||
@@ -47,6 +56,7 @@
|
||||
"company": "Firma",
|
||||
"contact": "Kontakte",
|
||||
"document": "Dokumente",
|
||||
"documents": "Dokumente",
|
||||
"files": "Dateien",
|
||||
"items": "Items",
|
||||
"logout": "Abmelden",
|
||||
|
||||
Reference in New Issue
Block a user