💵 TransactionHub Completed + Stock was modified
This commit is contained in:
parent
8606424041
commit
780bf72b24
|
@ -5,10 +5,14 @@ import User from './modules/User'
|
||||||
import Group from './modules/Group'
|
import Group from './modules/Group'
|
||||||
import Auth from './modules/Auth'
|
import Auth from './modules/Auth'
|
||||||
import District from './modules/District'
|
import District from './modules/District'
|
||||||
|
import Stock from './modules/Stock'
|
||||||
|
import TransactionHub from './modules/TransactionHub'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
User,
|
User,
|
||||||
Group,
|
Group,
|
||||||
Auth,
|
Auth,
|
||||||
District
|
District,
|
||||||
|
Stock,
|
||||||
|
TransactionHub
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,30 @@
|
||||||
// SpookVooper API - modules/Stock.js
|
// 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'
|
import axios from 'axios'
|
||||||
const ecoURL = 'https://api.spookvooper.com/eco'
|
const ecoURL = 'https://api.spookvooper.com/eco'
|
||||||
|
|
||||||
class Stock {
|
class Stock {
|
||||||
private ticker: string
|
private stockTicker: string
|
||||||
|
|
||||||
constructor (ticker) {
|
public get ticker (): string {
|
||||||
this.ticker = ticker.toUperCase()
|
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) => {
|
return await new Promise((resolve, reject) => {
|
||||||
axios.get(`${ecoURL}/getStockValue?ticker=${this.ticker}`, {
|
axios.get(`${ecoURL}/getStockValue`, {
|
||||||
|
params: {
|
||||||
|
ticker: this.stockTicker
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
resolve(response.data)
|
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 retryTime = 5
|
||||||
const retryTimeMS = retryTime * 1000
|
const retryTimeMS = retryTime * 1000
|
||||||
|
|
||||||
const fancy = true
|
|
||||||
|
|
||||||
class TransactionHub {
|
class TransactionHub {
|
||||||
private readonly connection = new HubConnectionBuilder()
|
private readonly connection = new HubConnectionBuilder()
|
||||||
.withUrl(URI)
|
.withUrl(URI)
|
||||||
|
@ -36,26 +34,22 @@ class TransactionHub {
|
||||||
})
|
})
|
||||||
|
|
||||||
constructor () {
|
constructor () {
|
||||||
this.connection.onclose(function (e: any): void {
|
this.connection.onclose((e) => {
|
||||||
this.onClosed(e)
|
this.onClosed(e)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
public async start (): Promise<void> {
|
public async start (): Promise<void> {
|
||||||
console.log(`[TransactionHub] Starting connection between local and ${URI}`)
|
console.log(`TransactionHub: Starting connection between local and ${URI}`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.connection.start()
|
await this.connection.start()
|
||||||
console.log('[TransactionHub] Connected!')
|
console.log('TransactionHub: Connected!')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (fancy) {
|
console.error('TransactionHub Error: Connection failed while trying to establish a connection\n', e)
|
||||||
console.log('--------------------------------')
|
console.log(`TransactionHub: Retrying in ${retryTime} seconds`)
|
||||||
}
|
|
||||||
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`)
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.start()
|
this.start()
|
||||||
}, retryTimeMS)
|
}, retryTimeMS)
|
||||||
|
@ -63,14 +57,7 @@ class TransactionHub {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async onClosed (e: any): Promise<void> {
|
private async onClosed (e: any): Promise<void> {
|
||||||
if (fancy) {
|
console.error('TransactionHub Error: Connection closed unexpectedly', e)
|
||||||
console.log('--------------------------------')
|
|
||||||
}
|
|
||||||
console.error('[TransactionHub] Error: Connection closed unexpectedly', e)
|
|
||||||
if (fancy) {
|
|
||||||
console.log('--------------------------------')
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.start()
|
await this.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue