Started adding async calls for upgrading to Meteor 3.0. Numerous other fixes.

This commit is contained in:
2025-07-02 11:18:09 -07:00
parent e1216741d6
commit 2e99ad007c
32 changed files with 549 additions and 373 deletions

View File

@@ -1,20 +1,30 @@
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";
const TYPES = ['Retail', "Farmer's Market", "Restaurant", "Mail"];
const FREQUENCIES = ['Daily', 'Weekly'];
let Venues = new Mongo.Collection('Venues');
if(Meteor.isServer) {
//Set MongoDB indexes (or remove them) here.
try {
Venues.rawCollection().createIndex({name: -1}, {unique: true})
} catch(e) {console.log("Caught exception while setting indexes in MongoDB"); console.error(e)}
}
let VenuesSchema = new SimpleSchema({
name: {
type: String,
label: "Name",
optional: false,
trim: true,
index: 1,
unique: true
//index: 1,
//unique: true
},
type: {
type: String,
@@ -70,13 +80,13 @@ if(Meteor.isServer) {
//});
Meteor.methods({
createVenue: function(name, type, frequency) {
createVenue: async function(name, type, frequency) {
check(name, String);
check(type, String);
check(frequency, String);
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
Venues.insert({name, type, frequency, createdAt: new Date()});
await Venues.insertAsync({name, type, frequency, createdAt: new Date()});
}
else throw new Meteor.Error(403, "Not authorized.");
},
@@ -86,40 +96,40 @@ if(Meteor.isServer) {
// }
// else throw new Meteor.Error(403, "Not authorized.");
//},
updateVenue: function(id, name, type, frequency) {
updateVenue: async function(id, name, type, frequency) {
check(id, String);
check(name, String);
check(type, String);
check(frequency, String);
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
Venues.update(id, {$set: {name, type, frequency, updatedAt: new Date()}});
await Venues.updateAsync(id, {$set: {name, type, frequency, updatedAt: new Date()}});
}
else throw new Meteor.Error(403, "Not authorized.");
},
deactivateVenue: function(id) {
deactivateVenue: async function(id) {
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
//Venues.remove(id);
Venues.update(id, {$set: {deactivated: true}}, {bypassCollection2: true});
await Venues.updateAsync(id, {$set: {deactivated: true}}, {bypassCollection2: true});
}
else throw new Meteor.Error(403, "Not authorized.");
},
reactivateVenue: function(id) {
reactivateVenue: async function(id) {
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
Venues.update(id, {$set: {deactivated: false}}, {bypassCollection2: true});
await Venues.updateAsync(id, {$set: {deactivated: false}}, {bypassCollection2: true});
}
else throw new Meteor.Error(403, "Not authorized.");
},
hideVenue: function(id) { //One step past deactivated - will only show in the venues list if hidden venues are enabled.
hideVenue: async function(id) { //One step past deactivated - will only show in the venues list if hidden venues are enabled.
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
//Venues.remove(id);
Venues.update(id, {$set: {hidden: true}}, {bypassCollection2: true});
await Venues.updateAsync(id, {$set: {hidden: true}}, {bypassCollection2: true});
}
else throw new Meteor.Error(403, "Not authorized.");
},
showVenue: function(id) { //Returns the venue to being simply deactivated. Will again show in lists.
showVenue: async function(id) { //Returns the venue to being simply deactivated. Will again show in lists.
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
Venues.update(id, {$set: {hidden: false}}, {bypassCollection2: true});
await Venues.updateAsync(id, {$set: {hidden: false}}, {bypassCollection2: true});
}
else throw new Meteor.Error(403, "Not authorized.");
}