def update(id:int):
    company_id = session["user"]["company_id"]
    ### check existing customer
    if not db.is_existing(table="customers", conditions={"id":id, "company_id": company_id}):
        return jsonify(info="Customer not found"),404

    req = request.get_json(force=True)
    req = Customer.parse(req, "update")

    if "errors" in req:
        return jsonify(errors=req["errors"]),400
    req = req["customer"]
        
    customer = {}
    #name
    if "name" in req:
        if db.is_existing(table="customers", conditions={"name":req["name"],"company_id": company_id}):
            return jsonify(info="Customer with the same name already exists"),400

        customer["name"] = req["name"]

    #address
    if "address" in req:
        customer["address"] = req["address"]

    #location
    if "location" in req :
        customer["location_lat"] = req["location"]["lat"]
        customer["location_lng"] = req["location"]["lng"]

    #phone
    if "phone" in req:
        customer["phone"] = req["phone"]

    db.update(table="customers", params=customer, conditions={"id":id})
    return jsonify(info="Customer data updated successfully"),200
def create():
    req = request.get_json(force=True)
    customer = Customer.parse(req, "create")
    if "errors" in customer:
        return jsonify(errors=customer["errors"]),400
    customer = customer["customer"]

    ### check customer name duplication
    company_id = session["user"]["company_id"]
    if db.is_existing(table="customers",
                      conditions={"name":customer["name"], "company_id":company_id}):
        return jsonify(info="Customer with the same name already exist"),400

    # record customer
    data = {
        "name" : customer["name"],
        "address" : customer["address"],
        "location_lat" : customer["location"]["lat"],
        "location_lng" : customer["location"]["lng"],
        "phone" : customer["phone"],
        "company_id" : company_id
    }
    customerId= db.insert(table="customers", params=data)
    return jsonify(info="Customer created successfully", customerId=customerId),200