Notificaciones push por países
This commit is contained in:
parent
444d364f1a
commit
ebfc1908d0
@ -3,10 +3,7 @@
|
|||||||
|
|
||||||
const _ = require("lodash");
|
const _ = require("lodash");
|
||||||
const moment = require("moment");
|
const moment = require("moment");
|
||||||
const {
|
const { generateService, parseParamsToFindOptions } = require("../../helpers/service.helper");
|
||||||
generateService,
|
|
||||||
parseParamsToFindOptions,
|
|
||||||
} = require("../../helpers/service.helper");
|
|
||||||
const models = require("../../core/models");
|
const models = require("../../core/models");
|
||||||
const Sequelize = require("sequelize");
|
const Sequelize = require("sequelize");
|
||||||
moment.locale("es");
|
moment.locale("es");
|
||||||
@ -28,12 +25,13 @@ const extraMethods = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_getActiveUserIds: async (offset = 0, limit = 10) => {
|
_getActiveUserIds: async (offset = 0, limit = 10, country = "ES") => {
|
||||||
return models.User.findAndCountAll({
|
return models.User.findAndCountAll({
|
||||||
attributes: ["id"],
|
attributes: ["id"],
|
||||||
where: {
|
where: {
|
||||||
state: "active",
|
state: "active",
|
||||||
phone: { [Sequelize.Op.ne]: null },
|
phone: { [Sequelize.Op.ne]: null },
|
||||||
|
country: country === "*" ? { [Sequelize.Op.ne]: null } : country,
|
||||||
},
|
},
|
||||||
raw: true,
|
raw: true,
|
||||||
limit: limit,
|
limit: limit,
|
||||||
|
|||||||
@ -1,25 +1,28 @@
|
|||||||
'use strict';
|
"use strict";
|
||||||
const httpStatus = require('http-status');
|
const httpStatus = require("http-status");
|
||||||
const moment = require('moment');
|
const moment = require("moment");
|
||||||
const generateControllers = require('../../core/controllers');
|
const generateControllers = require("../../core/controllers");
|
||||||
const { buildContext } = require('../../core/controllers');
|
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 userService = require('../auth/user.service');
|
const userService = require("../auth/user.service");
|
||||||
const userDeviceService = require('./user_device.service');
|
const userDeviceService = require("./user_device.service");
|
||||||
const eventInscriptionService = require('../events/events_inscriptions.service');
|
const eventInscriptionService = require("../events/events_inscriptions.service");
|
||||||
const { usersIdsComposer } = require('../../helpers/composes.helper');
|
const { usersIdsComposer } = require("../../helpers/composes.helper");
|
||||||
const pushHelper = require('../../helpers/push.helper');
|
const pushHelper = require("../../helpers/push.helper");
|
||||||
const notificationHelper = require('../../helpers/notification.helpers')
|
const notificationHelper = require("../../helpers/notification.helpers");
|
||||||
|
|
||||||
const { extractParamsFromRequest, handleErrorResponse, handleResultResponse } = require('../../helpers/controller.helper');
|
const {
|
||||||
const { get } = require('lodash');
|
extractParamsFromRequest,
|
||||||
|
handleErrorResponse,
|
||||||
|
handleResultResponse,
|
||||||
|
} = require("../../helpers/controller.helper");
|
||||||
|
const { get } = require("lodash");
|
||||||
|
|
||||||
// Module Name
|
// Module Name
|
||||||
const MODULE_NAME = '[notification.controller]';
|
const MODULE_NAME = "[notification.controller]";
|
||||||
const controllerOptions = { MODULE_NAME };
|
const controllerOptions = { MODULE_NAME };
|
||||||
|
|
||||||
|
|
||||||
async function _sendNotificationAllActiveUsers(notification) {
|
async function _sendNotificationAllActiveUsers(notification) {
|
||||||
let limit = 33;
|
let limit = 33;
|
||||||
let page = 1;
|
let page = 1;
|
||||||
@ -29,7 +32,7 @@ async function _sendNotificationAllActiveUsers(notification) {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
let offset = (page - 1) * limit;
|
let offset = (page - 1) * limit;
|
||||||
let result = await userService._getActiveUserIds(offset, limit);
|
let result = await userService._getActiveUserIds(offset, limit, notification.recipients.country);
|
||||||
|
|
||||||
if (totalPages == -1) {
|
if (totalPages == -1) {
|
||||||
totalPages = Math.ceil(result.count / limit);
|
totalPages = Math.ceil(result.count / limit);
|
||||||
@ -37,16 +40,15 @@ async function _sendNotificationAllActiveUsers(notification) {
|
|||||||
|
|
||||||
page = page + 1;
|
page = page + 1;
|
||||||
|
|
||||||
let ids = result.rows.map(function (item) { return item.id });
|
let ids = result.rows.map(function (item) {
|
||||||
|
return item.id;
|
||||||
|
});
|
||||||
notificationService.sendNotificationToUsers(notification, ids);
|
notificationService.sendNotificationToUsers(notification, ids);
|
||||||
|
|
||||||
|
|
||||||
} while (page <= totalPages);
|
} while (page <= totalPages);
|
||||||
|
|
||||||
return 'OK';
|
return "OK";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function _sendNotificationAllActiveDevices(notification) {
|
async function _sendNotificationAllActiveDevices(notification) {
|
||||||
let limit = 33;
|
let limit = 33;
|
||||||
let page = 1;
|
let page = 1;
|
||||||
@ -56,7 +58,7 @@ async function _sendNotificationAllActiveDevices(notification) {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
let offset = (page - 1) * limit;
|
let offset = (page - 1) * limit;
|
||||||
let result = await userDeviceService._getActiveDeviceIds(offset, limit);
|
let result = await userDeviceService._getActiveDeviceIds(offset, limit, notification.recipients.country);
|
||||||
|
|
||||||
console.log(result);
|
console.log(result);
|
||||||
|
|
||||||
@ -69,7 +71,7 @@ async function _sendNotificationAllActiveDevices(notification) {
|
|||||||
notificationService.sendNotificationToDevices(notification, result.rows);
|
notificationService.sendNotificationToDevices(notification, result.rows);
|
||||||
} while (page <= totalPages);
|
} while (page <= totalPages);
|
||||||
|
|
||||||
return 'OK';
|
return "OK";
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _getUserIdsForEventId(eventId, segment) {
|
async function _getUserIdsForEventId(eventId, segment) {
|
||||||
@ -77,16 +79,16 @@ async function _getUserIdsForEventId(eventId, segment) {
|
|||||||
|
|
||||||
switch (segment) {
|
switch (segment) {
|
||||||
//Todos los inscritos tanto invitados como libres
|
//Todos los inscritos tanto invitados como libres
|
||||||
case 'ALL_VALIDATED':
|
case "ALL_VALIDATED":
|
||||||
userIds = await eventInscriptionService._getInscriptionByEventAndValidated(eventId, true);
|
userIds = await eventInscriptionService._getInscriptionByEventAndValidated(eventId, true);
|
||||||
break;
|
break;
|
||||||
//Todos los de lista de espera tanto invitados como libres (Actualmente en invitados no hay lista de espera)
|
//Todos los de lista de espera tanto invitados como libres (Actualmente en invitados no hay lista de espera)
|
||||||
case 'ALL_NOT_VALIDATED':
|
case "ALL_NOT_VALIDATED":
|
||||||
userIds = await eventInscriptionService._getInscriptionByEventAndValidated(eventId, false);
|
userIds = await eventInscriptionService._getInscriptionByEventAndValidated(eventId, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//Solo invitados como actualmente no se usa codigo de reserva para los coles, vale con filtrar por aquellos que tengan codigo de reserva
|
//Solo invitados como actualmente no se usa codigo de reserva para los coles, vale con filtrar por aquellos que tengan codigo de reserva
|
||||||
case 'PARTNERS_ALL':
|
case "PARTNERS_ALL":
|
||||||
userIds = await eventInscriptionService._getInscriptionByEventFromPartner(eventId);
|
userIds = await eventInscriptionService._getInscriptionByEventFromPartner(eventId);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -99,11 +101,8 @@ async function _getUserIdsForEventId(eventId, segment) {
|
|||||||
return usersIdsComposer(userIds);
|
return usersIdsComposer(userIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const extraControllers = {
|
const extraControllers = {
|
||||||
|
|
||||||
sendNotification: (config) => {
|
sendNotification: (config) => {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* notificationSample = {
|
* notificationSample = {
|
||||||
* "title": "título de la notificación",
|
* "title": "título de la notificación",
|
||||||
@ -112,6 +111,7 @@ const extraControllers = {
|
|||||||
* OPCION 1- Unos usuarios determinados
|
* OPCION 1- Unos usuarios determinados
|
||||||
* "userIds": ["*" | "f428a317-6d1f-4eda-aa3e-22baff3f48d7", ...]
|
* "userIds": ["*" | "f428a317-6d1f-4eda-aa3e-22baff3f48d7", ...]
|
||||||
* "segment": "ALL" | "LAST_YEAR" | "LAST_MONTH"
|
* "segment": "ALL" | "LAST_YEAR" | "LAST_MONTH"
|
||||||
|
* "country": "*" | "ES" | "MX"
|
||||||
*
|
*
|
||||||
* OPCION 2 - A todos los usuarios inscritos a un evento, se puede segmentar
|
* OPCION 2 - A todos los usuarios inscritos a un evento, se puede segmentar
|
||||||
* "eventId": "xxx-xxx-xxx-xxx",
|
* "eventId": "xxx-xxx-xxx-xxx",
|
||||||
@ -120,6 +120,7 @@ const extraControllers = {
|
|||||||
* "COLLEGE_ALL" | "COLLEGE_VALIDATED" | "COLLEGE_NOT_VALIDATED"
|
* "COLLEGE_ALL" | "COLLEGE_VALIDATED" | "COLLEGE_NOT_VALIDATED"
|
||||||
* OPCION 3 - A todos los dispositivos activos
|
* OPCION 3 - A todos los dispositivos activos
|
||||||
* "deviceIds": ["*" | "ExponentPushToken[YbOS1AIZjQbchZbxNaVRqC]", ...]
|
* "deviceIds": ["*" | "ExponentPushToken[YbOS1AIZjQbchZbxNaVRqC]", ...]
|
||||||
|
* "country": "*" | "ES" | "MX"
|
||||||
* },
|
* },
|
||||||
* "data": {
|
* "data": {
|
||||||
* "type": "message",
|
* "type": "message",
|
||||||
@ -148,17 +149,28 @@ const extraControllers = {
|
|||||||
let deviceIds = undefined;
|
let deviceIds = undefined;
|
||||||
let eventId = undefined;
|
let eventId = undefined;
|
||||||
let segment = undefined;
|
let segment = undefined;
|
||||||
|
let country = undefined;
|
||||||
|
|
||||||
const { body } = req;
|
const { body } = req;
|
||||||
|
|
||||||
if (!body.title) {
|
if (!body.title) {
|
||||||
return handleErrorResponse(controllerOptions.MODULE_NAME, 'sendNotification', new Error('Missing message title'), res)
|
return handleErrorResponse(
|
||||||
|
controllerOptions.MODULE_NAME,
|
||||||
|
"sendNotification",
|
||||||
|
new Error("Missing message title"),
|
||||||
|
res
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!body.body) {
|
if (!body.body) {
|
||||||
return handleErrorResponse(controllerOptions.MODULE_NAME, 'sendNotification', new Error('Missing body content'), res)
|
return handleErrorResponse(
|
||||||
|
controllerOptions.MODULE_NAME,
|
||||||
|
"sendNotification",
|
||||||
|
new Error("Missing body content"),
|
||||||
|
res
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Evento?
|
// Evento?
|
||||||
if (body.recipients.eventId) {
|
if (body.recipients.eventId) {
|
||||||
eventId = body.recipients.eventId;
|
eventId = body.recipients.eventId;
|
||||||
@ -166,25 +178,30 @@ const extraControllers = {
|
|||||||
} else if (body.recipients.userIds) {
|
} else if (body.recipients.userIds) {
|
||||||
userIds = body.recipients.userIds;
|
userIds = body.recipients.userIds;
|
||||||
segment = body.recipients.segment;
|
segment = body.recipients.segment;
|
||||||
|
country = body.recipients.country;
|
||||||
} else if (body.recipients.deviceIds) {
|
} else if (body.recipients.deviceIds) {
|
||||||
deviceIds = body.recipients.deviceIds;
|
deviceIds = body.recipients.deviceIds;
|
||||||
|
country = body.recipients.country;
|
||||||
} else {
|
} else {
|
||||||
return handleErrorResponse(controllerOptions.MODULE_NAME, 'sendNotification', new Error('Missing user Ids or event Ids or devices Ids'), res)
|
return handleErrorResponse(
|
||||||
|
controllerOptions.MODULE_NAME,
|
||||||
|
"sendNotification",
|
||||||
|
new Error("Missing user Ids or event Ids or devices Ids"),
|
||||||
|
res
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let notification = notificationHelper.createNotification({
|
let notification = notificationHelper.createNotification({
|
||||||
...body,
|
...body,
|
||||||
userId: context.user.id
|
userId: context.user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if ((userIds) && (userIds.length == 1) && (userIds[0] == "*")) {
|
if (userIds && userIds.length == 1 && userIds[0] == "*") {
|
||||||
receipt = _sendNotificationAllActiveUsers(notification);
|
receipt = _sendNotificationAllActiveUsers(notification);
|
||||||
} else if ((deviceIds) && (deviceIds.length == 1) && (deviceIds[0] == "*")) {
|
} else if (deviceIds && deviceIds.length == 1 && deviceIds[0] == "*") {
|
||||||
receipt = _sendNotificationAllActiveDevices(notification);
|
receipt = _sendNotificationAllActiveDevices(notification);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
let _userIds = null;
|
let _userIds = null;
|
||||||
|
|
||||||
if (userIds) {
|
if (userIds) {
|
||||||
@ -193,7 +210,12 @@ const extraControllers = {
|
|||||||
if (eventId) {
|
if (eventId) {
|
||||||
_userIds = await _getUserIdsForEventId(eventId, segment);
|
_userIds = await _getUserIdsForEventId(eventId, segment);
|
||||||
} else {
|
} else {
|
||||||
return handleErrorResponse(controllerOptions.MODULE_NAME, 'sendNotification', new Error('Missing event and segment'), res)
|
return handleErrorResponse(
|
||||||
|
controllerOptions.MODULE_NAME,
|
||||||
|
"sendNotification",
|
||||||
|
new Error("Missing event and segment"),
|
||||||
|
res
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,9 +227,9 @@ const extraControllers = {
|
|||||||
return handleResultResponse(receipt, null, null, res, httpStatus.OK);
|
return handleResultResponse(receipt, null, null, res, httpStatus.OK);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return handleErrorResponse(controllerOptions.MODULE_NAME, 'sendNotification', error, res)
|
return handleErrorResponse(controllerOptions.MODULE_NAME, "sendNotification", error, res);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
updateNotificationsWithReceipts: (config) => {
|
updateNotificationsWithReceipts: (config) => {
|
||||||
@ -232,7 +254,7 @@ const extraControllers = {
|
|||||||
})
|
})
|
||||||
.then(sendNotificationsPromise)
|
.then(sendNotificationsPromise)
|
||||||
*/
|
*/
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
registerDevice: (config) => {
|
registerDevice: (config) => {
|
||||||
@ -241,46 +263,46 @@ const extraControllers = {
|
|||||||
scopes: [],
|
scopes: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const context = buildContext(req, config);
|
const context = buildContext(req, config);
|
||||||
const userId = context.user && context.user.id ? context.user.id : null;
|
const userId = context.user && context.user.id ? context.user.id : null;
|
||||||
|
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
token: req.body.token,
|
token: req.body.token,
|
||||||
valid: 1,
|
valid: 1,
|
||||||
userId
|
country: req.body.country,
|
||||||
|
userId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
let params = extractParamsFromRequest(req, res, {
|
let params = extractParamsFromRequest(req, res, {
|
||||||
includeAll: false,
|
includeAll: false,
|
||||||
paginate: { limit: 1, page: 1 },
|
paginate: { limit: 1, page: 1 },
|
||||||
params: {
|
params: {
|
||||||
token: data.token,
|
token: data.token,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(req.body, data, params);
|
||||||
|
|
||||||
// Buscamos el token y el usuario
|
// Buscamos el token y el usuario
|
||||||
console.log('>> Busco el token', params.params);
|
console.log(">> Busco el token", params.params);
|
||||||
let result = await userDeviceService.fetchOne(params, context);
|
let result = await userDeviceService.fetchOne(params, context);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
// Borramos el registro donde aparece el token
|
// Borramos el registro donde aparece el token
|
||||||
console.log('>> Borro el registro del token', params.params, data, context);
|
console.log(">> Borro el registro del token", params.params, data, context);
|
||||||
result = await userDeviceService.delete(params, context);
|
result = await userDeviceService.delete(params, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dar de alta el token
|
// Dar de alta el token
|
||||||
console.log('>> Dar de alta el token', data);
|
console.log(">> Dar de alta el token", data);
|
||||||
result = await userDeviceService.create(data, context);
|
result = await userDeviceService.create(data, context);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
// En todo caso devolver OK al cliente
|
// En todo caso devolver OK al cliente
|
||||||
return handleResultResponse('OK', null, null, res, httpStatus.OK);
|
return handleResultResponse("OK", null, null, res, httpStatus.OK);
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
const Joi = require('joi');
|
const Joi = require("joi");
|
||||||
|
|
||||||
const deviceTokenInputType = Joi.object().keys({
|
const deviceTokenInputType = Joi.object().keys({
|
||||||
token: Joi.string().required(),
|
token: Joi.string().required(),
|
||||||
|
country: Joi.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
/*const pushSendType = Joi.object().keys({
|
/*const pushSendType = Joi.object().keys({
|
||||||
@ -20,6 +21,7 @@ const pushSendEvent = Joi.object().keys({
|
|||||||
deviceIds: Joi.array().optional(),
|
deviceIds: Joi.array().optional(),
|
||||||
eventId: Joi.string().optional(),
|
eventId: Joi.string().optional(),
|
||||||
segment: Joi.string().optional(),
|
segment: Joi.string().optional(),
|
||||||
|
country: Joi.string().optional(),
|
||||||
}),
|
}),
|
||||||
priority: Joi.string().optional(),
|
priority: Joi.string().optional(),
|
||||||
ttl: Joi.string().optional(),
|
ttl: Joi.string().optional(),
|
||||||
@ -37,5 +39,6 @@ const pushSendEvent = Joi.object().keys({
|
|||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
deviceTokenInputType, pushSendEvent
|
deviceTokenInputType,
|
||||||
|
pushSendEvent,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
module.exports = function (sequelize, DataTypes) {
|
module.exports = function (sequelize, DataTypes) {
|
||||||
const UserDevice = sequelize.define('UserDevice', {
|
const UserDevice = sequelize.define(
|
||||||
|
"UserDevice",
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -16,8 +18,13 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
invalidated: {
|
invalidated: {
|
||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
},
|
},
|
||||||
}, {
|
country: {
|
||||||
tableName: 'users_devices',
|
type: DataTypes.STRING,
|
||||||
|
defaultValue: "ES",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tableName: "users_devices",
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
timestamps: true,
|
timestamps: true,
|
||||||
|
|
||||||
@ -26,12 +33,12 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
UserDevice.associate = function (models) {
|
UserDevice.associate = function (models) {
|
||||||
UserDevice.User = UserDevice.belongsTo(models.User, { foreignKey: 'userId', as: "user" });
|
UserDevice.User = UserDevice.belongsTo(models.User, { foreignKey: "userId", as: "user" });
|
||||||
};
|
};
|
||||||
|
|
||||||
return UserDevice;
|
return UserDevice;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1,7 +1,8 @@
|
|||||||
const moment = require('moment');
|
const moment = require("moment");
|
||||||
const { Expo } = require('expo-server-sdk');
|
const { Expo } = require("expo-server-sdk");
|
||||||
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
|
const { generateService, parseParamsToFindOptions } = require("../../helpers/service.helper");
|
||||||
const models = require('../../core/models');
|
const models = require("../../core/models");
|
||||||
|
const { Sequelize } = require("sequelize");
|
||||||
|
|
||||||
const extraMethods = {
|
const extraMethods = {
|
||||||
isValidPushToken: (token) => {
|
isValidPushToken: (token) => {
|
||||||
@ -9,30 +10,29 @@ const extraMethods = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
afterFetchAll: (result, params, context) => {
|
afterFetchAll: (result, params, context) => {
|
||||||
|
|
||||||
if (!result.count) {
|
if (!result.count) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
let rows = result.rows.map(row => row.toJSON());
|
let rows = result.rows.map((row) => row.toJSON());
|
||||||
|
|
||||||
return {
|
return {
|
||||||
count: result.count,
|
count: result.count,
|
||||||
rows: rows
|
rows: rows,
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
getPushToken: (params) => {
|
getPushToken: (params) => {
|
||||||
return models.UserDevice.findOne({
|
return models.UserDevice.findOne({
|
||||||
where: params,
|
where: params,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_getActiveDeviceIds: async (offset = 0, limit = 10) => {
|
_getActiveDeviceIds: async (offset = 0, limit = 10, country = "ES") => {
|
||||||
return models.UserDevice.findAndCountAll({
|
return models.UserDevice.findAndCountAll({
|
||||||
where: {
|
where: {
|
||||||
valid: 1,
|
valid: 1,
|
||||||
|
country: country === "*" ? { [Sequelize.Op.ne]: null } : country,
|
||||||
},
|
},
|
||||||
raw: true,
|
raw: true,
|
||||||
limit: limit,
|
limit: limit,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user