def my_balance(_, info, workspace_id): user = current_user_in_workspace_or_error(ws_id=workspace_id) rule_result = execute_balance_calculation_rule(ws_id=workspace_id, user_id=user.id) return Balance(left_paid_leaves=rule_result.left_paid_leaves, left_unpaid_leaves=rule_result.left_unpaid_leaves, left_sick_leaves=rule_result.left_sick_leaves, total_paid_leaves=rule_result.total_paid_leaves, total_unpaid_leaves=rule_result.total_unpaid_leaves, total_sick_leaves=rule_result.total_sick_leaves)
def mutate(self, _, type, start_date, end_date, workspace_id, user_id, comment): user_id = user_id or current_user_in_workspace_or_error( ws_id=workspace_id).id user = User.find_by_id(user_id) day_off = DayOff(leave_type=LeaveTypes[type], start_date=start_date, end_date=end_date, workspace_id=workspace_id, comment=comment, user_id=user.id) rule_result = execute_day_off_validation_rule(day_off=day_off) response = CreateDayOff(errors=rule_result.errors, warnings=rule_result.warnings, notes=rule_result.notes) if rule_result.is_rejected: return response try: day_off.save_and_persist() try: ws_owner = WorkspaceUserRole.find( ws_id=workspace_id, role=WorkspaceUserRoles.OWNER) if ws_owner is not None and ws_owner.user_id != user.id: profile = UserProfile.find(user_id=user.id) uds = UserDevice.find_all(user_id=ws_owner.user_id) for ud in uds: if ud is not None and ud.device_token is not None: push_body = 'Someone needs off ;)' if profile is not None: push_body = '{} {} requested {}'.format( profile.first_name, profile.last_name, LeaveTypesLabels[type]) send_push( to=ud.device_token, title='Leave request', body=push_body, custom_data={'type': 'new_leave_requested'}) except Exception as e: LOG.error( f'Failed to send push notification about new leave. Error: {e}' ) response.day_off = day_off except Exception as e: LOG.error(f'Could not add a day off. Error: {e}') raise GraphQLError('Could not add a day off') return response
def workspace_invitations(_, info, workspace_id): _ = current_user_in_workspace_or_error(ws_id=workspace_id) return db.session.query(WorkspaceInvitation).filter_by( ws_id=workspace_id).order_by(WorkspaceInvitation.status.desc()).all()
def workspace_by_id(_, info, workspace_id): _ = current_user_in_workspace_or_error(ws_id=workspace_id) return _WorkspaceModel.find(id=workspace_id)
def my_leaves(_, info, workspace_id): user = current_user_in_workspace_or_error(ws_id=workspace_id) return _DayOff.find_all(user_id=user.id, workspace_id=workspace_id)
def day_offs(_, info, workspace_id): user = current_user_in_workspace_or_error(ws_id=workspace_id) return _DayOff.query(). \ filter(_DayOff.workspace_id == workspace_id). \ all()
def team_calendar(_, info, workspace_id): user = current_user_in_workspace_or_error(ws_id=workspace_id) return _DayOff.query(). \ filter(_DayOff.workspace_id == workspace_id). \ filter(_DayOff.approved_by_id != None). \ all()
def workspace_dates(_, info, workspace_id): current_user_in_workspace_or_error(ws_id=workspace_id) return WorkspaceDate.find_all(ws_id=workspace_id)