Created
November 15, 2016 08:25
-
-
Save malikperang/c7458a9a302eb779ffc83114e5b38dc1 to your computer and use it in GitHub Desktop.
Sales api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Meteor } from 'meteor/meteor'; | |
import { Mongo } from 'meteor/mongo'; | |
import { check } from 'meteor/check'; | |
import { Transactions } from './transactions.js'; | |
export const Sales = new Mongo.Collection('sales', {idGeneration: 'MONGO'}); | |
if(Meteor.isServer){ | |
Meteor.publish('sales', function() { | |
return Sales.find({}); | |
}); | |
Meteor.methods({ | |
newSales: function(data) { | |
return Sales.insert(data); | |
}, | |
updateSales: function(quantity, totalAmount, date) { | |
var theDate = moment(date).add(1, 'days').format(); | |
Transactions.upsert({ | |
'date': new Date(theDate), | |
'createdBy': Meteor.userId(), | |
'createAt': new Date(theDate) | |
}, { | |
$inc: { | |
'totalSales': parseFloat(totalAmount), | |
'totalProfit': parseFloat(totalAmount) | |
} | |
}); | |
return Sales.update({ | |
// 'attachment': data | |
}, { | |
$set: { | |
'date': new Date(theDate), | |
'quantity': quantity, | |
'totalAmount': totalAmount, | |
'createdBy': Meteor.userId() | |
} | |
}); | |
}, | |
}); | |
Sales.allow({ | |
insert: function() {return true;}, | |
update: function() {return true;} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment