import { Meteor } from 'meteor/meteor'; import { Mongo } from 'meteor/mongo'; import { check } from 'meteor/check'; export const SysConfig = new Mongo.Collection('sysConfig'); SysConfig.allow({ insert: function(userId, doc){ // if use id exists, allow insert return !!userId; }, }); Meteor.methods({ async 'add.noSysAdminReg' (admReg, genReg) { check(admReg, Boolean); check(genReg, Boolean); if (!this.userId) { throw new Meteor.Error('Not able to change registration setting. Make sure you are logged in with valid system administrator credentials.'); } const currConfig = async() => { let curr = await SysConfig.findOneAsync({}); if (!curr) { try { return await SysConfig.insertAsync({ SysAdminReg: admReg, dateAdded: new Date(), allowReg: genReg, }); } catch(error) { console.log(" ERROR trying to insert system config:"); console.log(error.message); console.log(error.stack); } } else { try { let configId = curr._id; const addNoSys = await Meteor.callAsync('edit.noSysAdminReg', configId, admReg, genReg); if (!addNoSys) { // console.log(" Couldn't edit the system config."); } else { // console.log("Success updating sys admin reg."); } } catch(error) { console.log(" ERROR trying to pull current system config:"); console.log(error.message); console.log(error.stack); } } } currConfig(); }, async 'edit.noSysAdminReg' (configId, canReg, genReg) { check(canReg, Boolean); check(configId, String); check(genReg, Boolean); if (!this.userId) { throw new Meteor.Error('Not able to change registration setting. Make sure you are logged in with valid system administrator credentials.'); } return await SysConfig.updateAsync({ _id: configId }, { $set: { SysAdminReg: canReg, allowReg: genReg, dateUpdated: new Date(), } }); }, async 'allow.updateInfo' (allowUpdate) { check(allowUpdate, Boolean); if (!this.userId) { throw new Meteor.Error('Not able to change system update notification settings. Make sure you are logged in with valid system administrator credentials.'); } let curr = SysConfig.findOne({}); let configId = curr._id; return await SysConfig.updateAsync({ _id: configId }, { $set: { allowUpdates: allowUpdate, } }); }, });