aboutsummaryrefslogtreecommitdiffstats
path: root/db.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2018-03-15 22:13:42 -0700
committerAdam Soltys <[email protected]>2018-03-15 22:13:42 -0700
commit869b33813e72689c053ba8505c8806129ec3c7d5 (patch)
treef3044c3aeaf23d08efd7425df83be6695f0f3715 /db.js
parent79aeed9061db8b335e60bc4bee48571e717fa637 (diff)
downloadcoinos-server-869b33813e72689c053ba8505c8806129ec3c7d5.tar.gz
coinos-server-869b33813e72689c053ba8505c8806129ec3c7d5.zip
use payments table for in and out ln and onchain payments
Diffstat (limited to 'db.js')
-rw-r--r--db.js30
1 files changed, 23 insertions, 7 deletions
diff --git a/db.js b/db.js
index 42ba47f9..4c108d3a 100644
--- a/db.js
+++ b/db.js
@@ -25,8 +25,7 @@ const auto = new SequelizeAuto(
const tables = {
User: 'users',
- Transaction: 'transactions',
- Invoice: 'invoices',
+ Payment: 'payments',
}
const db = new Sequelize(
@@ -70,15 +69,32 @@ const p = (lnrpc) => {
db[k] = db.define(k, fields, { tableName: t })
- if (t === 'invoices') {
- db['Invoice'].belongsTo(db['User'], {
+ let typefields = {}
+
+ let options = {}
+
+ if (t === 'users') {
+ options = {
+ before: (findOptions, args, context) => {
+ findOptions.where = { id: context.user.id }
+ return findOptions
+ }
+ }
+ }
+
+ if (t === 'payments') {
+ db['Payment'].belongsTo(db['User'], {
as: 'user',
foreignKey: 'user_id'
})
- }
- let typefields = {}
- let options = {}
+ options = {
+ before: (findOptions, args, context) => {
+ findOptions.where = { user_id: context.user.id }
+ return findOptions
+ }
+ }
+ }
gqltypes[t] = new GraphQLObjectType({
name: t,