179 lines
2.0 KiB
JavaScript
179 lines
2.0 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 widget_catalog = sequelize.define(
|
|
'widget_catalog',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
widget_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"breathing_visual",
|
|
|
|
|
|
"noise_generator",
|
|
|
|
|
|
"grounding_prompt",
|
|
|
|
|
|
"body_map_checkin",
|
|
|
|
|
|
"regulation_menu",
|
|
|
|
|
|
"task_whisperer",
|
|
|
|
|
|
"transition_nudge",
|
|
|
|
|
|
"co_regulation_prompt",
|
|
|
|
|
|
"leave_a_note"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
description: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
is_embeddable: {
|
|
type: DataTypes.BOOLEAN,
|
|
|
|
allowNull: false,
|
|
defaultValue: false,
|
|
|
|
|
|
|
|
},
|
|
|
|
maturity: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"experimental",
|
|
|
|
|
|
"beta",
|
|
|
|
|
|
"stable"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
widget_catalog.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.widget_catalog.hasMany(db.widget_instances, {
|
|
as: 'widget_instances_widget',
|
|
foreignKey: {
|
|
name: 'widgetId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.widget_catalog.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.widget_catalog.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.widget_catalog.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return widget_catalog;
|
|
};
|
|
|
|
|