Skip to content

Timesheet API: Add in filtering by date range for GET timesheets endpoint #25

@izzyconner

Description

@izzyconner

Linked to story item 14

As a developer, I want to have an optional way to get only a certain amount of timesheets based on a date range.

To support this, we should add optional startDate and endDate queries to the getTimesheets endpoint on the backend. These should expect to take in an numerical epoch value. If the startDate given is not the start of the week, the backend should round the epcoh to 00:00:00 of that week's Sunday.

The backend should filter DynamoDB queries by:

  1. any timesheet item whose StartDate field is >= the startDate query AND
  2. any timesheet item whose StartDate field is < the endDate query

Default values for the queries should be as follows:

  1. If no startDate query is provided, the default start date should be 3 weeks prior to the current week's Sunday. That is, if today is Friday, May 12th, the default weeks returned should be for Sunday May 7th, Sunday April 30th, and Sunday April 23rd.
  2. If no endDate query is provided, the default end date should be the startDate + 1

If no timesheet is found for that week(s), create new TimesheetSchema object for all companies the user belongs to, write them to the BreaktimeTimesheet DynamoDB table, and return the new TimesheetSchemas. By default, the TimesheetSchema attributes that should be populated for a new timesheet are:

  • UserId : the current user's sub
  • TimesheetId : a new generated uuid
  • CompanyId: the companyId it's being generated for
  • StartDate: the 00:00:00 Sunday epoch for the week of the startDate query, or the appropriate week's epoch if multiple weeks are requested
  • Status: an status object with each flag undefined
  • all arrays (WeekNotes, HoursData, and ScheduleTableData) should default to empty arrays

Conditions of satisfaction (make sure to test these manually or with automated tests):

  • Can request timesheets without any date range queries, and I should receive this week's timesheet + 2 weeks prior timesheets
  • Can request timesheet with only a startDate query, and I should receive only that week's timesheet
  • Can request timesheet with a startDate and endDate query, and I should receive all timesheets for that user
  • Can request timesheets with a non-Sunday startDate query, and I should still receive the correct week's timesheet
  • Can request timesheets with dates (queried or default) that include 1 or more weeks that do not have a timesheet in DynamoDB, and all appropriate timesheets should be created in DynamoDB and returned with all necessary fields filled out. All existing timesheets for the requested date range should also be returned

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions