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 personal_dictionary_entries = sequelize.define( 'personal_dictionary_entries', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, status: { type: DataTypes.ENUM, values: [ "new", "learning", "known", "mastered" ], }, familiarity_score: { type: DataTypes.INTEGER, }, added_at: { type: DataTypes.DATE, }, last_reviewed_at: { type: DataTypes.DATE, }, student_note: { type: DataTypes.TEXT, }, is_favorite: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); personal_dictionary_entries.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.personal_dictionary_entries.belongsTo(db.tenants, { as: 'tenant', foreignKey: { name: 'tenantId', }, constraints: false, }); db.personal_dictionary_entries.belongsTo(db.users, { as: 'student', foreignKey: { name: 'studentId', }, constraints: false, }); db.personal_dictionary_entries.belongsTo(db.vocabulary_words, { as: 'vocabulary_word', foreignKey: { name: 'vocabulary_wordId', }, constraints: false, }); db.personal_dictionary_entries.belongsTo(db.organizations, { as: 'organizations', foreignKey: { name: 'organizationsId', }, constraints: false, }); db.personal_dictionary_entries.belongsTo(db.users, { as: 'createdBy', }); db.personal_dictionary_entries.belongsTo(db.users, { as: 'updatedBy', }); }; return personal_dictionary_entries; };