|
|
|
|
@ -63,14 +63,14 @@ public class DocumentApi extends BaseHandler {
@@ -63,14 +63,14 @@ public class DocumentApi extends BaseHandler {
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
long docId = Long.parseLong(head); |
|
|
|
|
return switch (path.pop()){ |
|
|
|
|
case POSITION -> deletePosition(ex,docId,user.get()); |
|
|
|
|
case null -> deleteDocument(ex,docId,user.get()); |
|
|
|
|
default -> super.doDelete(path,ex); |
|
|
|
|
}; |
|
|
|
|
} catch (NumberFormatException ignored) { |
|
|
|
|
return super.doDelete(path,ex); |
|
|
|
|
} catch (UmbrellaException e) { |
|
|
|
|
return send(ex,e); |
|
|
|
|
} |
|
|
|
|
@ -84,6 +84,17 @@ public class DocumentApi extends BaseHandler {
@@ -84,6 +84,17 @@ public class DocumentApi extends BaseHandler {
|
|
|
|
|
return sendContent(ex,db.deleteDoc(docId)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean deletePosition(HttpExchange ex, long docId, UmbrellaUser user) throws UmbrellaException, IOException { |
|
|
|
|
var doc = db.loadDoc(docId); |
|
|
|
|
var companyId = doc.companyId(); |
|
|
|
|
if (!companies.membership(companyId,user.id())) throw forbidden("You are mot a member of company {0}",doc.companyId()); |
|
|
|
|
if (doc.state() != NEW) throw new UmbrellaException(HTTP_BAD_REQUEST,"This document has already been sent"); |
|
|
|
|
var json = json(ex); |
|
|
|
|
if (!(json.has(POSITION) && json.get(POSITION) instanceof Number number)) throw missingFieldException(POSITION); |
|
|
|
|
db.dropPosition(docId,number.longValue()); |
|
|
|
|
return send(ex,db.loadDoc(docId).positions()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean doGet(Path path, HttpExchange ex) throws IOException { |
|
|
|
|
addCors(ex); |
|
|
|
|
@ -301,7 +312,7 @@ public class DocumentApi extends BaseHandler {
@@ -301,7 +312,7 @@ public class DocumentApi extends BaseHandler {
|
|
|
|
|
var pos = new Position(doc.positions().size()+1,itemCode,amount.doubleValue(),unit,title,description,unitPrice.longValue(),tax,timeId,false); |
|
|
|
|
doc.positions().add(pos); |
|
|
|
|
|
|
|
|
|
return sendContent(ex,db.save(doc).positions()); |
|
|
|
|
return send(ex,db.save(doc).positions()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean postTemplateList(HttpExchange ex, UmbrellaUser user) throws UmbrellaException, IOException { |
|
|
|
|
|