2022-02-12 22:12:49 +01:00
|
|
|
const os = require('os');
|
|
|
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
|
|
require('../config/config');
|
|
|
|
|
|
|
|
|
|
require('../models/subscribers');
|
|
|
|
|
|
|
|
|
|
const {ObjectID} = require('mongodb');
|
|
|
|
|
|
|
|
|
|
const {User} = require('../models/user');
|
|
|
|
|
const {MyGroup} = require('../models/mygroup');
|
|
|
|
|
const {Booking} = require('../models/booking');
|
|
|
|
|
const {Operator} = require('../models/operator');
|
|
|
|
|
const {Where} = require('../models/where');
|
|
|
|
|
const {MyEvent} = require('../models/myevent');
|
|
|
|
|
const {Contribtype} = require('../models/contribtype');
|
|
|
|
|
const {PaymentType} = require('../models/paymenttype');
|
|
|
|
|
const {Discipline} = require('../models/discipline');
|
|
|
|
|
const {Skill} = require('../models/skill');
|
2022-02-21 13:12:27 +01:00
|
|
|
const {Good} = require('../models/good');
|
2022-02-12 22:12:49 +01:00
|
|
|
const {SubSkill} = require('../models/subskill');
|
|
|
|
|
const {MySkill} = require('../models/myskill');
|
2022-02-21 13:12:27 +01:00
|
|
|
const {MyGood} = require('../models/mygood');
|
2022-02-16 19:21:12 +01:00
|
|
|
const {MyBacheca} = require('../models/mybacheca');
|
2022-02-12 22:12:49 +01:00
|
|
|
const {StatusSkill} = require('../models/statusSkill');
|
|
|
|
|
const {City} = require('../models/city');
|
|
|
|
|
const {Province} = require('../models/province');
|
|
|
|
|
const {Sector} = require('../models/sector');
|
2022-02-21 13:12:27 +01:00
|
|
|
const {SectorGood} = require('../models/sectorgood');
|
2022-02-12 22:12:49 +01:00
|
|
|
const {CatGrp} = require('../models/catgrp');
|
|
|
|
|
const {Level} = require('../models/level');
|
|
|
|
|
const {AdType} = require('../models/adtype');
|
2022-02-21 13:12:27 +01:00
|
|
|
const {AdTypeGood} = require('../models/adtypegood');
|
2022-02-12 22:12:49 +01:00
|
|
|
const Pickup = require('../models/pickup');
|
|
|
|
|
const {Newstosent} = require('../models/newstosent');
|
|
|
|
|
const {MyPage} = require('../models/mypage');
|
|
|
|
|
const {MyBot} = require('../models/bot');
|
|
|
|
|
const {CalZoom} = require('../models/calzoom');
|
|
|
|
|
const {Gallery} = require('../models/gallery');
|
|
|
|
|
const {TemplEmail} = require('../models/templemail');
|
|
|
|
|
const {OpzEmail} = require('../models/opzemail');
|
|
|
|
|
const {MailingList} = require('../models/mailinglist');
|
|
|
|
|
const {Settings} = require('../models/settings');
|
|
|
|
|
const {SendMsg} = require('../models/sendmsg');
|
|
|
|
|
const {Permission} = require('../models/permission');
|
|
|
|
|
const {MsgTemplate} = require('../models/msg_template');
|
|
|
|
|
const Product = require('../models/product');
|
|
|
|
|
const Producer = require('../models/producer');
|
|
|
|
|
const Cart = require('../models/cart');
|
|
|
|
|
const OrdersCart = require('../models/orderscart');
|
|
|
|
|
const Storehouse = require('../models/storehouse');
|
|
|
|
|
const Department = require('../models/department');
|
|
|
|
|
const ShareWithUs = require('../models/sharewithus');
|
|
|
|
|
const Site = require('../models/site');
|
|
|
|
|
const IscrittiConacreis = require('../models/iscrittiConacreis');
|
|
|
|
|
const Group = require('../models/group');
|
|
|
|
|
const {Todo} = require('../models/todo');
|
|
|
|
|
const Hours = require('../models/hours');
|
|
|
|
|
const Order = require('../models/order');
|
|
|
|
|
const Cash = require('../models/cash');
|
|
|
|
|
const CashCategory = require('../models/cashCategory');
|
|
|
|
|
const CashSubCategory = require('../models/cashSubCategory');
|
|
|
|
|
|
|
|
|
|
const tools = require('./general');
|
|
|
|
|
|
2022-02-16 19:21:12 +01:00
|
|
|
const shared_consts = require('./shared_nodejs');
|
|
|
|
|
|
2022-02-12 22:12:49 +01:00
|
|
|
module.exports = {
|
|
|
|
|
|
|
|
|
|
getTableByTableName(tablename) {
|
|
|
|
|
|
|
|
|
|
let mytable = '';
|
|
|
|
|
if (tablename === 'users')
|
|
|
|
|
mytable = User;
|
2022-02-28 17:20:47 +01:00
|
|
|
else if (tablename === shared_consts.TAB_MYGROUPS)
|
2022-02-12 22:12:49 +01:00
|
|
|
mytable = MyGroup;
|
|
|
|
|
else if (tablename === 'tessitura')
|
|
|
|
|
mytable = Tessitura;
|
|
|
|
|
// else if (tablename === 'extralist')
|
|
|
|
|
// mytable = ExtraList;
|
|
|
|
|
else if (tablename === 'bookings')
|
|
|
|
|
mytable = Booking;
|
|
|
|
|
else if (tablename === 'operators')
|
|
|
|
|
mytable = Operator;
|
|
|
|
|
else if (tablename === 'products')
|
|
|
|
|
mytable = Product;
|
|
|
|
|
else if (tablename === 'storehouses')
|
|
|
|
|
mytable = Storehouse;
|
|
|
|
|
else if (tablename === 'departments')
|
|
|
|
|
mytable = Department;
|
|
|
|
|
else if (tablename === 'sharewithus')
|
|
|
|
|
mytable = ShareWithUs;
|
|
|
|
|
else if (tablename === 'sites')
|
|
|
|
|
mytable = Site;
|
|
|
|
|
else if (tablename === 'iscritticonacreis')
|
|
|
|
|
mytable = IscrittiConacreis;
|
|
|
|
|
else if (tablename === 'groups')
|
|
|
|
|
mytable = Group;
|
|
|
|
|
else if (tablename === 'todos')
|
|
|
|
|
mytable = Todo;
|
|
|
|
|
else if (tablename === 'hours')
|
|
|
|
|
mytable = Hours;
|
|
|
|
|
else if (tablename === 'orders')
|
|
|
|
|
mytable = Order;
|
|
|
|
|
else if (tablename === 'cashs')
|
|
|
|
|
mytable = Cash;
|
|
|
|
|
else if (tablename === 'cashCategorys')
|
|
|
|
|
mytable = CashCategory;
|
|
|
|
|
else if (tablename === 'cashSubCategorys')
|
|
|
|
|
mytable = CashSubCategory;
|
|
|
|
|
else if (tablename === 'producers')
|
|
|
|
|
mytable = Producer;
|
|
|
|
|
else if (tablename === 'carts')
|
|
|
|
|
mytable = Cart;
|
|
|
|
|
else if (tablename === 'orderscart')
|
|
|
|
|
mytable = OrdersCart;
|
|
|
|
|
else if (tablename === 'sendmsgs')
|
|
|
|
|
mytable = SendMsg;
|
|
|
|
|
else if (tablename === 'wheres')
|
|
|
|
|
mytable = Where;
|
|
|
|
|
else if (tablename === 'myevents')
|
|
|
|
|
mytable = MyEvent;
|
|
|
|
|
else if (tablename === 'contribtypes')
|
|
|
|
|
mytable = Contribtype;
|
|
|
|
|
else if (tablename === 'paymenttypes')
|
|
|
|
|
mytable = PaymentType;
|
|
|
|
|
else if (tablename === 'disciplines')
|
|
|
|
|
mytable = Discipline;
|
|
|
|
|
else if (tablename === 'newstosent')
|
|
|
|
|
mytable = Newstosent;
|
|
|
|
|
else if (tablename === 'gallery')
|
|
|
|
|
mytable = Gallery;
|
|
|
|
|
else if (tablename === 'mypage')
|
|
|
|
|
mytable = MyPage;
|
|
|
|
|
else if (tablename === 'mybots')
|
|
|
|
|
mytable = MyBot;
|
|
|
|
|
else if (tablename === 'calzoom')
|
|
|
|
|
mytable = CalZoom;
|
|
|
|
|
else if (tablename === 'templemail')
|
|
|
|
|
mytable = TemplEmail;
|
|
|
|
|
else if (tablename === 'opzemail')
|
|
|
|
|
mytable = OpzEmail;
|
|
|
|
|
else if (tablename === 'settings')
|
|
|
|
|
mytable = Settings;
|
|
|
|
|
else if (tablename === 'permissions')
|
|
|
|
|
mytable = Permission;
|
|
|
|
|
else if (tablename === 'mailinglist')
|
|
|
|
|
mytable = MailingList;
|
|
|
|
|
else if (tablename === 'msg_templates')
|
|
|
|
|
mytable = MsgTemplate;
|
|
|
|
|
else if (tablename === 'navepersistente')
|
|
|
|
|
mytable = NavePersistente;
|
|
|
|
|
// else if (tablename === 'listaingressos')
|
|
|
|
|
// mytable = ListaIngresso;
|
|
|
|
|
else if (tablename === 'graduatorias')
|
|
|
|
|
mytable = Graduatoria;
|
|
|
|
|
else if (tablename === 'skills')
|
|
|
|
|
mytable = Skill;
|
2022-02-21 13:12:27 +01:00
|
|
|
else if (tablename === 'goods')
|
|
|
|
|
mytable = Good;
|
2022-02-12 22:12:49 +01:00
|
|
|
else if (tablename === 'subskills')
|
|
|
|
|
mytable = SubSkill;
|
2022-02-16 19:21:12 +01:00
|
|
|
else if (tablename === shared_consts.TABLES_MYSKILLS)
|
2022-02-12 22:12:49 +01:00
|
|
|
mytable = MySkill;
|
2022-02-16 19:21:12 +01:00
|
|
|
else if (tablename === shared_consts.TABLES_MYBACHECAS)
|
|
|
|
|
mytable = MyBacheca;
|
2022-02-21 13:12:27 +01:00
|
|
|
else if (tablename === shared_consts.TABLES_MYGOODS)
|
|
|
|
|
mytable = MyGood;
|
2022-02-12 22:12:49 +01:00
|
|
|
else if (tablename === 'statusSkills')
|
|
|
|
|
mytable = StatusSkill;
|
|
|
|
|
else if (tablename === 'cities')
|
|
|
|
|
mytable = City;
|
|
|
|
|
else if (tablename === 'provinces')
|
|
|
|
|
mytable = Province;
|
|
|
|
|
else if (tablename === 'sectors')
|
|
|
|
|
mytable = Sector;
|
2022-02-21 13:12:27 +01:00
|
|
|
else if (tablename === 'sectorgoods')
|
|
|
|
|
mytable = SectorGood;
|
2022-02-12 22:12:49 +01:00
|
|
|
else if (tablename === 'catgrps')
|
|
|
|
|
mytable = CatGrp;
|
|
|
|
|
else if (tablename === 'levels')
|
|
|
|
|
mytable = Level;
|
2022-02-21 13:12:27 +01:00
|
|
|
else if (tablename === 'adtypes')
|
|
|
|
|
mytable = AdType;
|
|
|
|
|
else if (tablename === 'adtypegoods')
|
|
|
|
|
mytable = AdTypeGood;
|
2022-02-12 22:12:49 +01:00
|
|
|
else if (shared_consts.TablePickup.includes(tablename))
|
|
|
|
|
mytable = Pickup;
|
|
|
|
|
//else if (shared_consts.TableCities.includes(tablename))
|
|
|
|
|
// mytable = City;
|
|
|
|
|
|
|
|
|
|
return mytable;
|
|
|
|
|
},
|
2022-03-06 00:48:33 +01:00
|
|
|
|
|
|
|
|
SendMsgToParam: async function(idapp, params) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const telegrambot = require('../telegram/telegrambot');
|
|
|
|
|
|
|
|
|
|
let query = {idapp};
|
|
|
|
|
let addquery = {};
|
|
|
|
|
|
|
|
|
|
let invia = true;
|
|
|
|
|
|
|
|
|
|
if (params.typemsg === shared_consts.TypeMsg.SEND_TO_ALL) {
|
|
|
|
|
addquery = {};
|
|
|
|
|
} else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_SOCI) {
|
|
|
|
|
addquery = {'profile.socio': true};
|
|
|
|
|
} else if (params.typemsg ===
|
|
|
|
|
shared_consts.TypeMsg.SEND_TO_SOCIO_RESIDENTE) {
|
|
|
|
|
addquery = {'profile.socioresidente': true};
|
|
|
|
|
} else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_CONSIGLIO) {
|
|
|
|
|
addquery = {'profile.consiglio': true};
|
|
|
|
|
} else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_NON_SOCI) {
|
|
|
|
|
addquery = {'profile.socio': false};
|
|
|
|
|
} else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_PAOLO) {
|
|
|
|
|
addquery = {username: 'paoloar77'};
|
|
|
|
|
} else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_USER) {
|
|
|
|
|
addquery = {username: params.usernameDest};
|
|
|
|
|
} else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_MYSELF) {
|
|
|
|
|
addquery = {username: params.usernameDest};
|
|
|
|
|
} else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_GROUP) {
|
|
|
|
|
if (params.groupnameDest) {
|
|
|
|
|
addquery = {
|
|
|
|
|
'profile.mygroups': {
|
|
|
|
|
$elemMatch: {groupname: {$eq: params.groupnameDest}},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
invia = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let numrec = 0;
|
|
|
|
|
let nummsgsent = 0;
|
|
|
|
|
|
|
|
|
|
if (invia) {
|
|
|
|
|
|
|
|
|
|
const allquery = {...query, ...addquery};
|
|
|
|
|
|
|
|
|
|
const arrusers = await User.find(
|
|
|
|
|
allquery,
|
|
|
|
|
{
|
|
|
|
|
username: 1,
|
|
|
|
|
'profile.teleg_id': 1,
|
|
|
|
|
},
|
|
|
|
|
).lean();
|
|
|
|
|
|
|
|
|
|
for (const user of arrusers) {
|
|
|
|
|
|
|
|
|
|
const mytitle = tools.convertSpecialTags(user, params.title);
|
|
|
|
|
const mycontent = tools.convertSpecialTags(user, params.content);
|
|
|
|
|
|
2022-03-08 01:01:20 +01:00
|
|
|
let risult = null;
|
|
|
|
|
|
2022-03-06 00:48:33 +01:00
|
|
|
if (params.sendreally) {
|
|
|
|
|
if (tools.isBitActive(params.typesend,
|
|
|
|
|
shared_consts.TypeSend.PUSH_NOTIFICATION)) {
|
2022-03-08 01:01:20 +01:00
|
|
|
risult = tools.sendNotificationToUser(user._id, mytitle, mycontent, params.openUrl, params.openUrl2, params.tag,
|
2022-03-06 00:48:33 +01:00
|
|
|
params.actions).
|
|
|
|
|
then(ris => {
|
|
|
|
|
|
|
|
|
|
}).
|
|
|
|
|
catch(e => {
|
|
|
|
|
console.error(e.message);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} else if (tools.isBitActive(params.typesend, shared_consts.TypeSend.TELEGRAM)) {
|
|
|
|
|
const telegid = user.profile.teleg_id;
|
|
|
|
|
|
|
|
|
|
if (telegid > 0) {
|
2022-03-08 01:01:20 +01:00
|
|
|
risult = await telegrambot.local_sendMsgTelegramByIdTelegram(idapp, telegid, mycontent);
|
|
|
|
|
await tools.snooze(100);
|
2022-03-06 00:48:33 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
numrec++;
|
2022-03-08 01:01:20 +01:00
|
|
|
if (params.sendreally && risult) {
|
2022-03-06 00:48:33 +01:00
|
|
|
nummsgsent++;
|
|
|
|
|
}
|
2022-03-08 01:01:20 +01:00
|
|
|
|
|
|
|
|
if ((nummsgsent % 100) === 0) {
|
|
|
|
|
console.log('Inviati ', nummsgsent, 'messaggi...')
|
|
|
|
|
}
|
2022-03-06 00:48:33 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-08 01:01:20 +01:00
|
|
|
if (nummsgsent > 0) {
|
|
|
|
|
console.log('FINE Invio Messaggi ! Inviati Totali: ', nummsgsent, 'su', numrec);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-06 00:48:33 +01:00
|
|
|
return {
|
|
|
|
|
numrec,
|
|
|
|
|
nummsgsent,
|
|
|
|
|
};
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('SendMsgToParam', e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
SendMsgToAll: async function(idapp, params) {
|
|
|
|
|
|
|
|
|
|
params.typemsg = shared_consts.TypeMsg.SEND_TO_ALL;
|
|
|
|
|
params.sendreally = true;
|
|
|
|
|
params.typesend = shared_consts.TypeSend.PUSH_NOTIFICATION;
|
|
|
|
|
|
|
|
|
|
return this.SendMsgToParam(idapp, params);
|
|
|
|
|
},
|
|
|
|
|
|
2022-02-12 22:12:49 +01:00
|
|
|
};
|