74 lines
2.5 KiB
JavaScript
74 lines
2.5 KiB
JavaScript
'use strict';
|
|
const Sequelize = require('sequelize');
|
|
|
|
const getStateText = (inscription) => {
|
|
|
|
if (inscription.validated == true)
|
|
return 'Inscripción confirmada'
|
|
else if (inscription.overflowEventId)
|
|
return 'Inscripción confirmada a lista de espera'
|
|
else if (inscription.reservationId)
|
|
return'Inscripción confirmada a lista de espera de tu reserva'
|
|
else
|
|
return 'N/A';
|
|
};
|
|
|
|
|
|
module.exports = function (sequelize, DataTypes) {
|
|
const EventInscription = sequelize.define('EventInscription', {
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
date: {
|
|
type: DataTypes.DATE,
|
|
},
|
|
code_ticket: {
|
|
type: DataTypes.STRING(45),
|
|
},
|
|
type: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
defaultValue: 'regular' //grupal, invitacion-regular, invitation-grupal
|
|
},
|
|
source: {
|
|
type: DataTypes.STRING, //app, web
|
|
},
|
|
marketing_memberId: {
|
|
type: DataTypes.STRING,
|
|
},
|
|
validated: {
|
|
type: DataTypes.BOOLEAN,
|
|
},
|
|
stateText: {
|
|
type: Sequelize.VIRTUAL(Sequelize.STRING, ['validated', 'reservationId', 'overflowEventId']),
|
|
get: function () {
|
|
return getStateText(this);
|
|
},
|
|
},
|
|
reservationId:{ //contendra el id de la reserva o de la lista de espera de la reserva
|
|
type: DataTypes.UUID,
|
|
foreignKey: true,
|
|
},
|
|
overflowEventId: { //contendra el id del evento de lista de espera del evento
|
|
type: DataTypes.UUID,
|
|
foreignKey: true,
|
|
}
|
|
|
|
}, {
|
|
tableName: 'events_inscriptions',
|
|
freezeTableName: true,
|
|
timestamps: true,
|
|
|
|
});
|
|
|
|
EventInscription.associate = function (models) {
|
|
EventInscription.Event = EventInscription.belongsTo(models.Event, { foreignKey: 'eventId', as: 'event' });
|
|
EventInscription.Reservation = EventInscription.belongsTo(models.EventReservation, { foreignKey: 'reservationId', as: 'reservation' });
|
|
EventInscription.User = EventInscription.belongsTo(models.User, { foreignKey: 'userId', as: 'user' });
|
|
EventInscription.UserValidate = EventInscription.belongsTo(models.User, { foreignKey: 'validateUserId' });
|
|
};
|
|
|
|
return EventInscription;
|
|
}; |