This repository has been archived by the owner on May 10, 2024. It is now read-only.
generated from Arquisoft/wiq_0
-
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.
Merge pull request #141 from Arquisoft/develop
Develop
- Loading branch information
Showing
45 changed files
with
35,951 additions
and
26,821 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
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 @@ | ||
MONGODB_URI="mongodb://mongodb:27017/wiq" |
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,27 @@ | ||
const mongoose = require("mongoose"); | ||
const { MongoMemoryServer } = require('mongodb-memory-server'); | ||
|
||
const connect = async() => | ||
{ | ||
try | ||
{ | ||
if (process.env.DB_URL) { | ||
await mongoose.connect('mongodb://mongodb:27017/wiq') | ||
console.log("MongoDB Server Selected") | ||
} else { | ||
const mongoServer = await MongoMemoryServer.create(); | ||
const mongoUri = mongoServer.getUri(); | ||
await mongoose.connect(mongoUri) | ||
|
||
console.log("MongoDB RAM MEMORY SERVER Selected") | ||
} | ||
|
||
console.log('MongoDB connected'); | ||
} | ||
catch(error) { | ||
console.log(error); | ||
throw new Error('Error to connect with MongoDB'); | ||
} | ||
} | ||
|
||
module.exports = connect; |
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,39 @@ | ||
const { Schema, model } = require("mongoose"); | ||
|
||
|
||
const Question = Schema | ||
({ | ||
title: { | ||
type: String, | ||
required: true, | ||
trim: true | ||
}, | ||
answer: { | ||
type: String, | ||
required: true, | ||
trim: true | ||
}, | ||
fakes: { | ||
type: [String], | ||
required: true | ||
}, | ||
imageUrl: { | ||
type: String, | ||
default: "" | ||
}, | ||
createdAt: { | ||
type: Date, | ||
default: Date.now | ||
} | ||
}); | ||
|
||
Question.methods.toJSON = function() | ||
{ | ||
const { __v, _id, ...question } = this.toObject(); | ||
|
||
question.uid = _id; | ||
|
||
return question; | ||
} | ||
|
||
module.exports = model('Question', Question); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function shuffleArray(array) { | ||
for (let i = array.length - 1; i > 0; i--) { | ||
const j = Math.floor(Math.random() * (i + 1)); | ||
// Swap array[i] and array[j] | ||
[array[i], array[j]] = [array[j], array[i]]; | ||
} | ||
return array; | ||
} | ||
|
||
module.exports = shuffleArray; |
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.