NewcastleRSE / dolfin-flutter

The Flutter-based app for the Dolfin Project
0 stars 0 forks source link

Create http function that lets app know if/when the option to display a weekly form rather than daily #46

Closed KateCourt closed 2 years ago

KateCourt commented 2 years ago
  1. App calls endpoint providing child ID as a parameter
  2. Endpoint responds with: { showWeeklyForms: true/false, startOfWeek: 0-6, lastWeekSubmitted: true/false }
  1. If showWeeklyForms is true, app should display weekly forms. In addition, if lastWeekSubmitted is false, then display button to add a new weekly form and display message along the lines of 'Please let us know about the 7 days prior to [startOfWeek]'. Else display daily forms as normal.
KateCourt commented 2 years ago

Should we also use this function to say if it has been over a year (and therefore participation is ended)?

KateCourt commented 2 years ago

The above relies on the date associated with the weekly form being the date it applies to (start of week) rather than the date it was submitted, so the app needs to know what date each form is due on even if the user fills it in a few days late. Given this, I've got an adjusted suggestion:

  1. App calls endpoint providing child ID as a parameter
  2. Endpoint responds with: { showWeeklyForms: true/false, lastWeekSubmittedEnds: string, startWeeklyFormsDate: string }
  1. If showWeeklyForms is true, app should display weekly forms. lastWeekSubmittedEnds should be used to work out if the user should be given the option to enter a new weekly form or not, and to be used to calculate what the date field of any forms they submit should be. Note: unlike presently where date refers date submitted, we would need to change this to refer to what date the weeks ends that the form refers to. So if '2022-05-04' is returned, the app knows that the 'add form' button should not be displayed until 2022-05-11. If a date older than 7 days previously is displayed then the user has missed a week and so perhaps this should be shown as an option to catch up. This assumes that once they are a full week late they cannot submit a late form - we could change this if needed.
KateCourt commented 2 years ago

Created a callable function.

Details of how to call function from Flutter: https://firebase.google.com/docs/functions/callable#call_the_function

Use something like this:

var childDetails = firebase.functions().httpsCallable('checkChild'); childDetails({child_id: string}).then((result)=> { console.log(result); }).catch((error)=> { console.log(error); })

mdsimpson42 commented 2 years ago

Working in the latest version on Dev. Will add any bugs as separate issues.