138 lines
1.8 KiB
JavaScript
138 lines
1.8 KiB
JavaScript
const config = require('../../config');
|
|
const providers = config.providers;
|
|
const crypto = require('crypto');
|
|
const bcrypt = require('bcrypt');
|
|
const moment = require('moment');
|
|
|
|
module.exports = function(sequelize, DataTypes) {
|
|
const quiz_attempts = sequelize.define(
|
|
'quiz_attempts',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"in_progress",
|
|
|
|
|
|
"submitted",
|
|
|
|
|
|
"graded"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
started_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
submitted_at: {
|
|
type: DataTypes.DATE,
|
|
|
|
|
|
|
|
},
|
|
|
|
score: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
passed: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
quiz_attempts.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.quiz_attempts.belongsTo(db.lesson_quizzes, {
|
|
as: 'quiz',
|
|
foreignKey: {
|
|
name: 'quizId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.quiz_attempts.belongsTo(db.users, {
|
|
as: 'student',
|
|
foreignKey: {
|
|
name: 'studentId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.quiz_attempts.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.quiz_attempts.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return quiz_attempts;
|
|
};
|
|
|
|
|