Al dar el estado de una inscripción, tener en cuenta las inscripciones online.
This commit is contained in:
parent
221a7169a9
commit
f2f78df93f
@ -1,125 +1,155 @@
|
|||||||
'use strict';
|
"use strict";
|
||||||
const Sequelize = require('sequelize');
|
const Sequelize = require("sequelize");
|
||||||
|
|
||||||
const getStateText = (inscription) => {
|
const getStateText = (inscription) => {
|
||||||
|
if (inscription.type !== "online" && inscription !== "online group") {
|
||||||
if (inscription.validated == true)
|
if (inscription.validated == true) {
|
||||||
return 'Inscripción confirmada'
|
return "Inscripción confirmada";
|
||||||
else if (inscription.overflowEventId)
|
} else if (inscription.overflowEventId) {
|
||||||
return 'Inscripción confirmada a lista de espera'
|
return "Inscripción confirmada a lista de espera";
|
||||||
else if (inscription.reservationId)
|
} else if (inscription.reservationId) {
|
||||||
return'Inscripción confirmada a lista de espera de tu reserva'
|
return "Inscripción confirmada a lista de espera de tu reserva";
|
||||||
else
|
} else return "N/A";
|
||||||
return 'N/A';
|
} else {
|
||||||
|
// online
|
||||||
|
return "Inscripción online confirmada";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function (sequelize, DataTypes) {
|
||||||
const EventInscription = sequelize.define('EventInscription', {
|
const EventInscription = sequelize.define(
|
||||||
id: {
|
"EventInscription",
|
||||||
type: DataTypes.UUID,
|
{
|
||||||
defaultValue: DataTypes.UUIDV4,
|
id: {
|
||||||
primaryKey: true,
|
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, online, online group, onsite, onsite group
|
||||||
|
},
|
||||||
|
source: {
|
||||||
|
type: DataTypes.STRING, //app, web
|
||||||
|
},
|
||||||
|
marketing_memberId: {
|
||||||
|
type: DataTypes.STRING,
|
||||||
|
},
|
||||||
|
validated: {
|
||||||
|
type: DataTypes.BOOLEAN,
|
||||||
|
},
|
||||||
|
stateText: {
|
||||||
|
type: Sequelize.VIRTUAL(Sequelize.STRING, ["validated", "reservationId", "overflowEventId", "type"]),
|
||||||
|
get: function () {
|
||||||
|
return getStateText(this);
|
||||||
},
|
},
|
||||||
date: {
|
},
|
||||||
type: DataTypes.DATE,
|
reservationId: {
|
||||||
},
|
//contendra el id de la reserva o de la lista de espera de la reserva
|
||||||
code_ticket: {
|
type: DataTypes.UUID,
|
||||||
type: DataTypes.STRING(45),
|
foreignKey: true,
|
||||||
},
|
},
|
||||||
type: {
|
overflowEventId: {
|
||||||
type: DataTypes.STRING,
|
//contendra el id del evento de lista de espera del evento
|
||||||
allowNull: false,
|
type: DataTypes.UUID,
|
||||||
defaultValue: 'regular' //grupal, invitacion-regular, invitation-grupal
|
foreignKey: true,
|
||||||
},
|
},
|
||||||
source: {
|
},
|
||||||
type: DataTypes.STRING, //app, web
|
{
|
||||||
},
|
tableName: "events_inscriptions",
|
||||||
marketing_memberId: {
|
freezeTableName: true,
|
||||||
type: DataTypes.STRING,
|
timestamps: true,
|
||||||
},
|
|
||||||
validated: {
|
defaultScope: {
|
||||||
type: DataTypes.BOOLEAN,
|
order: [["date", "DESC"]],
|
||||||
},
|
include: [
|
||||||
stateText: {
|
{
|
||||||
type: Sequelize.VIRTUAL(Sequelize.STRING, ['validated', 'reservationId', 'overflowEventId']),
|
model: sequelize.models.User,
|
||||||
get: function () {
|
as: "user",
|
||||||
return getStateText(this);
|
include: [{ model: sequelize.models.Entity, attributes: ["id", "name"], required: false }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
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" });
|
||||||
|
};
|
||||||
|
|
||||||
|
EventInscription.addScope("includeEventAndVenue", () => {
|
||||||
|
return {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: sequelize.models.Event,
|
||||||
|
as: "event",
|
||||||
|
attributes: [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"description",
|
||||||
|
"campaign_text",
|
||||||
|
"init_date",
|
||||||
|
"end_date",
|
||||||
|
"init_available_date",
|
||||||
|
"end_available_date",
|
||||||
|
"stateCode",
|
||||||
|
"stateText",
|
||||||
|
],
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: sequelize.models.Venue,
|
||||||
|
as: "venue",
|
||||||
|
attributes: {
|
||||||
|
exclude: ["createdAt", "updatedAt"],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
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,
|
|
||||||
|
|
||||||
defaultScope: {
|
|
||||||
order: [
|
|
||||||
['date', 'DESC']
|
|
||||||
],
|
|
||||||
include: [
|
|
||||||
{ model: sequelize.models.User, as: 'user',
|
|
||||||
include: [{ model: sequelize.models.Entity, attributes: ['id', 'name'], required: false }]
|
|
||||||
}],
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
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' });
|
|
||||||
};
|
};
|
||||||
|
});
|
||||||
|
|
||||||
EventInscription.addScope('includeEventAndVenue', () => {
|
EventInscription.addScope("includeReservation", () => {
|
||||||
return {
|
return {
|
||||||
include: [{
|
include: [
|
||||||
model: sequelize.models.Event,
|
{
|
||||||
as: 'event',
|
model: sequelize.models.EventReservation,
|
||||||
attributes: ['id', 'name', 'description', 'campaign_text', 'init_date', 'end_date', 'init_available_date',
|
as: "reservation",
|
||||||
'end_available_date', 'stateCode', 'stateText'],
|
require: false,
|
||||||
include: [{
|
include: [
|
||||||
model: sequelize.models.Venue,
|
{
|
||||||
as: 'venue',
|
model: sequelize.models.Entity,
|
||||||
attributes: {
|
required: false,
|
||||||
exclude: ['createdAt', 'updatedAt'],
|
},
|
||||||
}
|
],
|
||||||
}],
|
},
|
||||||
}],
|
],
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
EventInscription.addScope('includeReservation', () => {
|
EventInscription.addScope("includeUser", () => {
|
||||||
return {
|
return {
|
||||||
include: [{
|
include: [
|
||||||
model: sequelize.models.EventReservation,
|
{
|
||||||
as: 'reservation',
|
model: sequelize.models.User,
|
||||||
require: false,
|
as: "user",
|
||||||
include: [{
|
},
|
||||||
model: sequelize.models.Entity,
|
],
|
||||||
required: false,
|
};
|
||||||
}]
|
});
|
||||||
}],
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
EventInscription.addScope('includeUser', () => {
|
return EventInscription;
|
||||||
return {
|
};
|
||||||
include: [{
|
|
||||||
model: sequelize.models.User,
|
|
||||||
as: 'user',
|
|
||||||
}],
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return EventInscription;
|
|
||||||
};
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user