From 869b33813e72689c053ba8505c8806129ec3c7d5 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 15 Mar 2018 22:13:42 -0700 Subject: use payments table for in and out ln and onchain payments --- db.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'db.js') 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, -- cgit v1.2.3