Skip to content

Instantly share code, notes, and snippets.

@malikperang
Created November 15, 2016 08:25
Show Gist options
  • Save malikperang/c7458a9a302eb779ffc83114e5b38dc1 to your computer and use it in GitHub Desktop.
Save malikperang/c7458a9a302eb779ffc83114e5b38dc1 to your computer and use it in GitHub Desktop.
Sales api
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