def resolveReport(root, info, token, brokerId, accountNumber): try: auth.decodeToken(token) report = makeReport(brokerId, accountNumber, "Current Report") return serializeReport(report) except AssertionError as e: raise graphql.GraphQLError(e)
def mutate(self, info, token, _id): try: auth.decodeToken(token) response = requests.delete( "{}/brokers/{}".format(config.HARAMBE_DATA_SERVICE_ENDPOINT, _id)) assert (response.status_code == 200), "Error removing broker" return RemoveBrokerAccount(True) except AssertionError as e: raise graphql.GraphQLError(e)
def mutate(self, info, token, brokerId, accountNumber, description): try: auth.decodeToken(token) report = makeReport(brokerId, accountNumber, description) response = requests.post("{}/reports".format( config.HARAMBE_DATA_SERVICE_ENDPOINT), json=report) assert (response.status_code == 200), "Could not create report" return serializeReport(report) except AssertionError as e: raise graphql.GraphQLError(e)
def resolveBroker(root, info, _id, token): try: # decode token auth.decodeToken(token) response = requests.get( "{}/brokers/{}".format(config.HARAMBE_DATA_SERVICE_ENDPOINT, _id)) assert (response.status_code == 200), "Could not retrieve broker" data = response.json() broker = serializeBroker(data) return broker except AssertionError as e: raise graphql.GraphQLError(e)
def mutate(self, info, token, _id, default): try: auth.decodeToken(token) response = requests.patch( "{}/brokers/{}".format(config.HARAMBE_DATA_SERVICE_ENDPOINT, _id), json={ "default": default } ) assert (response.status_code == 200), "Error updating broker in db" data = response.json() broker = serializeBroker(data) return SetBrokerAccountDefault(broker=broker) except AssertionError as e: raise graphql.GraphQLError(e)
def resolveUser(root, info, token): try: decoded = auth.decodeToken(token) response = requests.get("{}/users/{}".format(config.HARAMBE_DATA_SERVICE_ENDPOINT, decoded.get("user_id"))) assert(response.status_code == 200), "Could not retrieve user" data = response.json() return serializeUser(data) except AssertionError as e: raise graphql.GraphQLError(e)
def mutate(self, info, token, type, method, allow): try: tokenData = auth.decodeToken(token) updateBody = { "notifications": { type: { method: allow } } } updateResponse = requests.patch( "{}/users/{}".format(config.HARAMBE_DATA_SERVICE_ENDPOINT, tokenData.get("user_id")), json=updateBody ) assert (updateResponse.status_code == 200), "Could not update notification info" return SetNotification(success=True) except AssertionError as e: raise graphql.GraphQLError(e)
def mutate(self, info, token, brokerName, oAuthVerifier): try: decoded = auth.decodeToken(token) # get broker info brokerResponse = requests.post( "{}/user/getOAuthAccessToken".format(config.TRADE_IT_API_ENDPOINT), json={ "apiKey": config.TRADE_IT_API_KEY, "oAuthVerifier": oAuthVerifier } ) brokerData = brokerResponse.json() assert (brokerData.get("status") == "SUCCESS"), "Unsuccessful response getting user access token" # add broker to database dbResponse = requests.post( "{}/brokers".format(config.HARAMBE_DATA_SERVICE_ENDPOINT), json={ "name": brokerName, "user_id": brokerData.get("userId"), "user_token": brokerData.get("userToken"), "user": decoded.get("user_id"), "default": False } ) assert (dbResponse.status_code == 200), "Error adding broker to db" # serialize broker data = dbResponse.json() broker = serializeBroker(data) return CreateBrokerAccount(broker=broker) except AssertionError as e: raise graphql.GraphQLError(e)