Fixes and updates.
This commit is contained in:
@@ -128,13 +128,15 @@ if(Meteor.isServer) {
|
||||
if(!_.isNumber(skipCount) || skipCount < 0) skipCount = 0;
|
||||
|
||||
dbQuery = dbQuery.length > 0 ? {$and: dbQuery} : {};
|
||||
return Meteor.collections.Batches.find(dbQuery, {limit: limit, sort, skip: skipCount});
|
||||
//console.log("dbQuery=" + JSON.stringify(dbQuery));
|
||||
//console.log("Result Count: " + Batches.find(query).count());
|
||||
return Batches.find(dbQuery, {limit: limit, sort, skip: skipCount});
|
||||
});
|
||||
|
||||
Meteor.methods({
|
||||
getBatchCount: function(query) {
|
||||
//TODO: Validate the query?
|
||||
return Sales.find(query).count();
|
||||
return Batches.find(query).count();
|
||||
},
|
||||
insertBatches: function(batches) { //Insert one or more batches (if one, you can pass just the batch).
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
@@ -198,40 +200,44 @@ if(Meteor.isServer) {
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
editBatchComment: function(id, comment) {
|
||||
//editBatchComment: 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) {
|
||||
// Batches.update(id, {$set: {comment}}, function(error, count) {
|
||||
// if(error) throw new Meteor.Error(400, "Unexpected database error: " + error);
|
||||
// });
|
||||
// }
|
||||
// else {
|
||||
// Batches.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.");
|
||||
//},
|
||||
updateBatch: function(id, amount, comment) {
|
||||
check(id, String);
|
||||
check(comment, String);
|
||||
check(amount, Number);
|
||||
check(comment, Match.OneOf(String, undefined));
|
||||
|
||||
//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) {
|
||||
Batches.update(id, {$set: {comment}}, function(error, count) {
|
||||
if(error) throw new Meteor.Error(400, "Unexpected database error: " + error);
|
||||
});
|
||||
}
|
||||
else {
|
||||
Batches.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.");
|
||||
},
|
||||
updateBatch: function(id, date, amount) {
|
||||
check(id, String);
|
||||
check(date, Number); // TODO: Check that the format is YYYYMMDD
|
||||
check(amount, Number);
|
||||
|
||||
let dateString = date.toString();
|
||||
let timestamp = new Date(dateString.substring(0, 4) + "-" + dateString.substring(4, 6) + "-" + dateString.substring(6, 8) + "T00:00:00Z");
|
||||
let weekOfYear = timestamp.getWeek().toString();
|
||||
//let dateString = date.toString();
|
||||
//let timestamp = new Date(dateString.substring(0, 4) + "-" + dateString.substring(4, 6) + "-" + dateString.substring(6, 8) + "T00:00:00Z");
|
||||
//let weekOfYear = timestamp.getWeek().toString();
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Batches.update(id, {$set: {date, amount, timestamp, weekOfYear}}, function(err, id) {
|
||||
Batches.update(id, {$set: {comment, amount}}, function(err, id) {
|
||||
if(err) console.log(err);
|
||||
}, {bypassCollection2: true});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user