Skip to content

Commit

Permalink
gh-112: Add API for Games
Browse files Browse the repository at this point in the history
  • Loading branch information
littlewhywhat committed Mar 18, 2020
1 parent 648e9f9 commit c588b92
Show file tree
Hide file tree
Showing 15 changed files with 4,606 additions and 438 deletions.
3 changes: 2 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
.env
coverage
16 changes: 15 additions & 1 deletion backend/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as express from 'express'
import { Response, Request, Application } from 'express'
import * as bodyParser from 'body-parser'

import * as storage from './storage/Storage'
import * as matchRepository from './repositories/MatchRepository'
import * as userRepository from './repositories/UserRepository'
import { addGame } from './repositories/GameRepository'

import { makeBot, SingleChannelBot } from './bot/bot-factory'

Expand All @@ -12,7 +14,7 @@ import { MatchReporter } from './match-reporter/MatchReporter'
const jsonParser = bodyParser.json()
const urlencodedParser = bodyParser.urlencoded({ extended: false })

const app = express()
const app: Application = express()
const port = 3000

const addCrossDomainHeaders = function(req, res, next): void {
Expand Down Expand Up @@ -53,6 +55,12 @@ app.get('/matches', (req, res) => {

})

app.get('/games', (req: Request, res: Response) => {
storage.getAllGames()
.then(res.send.bind(res))
.catch(error => processError(res, error))
})

app.post('/users', (req, res) => {
userRepository.addUser(req.body)
.then(res.send.bind(res))
Expand All @@ -76,4 +84,10 @@ app.post('/matches', async (req, res) => {
}
})

app.post('/games', (req: Request, res: Response) => {
addGame(req.body)
.then(res.send.bind(res))
.catch(error => processError(res, error))
})

app.listen(port, () => console.log(`Foosball backend running on ${port}!`))
6 changes: 6 additions & 0 deletions backend/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: [ '**/tests/**/*Test.ts' ],
collectCoverage: true,
}
Loading

0 comments on commit c588b92

Please sign in to comment.