def delete_client(self, request): cliente = Cliente.get_by_id(request.id) if not cliente: # If the stock doesn't exist, raise an error raise endpoints.BadRequestException("El ID de ese cliente no existe") cliente.key.delete() # If the stock exists, it removes it from the database time.sleep(1) clientes = Cliente.query().fetch() return ClientListResponse(clientes=[ClientApiHelper().to_message(cliente) for cliente in clientes if clientes])
def update_client(self, request): cliente = Cliente.get_by_id(request.id) if not cliente: # If the stock doesn't exist, raise an error raise endpoints.BadRequestException("El ID de ese cliente no existe") if not (request.documento and request.ruta and request.nombres and request.apellidos): raise endpoints.BadRequestException('Los datos: documento, ruta, nombres y apellidos, son obligatorios.') alert = ClientHelper.actualizar_registro( cliente.key, request.documento, request.ruta, request.nombres, request.apellidos, request.dir_casa, request.tel_casa, request.celular, request.nombre_est, request.dir_est) if alert[0] == "alert-danger": raise endpoints.BadRequestException(alert[1]) time.sleep(1) clientes = Cliente.query().fetch() return ClientListResponse(clientes=[ClientApiHelper().to_message(cliente) for cliente in clientes if clientes])