Last active
December 1, 2015 00:17
-
-
Save yamikuronue/d21b19166e83f7e52b8a to your computer and use it in GitHub Desktop.
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
function getBoard(req, res) { | |
if (!req.params.id) { | |
res.status(501).send({error: 'Missing ID'}); | |
return Promise.resolve(); | |
} | |
return dao.getBoard(req.params.id).then((data) => { | |
if (Array.isArray(data)) { | |
data = data[0]; //Only the first board | |
} | |
if (!data) { | |
res.status(404); | |
return; | |
} | |
data.Canonical = `/api/board/${data.ID}`; | |
res.send(data); | |
}).catch((err) => { | |
//TODO: logging errors | |
res.status(500).send({error: err.toString()}); | |
}); | |
} |
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
function getBoard(id) { | |
return db.Boards.findByPrimary(id, { | |
where: { | |
GameID: null | |
} | |
}).then((board) => { | |
return board; | |
}); | |
} |
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
it('should not return an invalid board', (done) => { | |
const req = http.request({ | |
host: 'localhost', | |
port: '8080', | |
path: '/api/board/1111', | |
method: 'GET' | |
}); | |
req.end(); | |
req.on('response', (response) => { | |
assert.equal(404, response.statusCode, 'Invalid board should not be returned'); | |
done(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment