MCPcopy Create free account
hub / github.com/RealDevSquad/website-backend / fetchUserTasks

Function fetchUserTasks

models/tasks.js:409–466  ·  view source on GitHub ↗
(username, statuses = [], field, order)

Source from the content-addressed store, hash-verified

407 */
408
409const fetchUserTasks = async (username, statuses = [], field, order) => {
410 try {
411 const userId = await userUtils.getUserId(username);
412
413 if (!userId) {
414 return { userNotFound: true };
415 }
416
417 let groupTasksSnapshot = [];
418 let featureTasksSnapshot = [];
419
420 if (statuses && statuses.length) {
421 if (field) {
422 groupTasksSnapshot = await tasksModel
423 .where("participants", "array-contains", userId)
424 .where("status", "in", statuses)
425 .orderBy(field, order)
426 .get();
427 featureTasksSnapshot = await tasksModel
428 .where("assignee", "==", userId)
429 .where("status", "in", statuses)
430 .orderBy(field, order)
431 .get();
432 } else {
433 groupTasksSnapshot = await tasksModel
434 .where("participants", "array-contains", userId)
435 .where("status", "in", statuses)
436 .get();
437 featureTasksSnapshot = await tasksModel.where("assignee", "==", userId).where("status", "in", statuses).get();
438 }
439 } else {
440 if (field) {
441 groupTasksSnapshot = await tasksModel
442 .where("participants", "array-contains", userId)
443 .orderBy(field, order)
444 .get();
445 featureTasksSnapshot = await tasksModel.where("assignee", "==", userId).orderBy(field, order).get();
446 } else {
447 groupTasksSnapshot = await tasksModel.where("participants", "array-contains", userId).get();
448 featureTasksSnapshot = await tasksModel.where("assignee", "==", userId).get();
449 }
450 }
451
452 const groupTasks = buildTasks(groupTasksSnapshot);
453 const tasks = buildTasks(featureTasksSnapshot, groupTasks);
454
455 const promises = tasks.map(async (task) => fromFirestoreData(task));
456 const updatedTasks = await Promise.all(promises);
457 const taskList = updatedTasks.map((task) => {
458 task.status = TASK_STATUS[task.status.toUpperCase()] || task.status;
459 return task;
460 });
461 return taskList;
462 } catch (err) {
463 logger.error("error getting tasks", err);
464 throw err;
465 }
466};

Callers 2

fetchSelfTasksFunction · 0.85
fetchUserCompletedTasksFunction · 0.85

Calls 3

buildTasksFunction · 0.85
fromFirestoreDataFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected