diff options
| author | Adam Soltys <[email protected]> | 2021-06-29 10:28:58 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2021-07-07 12:42:19 -0700 |
| commit | 0fb703b85d99c888d1df971e7c3562f7918e0ff8 (patch) | |
| tree | 2f167df25b172c3b7166952444e39e7f582e93c4 /db | |
| parent | 9bf4080d67d6342624c8f1fb543acab00191f730 (diff) | |
| download | coinos-server-0fb703b85d99c888d1df971e7c3562f7918e0ff8.tar.gz coinos-server-0fb703b85d99c888d1df971e7c3562f7918e0ff8.zip | |
add webhooks to invoices
Diffstat (limited to 'db')
| -rw-r--r-- | db/index.js | 50 | ||||
| l--------- | db/knexfile.js | 1 | ||||
| -rw-r--r-- | db/migrations/20210612181508_init_referrals.js | 19 | ||||
| -rw-r--r-- | db/migrations/20210612192804_init_waiting_list.js.js | 17 | ||||
| -rw-r--r-- | db/migrations/20210625232223_add_invoice_id_to_payments.js | 10 | ||||
| -rw-r--r-- | db/migrations/20210628221727_add_webhook_to_invoices.js | 11 | ||||
| -rw-r--r-- | db/migrations/user_adjustments.js | 53 | ||||
| -rw-r--r-- | db/models/invoices.js | 9 | ||||
| -rw-r--r-- | db/models/payments.js | 9 |
9 files changed, 68 insertions, 111 deletions
diff --git a/db/index.js b/db/index.js index 4c327d35..c1d316cc 100644 --- a/db/index.js +++ b/db/index.js @@ -1,28 +1,30 @@ const Sequelize = require("sequelize"); -const debug = require('debug')('debug'); +const debug = require("debug")("debug"); -const dbOptions = require('./../config/knexfile.js')[process.env.NODE_ENV || "development"] +const dbOptions = require("./../config/knexfile.js")[ + process.env.NODE_ENV || "development" +]; -db = new Sequelize(dbOptions.connection.database, dbOptions.connection.user, dbOptions.connection.password, { - host: dbOptions.connection.host, - dialect: "mariadb", - logging: false, - dialectOptions: { "multipleStatements": true, "timezone": "Etc/GMT+7" } -}); +db = new Sequelize( + dbOptions.connection.database, + dbOptions.connection.user, + dbOptions.connection.password, + { + host: dbOptions.connection.host, + dialect: "mariadb", + logging: false, + dialectOptions: { multipleStatements: true, timezone: "Etc/GMT+7" } + } +); -db.authenticate() -.then (response => { - console.log('DB Connection established'); -}) -.catch (err => { - console.debug('Error connecting to database: ' + err.message); - console.log(dbOptions.connection.database + '.' + dbOptions.connection.user); -}) +db.authenticate().catch(err => { + console.debug("Error connecting to database: " + err.message); + console.log(dbOptions.connection.database + "." + dbOptions.connection.user); +}); -console.log("DB: " + JSON.stringify(dbOptions)) -debug('knex dbOptions: ' + JSON.stringify(dbOptions)) +debug("knex dbOptions: " + JSON.stringify(dbOptions)); -knex = require('knex')(dbOptions) +knex = require("knex")(dbOptions); require("./models/accounts.js"); require("./models/codes.js"); @@ -62,7 +64,7 @@ require("./normalized/waiting_list.js"); // require("./normalized/orders.js"); // require("./normalized/invoices.js"); -const { User, Account, Payment, Invoice, Key, Order, Referral} = db; +const { User, Account, Payment, Invoice, Key, Order, Referral } = db; // move relationships to specfic models User.hasMany(Account, { @@ -125,6 +127,11 @@ Payment.belongsTo(User, { foreignKey: "user_id" }); +Payment.belongsTo(Invoice, { + as: "invoice", + foreignKey: "invoice_id" +}); + Order.belongsTo(User, { as: "user", foreignKey: "user_id" @@ -158,6 +165,5 @@ Referral.belongsTo(User, { foreignKey: "user_id" }); -debug('added model relationships') +debug("added model relationships"); db.Order = Order; - diff --git a/db/knexfile.js b/db/knexfile.js new file mode 120000 index 00000000..10bb1d03 --- /dev/null +++ b/db/knexfile.js @@ -0,0 +1 @@ +../config/knexfile.js
\ No newline at end of file diff --git a/db/migrations/20210612181508_init_referrals.js b/db/migrations/20210612181508_init_referrals.js deleted file mode 100644 index 260a2c8f..00000000 --- a/db/migrations/20210612181508_init_referrals.js +++ /dev/null @@ -1,19 +0,0 @@ - -exports.up = function(knex) { - return knex.schema.createTable('referrals', function(t) { - t.increments('id').unsigned().primary(); - - t.string('token').notNull(); - t.string('expiry').nullable(); - t.enum('status', ['pending', 'active', 'expired', 'cancelled')).notNull().defaultTo('pending'); - t.int('sponsor_id').notNull(); - t.foreign('sponsor_id').references('users.user_id') - t.int('user_id').nullable(); - t.foreign('user_id').references('users.user_id') - - t.timestamps(); -}; - -exports.down = function(knex) { - return knex.schema.dropTable('referrals'); -}; diff --git a/db/migrations/20210612192804_init_waiting_list.js.js b/db/migrations/20210612192804_init_waiting_list.js.js deleted file mode 100644 index 5322cf6d..00000000 --- a/db/migrations/20210612192804_init_waiting_list.js.js +++ /dev/null @@ -1,17 +0,0 @@ - -exports.up = function(knex) { - return knex.schema.createTable('waiting_list', function(t) { - t.increments('id').unsigned().primary(); - - t.string('email').nullable(); - t.string('sms').nullable(); - t.enum('status', ['pending', 'contacted', 'registered', 'cancelled')).notNull().defaultTo('pending'); - t.int('user_id').notNull(); - t.foreign('user_id').references('users.user_id'); - - t.timestamps(); -}; - -exports.down = function(knex) { - return knex.schema.dropTable('waiting_list'); -}; diff --git a/db/migrations/20210625232223_add_invoice_id_to_payments.js b/db/migrations/20210625232223_add_invoice_id_to_payments.js new file mode 100644 index 00000000..46e2a82e --- /dev/null +++ b/db/migrations/20210625232223_add_invoice_id_to_payments.js @@ -0,0 +1,10 @@ +exports.up = async knex => + knex.schema.table("payments", function(table) { + table.integer("invoice_id"); + table.foreign("invoice_id").references("invoices.id"); + }); + +exports.down = async knex => + knex.schema.table("payments", function(table) { + table.dropColumn("invoice_id"); + }); diff --git a/db/migrations/20210628221727_add_webhook_to_invoices.js b/db/migrations/20210628221727_add_webhook_to_invoices.js new file mode 100644 index 00000000..073b8d01 --- /dev/null +++ b/db/migrations/20210628221727_add_webhook_to_invoices.js @@ -0,0 +1,11 @@ +exports.up = async function(knex) { + return knex.schema.table("invoices", function(table) { + table.text("webhook"); + }); +}; + +exports.down = async function(knex) { + return knex.schema.table("invoices", function(table) { + table.dropColumn("webhook"); + }); +}; diff --git a/db/migrations/user_adjustments.js b/db/migrations/user_adjustments.js deleted file mode 100644 index b4273848..00000000 --- a/db/migrations/user_adjustments.js +++ /dev/null @@ -1,53 +0,0 @@ - -exports.up = function(knex) { - return Promise.all([ - - // move security fields to separate t (potentially different access permissions) - - knex.schema.createTable('user_security', function (t) { - t.increments('id').unsigned().primary(); - t.int('user_id').notNull(); - t.foreign('user_id').references('users.user_id'); - - t.boolean('twofa').notNull().defaultTo(false); - t.string('pin').notNull(); - t.string('otp_secret').nullable(); - t.string('seed').nullable(); - }, - - knex.raw("INSERT INTO user_security (user_id, twofa, pin, otp_secret, seed) SELECT users.id, twofa, pin, otpsecret, seed FROM users"), - - // move user-customizeable fields to separate t (potentially different access permissions) - - knex.schema.createTable('user_preferences', function (t) { - t.increments('id').unsigned().primary(); - t.int('user_id').notNull(); - t.foreign('user_id').references('users.user_id'); - - t.enum('default_unit', ['SAT', 'BTC', 'CAD']).notNull().defaultTo('SAT'); - t.enum('default_currency', ['CAD', 'USD']).notNull().defaultTo('CAD'); - t.enum('default_fiat', ['CAD', 'USD']).notNull().defaultTo('CAD'); - t.set('show_currencies', ['CAD', 'USD']).notNull().defaultTo('CAD'); - } - - knex.raw("INSERT INTO user_preferences (user_id, default_unit, default_currency, default_fiat, show_currencies) SELECT users.id, unit, currency, fiat, currencies FROM users"), - - // remove deprecated fields - - knex.schema.table('users', function (t) { - t.string('uuid'); - t.enum('access', ['Anonymous', 'Member', 'Admin']).defaultTo('Anonymous'); - - t.dropColumn('account_id'); - t.dropColumn('unit'); - t.dropColumn('fiat'); - t.dropColumn('currency'); - t.dropColumn('currencies'); - }, - ]) - -}; - -exports.down = function(knex) { - -}; diff --git a/db/models/invoices.js b/db/models/invoices.js index e2c499f4..a51ee3f9 100644 --- a/db/models/invoices.js +++ b/db/models/invoices.js @@ -145,6 +145,15 @@ const attributes = { comment: null, field: "amount" }, + webhook: { + type: DataTypes.TEXT, + allowNull: true, + defaultValue: null, + primaryKey: false, + autoIncrement: false, + comment: null, + field: "webhook" + }, tip: { type: DataTypes.DOUBLE, allowNull: true, diff --git a/db/models/payments.js b/db/models/payments.js index 94050a0b..c315a5a0 100644 --- a/db/models/payments.js +++ b/db/models/payments.js @@ -19,6 +19,15 @@ const attributes = { comment: null, field: "account_id" }, + invoice_id: { + type: DataTypes.INTEGER(11), + allowNull: true, + defaultValue: null, + primaryKey: false, + autoIncrement: false, + comment: null, + field: "invoice_id" + }, user_id: { type: DataTypes.INTEGER(11), allowNull: true, |
