From f2f78df93f2a9bba405e967c16c2a55b6ab10ba9 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 23 Feb 2022 19:48:50 +0100 Subject: [PATCH] =?UTF-8?q?Al=20dar=20el=20estado=20de=20una=20inscripci?= =?UTF-8?q?=C3=B3n,=20tener=20en=20cuenta=20las=20inscripciones=20online.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/events/events_inscriptions.model.js | 256 +++++++++++--------- 1 file changed, 143 insertions(+), 113 deletions(-) diff --git a/modules/events/events_inscriptions.model.js b/modules/events/events_inscriptions.model.js index d30646b..f37065b 100644 --- a/modules/events/events_inscriptions.model.js +++ b/modules/events/events_inscriptions.model.js @@ -1,125 +1,155 @@ -'use strict'; -const Sequelize = require('sequelize'); +"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'; + if (inscription.type !== "online" && inscription !== "online group") { + 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"; + } else { + // online + return "Inscripción online confirmada"; + } }; - module.exports = function (sequelize, DataTypes) { - const EventInscription = sequelize.define('EventInscription', { - id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, - primaryKey: true, + 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, 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, - }, - 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, + + 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", () => { + 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', () => { - 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'], - } - }], - }], - } - }); + EventInscription.addScope("includeReservation", () => { + return { + include: [ + { + model: sequelize.models.EventReservation, + as: "reservation", + require: false, + include: [ + { + model: sequelize.models.Entity, + required: false, + }, + ], + }, + ], + }; + }); - EventInscription.addScope('includeReservation', () => { - return { - include: [{ - model: sequelize.models.EventReservation, - as: 'reservation', - require: false, - include: [{ - model: sequelize.models.Entity, - required: false, - }] - }], - } - }); + EventInscription.addScope("includeUser", () => { + return { + include: [ + { + model: sequelize.models.User, + as: "user", + }, + ], + }; + }); - EventInscription.addScope('includeUser', () => { - return { - include: [{ - model: sequelize.models.User, - as: 'user', - }], - } - }); - - return EventInscription; -}; \ No newline at end of file + return EventInscription; +};