Log Daily Symptoms, Log Multiple Symptoms API - uoftblueprint/the-period-purse GitHub Wiki

Log Daily Symptoms

GETsymptomsForDate

  • Retrieves the user's symptom data for the given date.
  • Calls getItem() on year as the key value, then with getItem() on month, then navigate to the desired day to get data.

Signature

GETsymptomsForDate(<day: int>, <month: int>, <year: int>): Promise<symptoms object>

Returns

  • Returns promise resolving when the set operation is completed. Promise contains a dictionary of the day's symptoms {"Flow": "light", "Mood": "sad", ...} if it previously existed, otherwise the promise contains a default version of the symptoms.
  • If promise rejects (due to getItem() failing, the year or month not existing, or some other reason), return a default version of the symptoms

POSTsymptomsForDate

  • Posts the user's symptom data into the local storage for the given date.
  • Calls getItem() with the year as the key value. This is to retrieve the month array for the mergerItem call.
  • Calls mergeItem() with the year as the key value, and the JSONified symptom data as the value, {month: [...,{symptoms},...]}.
    • This means that if the element representing that day is empty, a new symptom object will be recorded. If there already is data there, POSTsymptomsForDate will rewrite over any existing data for that date.
  • async means that we can await for this function

Signature

async POSTsymptomsForDate(<day: int>, <month: int>, <year: int>, Object(flow: str, mood: str, cramps: str, sleep: float, exercise: array of str)): Promise<void>

Returns

  • Returns promise resolving when the set operation is completed. If rejected, communicate to the frontend that an error occurred (which will prompt the user to try again).

LogMultiDayPeriod

  • Given an array of dates, for each date:

    • Check if a year/month combo exists, if not create that year/month and add this entry into it.
      • If index is empty (no data): add object with flow symptom = “MEDIUM”
      • Else (data already there): Flip the flow value (no flow -> medium flow, any other flow -> no flow)
  • Call POSTsymptomsForDate on each date in the array, passing in the date and JSONified symptom data as the value, {month: [...,{symptoms},...].

Signature

LogMultiDayPeriod(array of dates): Promise<void>

Returns

  • Returns promise resolving when the set operation is completed. If rejected, communicate to the frontend that an error occurred (which will prompt the user to try again).
⚠️ **GitHub.com Fallback** ⚠️