Skip to content

Commit

Permalink
handle logic to show echo tasks b00tc4mp#426
Browse files Browse the repository at this point in the history
  • Loading branch information
pankelix committed Mar 10, 2024
1 parent c637b7c commit 2a9e977
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
36 changes: 34 additions & 2 deletions staff/miguel-arias/project/api/logic/retrieveTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,55 @@ function retrieveTasks(homeId, week) {

const endOfCurrentWeek = weekEnd(currentDate, 1)

// traer todas las tareas
let tasks
try {
tasks = await Task.find({ home: homeId, date: { $gte: startOfCurrentWeek, $lte: endOfCurrentWeek } }).populate('template', '-__v').select('-__v').sort({ date: 1 }).lean()
tasks = await Task.find({ home: homeId }).populate('template', '-__v').select('-__v').sort({ date: 1 }).lean()
} catch (error) {
throw new SystemError(error.message)
}

if (!tasks)
throw new NotFoundError('task not found')

let tasksAndEchoes = []
tasks.forEach(task => {
if (task.date >= startOfCurrentWeek && task.date <= endOfCurrentWeek)
tasksAndEchoes.push({ ...task })

let currentDate = new Date(task.date)
let idCounter = 1

while (currentDate <= endOfCurrentWeek) {
currentDate = addDay(currentDate, task.template.periodicity)
if (currentDate >= startOfCurrentWeek && currentDate <= endOfCurrentWeek) {
const newTask = { ...task, date: new Date(currentDate), assignee: '', _id: task._id + '_' + idCounter }
tasksAndEchoes.push(newTask)
idCounter++
}
}
})

// de cada tarea quiero que se haga un date = date x periodicity mientras date <= endOfCurrentWeek
// si task.date >= startOfCurrentWeek && task.date <= endOfCurrentWeek, la pusheo en un nuevo array
// devuelvo este nuevo array

/* let tasks
try {
tasks = await Task.find({ home: homeId, date: { $gte: startOfCurrentWeek, $lte: endOfCurrentWeek } }).populate('template', '-__v').select('-__v').sort({ date: 1 }).lean()
} catch (error) {
throw new SystemError(error.message)
} */

tasksAndEchoes.forEach(task => {
task.id = task._id.toString()
delete task._id

task.date = dayEnd(task.date)
})

tasksAndEchoes.sort((a, b) => a.date - b.date)

/* let duplicatedTasks = tasks.map(task => ({ ...task, date: new Date(task.date) }))
let newTasks = []
duplicatedTasks.forEach(task => {
Expand All @@ -56,7 +88,7 @@ function retrieveTasks(homeId, week) {
return allTasks */

return tasks
return tasksAndEchoes
})()
}

Expand Down
4 changes: 2 additions & 2 deletions staff/miguel-arias/project/api/logic/retrieveTasks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import retrieveTasks from './retrieveTasks.js'

(async () => {
try {
await mongoose.connect('mongodb://127.0.0.1:27017/project')
await mongoose.connect('mongodb://127.0.0.1:27017/project2')

const task = await retrieveTasks('65da45873f666061bc54cf1b', 0)
const task = await retrieveTasks('65eb75180a9a6ff9f9422237', 2)
console.log('task retrieved', task)

await mongoose.disconnect()
Expand Down
1 change: 1 addition & 0 deletions staff/miguel-arias/project/app/src/components/Calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function Calendar(props) {
}, [props.stamp, week])

const handleOnTaskClick = (task) => {
task.id = task.id.split('_')[0]
setTask(task)
setView('react-to-task-view')
}
Expand Down

0 comments on commit 2a9e977

Please sign in to comment.