Grouping items in a helper?

This is an odd one for me.

I have a collection of tasks, and each task can have 1 to many startDateTimes. Essentially a task can be started and stopped multiple times in order to track the amount of time spent on a task.

So my collection structure is this:

{
    _id: 'osXC3tA4G4Cagtyrw',
    taskTimes: [
      {
        id: 72382828928613,
        startDateTime: ISODate("2023-05-05T21:20:02.983Z"),
        endDateTime: ISODate("2023-05-05T21:40:25.868Z")
      },
      {
        id: 48816369597327,
        startDateTime: ISODate("2023-05-05T21:44:49.545Z"),
        endDateTime: ISODate("2023-05-05T21:47:56.860Z")
      }
    ],
    client: 'client 1',
    notes: 'Test notes only on this task.',
    tags: [ { tag: 'maintenance' }, { tag: 'remote' } ],
    taskBy: 'LK5kvuSQcvka4qM2N'
  }

What I would like to do is setup a helper to return my tasks, with some limit of how many are returned, and group them by date. So, first grouping would be ‘Today’, then 2nd would be yesterday’s date, and I can manipulate what’s shown in html to show ‘Yesterday’ after that just show the date for each group of tasks going back 5 or 6 days, then have a final grouping of “Further Back” for any dates beyond 5 or 6 days if the limit hasn’t been reached yet.

I’ve had a few thoughts, but haven’t really figured out if there is a right (clean) way to do this client side with minimongo.

I’ve got queries that pull back Tasks by time frame (e.g. 1 day, 2 days, 5 days, 1 week (7 days), 2 weeks This week (from start of week to today), 1 month, This month (from start of month to today), but can’t get my mind wrapped around how to loop through and display tasks in groups in a helper.

I was thinking I could run the query, then use raix:handlebar-helpers to check if the date matches today’s date, then do an ‘else if’ for yesterday, and so on, but seems a bit heavy to do that for 5 or six checks.

Ideally what I would like is something like: Assuming today’s date to be the 18th of the month.

Today
  - task 1 card
  - task 2 card
Yesterday
  - task 1 card
  - task 2 card
  - task 3 card
  - task 4 card
5/16
  - task 1 card
  - task 2 card
5/15
  - task 1 card
  - task 2 card
  - task 3 card
  - task 4 card
  - task 5 card
5/14
------------------------
5/13
  - task 1 card
  - task 2 card

The cards for each day are different cards even though I used task 1, task 2, over and over…they are not the same card on multiple days.

Any ideas or help is greatly appreciated as always.

what is id: 72382828928613 and what is the source of this information?
I am asking this because It seems that both times in the taskTimes are being created at the same time (or inserted at the same time). Or you need to be abble to $addToSet in that area new timings?

No, these are added at different times using $addToSet. The id is just the time in milliseconds multiplied by a random integer.

ok, what I’d do in order to benefit from Mongo’s query system:


// document 1
{
    _id: 'xxxx',
    time: {
        id: 72382828928613, // no need for this. You already have an id of the document.
        start: ISODate("2023-05-05T21:20:02.983Z"),
        end: ISODate("2023-05-05T21:40:25.868Z")
     },
    client: 'client 1',
    notes: 'Test notes only on this task.',
    tags: [ 'maintenance', 'remote' ],  // no need for an object format here ... unless you need it :)
    taskBy: 'LK5kvuSQcvka4qM2N',
    anythingElse: '... that would help me filter through records. Eg. completed: true/fals, allocated: true/false'
  }

// document 2
{
    _id: 'yyyyy',
    time: {
        id: 48816369597327, // no need for this. You already have an id of the document.
        start: ISODate("2023-05-05T21:44:49.545Z"),
        end: ISODate("2023-05-05T21:47:56.860Z")
     },
    client: 'client 1',
    notes: 'Test notes only on this task.',
    tags: [ 'maintenance' , 'remote' ],
    taskBy: 'LK5kvuSQcvka4qM2N',
    anythingElse: '... that would help me filter through records. Eg. completed: true/fals, allocated: true/false'
  }