a
This commit is contained in:
parent
5e759d63a8
commit
9fd846af95
@ -254,6 +254,18 @@ const entityComposer = (entity, context) => {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const usersIdsComposer = (inscriptions) => {
|
||||||
|
let usersId = []
|
||||||
|
if (inscriptions) {
|
||||||
|
inscriptions.map((inscription) => {
|
||||||
|
usersId.push({
|
||||||
|
userId: inscription.userId,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return usersId;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entityComposer,
|
entityComposer,
|
||||||
@ -261,5 +273,6 @@ module.exports = {
|
|||||||
eventComposer,
|
eventComposer,
|
||||||
commentComposer,
|
commentComposer,
|
||||||
citiesComposer,
|
citiesComposer,
|
||||||
locationComposer
|
locationComposer,
|
||||||
|
usersIdsComposer,
|
||||||
}
|
}
|
||||||
@ -6,6 +6,8 @@ const { buildContext } = require('../../core/controllers');
|
|||||||
const notificationService = require('./notification.service');
|
const notificationService = require('./notification.service');
|
||||||
const notificationDetailService = require('./notification_detail.service');
|
const notificationDetailService = require('./notification_detail.service');
|
||||||
const userDeviceService = require('./user_device.service');
|
const userDeviceService = require('./user_device.service');
|
||||||
|
const eventInscriptionService = require('../events/events_inscriptions.service');
|
||||||
|
const { usersIdsComposer } = require('../../helpers/composes.helper');
|
||||||
|
|
||||||
const { extractParamsFromRequest, handleErrorResponse, handleResultResponse } = require('../../helpers/controller.helper');
|
const { extractParamsFromRequest, handleErrorResponse, handleResultResponse } = require('../../helpers/controller.helper');
|
||||||
|
|
||||||
@ -15,11 +17,11 @@ const controllerOptions = { MODULE_NAME };
|
|||||||
|
|
||||||
const extraControllers = {
|
const extraControllers = {
|
||||||
|
|
||||||
sendNotificationEvent: () => {
|
sendNotificationEvent: async (req, res, next) => {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* notificationSample = {
|
* notificationSample = {
|
||||||
* "title": "título de la notificación",
|
* "tittle": "título de la notificación",
|
||||||
* "message": "cuerpo de la notificación",
|
* "message": "cuerpo de la notificación",
|
||||||
* "recipients": {
|
* "recipients": {
|
||||||
* "eventId": "xxx-xxx-xxx-xxx",
|
* "eventId": "xxx-xxx-xxx-xxx",
|
||||||
@ -40,22 +42,49 @@ const extraControllers = {
|
|||||||
* }
|
* }
|
||||||
*}
|
*}
|
||||||
*/
|
*/
|
||||||
|
let usersIds = null;
|
||||||
|
const params = req.body;
|
||||||
|
const eventId = params.recipients.eventId;
|
||||||
|
const segment = params.recipients.segment;
|
||||||
|
console.log('prueba de llamada>>>>> ', params);
|
||||||
|
|
||||||
|
try {
|
||||||
|
notificationService.createNotification(params.date, params.title, params.message, undefined, 'default', params.data, req.user.id);
|
||||||
|
switch (segment) {
|
||||||
|
//Todos los inscritos al evento tanto en validos como en lista de espera
|
||||||
|
case 'ALL':
|
||||||
|
usersIds = await eventInscriptionService._getInscriptionByEvent(eventId);
|
||||||
|
break;
|
||||||
|
//Todos los inscritos tanto invitados como libres
|
||||||
|
case 'ALL_VALIDATED':
|
||||||
|
usersIds = await eventInscriptionService._getInscriptionByEventAndValidated(eventId, true);
|
||||||
|
break;
|
||||||
|
//Todos los de lista de espera tanto invitados como libres (Actualmente en invitados no hay lista de espera)
|
||||||
|
case 'ALL_NOT_VALIDATED':
|
||||||
|
usersIds = await eventInscriptionService._getInscriptionByEventAndValidated(eventId, false);
|
||||||
|
break;
|
||||||
|
|
||||||
//eventId
|
//Solo invitados como actualmente no se usa codigo de reserva para los coles, vale con filtrar por aquellos que tengan codigo de reserva
|
||||||
//tittle
|
case 'PARTNERS_ALL':
|
||||||
//message
|
usersIds = await eventInscriptionService._getInscriptionByEventFromPartner(eventId);
|
||||||
//recipients: 1 - a todos
|
|
||||||
// 2 - inscritos con entrada (validated = 1) (libres e invitados)
|
break;
|
||||||
// 3 - solo a invitados (reservationId is not null, and entityId pertenece a partners)
|
|
||||||
// 4 - solo a lista de espera (validated = 0) (libres e invitados "si hubiera lista de espera en invitaciones")
|
|
||||||
//dataDestination: json con screen destino
|
|
||||||
//{
|
|
||||||
// type: URL | screen | notification
|
|
||||||
// parameter: {}
|
|
||||||
//}
|
|
||||||
|
|
||||||
// let params = extractParamsFromRequest(req, res);
|
//Todos los inscritos al evento, tanto validados como en lista de espera
|
||||||
console.log('prueba de llamada>>>>> ', params);
|
default: //ALL
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
usersIds = usersIdsComposer(usersIds);
|
||||||
|
console.log('usuarios inscritos>>>>> ', usersIds);
|
||||||
|
|
||||||
|
} catch(error) {
|
||||||
|
return handleErrorResponse(MODULE_NAME, 'sendNotificationEvent', error, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return handleResultResponse("sendNotificationEvent", null, params, res, httpStatus.OK);
|
||||||
},
|
},
|
||||||
|
|
||||||
sendNotification: (config) => {
|
sendNotification: (config) => {
|
||||||
|
|||||||
@ -6,7 +6,7 @@ const PaginateMiddleware = require('../../middlewares/paginate');
|
|||||||
const FieldMiddleware = require('../../middlewares/fields');
|
const FieldMiddleware = require('../../middlewares/fields');
|
||||||
const SortMiddleware = require('../../middlewares/sort');
|
const SortMiddleware = require('../../middlewares/sort');
|
||||||
const notificationController = require('./notification.controller');
|
const notificationController = require('./notification.controller');
|
||||||
const { deviceTokenInputType, notificationSendType } = require('./notification.validations');
|
const { pushSendEvent, deviceTokenInputType, notificationSendType } = require('./notification.validations');
|
||||||
|
|
||||||
const generalInvalidFields = [
|
const generalInvalidFields = [
|
||||||
'createdAt', 'updatedAt',
|
'createdAt', 'updatedAt',
|
||||||
@ -44,8 +44,8 @@ routes.post('/admin/notifications',
|
|||||||
|
|
||||||
routes.post('/admin/notifications/event',
|
routes.post('/admin/notifications/event',
|
||||||
isAdministratorUser,
|
isAdministratorUser,
|
||||||
// SchemaValidator(notificationSendType, true),
|
SchemaValidator(pushSendEvent, true),
|
||||||
notificationController.sendNotificationEvent()
|
notificationController.sendNotificationEvent
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Borrar cuando ya no aparezca la versión 1.0.10 */
|
/* Borrar cuando ya no aparezca la versión 1.0.10 */
|
||||||
|
|||||||
@ -6,7 +6,32 @@ const models = require('../../core/models');
|
|||||||
const expo = new Expo();
|
const expo = new Expo();
|
||||||
|
|
||||||
const extraMethods = {
|
const extraMethods = {
|
||||||
|
|
||||||
|
createNotification: (date, title, body, ttl, priority, data, userId) => {
|
||||||
|
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<valores de la notificacion');
|
||||||
|
console.log(title, body, ttl, priority, data, userId);
|
||||||
|
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
models.Notification.create({
|
||||||
|
date: date,
|
||||||
|
title: title,
|
||||||
|
body: body,
|
||||||
|
userId: userId,
|
||||||
|
ttl: ttl,
|
||||||
|
priority: priority,
|
||||||
|
data: data,
|
||||||
|
})
|
||||||
|
.then(function (result) {
|
||||||
|
resolve(result);
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
reject(error)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sendNotification: async (messages) => {
|
sendNotification: async (messages) => {
|
||||||
|
|
||||||
// The Expo push notification service accepts batches of notifications so
|
// The Expo push notification service accepts batches of notifications so
|
||||||
|
|||||||
@ -11,6 +11,27 @@ const pushSendType = Joi.object().keys({
|
|||||||
//token: Joi.string().required(),
|
//token: Joi.string().required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const pushSendEvent = Joi.object().keys({
|
||||||
|
date: Joi.date().required(),
|
||||||
|
title: Joi.string().required(),
|
||||||
|
message: Joi.string().required(),
|
||||||
|
recipients: Joi.object().keys({
|
||||||
|
eventId: Joi.string().required(),
|
||||||
|
segment: Joi.string().required(),
|
||||||
|
}),
|
||||||
|
data: Joi.object().keys({
|
||||||
|
type: Joi.string().required(),
|
||||||
|
title: Joi.string().required(),
|
||||||
|
message: Joi.string().required(),
|
||||||
|
button: Joi.object().keys({
|
||||||
|
caption: Joi.string().required(),
|
||||||
|
url: Joi.string().optional(),
|
||||||
|
screen: Joi.string().optional(),
|
||||||
|
paramId: Joi.string().optional(),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
deviceTokenInputType, pushSendType
|
deviceTokenInputType, pushSendType, pushSendEvent
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user