overview

E69 - Show Only In-Progress Questionnaires in Response List

๐Ÿ”น Main Requirement

Only In-Progress questionnaires (i.e., not submitted and still valid) should be shown in the response list.

Feedback module KT


๐Ÿ•ฐ๏ธ Previous Behavior (Old Process)

In the earlier implementation, the default behavior was to show All questionnaires in the response list.

๐Ÿ”ฝ "All" Option Logic:

  • No filtering based on validToDate.
  • Both submitted and not submitted questionnaires were shown.
  • All available records were displayed by default when the dropdown was not used or left on the "All" option.

This has now changed with the E69 update, where "InProgress" is the default view.

๐Ÿ”ฝ Dropdown Options

  • All โ€“ Show all questionnaires.
  • Completed โ€“ Show only submitted questionnaires.
  • InProgress โ€“ Show only unsubmitted and still valid questionnaires (Default Selected).

โœ… Conditions for "InProgress"

  • validToDate > currentTime (questionnaire is still valid).
  • Questionnaire has not been submitted.
{
validFromDate: {
$lte: new Date()
}
}

โš™๏ธ Logic Flow

  • getQAList()

1. Get Valid Question Sets

Call the getDocuments API with the following filter:

{
validToDate: { $gt: new Date() },
departments: { $in: ['HR'] }
}

Extract the questionSetIds from the API response.

๐Ÿ“ญ Note on Empty Results

If the response is empty, it means the user has either:

  • Submitted all valid questionnaires, or
  • There are no valid (non-expired) questionnaires available.

โžก๏ธ In this case, the response list will display no data to display (empty state).


2. Check Submitted Answers

  • After submitting the Questionnarie for that particular questionSetId - AnswerSetId will be created. Call the getDocument API using:
{
questionSetId: { $in: [extracted IDs] },
status: 1 // submitted
}

Identify the questionSetIds that have already been submitted.


3. Find In-Progress Questionnaires

Subtract submitted IDs from the valid question IDs:

RemainingValues = validIds - submittedIds;
returnVal.IdArr = RemainingValues;

These are the In-Progress questionnaires to be displayed in the list.


๐Ÿงช Example

Step 1 โ€“ Question Sets from DB

response.data = [
{ questionSetId: 'q1', title: 'Q1 Title' },
{ questionSetId: 'q2', title: 'Q2 Title' },
{ questionSetId: 'q3', title: 'Q3 Title' }
]

Step 2 โ€“ Submitted Answer Sets

ansResponse.data = [
{ questionSetId: 'q2', userId: 'user_123' }
]

Step 3 โ€“ Result

RemainingValues = ['q1', 'q3'];
returnVal.IdArr = ['q1', 'q3'];

These will be loaded in the response list under "InProgress".