-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
20 changed files
with
474 additions
and
301 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,46 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
const GameHistory = mongoose.model('GameHistory'); | ||
|
||
/* Save Game History */ | ||
|
||
/** | ||
* @class Game | ||
*/ | ||
class Game { | ||
/** | ||
* @static | ||
* @param {any} req JSON request | ||
* @param {any} res JSON response | ||
* @returns {any} any | ||
* @memberof Game | ||
*/ | ||
static gameHistory(req, res) { | ||
const { gameLog } = req.body; | ||
|
||
if (!gameLog) { | ||
return res.status(422).send({ | ||
errors: 'No data supplied' | ||
}); | ||
} | ||
const GameLog = new GameHistory({ | ||
gameID: gameLog.gameId, | ||
gamePlayers: gameLog.players, | ||
gameRound: gameLog.rounds, | ||
gameWinner: gameLog.gameWinner.username | ||
}); | ||
|
||
GameLog.save((err) => { | ||
if (err) { | ||
return res.status(422).send({ | ||
errors: err.errors | ||
}); | ||
} | ||
return res.status(201).send({ | ||
message: 'Game history successfully saved' | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
export default 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
const { Schema } = mongoose; | ||
|
||
/** | ||
* Game Schema | ||
*/ | ||
const gameSchema = new Schema( | ||
{ | ||
gameID: String, | ||
gamePlayers: [], | ||
gameRound: Number, | ||
gameWinner: { | ||
type: String, | ||
default: '' | ||
} | ||
}, | ||
{ timestamps: true } | ||
); | ||
|
||
mongoose.model('GameHistory', gameSchema); |
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
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
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
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
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
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
Oops, something went wrong.