aboutsummaryrefslogtreecommitdiffstats
path: root/db.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2019-06-13 14:39:22 -0700
committerAdam Soltys <[email protected]>2019-06-13 14:39:22 -0700
commitc995bdc94a2eec6cfd499ee1363b8a3b7151069e (patch)
treebecbca5b2ffe59695f1621e71a407068f5ba691a /db.js
parentdbd72428f1577485e3b0b610efd232630052f090 (diff)
downloadcoinos-server-c995bdc94a2eec6cfd499ee1363b8a3b7151069e.tar.gz
coinos-server-c995bdc94a2eec6cfd499ee1363b8a3b7151069e.zip
upgrade dependencies
Diffstat (limited to 'db.js')
-rw-r--r--db.js156
1 files changed, 77 insertions, 79 deletions
diff --git a/db.js b/db.js
index 2ab18e54..1a53eb17 100644
--- a/db.js
+++ b/db.js
@@ -1,124 +1,122 @@
-import config from './config'
-import Sequelize from 'sequelize'
-import SequelizeAuto from 'sequelize-auto'
-import { resolver, defaultArgs, defaultListArgs, attributeFields } from 'graphql-sequelize'
+import config from "./config";
+import Sequelize from "sequelize";
+import SequelizeAuto from "sequelize-auto";
import {
- graphql,
- GraphQLSchema,
- GraphQLObjectType,
- GraphQLInputObjectType,
- GraphQLString,
- GraphQLInt,
- GraphQLNonNull,
- GraphQLList
-} from 'graphql'
+ resolver,
+ defaultArgs,
+ defaultListArgs,
+ attributeFields
+} from "graphql-sequelize";
+import {
+ graphql,
+ GraphQLSchema,
+ GraphQLObjectType,
+ GraphQLInputObjectType,
+ GraphQLString,
+ GraphQLInt,
+ GraphQLNonNull,
+ GraphQLList
+} from "graphql";
-const Op = Sequelize.Op
-const conf = config.db[process.env.NODE_ENV || 'development']
+const conf = config.db[process.env.NODE_ENV || "development"];
const auto = new SequelizeAuto(
- conf.database,
- conf.username,
- conf.password,
- config.auto
-)
-
-const tables = {
- User: 'users',
- Payment: 'payments',
-}
-
-const db = new Sequelize(
conf.database,
conf.username,
conf.password,
- {
- host: conf.host,
- dialect: conf.dialect,
- logging: false,
- dialectOptions: { multipleStatements: true },
- operatorsAliases: false,
- },
-)
+ config.auto
+);
+
+const tables = {
+ User: "users",
+ Payment: "payments"
+};
-const gqlfields = {}
-const gqltypes = {}
+const db = new Sequelize(conf.database, conf.username, conf.password, {
+ host: conf.host,
+ dialect: conf.dialect,
+ logging: false,
+ dialectOptions: { multipleStatements: true }
+});
-const p = (lnrpc) => {
+const gqlfields = {};
+const gqltypes = {};
+
+const p = lnrpc => {
return new Promise((resolve, reject) => {
return auto.run(() => {
- Object.keys(tables).forEach((k) => {
- let t = tables[k]
- let fields = {}
+ Object.keys(tables).forEach(k => {
+ let t = tables[k];
+ let fields = {};
Object.keys(auto.tables[t]).forEach(f => {
- let isKey = f === 'id'
- let rawtype = auto.tables[t][f].type.toLowerCase()
- let type = Sequelize.STRING
+ let isKey = f === "id";
+ let rawtype = auto.tables[t][f].type.toLowerCase();
+ let type = Sequelize.STRING;
- if (rawtype.match(/^int/)) type = Sequelize.INTEGER
- if (rawtype.match(/^date/)) type = Sequelize.DATE
+ if (rawtype.match(/^int/)) type = Sequelize.INTEGER;
+ if (rawtype.match(/^date/)) type = Sequelize.DATE;
fields[f] = {
type: type,
field: f,
primaryKey: isKey,
- autoIncrement: isKey,
- }
- })
+ autoIncrement: isKey
+ };
+ });
- db[k] = db.define(k, fields, { tableName: t })
+ db[k] = db.define(k, fields, { tableName: t });
- let typefields = {}
+ let typefields = {};
- let options = {}
+ let options = {};
- if (t === 'users') {
+ if (t === "users") {
options = {
before: (findOptions, args, context) => {
- findOptions.where = { id: context.user.id }
- return findOptions
- }
- }
+ findOptions.where = { id: context.user.id };
+ return findOptions;
+ }
+ };
}
- if (t === 'payments') {
- db['Payment'].belongsTo(db['User'], {
- as: 'user',
- foreignKey: 'user_id'
- })
+ if (t === "payments") {
+ db["Payment"].belongsTo(db["User"], {
+ as: "user",
+ foreignKey: "user_id"
+ });
options = {
before: (findOptions, args, context) => {
- findOptions.where = { user_id: context.user.id }
- return findOptions
- }
- }
+ findOptions.where = { user_id: context.user.id };
+ return findOptions;
+ }
+ };
}
gqltypes[t] = new GraphQLObjectType({
name: t,
desc: t,
- fields: Object.assign(typefields, attributeFields(db[k])),
- })
+ fields: Object.assign(typefields, attributeFields(db[k]))
+ });
gqlfields[t] = {
type: new GraphQLList(gqltypes[t]),
args: Object.assign({}, defaultArgs(db[k]), defaultListArgs()),
- resolve: resolver(db[k], options),
- }
- })
+ resolve: resolver(db[k], options)
+ };
+ });
db.gqlschema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'RootQueryType',
+ name: "RootQueryType",
fields: gqlfields
- }),
- })
+ })
+ });
- resolve(db)
- })
- })
-}
+ resolve(db);
+ });
+ });
+};
-module.exports = p
+module.exports = p;