-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Naming changes and express server ready
- Loading branch information
1 parent
02b4aa4
commit c2d28ed
Showing
26 changed files
with
178 additions
and
114 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import Account, { AccountOptions } from './account'; | ||
|
||
const accounts = new Map<string, Account>(); | ||
|
||
export function getAll() { | ||
return [true, [...accounts.values()].map((acc) => acc.options)]; | ||
} | ||
|
||
export function getByName(name: string) { | ||
return [true, accounts.get(name)]; | ||
} | ||
|
||
export function create(options: AccountOptions) { | ||
const { username } = options.login; | ||
if (accounts.has(username)) { | ||
return [false, 'Account already exists']; | ||
} else { | ||
const account = new Account(options); | ||
accounts.set(username, account); | ||
return [true, 'Created.']; | ||
} | ||
} | ||
|
||
export function edit(name: string, { status, trading }: AccountOptions) { | ||
const account = accounts.get(name); | ||
if (!account) { | ||
return [false, `Account doesn't exist`]; | ||
} else { | ||
account.options.status = { ...account.options.status, ...status }; | ||
account.options.trading = { ...account.options.trading, ...trading }; | ||
account.logoff(); | ||
return [true, 'Modified.']; | ||
} | ||
} | ||
|
||
export function remove(name: string) { | ||
const account = accounts.get(name); | ||
if (!account) { | ||
return [false, `Account doesn't exist`]; | ||
} else { | ||
account.logoff(); | ||
accounts.delete(name); | ||
return [true, 'Deleted.']; | ||
} | ||
} | ||
|
||
// export function add(acc: Account) { | ||
// const exists = contains(acc.options.login.username); | ||
// accounts.set(acc.options.login.username, acc); | ||
// return exists; | ||
// } | ||
|
||
// export function remove(username: string): Account | undefined { | ||
// const acc = get(username); | ||
// acc && accounts.delete(username); | ||
// return acc; | ||
// } | ||
|
||
// export function get(username: string) { | ||
// return accounts.get(username); | ||
// } | ||
|
||
// export function getAll() { | ||
// return [...accounts.values()]; | ||
// } | ||
|
||
// export function contains(username: string) { | ||
// return accounts.has(username); | ||
// } |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
function log(...msg: string[]) { | ||
msg.forEach(msg => console.log(msg)); | ||
async function log(...msg: string[]) { | ||
msg.forEach((msg) => console.log(msg)); | ||
console.log(); | ||
} | ||
|
||
export function startup() { | ||
log( | ||
'This app was developed by Arthur Fiorette', | ||
'Visit us on GitHub!', | ||
'https://github.com/ArthurFiorette/steam-trader', | ||
'', | ||
'Loading...' | ||
); | ||
} | ||
|
||
export function listening(port: any) { | ||
log( | ||
`We started at port '${port}'`, | ||
'If you are using docker-compose you only need', | ||
'to wait the web service starts itself.', | ||
'If not, you are able to start it now.' | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,8 @@ | ||
import config from '../config.json'; | ||
import * as Ads from './ads'; | ||
import Account from './account/account'; | ||
import app from './server'; | ||
|
||
import express from 'express'; | ||
import cors from 'cors'; | ||
|
||
import { Accounts } from './routes'; | ||
const PORT = process.env.PORT || 1228; | ||
|
||
Ads.startup(); | ||
|
||
// const account = new Account(config); | ||
|
||
// account.login(); | ||
|
||
const app = express(); | ||
|
||
app.use(cors()); | ||
app.use('/users', Accounts()); | ||
|
||
app.listen(process.env.PORT); | ||
app.listen(PORT, () => Ads.listening(PORT)); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import express from 'express'; | ||
import cors from 'cors'; | ||
import setRoutes from './routes'; | ||
|
||
const app = express(); | ||
|
||
app.use(cors()); | ||
app.use((req, res, next) => { | ||
const oldSend = res.send; | ||
res.send = function ([status, response]: [boolean, any]) { | ||
res.send = oldSend; | ||
return res.send({ | ||
status: status ? 'Success' : 'Failure', | ||
timestamp: new Date().toLocaleString(), | ||
response | ||
}); | ||
}; | ||
next(); | ||
}); | ||
|
||
setRoutes(app); | ||
|
||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Express } from 'express'; | ||
import users from './users'; | ||
import ping from './ping'; | ||
|
||
export default function apply(app: Express) { | ||
app.use('/users', users); | ||
app.use('/ping', ping); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Router, json } from 'express'; | ||
|
||
const router = Router(); | ||
|
||
router.use(json()); | ||
|
||
router.use('/', (req, res) => res.send([true, 'Pong'])); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Router, json } from 'express'; | ||
import { getAll, getByName, create, edit, remove } from '../../accounts/controller'; | ||
|
||
const router = Router(); | ||
|
||
router.use(json()); | ||
|
||
router.get('/', (_req, res) => res.send(getAll())); | ||
|
||
router.post('/', (req, res) => res.send(create(req.body))); | ||
|
||
router.get('/:name', (req, res) => res.send(getByName(req.params.name))); | ||
|
||
router.put('/:name', (req, res) => res.send(edit(req.params.name, req.body))); | ||
|
||
router.delete('/:name', (req, res) => res.send(remove(req.params.name))); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/trading/logic/calculatePrices.ts → ...src/transactions/logic/calculatePrices.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Item, OfferContext } from '../transactions/types'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
const PATH = path.resolve(__dirname, '../../output/trades/'); | ||
|
||
export default function save(context: OfferContext, reason: string) { | ||
const { account } = context.processor; | ||
const name = account.options.login.username; | ||
const { id } = context.offer; | ||
const filePath = path.resolve(PATH, `${name}/${id}`); | ||
account.logger.debug(`Saving transaction ${id}`); | ||
fs.writeFileSync(filePath, stringifyTransaction(name, context, reason)); | ||
} | ||
|
||
function stringifyTransaction(account: string, { offer, profit }: OfferContext, reason: string) { | ||
const mapItems = (items: Item[]) => items.map((item) => item.market_hash_name); | ||
return JSON.stringify({ | ||
account, | ||
partner: offer.partner.getSteamID64(), | ||
offerId: offer.id, | ||
profit, | ||
ourItems: mapItems(offer.itemsToGive), | ||
theirItems: mapItems(offer.itemsToReceive), | ||
reason | ||
}); | ||
} |
File renamed without changes.