def CreateMultipleInvites(current_user, user_type): if not request.data: return ResponseHelper.ReturnBadRequestResponse() else: request_data = json.loads(request.data) invite = Invite( None, # For Id that is auto generated by a trigger request_data[str(InvitesTable.INVITE_TYPE)], current_user, # Ensure log is created for the current user, None, request_data[str(InvitesTable.STATUS)], request_data[str(InvitesTable.SEND_DATE)], request_data[str(InvitesTable.EVENT_ID)]) recipients = request_data["Recipients"] invite_dao = InviteDao() if invite_dao.CreateMultipleInvites(invite, recipients): return ResponseHelper.ReturnCreatedResponse("Invites Created") else: return ResponseHelper.ReturnConflictResponse( "Unable to Create Invites!")
def DeleteEvent(current_user, user_type, event_id): if not event_id: return ResponseHelper.ReturnBadRequestResponse() host_check_dao = EventDao() if not host_check_dao.CheckHostAccess(current_user, event_id): return ResponseHelper.ReturnBadRequestResponse() invite_dao = InviteDao() invite_dao.DeleteInvitesFromEvent(event_id) event_dao = EventDao() if event_dao.DeleteEvent(event_id): return ResponseHelper.ReturnOkResponse("Event Deleted!") else: return ResponseHelper.ReturnConflictResponse("Unable to Delete Event!")
def DeleteInvite(current_user, user_type, invite_id): invite_check_dao = InviteDao() if invite_check_dao.CanEditOrDelete(current_user, invite_id): invite_dao = InviteDao() if invite_dao.DeclineInvite(invite_id): return ResponseHelper.ReturnOkResponse("Invite Declined") else: return ResponseHelper.ReturnConflictResponse( "Unable to Decline Invite!") else: return ResponseHelper.ReturnBadRequestResponse()
def UpdateMultipleInvite(current_user, user_type): if not request.data: return ResponseHelper.ReturnBadRequestResponse() else: request_data = json.loads(request.data) update_data = UpdateInviteData( request_data[RequestConstants.UPDATE_REQUEST_MEMBER_KEYS], request_data[RequestConstants.UPDATE_REQUEST_MEMBER_VALUES], len(request_data[RequestConstants.UPDATE_REQUEST_MEMBER_VALUES]), request_data["Invite_Ids"], None, None) invite_check_dao = InviteDao() if invite_check_dao.CanEditOrDeleteMultiple(current_user, update_data.inviteIds): if InvitesTable.ID in update_data.memberKeys: return ResponseHelper.ReturnBadRequestResponse() if InvitesTable.SENT_BY in update_data.memberKeys: return ResponseHelper.ReturnBadRequestResponse() if InvitesTable.SENT_TO in update_data.memberKeys: return ResponseHelper.ReturnBadRequestResponse() invite_dao = InviteDao() if invite_dao.UpdateMultipleInvites(update_data): return ResponseHelper.ReturnOkResponse("Invite Updated") else: return ResponseHelper.ReturnConflictResponse( "Unable to Update Invite!") else: return ResponseHelper.ReturnBadRequestResponse()
def GetInvites(current_user, user_type, invite_status_type): invite_type = request.args.get('type') invite_types = ["one-one", "vid-con", "coa-dat", "ath-dat"] if not invite_status_type: return ResponseHelper.ReturnBadRequestResponse() if not invite_type or invite_type not in invite_types: if invite_status_type == "sent" or invite_status_type == "received": invite_dao = InviteDao() invites = invite_dao.GetInvites(current_user, invite_status_type) if invites: return ResponseHelper.ReturnOkDataResponse( "Request OK", {"Invites": invites}) else: return ResponseHelper.ReturnNotFoundResponse( "No Invites Found!") elif invite_status_type == "new": invite_dao = InviteDao() count = invite_dao.GetNewInvitesCount(current_user) if count: return ResponseHelper.ReturnOkDataResponse("Request OK", count) else: return ResponseHelper.ReturnOkDataResponse("Request OK", 0) else: return ResponseHelper.ReturnBadRequestResponse() else: if invite_status_type == "sent" or invite_status_type == "received": if invite_type == "ath-dat" and user_type != RequestConstants.USER_TYPE_ATH: return ResponseHelper.ReturnBadRequestResponse() if invite_type == "coa-dat" and user_type != RequestConstants.USER_TYPE_COA: return ResponseHelper.ReturnBadRequestResponse() invite_dao = InviteDao() invites = invite_dao.GetInvites( current_user, invite_status_type, (invite_types.index(invite_type) + 1)) if invites: return ResponseHelper.ReturnOkDataResponse( "Request OK", {"Invites": invites}) else: return ResponseHelper.ReturnNotFoundResponse( "No Invites Found!") else: return ResponseHelper.ReturnBadRequestResponse()
def CreateCoachAccessWithInvite(self, access): create_invite_dao = InviteDao() invite = Invite( None, # For Id that is auto generated by a trigger 3, access.Coach_Id.__str__(), access.Athlete_Id.__str__(), 1, access.Start_Date.__str__(), None) if create_invite_dao.CreateSingleInvite(invite): get_invite_dao = InviteDao() invite_confirm = get_invite_dao.GetInvite(invite.Sent_By, invite.Sent_To, invite.Status, invite.Invite_Type, invite.Send_Date) if invite_confirm: cursor = self.db.cursor() sql = QueryBuilder() \ .Insert() \ .Into() \ .Table(CoachAthleteTable.TABLE_NAME) \ .ColumnsBrackets([ CoachAthleteTable.ATHLETE_ID, CoachAthleteTable.COACH_ID, CoachAthleteTable.CAN_ACCESS_TRAINING_LOG, CoachAthleteTable.CAN_ACCESS_TARGETS, CoachAthleteTable.IS_ACTIVE, CoachAthleteTable.START_DATE, CoachAthleteTable.INVITE_ID, ]) \ .ValuesKeyword() \ .ValuesBrackets([ access.Athlete_Id.__str__(), access.Coach_Id.__str__(), access.Can_Access_Training_Log.__str__(), access.Can_Access_Targets.__str__(), access.Is_Active.__str__(), access.Start_Date.__str__(), invite_confirm[str(InvitesTable.ID)] ]) \ .Build() cursor.execute(sql, QueryBuilder().CountNulls(sql).BuildNullTuple()) if cursor.rowcount != 0: self.db.commit() cursor.close() self.db.close() return True else: cursor.close() self.db.close() return None else: return None else: return None