a
This commit is contained in:
parent
85438d7ac5
commit
948bd01edc
@ -3,6 +3,39 @@ const moment = require('moment');
|
|||||||
const Sequelize = require('sequelize');
|
const Sequelize = require('sequelize');
|
||||||
moment.locale('es');
|
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) => {
|
const getStateText = (event) => {
|
||||||
var currentDate = moment().utc(),
|
var currentDate = moment().utc(),
|
||||||
initDate = moment.utc(event.ini_date),
|
initDate = moment.utc(event.ini_date),
|
||||||
@ -16,10 +49,19 @@ const getStateText = (event) => {
|
|||||||
if (moment(endDate).isBefore(currentDate)) {
|
if (moment(endDate).isBefore(currentDate)) {
|
||||||
return 'Congreso finalizado';
|
return 'Congreso finalizado';
|
||||||
} else {
|
} else {
|
||||||
if (moment(currentDate).isBetween(init_availableDate, end_availableDate)) {
|
if (moment(currentDate).isBefore(init_availableDate)) {
|
||||||
return (event.sold_out == 1) ? 'Inscripciones abiertas a lista de espera' : 'Inscripciones abiertas';
|
|
||||||
} else {
|
|
||||||
return 'Inscripciones a partir del ' + moment(init_availableDate).format('D [de] MMMM');
|
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,
|
allowNull: false,
|
||||||
defaultValue: 'draft'
|
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: {
|
stateText: {
|
||||||
type: Sequelize.VIRTUAL(Sequelize.STRING, ['init_date', 'end_date', 'init_available_date', 'end_available_date', 'sold_out']),
|
type: Sequelize.VIRTUAL(Sequelize.STRING, ['init_date', 'end_date', 'init_available_date', 'end_available_date', 'sold_out']),
|
||||||
get: function () {
|
get: function () {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user