38364-vm/backend/src/db/models/vocabulary_words.js
2026-02-11 19:11:48 +00:00

168 lines
2.1 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 vocabulary_words = sequelize.define(
'vocabulary_words',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
word: {
type: DataTypes.TEXT,
},
definition: {
type: DataTypes.TEXT,
},
example_sentence: {
type: DataTypes.TEXT,
},
part_of_speech: {
type: DataTypes.ENUM,
values: [
"noun",
"verb",
"adjective",
"adverb",
"other"
],
},
difficulty: {
type: DataTypes.ENUM,
values: [
"easy",
"medium",
"hard"
],
},
synonyms: {
type: DataTypes.TEXT,
},
tags: {
type: DataTypes.TEXT,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
vocabulary_words.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.vocabulary_words.hasMany(db.session_vocabulary, {
as: 'session_vocabulary_vocabulary_word',
foreignKey: {
name: 'vocabulary_wordId',
},
constraints: false,
});
//end loop
db.vocabulary_words.hasMany(db.file, {
as: 'illustration',
foreignKey: 'belongsToId',
constraints: false,
scope: {
belongsTo: db.vocabulary_words.getTableName(),
belongsToColumn: 'illustration',
},
});
db.vocabulary_words.belongsTo(db.users, {
as: 'createdBy',
});
db.vocabulary_words.belongsTo(db.users, {
as: 'updatedBy',
});
};
return vocabulary_words;
};