mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 00:08:49 +00:00
Updating framework to meteor 3 and later
This commit is contained in:
parent
717994508a
commit
cca29bc591
58 changed files with 2332 additions and 1611 deletions
299
server/main.js
299
server/main.js
|
|
@ -1,3 +1,5 @@
|
|||
// this file has been converted for meteor 3 and later
|
||||
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { SysConfig } from '../imports/api/systemConfig';
|
||||
import { MenuItems } from '../imports/api/menuItems';
|
||||
|
|
@ -5,142 +7,178 @@ import { Products } from '../imports/api/products.js';
|
|||
import { Menus } from '../imports/api/menu.js';
|
||||
import { MScripts } from '../imports/api/mScripts.js';
|
||||
import { UpdateInfo } from '../imports/api/updateInfo.js';
|
||||
import { Roles } from 'meteor/roles';
|
||||
|
||||
Meteor.startup(() => {
|
||||
Meteor.startup(async() => {
|
||||
// code to run on server at startup
|
||||
Roles.createRole("user", {unlessExists: true});
|
||||
Roles.createRole("admin", {unlessExists: true});
|
||||
Roles.createRole("systemadmin", {unlessExists: true});
|
||||
Roles.createRoleAsync("user", {unlessExists: true});
|
||||
Roles.createRoleAsync("admin", {unlessExists: true});
|
||||
Roles.createRoleAsync("systemadmin", {unlessExists: true});
|
||||
|
||||
// set the systemconfig defaults for registration
|
||||
// check if this has already been run
|
||||
let regPolRun = MScripts.findOne({ scriptName: "DefaultRegPolicy", scriptRun: true });
|
||||
if (typeof regPolRun == "undefined" || regPolRun == null || regPolRun == "") {
|
||||
let regPolicy = SysConfig.findOne({});
|
||||
if (typeof regPolicy == 'undefined') {
|
||||
return SysConfig.insert({
|
||||
SysAdminReg: false,
|
||||
dateAdded: new Date(),
|
||||
allowReg: true,
|
||||
allowUpdates: true,
|
||||
});
|
||||
} else {
|
||||
// console.log("Registration policy already set.");
|
||||
markScriptRun("DefaultRegPolicy");
|
||||
}
|
||||
let regPolRun = await MScripts.findOneAsync({ scriptName: "DefaultRegPolicy", scriptRun: true });
|
||||
if (!regPolRun) {
|
||||
try {
|
||||
let regPolicy = await SysConfig.findOneAsync({});
|
||||
if (!regPolicy) {
|
||||
SysConfig.insertAsync({
|
||||
SysAdminReg: false,
|
||||
dateAdded: new Date(),
|
||||
allowReg: true,
|
||||
allowUpdates: true,
|
||||
});
|
||||
markScriptRun("DefaultRegPolicy");
|
||||
} else {
|
||||
// console.log("Registration policy already set.");
|
||||
markScriptRun("DefaultRegPolicy");
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR trying to check if registration policy was set.");
|
||||
console.log(error.message);
|
||||
console.log(error.stack);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// check if the isLInked item exists on menuitems, and if not, add it (data cleanup task)
|
||||
// see if already updated
|
||||
let linkUpdateRun = MScripts.findOne({ scriptName: "updateMenuItemLinks", scriptRun: true });
|
||||
if (typeof linkUpdateRun == 'undefined' || linkUpdateRun == null || linkUpdateRun == "") {
|
||||
let itemInfoNoLink = MenuItems.find({ isLinked: { $exists: false } }).fetch();
|
||||
// console.log("No Ites with isLinked not set: " + itemInfoNoLink.length);
|
||||
if (itemInfoNoLink.length > 0) {
|
||||
// console.log("found items with isLinked not set.");
|
||||
// console.dir(itemInfoNoLink);
|
||||
let infoLength = itemInfoNoLink.length;
|
||||
for (i=0; i < infoLength; i++) {
|
||||
MenuItems.update({ _id: itemInfoNoLink[i]._id }, {
|
||||
$set: {
|
||||
isLinked: false,
|
||||
let linkUpdateRun = await MScripts.findOneAsync({ scriptName: "updateMenuItemLinks", scriptRun: true });
|
||||
try {
|
||||
if (!linkUpdateRun) {
|
||||
let itemInfoNoLink = MenuItems.find({ isLinked: { $exists: false } }).fetch();
|
||||
// console.log("No Ites with isLinked not set: " + itemInfoNoLink.length);
|
||||
if (itemInfoNoLink.length > 0) {
|
||||
// console.log("Found items with isLinked not set. Updating...");
|
||||
// console.dir(itemInfoNoLink);
|
||||
let infoLength = itemInfoNoLink.length;
|
||||
for (i=0; i < infoLength; i++) {
|
||||
MenuItems.updateAsync({ _id: itemInfoNoLink[i]._id }, {
|
||||
$set: {
|
||||
isLinked: false,
|
||||
}
|
||||
});
|
||||
if (i == (infoLength -1)) {
|
||||
markScriptRun("updateMenuItemLinks");
|
||||
}
|
||||
});
|
||||
if (i == (infoLength -1)) {
|
||||
markScriptRun("updateMenuItemLinks");
|
||||
}
|
||||
} else {
|
||||
// this will show if all items are found to have isLInked set.
|
||||
// console.log("No items with isLinked not set.");
|
||||
markScriptRun("updateMenuItemLinks");
|
||||
}
|
||||
} else {
|
||||
// this will show if all items are found to have isLInked set.
|
||||
// console.log("No items with isLinked not set.");
|
||||
markScriptRun("updateMenuItemLinks");
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR running check for isLinked items.");
|
||||
console.log(error.message);
|
||||
console.log(error.stack);
|
||||
}
|
||||
|
||||
|
||||
// update Products to be able to have multiple stores in the document
|
||||
// check if update already run
|
||||
let prodStoreArrayRun = MScripts.findOne({ scriptName: "changeProdStoreToArray", scriptRun: true });
|
||||
let prodStoreArrayRun = await MScripts.findOneAsync({ scriptName: "changeProdStoreToArray", scriptRun: true });
|
||||
if (!prodStoreArrayRun) {
|
||||
let prodInfo = Products.find({}).fetch();
|
||||
let prodCount = prodInfo.length;
|
||||
console.log("Updating Products to allow multiple store assocation for " + prodCount + " products.");
|
||||
for (j = 0; j < prodCount; j++) {
|
||||
if (typeof prodInfo[j].prodStore == 'object') {
|
||||
// console.log(typeof prodInfo[j].prodStore);
|
||||
// console.log("Is Array already");
|
||||
} else {
|
||||
let prodStoreArray = [];
|
||||
// console.log("---- ---- ----");
|
||||
// console.log(typeof prodInfo[j].prodStore);
|
||||
// console.log("---- Is Not Array.");
|
||||
let prodStore = prodInfo[j].prodStore;
|
||||
try {
|
||||
let prodInfo = Products.find({}).fetch();
|
||||
let prodCount = prodInfo.length;
|
||||
// console.log("Updating Products to allow multiple store assocation for " + prodCount + " products.");
|
||||
for (let j = 0; j < prodCount; j++) {
|
||||
if (typeof prodInfo[j].prodStore == 'object') {
|
||||
// console.log(typeof prodInfo[j].prodStore);
|
||||
// console.log("Is Array already");
|
||||
} else {
|
||||
let prodStoreArray = [];
|
||||
// console.log("---- ---- ----");
|
||||
// console.log(typeof prodInfo[j].prodStore);
|
||||
// console.log("---- Is Not Array.");
|
||||
let prodStore = prodInfo[j].prodStore;
|
||||
|
||||
prodStoreArray.push(prodStore);
|
||||
// console.dir(prodStoreArray);
|
||||
Products.update({ _id: prodInfo[j]._id }, {
|
||||
$set: {
|
||||
prodStore: prodStoreArray,
|
||||
}
|
||||
});
|
||||
prodStoreArray.push(prodStore);
|
||||
// console.dir(prodStoreArray);
|
||||
Products.update({ _id: prodInfo[j]._id }, {
|
||||
$set: {
|
||||
prodStore: prodStoreArray,
|
||||
}
|
||||
});
|
||||
}
|
||||
if (j == (prodCount -1)) {
|
||||
markScriptRun("changeProdStoreToArray");
|
||||
}
|
||||
}
|
||||
if (j == (prodCount -1)) {
|
||||
markScriptRun("changeProdStoreToArray");
|
||||
}
|
||||
}
|
||||
} catch(error) {
|
||||
console.log("Script to update product stores couldn't run.");
|
||||
console.log(error.message);
|
||||
console.log(error.stack);
|
||||
}
|
||||
}
|
||||
|
||||
// update menu items to new format so they get the linked products
|
||||
// check if this update has run
|
||||
let menuItemUpdRun = MScripts.findOne({ scriptName: "updateMenuProdLinks", scriptRun: true });
|
||||
let menuItemUpdRun = await MScripts.findOneAsync({ scriptName: "updateMenuProdLinks", scriptRun: true });
|
||||
if (!menuItemUpdRun) {
|
||||
let openMenus = Menus.find({ menuComplete: false }).fetch();
|
||||
let openMenuCount = openMenus.length;
|
||||
// console.log("Open Menu count is: " + openMenuCount);
|
||||
for (k = 0; k < openMenuCount; k++) {
|
||||
if (typeof openMenus.menuItems == 'object') {
|
||||
// console.log(openMenus.menuName + " appears to be converted.");
|
||||
markScriptRun("updateMenuProdLinks");
|
||||
} else {
|
||||
let menuId = openMenus[k]._id;
|
||||
try {
|
||||
let openMenus = Menus.find({ menuComplete: false }).fetch();
|
||||
let openMenuCount = openMenus.length;
|
||||
// console.log("Open Menu count is: " + openMenuCount);
|
||||
for (let k = 0; k < openMenuCount; k++) {
|
||||
if (typeof openMenus.menuItems == 'object') {
|
||||
// console.log(openMenus.menuName + " appears to be converted.");
|
||||
markScriptRun("updateMenuProdLinks");
|
||||
} else {
|
||||
let menuId = openMenus[k]._id;
|
||||
|
||||
let thisMenuItems = MenuItems.find({ menuId: menuId }).fetch();
|
||||
let thisMenuItems = MenuItems.find({ menuId: menuId }).fetch();
|
||||
|
||||
let itemCount = thisMenuItems.length;
|
||||
let itemCount = thisMenuItems.length;
|
||||
|
||||
for (l = 0; l < itemCount; l++) {
|
||||
Menus.update({ _id: menuId }, {
|
||||
$addToSet: {
|
||||
menuItems:
|
||||
{
|
||||
menuItemId: thisMenuItems[l]._id,
|
||||
menuItemName: thisMenuItems[l].itemName,
|
||||
serveDate: thisMenuItems[l].serveDate,
|
||||
serveDateActual: thisMenuItems[l].serveDateActual,
|
||||
isLinked: thisMenuItems[l].isLinked
|
||||
},
|
||||
}
|
||||
});
|
||||
for (l = 0; l < itemCount; l++) {
|
||||
Menus.update({ _id: menuId }, {
|
||||
$addToSet: {
|
||||
menuItems:
|
||||
{
|
||||
menuItemId: thisMenuItems[l]._id,
|
||||
menuItemName: thisMenuItems[l].itemName,
|
||||
serveDate: thisMenuItems[l].serveDate,
|
||||
serveDateActual: thisMenuItems[l].serveDateActual,
|
||||
isLinked: thisMenuItems[l].isLinked
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (k == (openMenuCount - 1)) {
|
||||
markScriptRun("updateMenuProdLinks");
|
||||
}
|
||||
}
|
||||
if (k == (openMenuCount - 1)) {
|
||||
markScriptRun("updateMenuProdLinks");
|
||||
}
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR updating the menu product links: ");
|
||||
console.log(error.message);
|
||||
console.log(error.stack);
|
||||
}
|
||||
} else {
|
||||
// console.log("Menu Item updates have already been run.");
|
||||
}
|
||||
|
||||
// get update available information if enabled in system confiuration
|
||||
let currConfig = SysConfig.findOne({});
|
||||
let feedurl = "https://gitlab.com/bmcgonag/get_my/-/releases.atom"
|
||||
if (currConfig.allowUpdates == true) {
|
||||
// console.log("Allow Updates is true");
|
||||
startCronForUpdates(feedurl);
|
||||
} else if (typeof currConfig.allowUpdates == 'undefined' || currConfig.allowUpdates == null) {
|
||||
SysConfig.update({ _id: currConfig._id }, { $set: {
|
||||
allowUpdates: true,
|
||||
}});
|
||||
startCronForUpdates(feedurl);
|
||||
let currConfig = await SysConfig.findOneAsync({});
|
||||
if (!currConfig) {
|
||||
// console.log("No Current Config found.")
|
||||
} else {
|
||||
try {
|
||||
let feedurl = "https://gitlab.com/bmcgonag/get_my/-/releases.atom"
|
||||
if (currConfig.allowUpdates == true) {
|
||||
// console.log("Allow Updates is true");
|
||||
startCronForUpdates(feedurl);
|
||||
} else if (typeof currConfig.allowUpdates == 'undefined' || currConfig.allowUpdates == null) {
|
||||
SysConfig.update({ _id: currConfig._id }, { $set: {
|
||||
allowUpdates: true,
|
||||
}});
|
||||
startCronForUpdates(feedurl);
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR checking current config for updates: " + error);
|
||||
console.log(error.message);
|
||||
console.log(error.stack);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -152,18 +190,23 @@ var startCronForUpdates = function(feedurl) {
|
|||
});
|
||||
}
|
||||
|
||||
var markScriptRun = function(scriptName) {
|
||||
var markScriptRun = async function(scriptName) {
|
||||
// check if this is already set
|
||||
let scriptRun = MScripts.findOne({ scriptName: scriptName });
|
||||
|
||||
if (scriptRun) {
|
||||
console.log(scriptName + " already set as run on " + scriptRun.runOn);
|
||||
let scriptRun = await MScripts.findOneAsync({ scriptName: scriptName });
|
||||
if (!scriptRun) {
|
||||
try {
|
||||
return MScripts.insertAsync({
|
||||
scriptName: scriptName,
|
||||
scriptRun: true,
|
||||
runOn: new Date()
|
||||
});
|
||||
} catch(error) {
|
||||
console.log(" ERROR inserting the script run log: " + error);
|
||||
console.log(error.message);
|
||||
console.log(error.stack);
|
||||
}
|
||||
} else {
|
||||
MScripts.insert({
|
||||
scriptName: scriptName,
|
||||
scriptRun: true,
|
||||
runOn: new Date()
|
||||
});
|
||||
// console.log(scriptName + " already set as run on " + scriptRun.runOn);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -175,16 +218,22 @@ var getUpdateInfoNow = async function(feedurl) {
|
|||
// console.dir(data[0].title);
|
||||
|
||||
// check if this title already exists in db
|
||||
let updatesExist = UpdateInfo.findOne({ title: data[0].title });
|
||||
if (!updatesExist) {
|
||||
UpdateInfo.insert({
|
||||
title: data[0].title,
|
||||
description: data[0].description,
|
||||
dateRelease: data[0].date,
|
||||
releaseLink: data[0].link,
|
||||
viewed: false
|
||||
});
|
||||
} else {
|
||||
console.log("No new updates available at this time.");
|
||||
let updatesExist = await UpdateInfo.findOneAsync({ title: data[0].title });
|
||||
try {
|
||||
if (!updatesExist) {
|
||||
UpdateInfo.insertAsync({
|
||||
title: data[0].title,
|
||||
description: data[0].description,
|
||||
dateRelease: data[0].date,
|
||||
releaseLink: data[0].link,
|
||||
viewed: false
|
||||
});
|
||||
} else {
|
||||
console.log("No new updates available at this time.");
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR checking for update: " + error);
|
||||
console.log(error.message);
|
||||
console.log(error.stack);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,52 +3,60 @@ import { Mongo } from 'meteor/mongo';
|
|||
import { check } from 'meteor/check';
|
||||
import { TaskItems } from '../imports/api/tasks';
|
||||
import { SysConfig } from '../imports/api/systemConfig';
|
||||
import { Roles } from 'meteor/roles';
|
||||
|
||||
Meteor.methods({
|
||||
'addToRole' (role) {
|
||||
let countOfUsers = Meteor.users.find().count();
|
||||
|
||||
// if users = 1 - set to role passed in function call
|
||||
if (countOfUsers > 1) {
|
||||
console.log("User id for role: " + Meteor.userId() );
|
||||
let userId = Meteor.userId();
|
||||
Roles.addUsersToRoles(userId, role);
|
||||
Meteor.call('add.darkModePref', "light", function(err, result) {
|
||||
if (err) {
|
||||
console.log(" ERROR: can't set user dark mode preference: " + err);
|
||||
const getUserInfo = async() => {
|
||||
try {
|
||||
let countOfUsers = await Meteor.users.find().countAsync();
|
||||
const user = await Meteor.userAsync();
|
||||
if (user) {
|
||||
let userId = user._id;
|
||||
if (countOfUsers > 1) {
|
||||
Roles.addUsersToRolesAsync(userId, role);
|
||||
const result = await Meteor.callAsync('add.darkModePref', "light");
|
||||
if (!result) {
|
||||
console.log(" ERROR: can't set user dark mode preference: " + err);
|
||||
} else {
|
||||
// console.log(" SUCCESSFULLY set user dark mode preference.");
|
||||
}
|
||||
} else if (countOfUsers == 1) {
|
||||
Roles.addUsersToRolesAsync(userId, "systemadmin");
|
||||
const result = await Meteor.callAsync('add.darkModePref', "light");
|
||||
if (!result) {
|
||||
console.log(" ERROR: can't set user dark mode preference: " + err);
|
||||
} else {
|
||||
console.log(" SUCCESSFULLY set user dark mode preference.");
|
||||
}
|
||||
} else {
|
||||
console.log("The count of users didn't seem to work when adding a new user.");
|
||||
}
|
||||
} else {
|
||||
// console.log(" SUCCESSFULLY set user dark mode preference.");
|
||||
console.log(" ---- No user info found.")
|
||||
}
|
||||
});
|
||||
} else if (countOfUsers == 1) {
|
||||
console.log("Creating first system admin user: " + Meteor.userId() );
|
||||
let userId = Meteor.userId();
|
||||
Roles.addUsersToRoles(userId, "systemadmin");
|
||||
Meteor.call('add.darkModePref', "light", function(err, result) {
|
||||
if (err) {
|
||||
console.log(" ERROR: can't set user dark mode preference: " + err);
|
||||
} else {
|
||||
// console.log(" SUCCESSFULLY set user dark mode preference.");
|
||||
}
|
||||
});
|
||||
} catch(error) {
|
||||
console.log(" ERROR getting user info on server: " + error);
|
||||
}
|
||||
}
|
||||
getUserInfo();
|
||||
},
|
||||
'edit.userPass' (userId, newPassword) {
|
||||
check(userId, String);
|
||||
check(newPassword, String);
|
||||
|
||||
return Accounts.setPassword(userId, newPassword);
|
||||
return Accounts.setPasswordAsync(userId, newPassword);
|
||||
},
|
||||
'delete.userFromSys' (userId) {
|
||||
check(userId, String);
|
||||
|
||||
return Meteor.users.remove({ _id: userId });
|
||||
return Meteor.users.removeAsync({ _id: userId });
|
||||
},
|
||||
'update.userEmail' (userId, email) {
|
||||
check(userId, String);
|
||||
check(email, String);
|
||||
|
||||
return Meteor.users.update({ _id: userId }, {
|
||||
return Meteor.users.updateAsync({ _id: userId }, {
|
||||
$set: {
|
||||
'emails.0.address': email,
|
||||
}
|
||||
|
|
@ -58,6 +66,6 @@ Meteor.methods({
|
|||
check(userId, String);
|
||||
check(role, String);
|
||||
|
||||
return Roles.setUserRoles(userId, role);
|
||||
return Roles.setUserRolesAsync(userId, role);
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,6 +13,13 @@ import { MenuProdLinks } from '../imports/api/menuProdLinks.js';
|
|||
import { UserLast } from '../imports/api/userLast.js';
|
||||
import { UpdateInfo } from '../imports/api/updateInfo.js';
|
||||
|
||||
Meteor.publish(null, function () {
|
||||
if (this.userId) {
|
||||
return Meteor.roleAssignment.find({ "user._id": this.userId });
|
||||
}
|
||||
this.ready();
|
||||
});
|
||||
|
||||
Meteor.publish("SystemConfig", function() {
|
||||
try {
|
||||
return SysConfig.find({});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue