forked from Arquisoft/wichat_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from Arquisoft/UserDataBase
Functioning user system + created schema for game database.
- Loading branch information
Showing
16 changed files
with
341 additions
and
228 deletions.
There are no files selected for viewing
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 @@ | ||
const mongoose = require('mongoose'); | ||
//const { Match, Answer, User } = require('./game-model'); para usarlo luego en otras partes se añade así el esquema | ||
const answerSchema = new mongoose.Schema({ | ||
isCorrect: Boolean, | ||
text: String, | ||
}); | ||
|
||
const matchSchema = new mongoose.Schema({ | ||
date: { type: Date, default: Date.now }, | ||
question: { type: String, required: true }, | ||
answers: { type: [answerSchema], required: true}, | ||
dni: { type: String, required: true }, | ||
}); | ||
|
||
const userSchema = new mongoose.Schema({ | ||
username: { | ||
type: String, | ||
}, | ||
matches: [matchSchema], | ||
}); | ||
|
||
const User = mongoose.model('User', userSchema); | ||
const Answer = mongoose.model('Answer', answerSchema); | ||
const Match = mongoose.model('Match', matchSchema); | ||
|
||
|
||
module.exports = { Match, Answer, User }; | ||
|
||
// async function createMatchForUser(dni) { | ||
// const user = await User.findOne({ dni }); | ||
// if (!user) { | ||
// console.log('User not found'); | ||
// return; | ||
// } | ||
// | ||
// const match = new Match({ | ||
// question: 'What is 2+2?', | ||
// answers: [ | ||
// { text: '4', isCorrect: true }, | ||
// { text: '5', isCorrect: false }, | ||
// ], | ||
// dni: user.dni, | ||
// }); | ||
// | ||
// await match.save(); | ||
// } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.