determineMember static method

Future<String?> determineMember(
  1. Responsible? responsible,
  2. AppModel app,
  3. MemberModel member,
  4. AssignmentModel currentAssignment,
)

Implementation

static Future<String?> determineMember(Responsible? responsible, AppModel app,
    MemberModel member, AssignmentModel currentAssignment) async {
  switch (responsible) {
    case Responsible.currentMember:
      return member.documentID;
    case Responsible.owner:
      return app.ownerID;
    case Responsible.first:
      var findAssignment = currentAssignment;
      String? assigneeId;
      while (findAssignment.triggeredById != null) {
        assigneeId = findAssignment.assigneeId;
        var found = await (assignmentRepository(appId: app.documentID)!
            .get(findAssignment.triggeredById));
        if (found != null) {
          findAssignment = found;
        } else {
          return null;
        }
      }
      return assigneeId;
    case Responsible.previous:
      if (currentAssignment.triggeredById != null) {
        var triggeredBy = await (assignmentRepository(appId: app.documentID)!
            .get(currentAssignment.triggeredById));
        if (triggeredBy != null) {
          return triggeredBy.assigneeId;
        } else {
          return null;
        }
      }
      break;
    case null:
      break;
  }
  return null;
}