Started adding async calls for upgrading to Meteor 3.0. Numerous other fixes.
This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
import {SimpleSchema} from 'meteor/aldeed:simple-schema';
|
||||
import 'meteor/aldeed:collection2/static'
|
||||
import SimpleSchema from 'meteor/aldeed:simple-schema';
|
||||
import Measures from "./Measure";
|
||||
|
||||
SalesSheets = new Mongo.Collection('SalesSheets');
|
||||
let SalesSheets = new Mongo.Collection('SalesSheets');
|
||||
|
||||
if(Meteor.isServer) {
|
||||
//Set MongoDB indexes (or remove them) here.
|
||||
try {
|
||||
SalesSheets.rawCollection().createIndex({name: -1}, {unique: false})
|
||||
} catch(e) {console.log("Caught exception while setting indexes in MongoDB"); console.error(e)}
|
||||
}
|
||||
|
||||
const SalesSheetSchema = new SimpleSchema({
|
||||
name: {
|
||||
@@ -11,8 +20,8 @@ const SalesSheetSchema = new SimpleSchema({
|
||||
label: "Name",
|
||||
optional: false,
|
||||
trim: true,
|
||||
index: 1,
|
||||
unique: false
|
||||
//index: 1,
|
||||
//unique: false
|
||||
},
|
||||
products: { //An ordered array of product id's included on the sheet.
|
||||
type: Array,
|
||||
@@ -27,7 +36,7 @@ const SalesSheetSchema = new SimpleSchema({
|
||||
label: "Name",
|
||||
optional: false,
|
||||
trim: true,
|
||||
unique: false
|
||||
//unique: false
|
||||
},
|
||||
productId: { //Note: Will be non-existent for headings.
|
||||
type: String,
|
||||
@@ -37,10 +46,13 @@ const SalesSheetSchema = new SimpleSchema({
|
||||
optional: true
|
||||
},
|
||||
measureIds: { //Note: Will be non-existent for headings.
|
||||
type: [String],
|
||||
type: Array, //[String],
|
||||
label: "Measure IDs",
|
||||
optional: true
|
||||
}
|
||||
},
|
||||
'measureIds.$': {
|
||||
type: String,
|
||||
},
|
||||
//measureIds: {
|
||||
// type: Array,
|
||||
// label: "Measure IDs",
|
||||
@@ -74,11 +86,11 @@ if(Meteor.isServer) {
|
||||
});
|
||||
|
||||
Meteor.methods({
|
||||
createSalesSheet: function(name) {
|
||||
createSalesSheet: async function(name) {
|
||||
check(name, String);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
return SalesSheets.insert({name, products: [], createdAt: new Date()});
|
||||
return await SalesSheets.insertAsync({name, products: [], createdAt: new Date()});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
@@ -98,7 +110,7 @@ if(Meteor.isServer) {
|
||||
//updateSalesSheet_updateProduct_removeMeasure: function(id, productId, productName, productMeasures) {
|
||||
//
|
||||
//},
|
||||
updateSalesSheet: function(id, name, products) {
|
||||
updateSalesSheet: async function(id, name, products) {
|
||||
check(id, String);
|
||||
check(name, String);
|
||||
check(products, [{
|
||||
@@ -128,7 +140,7 @@ if(Meteor.isServer) {
|
||||
//console.log("db.SalesSheet.update({_id: '" + id + "'}, {$set: {name: '" + name + "', updatedAt: " + new Date() + "}, $pull: {$exists: true}, $pushAll: [" + productList + "]})");
|
||||
|
||||
// Forces the object to be re-written, versus piecemeal updated.
|
||||
SalesSheets.update({_id: id}, {$set: {name: name, products: products, updatedAt: new Date()}}, {validate: false}, function(err, count) {
|
||||
await SalesSheets.updateAsync({_id: id}, {$set: {name: name, products: products, updatedAt: new Date()}}, {validate: false}, function(err, count) {
|
||||
if(err) console.log(err);
|
||||
});
|
||||
|
||||
@@ -146,11 +158,11 @@ if(Meteor.isServer) {
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
removeSalesSheet: function(id) {
|
||||
removeSalesSheet: async function(id) {
|
||||
check(id, String);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
SalesSheets.remove(id);
|
||||
await SalesSheets.removeAsync(id);
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user