Ivan Asmer 5 years ago
parent
commit
d335f49e01
2 changed files with 3 additions and 3 deletions
  1. 2 2
      index.js
  2. 1 1
      models.js

+ 2 - 2
index.js

@@ -270,13 +270,13 @@ const anonResolvers = ['login', 'createUser'];
 
 
         async setOrderGood({orderGood}, {jwt: {id}, models: {SlicedSavable, OrderGood, thisUser}}){
-            console.log(orderGood)
             let order  = await SlicedSavable.m.Order.findOne({'_id': ObjectID(orderGood.order)})
             let good   = await SlicedSavable.m.Good.findOne ({'_id': ObjectID(orderGood.good)})
             if (order && good){
                 let entity = await SlicedSavable.m.OrderGood.findOne({'order._id': order._id,
                                                                          'good._id':  good._id})
                 if (!entity){
+                    console.log('wtf')
                     entity = new OrderGood({})
                 }
 
@@ -303,7 +303,7 @@ const anonResolvers = ['login', 'createUser'];
         }
         const operationMatch = gql.query.match(/\{\s*([a-zA-Z]+)\s*/)
         const operationName  = gql.operationName || operationMatch[1]
-        console.log('before oper', operationName, operationMatch)
+        console.log('before oper', operationName)
         if ((!operationName) || anonResolvers.includes(operationName)){
             return {
                 schema: schema,

+ 1 - 1
models.js

@@ -59,7 +59,7 @@ module.exports = async (dbName='shop') => {
             }
 
             get total(){
-                return (async() => (await Promise.all(this.orderGoods)).reduce((a,b) => a.total + b.total))()
+                return (async() => (await Promise.all(this.orderGoods)).reduce((a,b) => (a.total || a) + b.total, 0))()
             }
 
             static get relations(){