Skip to content

Commit

Permalink
Merge pull request #243 from abakusbackup/update-tracks
Browse files Browse the repository at this point in the history
Add more information to the product sale track call
  • Loading branch information
larseen authored Mar 17, 2017
2 parents 8105243 + 1e42d5b commit 981ab6e
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/models/transactionProduct.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,50 @@ import db from '.';
import analytics from '../components/stats';

const trackProductUsage = transactionProduct => {
let product = null;
let customer = null;
let transaction = null;

db.Product.findOne({
where: {
id: transactionProduct.productId
}
})
.then(product => {
if (product) {
.then(result => {
product = result;
return result;
})
.then(() =>
db.Transaction.findOne({
where: {
id: transactionProduct.transactionId
}
})
)
.then(result => {
if (result) {
transaction = result;
return result;
}
return Promise.resolve();
})
.then(() => transaction.getCustomer())
.then(result => {
customer = result;
return result;
})

.then(() => {
if (product && customer && transaction) {
return analytics.track({
anonymousId: 'system',
userId: customer.id,
event: 'product_sale',
properties: {
systemId: product.systemId,
username: customer.username,
displayName: customer.displayName,
sellerId: transaction.sellerId,
transactionId: transaction.id,
productId: product.id,
name: product.name,
type: product.type,
Expand Down

0 comments on commit 981ab6e

Please sign in to comment.