Started adding async calls for upgrading to Meteor 3.0. Numerous other fixes.
This commit is contained in:
@@ -1,17 +1,26 @@
|
||||
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';
|
||||
|
||||
let Measures = new Mongo.Collection('Measures');
|
||||
|
||||
if(Meteor.isServer) {
|
||||
//Set MongoDB indexes (or remove them) here.
|
||||
try {
|
||||
Measures.rawCollection().createIndex({name: -1}, {unique: true})
|
||||
} catch(e) {console.log("Caught exception while setting indexes in MongoDB"); console.error(e)}
|
||||
}
|
||||
|
||||
Measures.attachSchema(new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
label: "Name",
|
||||
optional: false,
|
||||
trim: true,
|
||||
index: 1,
|
||||
unique: true
|
||||
// index: 1, Requires aldeed:schema-index which requires an older version fo aldeed:collection2 (3.5.0 vs 4.0.2) This can be achieved by adding indexes to MongoDB directly.
|
||||
//unique: true
|
||||
},
|
||||
postfix: {
|
||||
type: String,
|
||||
@@ -63,39 +72,39 @@ if(Meteor.isServer) Meteor.publish('measures', function() {
|
||||
|
||||
if(Meteor.isServer) {
|
||||
Meteor.methods({
|
||||
createMeasure: function(name, postfix, order) {
|
||||
createMeasure: async function(name, postfix, order) {
|
||||
check(name, String);
|
||||
check(postfix, String);
|
||||
check(order, Number);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Measures.insert({name, postfix, order, createdAt: new Date()});
|
||||
await Measures.insertAsync({name, postfix, order, createdAt: new Date()});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
deactivateMeasure: function(id) {
|
||||
deactivateMeasure: async function(id) {
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
//Measures.remove(id);
|
||||
Measures.update(id, {$set: {deactivated: true}}, {bypassCollection2: true});
|
||||
await Measures.updateAsync(id, {$set: {deactivated: true}}, {bypassCollection2: true});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
reactivateMeasure: function(id) {
|
||||
reactivateMeasure: async function(id) {
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Measures.update(id, {$set: {deactivated: false}}, {bypassCollection2: true});
|
||||
await Measures.updateAsync(id, {$set: {deactivated: false}}, {bypassCollection2: true});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
hideMeasure: function(id) { //One step past deactivated - will only show in the measures list if hidden measures are enabled.
|
||||
hideMeasure: async function(id) { //One step past deactivated - will only show in the measures list if hidden measures are enabled.
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
//Measures.remove(id);
|
||||
Measures.update(id, {$set: {hidden: true}}, {bypassCollection2: true});
|
||||
await Measures.updateAsync(id, {$set: {hidden: true}}, {bypassCollection2: true});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
showMeasure: function(id) { //Returns the measure to being simply deactivated. Will again show in lists.
|
||||
showMeasure: async function(id) { //Returns the measure to being simply deactivated. Will again show in lists.
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Measures.update(id, {$set: {hidden: false}}, {bypassCollection2: true});
|
||||
await Measures.updateAsync(id, {$set: {hidden: false}}, {bypassCollection2: true});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
@@ -106,14 +115,14 @@ if(Meteor.isServer) {
|
||||
// }
|
||||
// else throw new Meteor.Error(403, "Not authorized.");
|
||||
//},
|
||||
updateMeasure: function(id, name, postfix, order) {
|
||||
updateMeasure: async function(id, name, postfix, order) {
|
||||
check(id, String);
|
||||
check(name, String);
|
||||
check(postfix, String);
|
||||
check(order, Number);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Measures.update(id, {$set: {name, postfix, order, updatedAt: new Date()}});
|
||||
await Measures.updateAsync(id, {$set: {name, postfix, order, updatedAt: new Date()}});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user