💵 TransactionHub Completed + Stock was modified
This commit is contained in:
parent
fad6635cc9
commit
37ccc20cdc
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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<any> {
|
||||
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
|
||||
|
|
|
@ -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<void> {
|
||||
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<void> {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue