app2-api/modules/events/events_inscriptions.model.js

99 lines
3.3 KiB
JavaScript
Raw Normal View History

2019-07-05 07:06:29 +00:00
'use strict';
2019-07-23 16:00:04 +00:00
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';
};
2019-07-05 07:06:29 +00:00
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: {
2019-07-25 16:39:18 +00:00
type: DataTypes.STRING(45),
2019-07-05 07:06:29 +00:00
},
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: {
2019-07-21 13:30:49 +00:00
type: DataTypes.BOOLEAN,
2019-07-05 07:06:29 +00:00
},
2019-07-23 16:00:04 +00:00
stateText: {
type: Sequelize.VIRTUAL(Sequelize.STRING, ['validated', 'reservationId', 'overflowEventId']),
get: function () {
return getStateText(this);
},
},
2019-07-21 13:30:49 +00:00
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
2019-07-19 17:39:19 +00:00
type: DataTypes.UUID,
foreignKey: true,
}
2019-07-21 13:30:49 +00:00
2019-07-05 07:06:29 +00:00
}, {
tableName: 'events_inscriptions',
freezeTableName: true,
timestamps: true,
2019-07-25 16:39:18 +00:00
2019-07-26 09:13:33 +00:00
defaultScope: {
order: [
['date', 'DESC']
2019-08-16 17:49:25 +00:00
],
include: [{ model: sequelize.models.User, as: 'user' }],
2019-07-26 09:13:33 +00:00
},
2019-07-05 07:06:29 +00:00
});
EventInscription.associate = function (models) {
2019-07-14 16:44:59 +00:00
EventInscription.Event = EventInscription.belongsTo(models.Event, { foreignKey: 'eventId', as: 'event' });
2019-08-17 12:42:20 +00:00
EventInscription.Reservation = EventInscription.belongsTo(models.EventReservation, { foreignKey: 'reservationId', as: 'reservation'});
2019-07-14 16:44:59 +00:00
EventInscription.User = EventInscription.belongsTo(models.User, { foreignKey: 'userId', as: 'user' });
2019-07-05 07:06:29 +00:00
EventInscription.UserValidate = EventInscription.belongsTo(models.User, { foreignKey: 'validateUserId' });
};
2019-07-26 09:13:33 +00:00
EventInscription.addScope('includeEventAndVenue', () => {
return {
include: [{
model: sequelize.models.Event,
as: 'event',
2019-07-30 16:24:06 +00:00
attributes: ['id', 'name', 'description', 'campaign_text', 'init_date', 'end_date', 'init_available_date',
'end_available_date', 'stateCode', 'stateText'],
2019-07-26 09:13:33 +00:00
include: [{
model: sequelize.models.Venue,
as: 'venue',
attributes: {
exclude: ['createdAt', 'updatedAt'],
}
}]
}],
}
});
2019-07-05 07:06:29 +00:00
return EventInscription;
};