def search_customer(customer_id): """ Look up a customer in the DB and return a dictionary of their contact information including first name, last_name, phone number, and email address. :customer_id: String representing the customer's ID """ cust_dict = {} try: customer = Customers.get_or_none(Customers.customer_id == customer_id) if customer is not None: cust_dict = customer.as_contact_info_dictionary() else: LOGGER.info("No customer exists with customer_id: %s", customer_id) except OperationalError as op_error: LOGGER.info("Failed look up of customer with customer_id: %s", customer_id) LOGGER.error(op_error) return cust_dict
def update_customer_credit(customer_id, credit_limit): """ Update a customer's credit limit. :customer_id: String representing the customer's ID :credit_limit: A decimal representing the customer's credit limit """ try: customer = Customers.get_or_none(Customers.customer_id == customer_id) if customer is not None: limit = customer.credit_limit customer.credit_limit = credit_limit customer.save() msg = str("Credit limit updated from " + f"{limit} to {customer.credit_limit}") LOGGER.info(msg) else: msg = f"No customer exists with customer_id: {customer_id}" LOGGER.info(msg) raise ValueError(msg) except (IntegrityError, OperationalError) as error: raise ValueError(error)