app2-api/modules/events/event.model.js
2019-06-26 12:24:58 +02:00

113 lines
2.9 KiB
JavaScript

'use strict';
module.exports = function (sequelize, DataTypes) {
const Event = sequelize.define('Event', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
description: {
type: DataTypes.STRING,
},
campaign_text: {
type: DataTypes.TEXT,
allowNull: true
},
date: {
type: DataTypes.DATE,
allowNull: false,
},
init_avalible_date: {
type: DataTypes.DATE,
},
end_avalible_date: {
type: DataTypes.DATE,
},
gmt: {
type: DataTypes.INTEGER,
defaultValue: 1,
},
assistants: {
type: DataTypes.INTEGER,
},
confirmed: {
type: DataTypes.INTEGER,
},
allow_multiple: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
multiple_limit: {
type: DataTypes.INTEGER,
},
allow_overflow: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
overflow_eventId: {
type: DataTypes.UUID,
foreignKey: true,
},
state: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 'borrador'
},
typeId: {
type: DataTypes.UUID,
foreignKey: true,
},
schedule: {
type: DataTypes.TEXT,
},
venueId: {
type: DataTypes.UUID,
foreignKey: true,
},
url_streaming: {
type: DataTypes.STRING,
},
url_poll: {
type: DataTypes.STRING,
},
url_registration: {
type: DataTypes.STRING,
},
user_id: {
type: DataTypes.UUID,
foreignKey: true,
},
}, {
tableName: 'events',
freezeTableName: true,
timestamps: true,
});
Event.associate = function (models) {
Event.OverflowEvent = Event.belongsTo(models.Event, { foreignKey: 'overflow_eventId' });
Event.EventType = Event.belongsTo(models.EventType, { foreignKey: 'typeId' });
Event.UserCreate = Event.belongsTo(models.User, { foreignKey: 'userId' });
Event.Venue = Event.belongsTo(models.Venue, { foreignKey: 'venueId' });
Event.Speakers = Event.belongsToMany(models.Speaker, {
through: models.EventSpeaker,
foreignKey: 'eventId'
});
Event.Multimedias = Event.belongsToMany(models.MultimediaFile, {
through: models.MultimediaEvent,
foreignKey: 'eventId',
otherKey: 'type'
});
};
return Event;
};