From 780bf72b240d64be561f6776bfe2430539375a55 Mon Sep 17 00:00:00 2001 From: Brendan Lane Date: Sun, 20 Dec 2020 02:43:51 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=B5=20TransactionHub=20Completed=20+?= =?UTF-8?q?=20Stock=20was=20modified?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 6 +++++- src/modules/Stock.ts | 26 ++++++++++++++++++++------ src/modules/TransactionHub.ts | 29 ++++++++--------------------- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/main.ts b/src/main.ts index a797498..981ee3e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,10 +5,14 @@ import User from './modules/User' import Group from './modules/Group' import Auth from './modules/Auth' import District from './modules/District' +import Stock from './modules/Stock' +import TransactionHub from './modules/TransactionHub' export { User, Group, Auth, - District + District, + Stock, + TransactionHub } diff --git a/src/modules/Stock.ts b/src/modules/Stock.ts index 366e578..181b1aa 100644 --- a/src/modules/Stock.ts +++ b/src/modules/Stock.ts @@ -1,18 +1,30 @@ // SpookVooper API - modules/Stock.js -// Written by Bryce Bauer - https://github.com/bluebeargreen-2 +// Written by Bryce Bauer and Brendan Lane - https://github.com/bluebeargreen-2 and https://brndnln.dev/ import axios from 'axios' const ecoURL = 'https://api.spookvooper.com/eco' class Stock { - private ticker: string + private stockTicker: string - constructor (ticker) { - this.ticker = ticker.toUperCase() + public get ticker (): string { + return this.stockTicker } - public async getValue () { + + public set ticker (ticker: string) { + this.stockTicker = ticker.toUpperCase() + } + + constructor (ticker: string) { + this.ticker = ticker.toUpperCase() + } + + public async getValue (): Promise { return await new Promise((resolve, reject) => { - axios.get(`${ecoURL}/getStockValue?ticker=${this.ticker}`, { + axios.get(`${ecoURL}/getStockValue`, { + params: { + ticker: this.stockTicker + } }) .then((response) => { resolve(response.data) @@ -23,3 +35,5 @@ class Stock { }) } } + +export default Stock diff --git a/src/modules/TransactionHub.ts b/src/modules/TransactionHub.ts index 03bd762..2c228f8 100644 --- a/src/modules/TransactionHub.ts +++ b/src/modules/TransactionHub.ts @@ -11,8 +11,6 @@ const URI = 'https://spookvooper.com/transactionHub' const retryTime = 5 const retryTimeMS = retryTime * 1000 -const fancy = true - class TransactionHub { private readonly connection = new HubConnectionBuilder() .withUrl(URI) @@ -36,26 +34,22 @@ class TransactionHub { }) constructor () { - this.connection.onclose(function (e: any): void { + this.connection.onclose((e) => { this.onClosed(e) }) + + this.start() } public async start (): Promise { - console.log(`[TransactionHub] Starting connection between local and ${URI}`) + console.log(`TransactionHub: Starting connection between local and ${URI}`) try { await this.connection.start() - console.log('[TransactionHub] Connected!') + console.log('TransactionHub: Connected!') } catch (e) { - if (fancy) { - console.log('--------------------------------') - } - console.error('[TransactionHub] Error: Connection failed while trying to establish a connection\n', e) - if (fancy) { - console.log('--------------------------------') - } - console.log(`[TransactionHub] Retrying in ${retryTime} seconds`) + console.error('TransactionHub Error: Connection failed while trying to establish a connection\n', e) + console.log(`TransactionHub: Retrying in ${retryTime} seconds`) setTimeout(() => { this.start() }, retryTimeMS) @@ -63,14 +57,7 @@ class TransactionHub { } private async onClosed (e: any): Promise { - if (fancy) { - console.log('--------------------------------') - } - console.error('[TransactionHub] Error: Connection closed unexpectedly', e) - if (fancy) { - console.log('--------------------------------') - } - + console.error('TransactionHub Error: Connection closed unexpectedly', e) await this.start() } }