a
This commit is contained in:
parent
3f8ed0c823
commit
1b50515227
@ -73,7 +73,6 @@ const generateControllers = (service, extraControllers = {}, options = {}) => {
|
||||
create: (config) => {
|
||||
return async (req, res, next) => {
|
||||
try {
|
||||
console.log(req.body);
|
||||
const result = await service.create(req.body, buildContext(req, config));
|
||||
return handleResultResponse(result, null, null, res, httpStatus.CREATED)
|
||||
} catch (error) {
|
||||
|
||||
@ -51,7 +51,6 @@ function buildErrorResponse(nameController, nameMethod, error) {
|
||||
}
|
||||
|
||||
function getTotalCount(result) {
|
||||
|
||||
const toType = function (obj) {
|
||||
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
|
||||
}
|
||||
|
||||
@ -164,7 +164,6 @@ const generateService = (model, extraMethods = {}, options = defaultOptions) =>
|
||||
fetchOne: async (params, context) => {
|
||||
const findOptions = parseParamsToFindOptions(params);
|
||||
const result = await model.scope(context.scopes).findOne(findOptions);
|
||||
|
||||
if (extraMethods.afterFetchOne) {
|
||||
return extraMethods.afterFetchOne(result, params, context);
|
||||
} else {
|
||||
|
||||
@ -2,7 +2,33 @@
|
||||
const moment = require('moment');
|
||||
const Sequelize = require('sequelize');
|
||||
|
||||
const getStateText = (conference) => {
|
||||
|
||||
var currentDate = moment().utc(),
|
||||
initDate = moment.utc(conference.ini_date),
|
||||
endDate = moment.utc(conference.end_date),
|
||||
init_availableDate = moment.utc(conference.init_available_date),
|
||||
end_availableDate = moment.utc(conference.end_available_date),
|
||||
isFull = (conference.confirmed > conference.assistans);
|
||||
|
||||
if (moment(currentDate).isBetween(initDate, endDate)) {
|
||||
return 'Congreso en curso';
|
||||
} else {
|
||||
if (moment(endDate).isBefore(currentDate)) {
|
||||
return 'Congreso finalizado';
|
||||
} else {
|
||||
if (moment(currentDate).isBetween(init_availableDate, end_availableDate)) {
|
||||
return isFull ? 'Inscripciones abiertas a lista de espera' : 'Inscripciones abiertas';
|
||||
} else {
|
||||
return 'Inscripciones a partir del ' + moment(init_availableDate).format('ll');
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
module.exports = function (sequelize, DataTypes) {
|
||||
|
||||
const Event = sequelize.define('Event', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
@ -66,6 +92,12 @@ module.exports = function (sequelize, DataTypes) {
|
||||
allowNull: false,
|
||||
defaultValue: 'draft'
|
||||
},
|
||||
stateText: {
|
||||
type: Sequelize.VIRTUAL(Sequelize.STRING, ['init_date', 'end_date', 'init_available_date', 'end_available_date', 'assistants', 'confirmed']),
|
||||
get: function () {
|
||||
return getStateText(this);
|
||||
},
|
||||
},
|
||||
typeId: {
|
||||
type: DataTypes.UUID,
|
||||
foreignKey: true,
|
||||
|
||||
@ -70,12 +70,12 @@ routes.get('/events/:id',
|
||||
isLoggedUser,
|
||||
FieldMiddleware.middleware({
|
||||
invalidFields: generalInvalidFields
|
||||
}),
|
||||
}),
|
||||
(req, res, next) => {
|
||||
console.log(req.user.id);
|
||||
return eventController.findOne({
|
||||
scopes: ['defaultScope', 'includeVenue', 'includeMultimedias', 'includeSpeakers', { method: ['includeInscription', req.user.id] }]
|
||||
})(res, req, next)
|
||||
})(req, res, next)
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user