예제 #1
0
def update_business(business_id):
    '''
        Update business
    '''
    sent_data = request.get_json(force=True)
    user_id = token_id(request.headers.get('Authorization'))
    business = Business.get_by_user(business_id, user_id)
    if business is not None:
        valid = validate(sent_data, REGISTER_BUSINESS_RULES)
        if valid is not True:
            response = jsonify(status='error',
                               message="Please provide required info",
                               errors=valid)
            response.status_code = 400
            return response
        data = {
            'name': sent_data['name'],
            'description': sent_data['description'],
            'category': sent_data['category'],
            '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"
                                        " a 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
예제 #2
0
def delete_business(business_id):
    '''
        Delete business
    '''
    user_id = token_id(request.headers.get('Authorization'))
    business = Business.get_by_user(business_id, user_id)
    if business is not None:
        Review.delete_all(business.id)
        business.delete(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