aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--db/index.js3
-rw-r--r--db/models/invoices.js120
-rw-r--r--db/schema.sql30
-rw-r--r--index.js1
-rw-r--r--routes/invoices.js6
-rw-r--r--routes/lightning/invoice.js15
6 files changed, 157 insertions, 18 deletions
diff --git a/db/index.js b/db/index.js
index dac6924e..9e78da9d 100644
--- a/db/index.js
+++ b/db/index.js
@@ -8,8 +8,9 @@ db = new Sequelize(conf.database, conf.username, conf.password, {
dialectOptions: { multipleStatements: true }
});
-require("./models/users.js");
+require("./models/invoices.js");
require("./models/payments.js");
+require("./models/users.js");
db["User"].hasMany(db["Payment"], {
as: "payments",
diff --git a/db/models/invoices.js b/db/models/invoices.js
new file mode 100644
index 00000000..2a7f3013
--- /dev/null
+++ b/db/models/invoices.js
@@ -0,0 +1,120 @@
+const { DataTypes } = require('sequelize');
+
+const attributes = {
+ id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: true,
+ autoIncrement: true,
+ comment: null,
+ field: "id"
+ },
+ user_id: {
+ type: DataTypes.INTEGER(11),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "user_id"
+ },
+ text: {
+ type: DataTypes.TEXT,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "text"
+ },
+ createdAt: {
+ type: DataTypes.DATE,
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "createdAt"
+ },
+ updatedAt: {
+ type: DataTypes.DATE,
+ allowNull: false,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "updatedAt"
+ },
+ rate: {
+ type: DataTypes.DOUBLE,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "rate"
+ },
+ asset: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "asset"
+ },
+ currency: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "currency"
+ },
+ address: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "address"
+ },
+ received: {
+ type: DataTypes.STRING(255),
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "received"
+ },
+ amount: {
+ type: DataTypes.DOUBLE,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "amount"
+ },
+ tip: {
+ type: DataTypes.DOUBLE,
+ allowNull: true,
+ defaultValue: null,
+ primaryKey: false,
+ autoIncrement: false,
+ comment: null,
+ field: "tip"
+ },
+};
+
+const options = {
+ tableName: "invoices",
+ comment: "",
+ indexes: []
+};
+
+db["Invoice"] = db.define("invoices_model", attributes, options);
diff --git a/db/schema.sql b/db/schema.sql
index 0146c139..83d143ce 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -39,6 +39,30 @@ CREATE TABLE `SequelizeMeta` (
/*!40101 SET character_set_client = @saved_cs_client */;
--
+-- Table structure for table `invoices`
+--
+
+DROP TABLE IF EXISTS `invoices`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `invoices` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `user_id` int(11) DEFAULT NULL,
+ `text` text DEFAULT NULL,
+ `createdAt` datetime NOT NULL,
+ `updatedAt` datetime NOT NULL,
+ `rate` double DEFAULT NULL,
+ `currency` varchar(255) NOT NULL,
+ `address` varchar(255) DEFAULT NULL,
+ `received` double DEFAULT NULL,
+ `amount` double DEFAULT NULL,
+ `tip` double DEFAULT NULL,
+ `asset` varchar(255) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=3646 DEFAULT CHARSET=latin1;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
-- Table structure for table `payments`
--
@@ -61,7 +85,7 @@ CREATE TABLE `payments` (
`fee` double DEFAULT NULL,
`asset` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=3140 DEFAULT CHARSET=latin1;
+) ENGINE=InnoDB AUTO_INCREMENT=3142 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -109,7 +133,7 @@ CREATE TABLE `users` (
`currencies` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
`otpsecret` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=463 DEFAULT CHARSET=latin1;
+) ENGINE=InnoDB AUTO_INCREMENT=474 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
@@ -121,4 +145,4 @@ CREATE TABLE `users` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2020-03-19 22:56:40
+-- Dump completed on 2020-03-27 16:59:40
diff --git a/index.js b/index.js
index 8eabff97..369cf5ea 100644
--- a/index.js
+++ b/index.js
@@ -24,6 +24,7 @@ require("./lib/sockets");
require("./lib/passport");
require("./lib/rates");
+require("./routes/invoices");
require("./routes/payments");
require("./routes/users");
diff --git a/routes/invoices.js b/routes/invoices.js
new file mode 100644
index 00000000..d188ff44
--- /dev/null
+++ b/routes/invoices.js
@@ -0,0 +1,6 @@
+app.post("/invoice", auth, async (req, res) => {
+ let { invoice } = req.body;
+ invoice.user_id = req.user.id;
+ invoice.currency = req.user.currency;
+ res.send(await db.Invoice.create(invoice));
+});
diff --git a/routes/lightning/invoice.js b/routes/lightning/invoice.js
index 840321fb..50be961d 100644
--- a/routes/lightning/invoice.js
+++ b/routes/lightning/invoice.js
@@ -9,18 +9,5 @@ module.exports = async (req, res) => {
return err(e.message);
}
- let hash = invoice.payment_request;
-
- await db.Payment.create({
- user_id: req.user.id,
- hash,
- amount,
- currency: "CAD",
- rate: app.get("rates")[req.user.currency],
- tip,
- confirmed: 1,
- asset: 'LNBTC',
- });
-
- res.send(invoice);
+ res.send(invoice.payment_request);
};