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
define([ | |
"intern!object", | |
"intern/chai!assert", | |
"intern/dojo/node!../../../src/dao/todoItems", | |
"intern/dojo/node!fs", | |
"intern/dojo/node!is-there", | |
"intern/dojo/node!sinon", | |
"intern/dojo/node!sqlite3", | |
"intern/dojo/node!async" | |
], function (registerSuite, assert, dao, fs, IsThere, sinon, sqlite3, async) { |
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
//Controller module | |
var express = require('express'); | |
var router = express.Router(); | |
app.route('/book') | |
.get(function(req, res) { | |
res.send('Get a random book'); | |
}) | |
.post(function(req, res) { | |
res.send('Add a book'); |
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
let data = [{ | |
ID: '1', | |
Name: 'test game', | |
Adult: false, | |
GameMasters: null, | |
Tags: [], | |
IC: null | |
}, | |
{ | |
ID: '2', |
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
dao.getAllGames().then((data) => { | |
for (let i = 0; i < data.length; i++) { | |
data[i].canonical = `/api/game/${data[i].id}`; | |
} | |
res.send(data); | |
}).catch((err) => { | |
//TODO: logging errors | |
res.status(500).send({ error: 'Database error.' }); | |
}); |
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
getAllGames: (res) => { | |
//For this sprint, all users can see all games | |
return new Promise((resolve, reject) => { | |
dao.getAllGames().then((data) => { | |
for (let i = 0; i < data.length; i++) { | |
data[i].canonical = `/api/game/${data[i].id}`; | |
} | |
res.send(data); | |
resolve(); |
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
getGame: (req, res) => { | |
if (!req.params.id) { | |
res.status(501).send({error: 'Missing ID'}); | |
return; | |
} | |
return dao.getGame(req.params.id).then((data) => { | |
if (Array.isArray(data)) { | |
data = data[0]; //Only the first game | |
} |
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
//The Rules: | |
[07:22:05 PM] <yamikuronue> T directs everyone to sit on the bleachers; once Dog drags Li back into the room, T moves to the front, clearing her throat. "Right. So. Most of you lot aren't very impressive physically -- there's a few outliers, but typically, your best chance for survival against someone who outclasses you is to hide what you are. For today's lesson, I've asked a friend to lend a hand. I've told him nothing about you; each of you are | |
[07:22:05 PM] <yamikuronue> going to take a turn having a chat with him. After five minutes, if he guesses your power type reasonably accurately, he gets a point. If he gets it exactly, he gets two points. If he can't guess, the students get a point. If he guesses wrong, students get two points." She wheels over a chalkboard, writing up "Home" and "Away" on the board to keep track. "Understand?" | |
//The Cast: | |
//O: Faerie, the guesser | |
//Gregor: Wizard, the previous victim | |
//Li: Native-american Coyote Shapeshifter. | |
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
//Set up middleware | |
const bodyParser = require('body-parser'); | |
let jsonParser = bodyParser.json(); | |
//Attach to route | |
app.route('/api/boards') | |
.get(cApi.getAllBoards) | |
.post(jsonParser, cApi.addBoard) | |
.patch((_, res) => res.status(405).end()) | |
.delete((_, res) => res.status(405).end()) |
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 | |
} |
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
const req = http.request({ | |
host: 'localhost', | |
port: '8080', | |
path: '/api/game/1111', | |
method: 'PUT' | |
}); | |
req.write(JSON.stringify(formData) + "\n"); | |
req.end(); |
OlderNewer