144 lines
2.8 KiB
JavaScript
144 lines
2.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 words = sequelize.define(
|
|
'words',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
word_tamil: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
english_transliteration: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
pronunciation: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
parts_of_speech: {
|
|
type: DataTypes.ENUM,
|
|
|
|
values: ['noun', 'verb', 'adjective', 'adverb'],
|
|
},
|
|
|
|
colloquial_forms: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
definitions: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
example_usage: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
etymology: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
values: ['pending', 'approved', 'rejected'],
|
|
},
|
|
|
|
review_notes: {
|
|
type: DataTypes.TEXT,
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
words.associate = (db) => {
|
|
db.words.belongsToMany(db.words, {
|
|
as: 'root_words',
|
|
foreignKey: {
|
|
name: 'words_root_wordsId',
|
|
},
|
|
constraints: false,
|
|
through: 'wordsRoot_wordsWords',
|
|
});
|
|
|
|
db.words.belongsToMany(db.words, {
|
|
as: 'root_words_filter',
|
|
foreignKey: {
|
|
name: 'words_root_wordsId',
|
|
},
|
|
constraints: false,
|
|
through: 'wordsRoot_wordsWords',
|
|
});
|
|
|
|
db.words.belongsToMany(db.words, {
|
|
as: 'related_words',
|
|
foreignKey: {
|
|
name: 'words_related_wordsId',
|
|
},
|
|
constraints: false,
|
|
through: 'wordsRelated_wordsWords',
|
|
});
|
|
|
|
db.words.belongsToMany(db.words, {
|
|
as: 'related_words_filter',
|
|
foreignKey: {
|
|
name: 'words_related_wordsId',
|
|
},
|
|
constraints: false,
|
|
through: 'wordsRelated_wordsWords',
|
|
});
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
//end loop
|
|
|
|
db.words.belongsTo(db.users, {
|
|
as: 'submitted_by',
|
|
foreignKey: {
|
|
name: 'submitted_byId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.words.hasMany(db.file, {
|
|
as: 'hear_the_word',
|
|
foreignKey: 'belongsToId',
|
|
constraints: false,
|
|
scope: {
|
|
belongsTo: db.words.getTableName(),
|
|
belongsToColumn: 'hear_the_word',
|
|
},
|
|
});
|
|
|
|
db.words.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.words.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
return words;
|
|
};
|