Exemplo n.º 1
0
    def update_service(jwt, service_id):
        body = request.get_json()
        try:
            name = body.get('name', None)
            type = body.get('type', None)
            address = body.get('address', None)
            region_id = body.get('region_id', None)
            email = body.get('email', None)
            phone = body.get('phone', None)
            website = body.get('website', None)
            image = body.get('image', None)

            if (name is None) and (type is None) and (address is None) \
                    and (region_id is None) and (email is None) \
                    and (phone is None)\
                    and (website is None) and (image is None):
                abort(422)

            service = Service.query.get(service_id)
            if (service is None):
                abort(402)

            if name is not None:
                service.name = name
            if type is not None:
                service.type = type
            if address is not None:
                service.address = address
            if region_id is not None:
                service.region_id = region_id
            if email is not None:
                service.email = email
            if phone is not None:
                service.phone = phone
            if image is not None:
                service.image = image
            if website is not None:
                service.website = website

            Service.update(service)
            return jsonify({'success': True, 'updated': service.id}), 200
        except BaseException:
            print(sys.exc_info())
            abort(500)