Added a Sales Sheet page along with other changes.
This commit is contained in:
@@ -53,6 +53,11 @@ let SalesSchema = new SimpleSchema({
|
||||
// }
|
||||
// }
|
||||
},
|
||||
comment: {
|
||||
type: String,
|
||||
trim: false,
|
||||
optional: true
|
||||
},
|
||||
createdAt: {
|
||||
type: Date,
|
||||
label: "Created On",
|
||||
@@ -62,7 +67,7 @@ let SalesSchema = new SimpleSchema({
|
||||
Sales.attachSchema(SalesSchema);
|
||||
|
||||
if(Meteor.isServer) {
|
||||
Meteor.publish('sales', function(query, limit = 100, skipCount) {
|
||||
Meteor.publish('sales', function(query, sort, limit = 100, skipCount) {
|
||||
let dbQuery = [];
|
||||
|
||||
if(query) {
|
||||
@@ -90,7 +95,7 @@ if(Meteor.isServer) {
|
||||
if(!_.isNumber(skipCount) || skipCount < 0) skipCount = 0;
|
||||
|
||||
dbQuery = dbQuery.length > 0 ? {$and: dbQuery} : {};
|
||||
return Meteor.collections.Sales.find(dbQuery, {limit: limit, sort: {date: -1, createdAt: -1}, skip: skipCount});
|
||||
return Meteor.collections.Sales.find(dbQuery, {limit: limit, sort, skip: skipCount});
|
||||
});
|
||||
// time: expects either undefined, 'weekly', or 'monthly'
|
||||
// options: expects either undefined, 'markets', or 'types'
|
||||
@@ -179,6 +184,21 @@ if(Meteor.isServer) {
|
||||
return Sales.find(query).count();
|
||||
},
|
||||
insertSale: function(sale) {
|
||||
check(sale, {
|
||||
date: Date,
|
||||
amount: Match.Where(function(x) {
|
||||
check(x, Number);
|
||||
return x > 0;
|
||||
}),
|
||||
price: Match.Where(function(x) {
|
||||
check(x, Number);
|
||||
return x > 0;
|
||||
}),
|
||||
measureId: String,
|
||||
productId: String,
|
||||
venueId: String,
|
||||
comment: Match.Optional(String)
|
||||
});
|
||||
//TODO: Check the structure of sale. Use: check(sale, {name: String, ...});
|
||||
sale.createdAt = new Date();
|
||||
|
||||
@@ -193,9 +213,45 @@ if(Meteor.isServer) {
|
||||
check(id, String);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Sales.remove(id, {bypassCollection2: true});
|
||||
Sales.remove(id);
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
editSaleComment: function(id, comment) {
|
||||
check(id, String);
|
||||
check(comment, String);
|
||||
//Trim and convert empty comment to undefined.
|
||||
comment = comment ? comment.trim() : undefined;
|
||||
comment = comment && comment.length > 0 ? comment : undefined;
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
console.log("Changed comment of " + id + " to: " + comment);
|
||||
|
||||
if(comment) {
|
||||
Sales.update(id, {$set: {comment}}, function(error, count) {
|
||||
if(error) throw new Meteor.Error(400, "Unexpected database error: " + error);
|
||||
});
|
||||
}
|
||||
else {
|
||||
Sales.update(id, {$unset: {comment: ""}}, function(error, count) {
|
||||
if(error) throw new Meteor.Error(400, "Unexpected database error: " + error);
|
||||
});
|
||||
}
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
updateSale: function(id, date, venueId, price, amount) {
|
||||
check(id, String);
|
||||
check(date, Date);
|
||||
check(venueId, String);
|
||||
check(price, Number);
|
||||
check(amount, Number);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Sales.update(id, {$set: {date, venueId, price, amount}}, function(err, id) {
|
||||
if(err) console.log(err);
|
||||
}, {bypassCollection2: true});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user