summaryrefslogtreecommitdiff
path: root/db/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'db/index.js')
-rw-r--r--db/index.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/db/index.js b/db/index.js
index 2fd3f62..d74e7b8 100644
--- a/db/index.js
+++ b/db/index.js
@@ -30,9 +30,20 @@ db.ordersBySku = function (sku) {
var sku = skus.at(0)
var sku_id = sku.get('sku_id')
OrderSKU.where('ordersku_sku', sku_id).fetchAll({ columns: 'ordersku_order_id' }).then(function(ordersku_ids){
- var order_ids = ordersku_ids.map(function(el){ return el.get('ordersku_order_id') })
+ var order_ids = ordersku_ids.pluck('ordersku_order_id')
Order.where('order_id', 'in', order_ids).fetchAll().then(function(orders){
- resolve(orders)
+ var customer_ids = orders.pluck('order_customer_id')
+ Customer.where('customer_id', 'in', customer_ids).fetchAll().then(function(customers){
+ customers.forEach(function(customer){
+ var order = orders.find(function(order, id){
+ return order.get('order_customer_id') === customer.get('customer_id')
+ })
+ if (order) {
+ order.set('order_email', customer.get('customer_email'))
+ }
+ })
+ resolve(orders)
+ })
})
})
})