Exemple #1
0
def delete_business(business_id):
    """
        Delete business
    """
    user_id = token_id(request.headers.get('Authorization'))
    if Business.has_this_business(user_id, business_id):
        Business.delete_business(business_id)
        response = jsonify({
            'status': 'ok',
            'message': "Your business has been successfully deleted"
        })
        response.status_code = 202
        return response
    response = jsonify(
        status='error',
        message="This business doesn't exist or you don't have privileges to it")
    response.status_code = 400
    return response
Exemple #2
0
def update_business(business_id):
    """
        Update business
    """
    sent_data = request.get_json(force=True)
    user_id = token_id(request.headers.get('Authorization'))
    if Business.has_this_business(user_id, business_id):
        valid = validate(sent_data, REGISTER_BUSINESS_RULES)
        if valid != True:
            response = jsonify(
                status='error', message="Please provide required info", errors=valid)
            response.status_code = 400
            return response
        data = {
            'user_id': user_id,
            'name': sent_data['name'],
            'description': sent_data['description'],
            'country': sent_data['country'],
            'city': sent_data['city'],
        }
        if Business.has_two_same_business(user_id, sent_data['name'], business_id):
            response = jsonify(
                status='error',
                message="You have already registered this other business with same name")
            response.status_code = 400
            return response
        Business.update(business_id, data)
        response = jsonify({
            'status': 'ok',
            'message': "Your business has been successfully updated"
        })
        response.status_code = 202
        return response
    response = jsonify(
        status='error',
        message="This business doesn't exist or you don't have privileges to it")
    response.status_code = 400
    return response