-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1938fef
Showing
7 changed files
with
2,444 additions
and
0 deletions.
There are no files selected for viewing
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,32 @@ | ||
# OS X | ||
.DS_Store* | ||
Icon? | ||
._* | ||
|
||
# Windows | ||
Thumbs.db | ||
ehthumbs.db | ||
Desktop.ini | ||
|
||
# Linux | ||
.directory | ||
*~ | ||
|
||
|
||
# npm | ||
node_modules | ||
package-lock.json | ||
*.log | ||
*.gz | ||
|
||
|
||
# Coveralls | ||
coverage | ||
|
||
# Benchmarking | ||
benchmarks/graphs | ||
|
||
# editor | ||
.vscode | ||
|
||
dist/ |
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,22 @@ | ||
{ | ||
"name": "eldolar", | ||
"version": "1.0.0", | ||
"description": "bank exchange by eldolar", | ||
"main": "app.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@types/express": "^4.16.0", | ||
"concurrently": "^4.0.1", | ||
"express": "^4.16.3", | ||
"mongoose": "^5.2.17", | ||
"nodemon": "^1.18.4" | ||
}, | ||
"scripts": { | ||
"watch-ts": "tsc -w", | ||
"watch-node": "nodemon dist/app.js", | ||
"watch": "concurrently -k -p \"[{name}]\" -n \"TypeScript, Node\" -c \"yello.bold, cyan.bold\" \"yarn run watch-ts\" \"yarn run watch-node\"" | ||
}, | ||
"devDependencies": { | ||
"@types/mongoose": "^5.2.17" | ||
} | ||
} |
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,28 @@ | ||
import * as express from "express"; | ||
import * as bodyParse from "body-parser"; | ||
import * as mongoose from 'mongoose'; | ||
import ExchangeRouter from './routers/exchangeRouter' | ||
|
||
const app = express(); | ||
|
||
// set up mongoose | ||
const URI: string = "mongodb://127.0.0.1:27017/eldolar"; | ||
mongoose.connect(process.env.MONGODB_URI || URI, (err: any) => { | ||
if (err) { | ||
console.log(err.message) | ||
} else { | ||
console.log("Successfully Connected") | ||
} | ||
}) | ||
|
||
// config | ||
app.use(bodyParse.json()); | ||
app.set("port", 3000); | ||
|
||
// routers | ||
app.use('/api/v1/exchanges', ExchangeRouter) | ||
|
||
// start | ||
app.listen(app.get("port"), () => { | ||
console.log("App is running on localhost:%d", app.get("port")); | ||
}) |
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,16 @@ | ||
import { Schema, model } from 'mongoose'; | ||
import { Decimal128 } from 'bson'; | ||
|
||
export const ExchangeSchema = new Schema({ | ||
createdAt: { type: Date, required: true }, | ||
banks: [ | ||
{ | ||
name: String, | ||
buy: { type: Decimal128, default: 0 }, | ||
sell: { type: Decimal128, default: 0 } | ||
} | ||
] | ||
}); | ||
|
||
const Exchange = model("Exchange", ExchangeSchema); | ||
export default Exchange; |
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,33 @@ | ||
import { Router, Request, Response } from 'express'; | ||
import Exchange from '../models/exchange'; | ||
|
||
const router: Router = Router(); | ||
|
||
// - GET /exchanges # returns all exchanges | ||
function allExchanges(req: Request, res: Response) : void { | ||
Exchange.find({}) | ||
.then(exchanges => { | ||
res.send(exchanges) | ||
}) | ||
.catch(err => { | ||
res.send(err) | ||
}) | ||
} | ||
|
||
// - POST /exchanges # insert new one | ||
function addExchange(req: Request, res: Response) : void { | ||
let exchange = new Exchange(req.body); | ||
|
||
exchange.save() | ||
.then(data => { | ||
res.send(data) | ||
}) | ||
.catch(err => { | ||
res.send(err) | ||
}) | ||
} | ||
|
||
router.get('/', allExchanges); | ||
router.post('/', addExchange); | ||
|
||
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,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"noImplicitAny": true, | ||
"removeComments": true, | ||
"target": "es6", | ||
"preserveConstEnums": true, | ||
"moduleResolution": "node", | ||
"outDir": "dist", | ||
"sourceMap": true | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"**/*.spec.ts" | ||
] | ||
} |
Oops, something went wrong.