Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-112: Add API for games #113

Merged
merged 3 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
.env
coverage
14 changes: 14 additions & 0 deletions 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 } 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 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: [ '**/*.test.ts' ],
collectCoverage: true,
}
Loading