aboutsummaryrefslogtreecommitdiffstats
path: root/routes/invoices.js
blob: 50f578ac96d03bc7e877a4fd976e23ec515e6e38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const { Op } = require("sequelize");

app.post("/invoice", auth, async (req, res) => {
  const { invoice } = req.body;
  invoice.user_id = req.user.id;
  l.info("creating invoice", req.user.username, invoice.asset, invoice.amount, invoice.tip, invoice.currency, invoice.rate.toFixed(2));

  const exists = await db.Invoice.findOne({
    where: {
      [Op.or]: {
        address: invoice.address || "undefined",
        text: invoice.text
      }
    }
  });

  res.send(
    exists ? await exists.update(invoice) : await db.Invoice.create(invoice)
  );
});