Esempio n. 1
0
def new_customer():
    data_schema = CustomerCreateInputSchema()
    try:
        handle_request_validation(data_schema)
    except ValidationError as err:
        return jsonify(err.message), 400
    if not is_logged():
        return (jsonify({'message': 'Not Authorized'})), 401
    return CustomerService.save(request.get_json())
Esempio n. 2
0
def new_waiting_line():
    req_data = request.get_json()
    data_schema = WaitingLineCreateInputSchema()
    try:
        handle_request_validation(data_schema)
    except ValidationError as err:
        return jsonify(err.message), 400

    if not is_logged(
    ) or req_data['company_id'] != g.user.company_id or not is_admin():
        return (jsonify({'message': 'Not Authorized'})), 401

    return WaitingLineService.save(req_data)
Esempio n. 3
0
def save(data):
  line_up = LineUp(waiting_line_id= data['waiting_line_id'],
                     customer_id= data['customer_id'],
                     status=0, # ENTROU NA FILA
                     joined_at=datetime.now())

  if not is_logged(): # TODO: VALIDAR SE O USUÁRIO PERTENCE A EMPRESA
      return (jsonify({'message': 'Not Authorized' })), 401

  if line_up.query.filter(and_(LineUp.customer_id==data['customer_id'],LineUp.status < 3)).first() is not None:
      return (jsonify({'message': 'Customer already in an active Waiting Line'}), 400)

  db.session.add(line_up)
  db.session.commit()

  response = flask.make_response(jsonify({ 'data': {
                                      'id': line_up.id,
                                      'customer_id': line_up.customer_id,
                                      'waiting_line_id': line_up.waiting_line_id,
                                      'status': line_up.status,
                                      'joined_at': format_datetime(line_up.joined_at)}}), 201)
  response.headers["Content-Type"] = "application/json"
  return response
Esempio n. 4
0
def get_waiting_lines():
    if not is_logged():
        return (jsonify({'message': 'Not Authorized'})), 401

    return WaitingLineService.getAll()
Esempio n. 5
0
def call_customer(id):

    if not is_logged():  # TODO: VALIDAR SE O USUÁRIO PERTENCE A EMPRESA
        return (jsonify({'message': 'Not Authorized'})), 401
    return LineUpService.call_customer(id)
Esempio n. 6
0
def get_next_customer():

    if not is_logged():  # TODO: VALIDAR SE O USUÁRIO PERTENCE A EMPRESA
        return (jsonify({'message': 'Not Authorized'})), 401
    waiting_line_id = request.args['waiting_line_id']
    return LineUpService.get_next_customer(waiting_line_id)
Esempio n. 7
0
def get_current_user():
    if not is_logged():
        return (jsonify({'message': 'Not Authorized'})), 401
    return UserService.get_current_user()
Esempio n. 8
0
def get_company(id):
    if not is_logged() or id != g.user.company_id or not is_admin():
        return (jsonify({'message': 'Not Authorized' })), 401
    return CompanyService.get(id)
Esempio n. 9
0
def get_customer(id):
    if not is_logged():
        return (jsonify({'message': 'Not Authorized'})), 401
    return CustomerService.get(id)