Revisión de notificaciones

This commit is contained in:
David Arranz 2022-03-21 17:39:56 +01:00
parent 7702da6267
commit 80f3449839
3 changed files with 67 additions and 69 deletions

View File

@ -37,7 +37,7 @@ async function _sendNotificationAllActiveUsers(notification) {
page = page + 1;
let ids = result.rows.map(function(item) { return item.id });
let ids = result.rows.map(function (item) { return item.id });
notificationService.sendNotification(notification, ids);
@ -47,7 +47,7 @@ async function _sendNotificationAllActiveUsers(notification) {
}
async function _getUserIdsForEventId(eventId, segment) {
let userIds =[];
let userIds = [];
switch (segment) {
//Todos los inscritos tanto invitados como libres
@ -78,34 +78,34 @@ const extraControllers = {
sendNotification: (config) => {
/**
* notificationSample = {
* "tittle": "título de la notificación",
* "message": "cuerpo de la notificación",
* "recipients": {
* OPCION 1- Unos usuarios determinados
* "userIds": ["*" | "f428a317-6d1f-4eda-aa3e-22baff3f48d7", ...]
* "segment": "ALL" | "LAST_YEAR" | "LAST_MONTH"
*
* OPCION 2 - A todos los usuarios inscritos a un evento, se puede segmentar
* "eventId": "xxx-xxx-xxx-xxx",
* "segment": "ALL" | "ALL_VALIDATED" | "ALL_NOT_VALIDATED" |
* "PARTNERS_ALL" | "PARTNERS_VALIDATED" | "PARTNERS_NOT_VALIDATED" |
* "COLLEGE_ALL" | "COLLEGE_VALIDATED" | "COLLEGE_NOT_VALIDATED"
* },
* "data": {
* "type": "message",
* "title": "Título del mensaje",
* "message": "Cuerpo del mensaje",
* "button": {
* "caption": "Etiqueta del boton",
* "url": "https://www.site.es",
* "screen": "<RouterName>",
* "paramId": "23",
* }
* }
*}
*/
/**
* notificationSample = {
* "tittle": "título de la notificación",
* "message": "cuerpo de la notificación",
* "recipients": {
* OPCION 1- Unos usuarios determinados
* "userIds": ["*" | "f428a317-6d1f-4eda-aa3e-22baff3f48d7", ...]
* "segment": "ALL" | "LAST_YEAR" | "LAST_MONTH"
*
* OPCION 2 - A todos los usuarios inscritos a un evento, se puede segmentar
* "eventId": "xxx-xxx-xxx-xxx",
* "segment": "ALL" | "ALL_VALIDATED" | "ALL_NOT_VALIDATED" |
* "PARTNERS_ALL" | "PARTNERS_VALIDATED" | "PARTNERS_NOT_VALIDATED" |
* "COLLEGE_ALL" | "COLLEGE_VALIDATED" | "COLLEGE_NOT_VALIDATED"
* },
* "data": {
* "type": "message",
* "title": "Título del mensaje",
* "message": "Cuerpo del mensaje",
* "button": {
* "caption": "Etiqueta del boton",
* "url": "https://www.site.es",
* "screen": "<RouterName>",
* "paramId": "23",
* }
* }
*}
*/
return async (req, res, next) => {
config = config || {
@ -143,7 +143,7 @@ const extraControllers = {
try {
let notification = notificationHelper.createNotification ({
let notification = notificationHelper.createNotification({
...body,
userId: context.user.id
});
@ -204,18 +204,17 @@ const extraControllers = {
//receipt = notificationService.sendNotification(notification, await getUserIds());
return handleResultResponse(receipt, null, null, res, httpStatus.OK);
} catch (error) {
console.error(error);
return handleErrorResponse(controllerOptions.MODULE_NAME, 'sendNotification', error, res)
} finally {
return handleResultResponse(receipt, null, null, res, httpStatus.OK);
}
}
},
updateNotificationsWithReceipts: (config) => {
return async (req, res, next) => {
config = config || {
/*config = config || {
scopes: [],
};
@ -224,7 +223,7 @@ const extraControllers = {
let getNotificationsWithoutReceipt = async () => {
let params = {
where: { }
where: {}
};
return await notificationDetailService.fetchAll(params, context);
}
@ -234,6 +233,7 @@ const extraControllers = {
return Promise.all(userDeviceList.map(buildMessagePromise))
})
.then(sendNotificationsPromise)
*/
}
},
@ -257,13 +257,12 @@ const extraControllers = {
includeAll: false,
paginate: { limit: 1, page: 1 },
params: {
//userId,
token: data.token,
}
});
// Buscamos el token y el usuario
console.log('>> Busco el usuario y el token', params.params);
console.log('>> Busco el token', params.params);
let result = await userDeviceService.fetchOne(params, context);
if (!result) {
// Dar de alta el token
@ -272,14 +271,13 @@ const extraControllers = {
} else {
// Actualizar el token
console.log('>> Actualizar el token', params.params, data, context);
result = await userDeviceService.update(params, { valid : 1 }, context);
result = await userDeviceService.update(params, { valid: 1 }, context);
}
} catch(error) {
} catch (error) {
console.error(error);
} finally {
// En todo caso devolver OK al cliente
return handleResultResponse('OK', null, null, res, httpStatus.OK);
}
// En todo caso devolver OK al cliente
return handleResultResponse('OK', null, null, res, httpStatus.OK);
}
},
};

View File

@ -1,6 +1,6 @@
const routes = require('express').Router();
const { isAdministratorUser, isLoggedUser } = require('../../middlewares/accessValidator');
const { isAdministratorUser, isOptionalUser, isLoggedUser } = require('../../middlewares/accessValidator');
const SchemaValidator = require('../../middlewares/schemaValidator');
const PaginateMiddleware = require('../../middlewares/paginate');
const FieldMiddleware = require('../../middlewares/fields');
@ -56,7 +56,7 @@ routes.post('/admin/notifications',
);*/
routes.post('/notifications/devices',
//isLoggedUser,
isOptionalUser,
SchemaValidator(deviceTokenInputType, true),
notificationController.registerDevice()
);

View File

@ -132,14 +132,14 @@ const extraMethods = {
getNotificationsWithoutReceipt: async() => {
getNotificationsWithoutReceipt: async () => {
},
updateNotificationsWithReceipts: async (receiptIds) => {
let receiptIdChunks = expo.chunkPushNotificationReceiptIds(receiptIds);
let xxx = await _getPushNotificationsResultAsync(receiptIdChunks);
//let receiptIdChunks = expo.chunkPushNotificationReceiptIds(receiptIds);
//let xxx = await _getPushNotificationsResultAsync(receiptIdChunks);
}
};