generated from Codaisseur/express-template
-
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 #4 from codeMonkeyMasters/darian-QuizSetup
Darian quiz setup
- Loading branch information
Showing
11 changed files
with
645 additions
and
1 deletion.
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,54 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: async (queryInterface, Sequelize) => { | ||
await queryInterface.createTable('quizQuestions', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
question: { | ||
type: Sequelize.TEXT, | ||
allowNull: false, | ||
}, | ||
answer: { | ||
type: Sequelize.TEXT, | ||
allowNull: false, | ||
}, | ||
incorrect1: { | ||
type: Sequelize.TEXT, | ||
allowNull: false, | ||
}, | ||
incorrect2: { | ||
type: Sequelize.TEXT, | ||
allowNull: false, | ||
}, | ||
incorrect3: { | ||
type: Sequelize.TEXT, | ||
allowNull: false, | ||
}, | ||
exerciseId: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: "exercises", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "SET NULL", | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: async (queryInterface, Sequelize) => { | ||
await queryInterface.dropTable('quizQuestions'); | ||
} | ||
}; |
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,48 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: async (queryInterface, Sequelize) => { | ||
await queryInterface.createTable('completedQuizzes', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
userId: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: "users", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}, | ||
quizQuestionId: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: "quizQuestions", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}, | ||
exp: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false, | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: async (queryInterface, Sequelize) => { | ||
await queryInterface.dropTable('completedQuizzes'); | ||
} | ||
}; |
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 @@ | ||
'use strict'; | ||
const { | ||
Model | ||
} = require('sequelize'); | ||
module.exports = (sequelize, DataTypes) => { | ||
class completedQuiz extends Model { | ||
/** | ||
* Helper method for defining associations. | ||
* This method is not a part of Sequelize lifecycle. | ||
* The `models/index` file will call this method automatically. | ||
*/ | ||
static associate(models) { | ||
// define association here | ||
} | ||
}; | ||
completedQuiz.init({ | ||
userId: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: "users", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}, | ||
quizQuestionId: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: "quizQuestions", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}, | ||
exp: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
} | ||
}, { | ||
sequelize, | ||
modelName: 'completedQuiz', | ||
}); | ||
return completedQuiz; | ||
}; |
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,55 @@ | ||
'use strict'; | ||
const { | ||
Model | ||
} = require('sequelize'); | ||
module.exports = (sequelize, DataTypes) => { | ||
class quizQuestion extends Model { | ||
/** | ||
* Helper method for defining associations. | ||
* This method is not a part of Sequelize lifecycle. | ||
* The `models/index` file will call this method automatically. | ||
*/ | ||
static associate(models) { | ||
quizQuestion.belongsToMany(models.user, { | ||
through: "completedQuizzes", | ||
key: "quizQuestionId", | ||
}) | ||
} | ||
}; | ||
quizQuestion.init({ | ||
question: { | ||
type: DataTypes.TEXT, | ||
allowNull: false, | ||
}, | ||
answer: { | ||
type: DataTypes.TEXT, | ||
allowNull: false, | ||
}, | ||
incorrect1: { | ||
type: DataTypes.TEXT, | ||
allowNull: false, | ||
}, | ||
incorrect2: { | ||
type: DataTypes.TEXT, | ||
allowNull: false, | ||
}, | ||
incorrect3: { | ||
type: DataTypes.TEXT, | ||
allowNull: false, | ||
}, | ||
exerciseId: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: "exercises", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "SET NULL", | ||
} | ||
}, { | ||
sequelize, | ||
modelName: 'quizQuestion', | ||
}); | ||
return quizQuestion; | ||
}; |
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.