mirror of
https://gitlab.com/bmcgonag/get_my.git
synced 2026-03-27 00:08:49 +00:00
Fixing add task calls for async await
This commit is contained in:
parent
ca7bcb1a8f
commit
febb36d75f
5 changed files with 623 additions and 484 deletions
|
|
@ -13,7 +13,7 @@ TaskItems.allow({
|
|||
});
|
||||
|
||||
Meteor.methods({
|
||||
'add.task' (taskNameArr, assignedTo, assignedToId, taskDateArr, actDate) {
|
||||
async 'add.task' (taskNameArr, assignedTo, assignedToId, taskDateArr, actDate) {
|
||||
check(taskNameArr, [Object]);
|
||||
check(assignedTo, String);
|
||||
check(taskDateArr, [String]);
|
||||
|
|
@ -23,41 +23,15 @@ Meteor.methods({
|
|||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to add tasks. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
let username;
|
||||
let usInfo;
|
||||
|
||||
if (assignedTo == "self") {
|
||||
const uInfo = async() => {
|
||||
let userInfo = await Meteor.users.findOneAsync({ _id: this.userId });
|
||||
if (!userInfo) {
|
||||
console.log("No matching user info found.")
|
||||
} else {
|
||||
username = userInfo.profile.fullname;
|
||||
assignedToId = this.userId;
|
||||
let usInf = { "username": username, "assignedToId": assignedToId };
|
||||
console.log("setting username = " + username +", and id = " + assignedToId);
|
||||
return usInf;
|
||||
}
|
||||
}
|
||||
usInfo = uInfo();
|
||||
console.dir(usInfo);
|
||||
} else {
|
||||
username = assignedTo;
|
||||
usInfo = { "username": assignedTo, "assignedToId": assignedToId };
|
||||
console.log("Set username = " + assignedTo);
|
||||
}
|
||||
|
||||
console.log("assignedToId = " + usInfo.assignedToId);
|
||||
|
||||
|
||||
for (let i=0; i < taskDateArr.length; i++) {
|
||||
for (let j=0; j < taskNameArr.length; j++) {
|
||||
TaskItems.insertAsync({
|
||||
await TaskItems.insertAsync({
|
||||
taskName: taskNameArr[j].id,
|
||||
taskDate: taskDateArr[i],
|
||||
actualDate: actDate[i],
|
||||
assignedTo: usInfo.username,
|
||||
assignedToId: usInfo.assignedToId,
|
||||
assignedTo: assignedTo,
|
||||
assignedToId: assignedToId,
|
||||
isComplete: false,
|
||||
completedOn: null,
|
||||
assignedOn: new Date(),
|
||||
|
|
@ -65,9 +39,8 @@ Meteor.methods({
|
|||
});
|
||||
}
|
||||
}
|
||||
return;
|
||||
},
|
||||
'add.mytask' (taskName, assignedTo, assignedToId, taskDate, actDate) {
|
||||
async 'add.myTask' (taskName, taskDate, actDate) {
|
||||
check(taskName, String);
|
||||
check(taskDate, String);
|
||||
check(actDate, Date);
|
||||
|
|
@ -76,40 +49,28 @@ Meteor.methods({
|
|||
throw new Meteor.Error('You are not allowed to add tasks. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
let username;
|
||||
let usInfo;
|
||||
|
||||
if (assignedTo == "self") {
|
||||
const uInfo = async() => {
|
||||
let userInfo = await Meteor.users.findOneAsync({ _id: this.userId });
|
||||
if (!userInfo) {
|
||||
console.log("No matching user info found.")
|
||||
} else {
|
||||
username = userInfo.profile.fullname;
|
||||
assignedToId = this.userId;
|
||||
let usinf = { username: username, assignedToId: assignedToId };
|
||||
return usinf;
|
||||
}
|
||||
}
|
||||
usInfo = uInfo();
|
||||
let userInfo = await Meteor.users.findOneAsync({ _id: this.userId });
|
||||
if (!userInfo) {
|
||||
console.log("No matching user info found.")
|
||||
} else {
|
||||
username = assignedTo;
|
||||
usInfo = { username: assignedTo, assignedToId: assignedToId };
|
||||
try {
|
||||
return await TaskItems.insertAsync({
|
||||
taskName: taskName,
|
||||
taskDate: taskDate,
|
||||
actualDate: actDate,
|
||||
assignedTo: userInfo.profile.fullname,
|
||||
assignedToId: this.userId,
|
||||
isComplete: false,
|
||||
completedOn: null,
|
||||
assignedOn: new Date(),
|
||||
assignedBy: this.userId,
|
||||
});
|
||||
} catch(error) {
|
||||
console.log(" ERROR adding tasksL " + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
return TaskItems.insertAsync({
|
||||
taskName: taskName,
|
||||
taskDate: taskDate,
|
||||
actualDate: actDate,
|
||||
assignedTo: usInfo.username,
|
||||
assignedToId: usInfo.assignedToId,
|
||||
isComplete: false,
|
||||
completedOn: null,
|
||||
assignedOn: new Date(),
|
||||
assignedBy: this.userId,
|
||||
});
|
||||
},
|
||||
'edit.task' (taskId, taskName, assignedTo, taskDate) {
|
||||
async 'edit.task' (taskId, taskName, assignedTo, taskDate) {
|
||||
check(taskId, String);
|
||||
check(taskName, String);
|
||||
check(assignedTo, String);
|
||||
|
|
@ -119,7 +80,7 @@ Meteor.methods({
|
|||
throw new Meteor.Error('You are not allowed to edit tasks. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
return TaskItems.updateAsync({ _id: taskId }, {
|
||||
return await TaskItems.updateAsync({ _id: taskId }, {
|
||||
$set: {
|
||||
taskName: taskName,
|
||||
taskDate: taskDate,
|
||||
|
|
@ -129,23 +90,23 @@ Meteor.methods({
|
|||
}
|
||||
});
|
||||
},
|
||||
'delete.task' (taskId) {
|
||||
async 'delete.task' (taskId) {
|
||||
check(taskId, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to delete tasks. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
return TaskItems.removeAsync({ _id: taskId });
|
||||
return await TaskItems.removeAsync({ _id: taskId });
|
||||
},
|
||||
'markTask.complete' (taskId) {
|
||||
async 'markTask.complete' (taskId) {
|
||||
check(taskId, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to mark tasks complete. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
return TaskItems.updateAsync({ _id: taskId }, {
|
||||
return await TaskItems.updateAsync({ _id: taskId }, {
|
||||
$set: {
|
||||
isComplete: true,
|
||||
completedOn: new Date(),
|
||||
|
|
@ -153,14 +114,14 @@ Meteor.methods({
|
|||
}
|
||||
});
|
||||
},
|
||||
'markTask.notComplete' (taskId) {
|
||||
async 'markTask.notComplete' (taskId) {
|
||||
check(taskId, String);
|
||||
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error('You are not allowed to mark tasks not complete. Make sure you are logged in with valid user credentials.');
|
||||
}
|
||||
|
||||
return TaskItems.updateAsync({ _id: taskId }, {
|
||||
return await TaskItems.updateAsync({ _id: taskId }, {
|
||||
$set: {
|
||||
isComplete: false,
|
||||
markedUncomplteOn: new Date(),
|
||||
|
|
@ -168,7 +129,7 @@ Meteor.methods({
|
|||
}
|
||||
});
|
||||
},
|
||||
'clean.Tasks' (timeFrame) {
|
||||
async 'clean.Tasks' (timeFrame) {
|
||||
check(timeFrame, String);
|
||||
|
||||
if (!this.userId) {
|
||||
|
|
@ -202,6 +163,6 @@ Meteor.methods({
|
|||
break;
|
||||
}
|
||||
|
||||
return TaskItems.removeAsync({ actualDate: { $lt: new Date((new Date()) - upToDate )}});
|
||||
return await TaskItems.removeAsync({ actualDate: { $lt: new Date((new Date()) - upToDate )}});
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue