Started adding async calls for upgrading to Meteor 3.0. Numerous other fixes.
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
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";
|
||||
|
||||
let Workers = new Mongo.Collection('Workers');
|
||||
|
||||
if(Meteor.isServer) {
|
||||
//Set MongoDB indexes (or remove them) here.
|
||||
try {
|
||||
Workers.rawCollection().createIndex({name: -1}, {unique: true})
|
||||
} catch(e) {console.log("Caught exception while setting indexes in MongoDB"); console.error(e)}
|
||||
}
|
||||
|
||||
let WORKER_ACTIVITIES = ['sales', 'prep', 'canning', 'farming'];
|
||||
let workersSchema = new SimpleSchema({
|
||||
name: {
|
||||
@@ -11,15 +21,18 @@ let workersSchema = new SimpleSchema({
|
||||
label: "Name",
|
||||
optional: false,
|
||||
trim: true,
|
||||
index: 1,
|
||||
unique: true
|
||||
//index: 1,
|
||||
//unique: true
|
||||
},
|
||||
activities: {
|
||||
type: [String],
|
||||
type: Array, //[String],
|
||||
label: "Activities",
|
||||
optional: false,
|
||||
trim: true
|
||||
},
|
||||
'activities.$': {
|
||||
type: String,
|
||||
},
|
||||
hourlyRate: {
|
||||
type: SimpleSchema.Integer,
|
||||
label: "HourlyRate",
|
||||
@@ -66,13 +79,13 @@ if(Meteor.isServer) Meteor.publish('workers', function() {
|
||||
|
||||
if(Meteor.isServer) {
|
||||
Meteor.methods({
|
||||
createWorker: function(name, activities, hourlyRate) {
|
||||
createWorker: async function(name, activities, hourlyRate) {
|
||||
check(name, String);
|
||||
check(activities, [String]);
|
||||
check(hourlyRate, Number);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Workers.insert({name, activities, hourlyRate, createdAt: new Date()});
|
||||
await Workers.insertAsync({name, activities, hourlyRate, createdAt: new Date()});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
@@ -83,39 +96,39 @@ if(Meteor.isServer) {
|
||||
// }
|
||||
// else throw new Meteor.Error(403, "Not authorized.");
|
||||
//},
|
||||
updateWorker: function(id, name, activities, hourlyRate) {
|
||||
updateWorker: async function(id, name, activities, hourlyRate) {
|
||||
check(id, String);
|
||||
check(name, String);
|
||||
check(activities, [String]);
|
||||
check(hourlyRate, Number);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Workers.update(id, {$set: {name, activities, hourlyRate, updatedAt: new Date()}});
|
||||
await Workers.updateAsync(id, {$set: {name, activities, hourlyRate, updatedAt: new Date()}});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
deactivateWorker: function(id) {
|
||||
deactivateWorker: async function(id) {
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
//Workers.remove(id);
|
||||
Workers.update(id, {$set: {deactivated: true}}, {bypassCollection2: true});
|
||||
await Workers.updateAsync(id, {$set: {deactivated: true}}, {bypassCollection2: true});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
reactivateWorker: function(id) {
|
||||
reactivateWorker: async function(id) {
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Workers.update(id, {$set: {deactivated: false}}, {bypassCollection2: true});
|
||||
await Workers.updateAsync(id, {$set: {deactivated: false}}, {bypassCollection2: true});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
hideWorker: function(id) { //One step past deactivated - will only show in the Workers list if hidden Workers are enabled.
|
||||
hideWorker: async function(id) { //One step past deactivated - will only show in the Workers list if hidden Workers are enabled.
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Workers.update(id, {$set: {hidden: true}}, {bypassCollection2: true});
|
||||
await Workers.updateAsync(id, {$set: {hidden: true}}, {bypassCollection2: true});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
showWorker: function(id) { //Returns the measure to being simply deactivated. Will again show in lists.
|
||||
showWorker: async function(id) { //Returns the measure to being simply deactivated. Will again show in lists.
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Workers.update(id, {$set: {hidden: false}}, {bypassCollection2: true});
|
||||
await Workers.updateAsync(id, {$set: {hidden: false}}, {bypassCollection2: true});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user