aboutsummaryrefslogtreecommitdiffstats
path: root/routes/invoices.js
diff options
context:
space:
mode:
Diffstat (limited to 'routes/invoices.js')
-rw-r--r--routes/invoices.js24
1 files changed, 15 insertions, 9 deletions
diff --git a/routes/invoices.js b/routes/invoices.js
index 3ef0b4e3..9a24a8c0 100644
--- a/routes/invoices.js
+++ b/routes/invoices.js
@@ -21,11 +21,14 @@ app.get(
app.post(
"/invoice",
+ optionalAuth,
ah(async (req, res, next) => {
try {
- let { invoice, user } = req.body;
+ let { liquidAddress, invoice, user } = req.body;
let { blindkey } = invoice;
+ if (liquidAddress) convert[invoice.text] = liquidAddress;
+
if (!user) ({ user } = req);
else {
user = await db.User.findOne({
@@ -35,6 +38,7 @@ app.post(
});
}
if (!user) throw new Error("user not provided");
+ if (!invoice.currency) invoice.currency = user.currency;
invoice.user_id = user.id;
invoice.account_id = user.account_id;
@@ -49,15 +53,17 @@ app.post(
if (!invoice.tip) invoice.tip = 0;
- const exists = await db.Invoice.findOne({
- where: {
- [Op.or]: {
- address: invoice.address || "",
- unconfidential: invoice.unconfidential || "",
- text: invoice.text
+ const exists =
+ invoice.text &&
+ (await db.Invoice.findOne({
+ where: {
+ [Op.or]: {
+ address: invoice.address || "",
+ unconfidential: invoice.unconfidential || "",
+ text: invoice.text
+ }
}
- }
- });
+ }));
invoice = exists
? await exists.update(invoice)