Updates for async and await - still

This commit is contained in:
Brian McGonagill 2025-07-22 13:50:49 -05:00
parent febb36d75f
commit 706c5dc3ef
18 changed files with 220 additions and 233 deletions

View file

@ -12,7 +12,7 @@ UserLast.allow({
});
Meteor.methods({
'add.userLast' (view, viewId) {
async 'add.userLast' (view, viewId) {
check(view, String);
check(viewId, String);
@ -22,36 +22,33 @@ Meteor.methods({
// first let's find out if there's an entry for this user and view, and if so
// we'll just edit that entry with updated information
const getUserLast = async() => {
let userListInfo = await UserLast.findOneAsync({ userId: this.userId, view: view });
if (!userListInfo) {
console.log("Adding new user last item.");
return UserLast.insertAsync({
userId: this.userId,
view: view,
viewId: viewId,
dateAdded: Date(),
});
let userListInfo = await UserLast.findOneAsync({ userId: this.userId, view: view });
if (!userListInfo) {
console.log("Adding new user last item.");
return await UserLast.insertAsync({
userId: this.userId,
view: view,
viewId: viewId,
dateAdded: Date(),
});
} else {
console.log("Editing existing user last itme.");
// entry exists, call the edit function instead
let result = await Meteor.callAsync('edit.userLast', view, viewId);
if (!result) {
try {
console.log("Issue editing existing entry in userLast. Check the logs.");
} catch(error) {
console.log(" ERROR adding userLast item: " + error);
console.log(error.message);
console.log(error.stack);
}
} else {
console.log("Editing existing user last itme.");
// entry exists, call the edit function instead
let result = await Meteor.callAsync('edit.userLast', view, viewId);
if (!result) {
try {
console.log("Issue editing existing entry in userLast. Check the logs.");
} catch(error) {
console.log(" ERROR adding userLast item: " + error);
console.log(error.message);
console.log(error.stack);
}
} else {
return true;
}
return true;
}
}
return getUserLast();
},
'edit.userLast' (view, viewId) {
async 'edit.userLast' (view, viewId) {
check(view, String);
check(viewId, String);
@ -60,7 +57,7 @@ Meteor.methods({
}
console.log("Edit in progress.");
return UserLast.updateAsync({ view: view, userId: this.userId }, {
return await UserLast.updateAsync({ view: view, userId: this.userId }, {
$set: {
viewId: viewId,
dateLastUpdate: Date(),