This commit is contained in:
David Arranz 2019-07-26 19:06:19 +02:00
parent 85438d7ac5
commit 948bd01edc

View File

@ -3,6 +3,39 @@ const moment = require('moment');
const Sequelize = require('sequelize');
moment.locale('es');
const getStateCode = (event) => {
var currentDate = moment().utc(),
initDate = moment.utc(event.ini_date),
endDate = moment.utc(event.end_date),
init_availableDate = moment.utc(event.init_available_date),
end_availableDate = moment.utc(event.end_available_date);
if (moment(currentDate).isBetween(initDate, endDate)) {
return 'current_event';
} else {
if (moment(endDate).isBefore(currentDate)) {
return 'closed_event';
} else {
if (moment(currentDate).isBefore(init_availableDate)){
return 'future_registrations'
} else {
if (moment(currentDate).isBetween(init_availableDate, end_availableDate)) {
return (event.sold_out == 1) ? 'waitinglist_open' : 'registrations_open';
}
else {
if (moment(currentDate).isAfter(end_availableDate))
return 'closed_registrations'
else
return 'N/A';
}
}
}
};
};
const getStateText = (event) => {
var currentDate = moment().utc(),
initDate = moment.utc(event.ini_date),
@ -16,10 +49,19 @@ const getStateText = (event) => {
if (moment(endDate).isBefore(currentDate)) {
return 'Congreso finalizado';
} else {
if (moment(currentDate).isBetween(init_availableDate, end_availableDate)) {
return (event.sold_out == 1) ? 'Inscripciones abiertas a lista de espera' : 'Inscripciones abiertas';
} else {
if (moment(currentDate).isBefore(init_availableDate)) {
return 'Inscripciones a partir del ' + moment(init_availableDate).format('D [de] MMMM');
} else {
if (moment(currentDate).isBetween(init_availableDate, end_availableDate)) {
return (event.sold_out == 1) ? 'Inscripciones abiertas a lista de espera' : 'Inscripciones abiertas';
}
else {
if (moment(currentDate).isAfter(end_availableDate))
return 'Inscripciones cerradas'
else
return 'N/A';
}
}
}
};
@ -95,6 +137,12 @@ module.exports = function (sequelize, DataTypes) {
allowNull: false,
defaultValue: 'draft'
},
stateCode: {
type: Sequelize.VIRTUAL(Sequelize.STRING, ['init_date', 'end_date', 'init_available_date', 'end_available_date', 'sold_out']),
get: function () {
return getStateCode(this);
},
},
stateText: {
type: Sequelize.VIRTUAL(Sequelize.STRING, ['init_date', 'end_date', 'init_available_date', 'end_available_date', 'sold_out']),
get: function () {