get_my/imports/api/userConfig.js
2025-07-22 13:50:49 -05:00

46 lines
No EOL
1.3 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const UserConfig = new Mongo.Collection('userConfig');
UserConfig.allow({
insert: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
update: function(userId, doc){
// if use id exists, allow insert
return !!userId;
},
});
Meteor.methods({
async 'add.darkModePref' (pref) {
check(pref, String);
if (!this.userId) {
throw new Meteor.Error('Not able to change theme setting. Make sure you are logged in with valid system administrator credentials.');
}
return await UserConfig.insertAsync({
user: this.userId,
darkMode: pref,
dateAdded: Date()
});
},
async 'update.darkModePref' (pref) {
check(pref, String);
if (!this.userId) {
throw new Meteor.Error('Not able to change theme setting. Make sure you are logged in with valid system administrator credentials.');
}
return await UserConfig.updateAsync({ user: this.userId }, {
$set: {
darkMode: pref,
dateUpdate: Date()
}
});
}
});