Compare commits
40 Commits
cambio_nom
...
beforeRisI
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0cfabed233 | ||
|
|
c92dc8f216 | ||
|
|
7b14c09fd5 | ||
|
|
2258e8e7e1 | ||
|
|
e8c961f500 | ||
|
|
b395d1a30a | ||
|
|
341af6a3b2 | ||
|
|
3d876687b6 | ||
|
|
560a532a85 | ||
|
|
aac8ce0a4c | ||
|
|
d434374ed9 | ||
|
|
045057082c | ||
|
|
18c5630a45 | ||
|
|
7f1bd15bcf | ||
|
|
c1a9a9a555 | ||
|
|
536fbd1752 | ||
|
|
d6303f5880 | ||
|
|
b6579832b6 | ||
|
|
04c8e929ee | ||
|
|
142dcadca9 | ||
|
|
ad6b4c2bfa | ||
|
|
ba81a33c88 | ||
|
|
baf56b59d0 | ||
|
|
3393af36aa | ||
|
|
95a812f002 | ||
|
|
aff50b03d4 | ||
|
|
e28cd5f043 | ||
|
|
9e499b8f43 | ||
|
|
84328e7bcd | ||
|
|
a79e79a85e | ||
|
|
0945f1af08 | ||
|
|
eea6e63c58 | ||
|
|
cda0bff21f | ||
|
|
cada7aa0b6 | ||
|
|
f13786fca1 | ||
|
|
5bb6611384 | ||
|
|
0d5bff5849 | ||
|
|
198b5914bc | ||
|
|
94ef2c4c85 | ||
|
|
8a77dabc22 |
4
.dockerignore
Normal file
4
.dockerignore
Normal file
@@ -0,0 +1,4 @@
|
||||
./node_modules
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
docker-compose.yml
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -25,3 +25,6 @@ src/.DS_Store
|
||||
.gitignore
|
||||
src/server/router/.DS_Store
|
||||
src/server/.DS_Store
|
||||
emails/.DS_Store
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
|
||||
46
.vscode/launch.json
vendored
46
.vscode/launch.json
vendored
@@ -2,6 +2,48 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch via Nodemon",
|
||||
"program": "${workspaceFolder}/node_modules/nodemon/bin/nodemon.js",
|
||||
"restart": true,
|
||||
"runtimeExecutable": "node",
|
||||
"runtimeArgs": [
|
||||
"--inspect=9229" // Use "--inspect=0.0.0.0:9229" for remote debugging
|
||||
],
|
||||
"args": ["${workspaceFolder}/src/server/server.js"], // Replace with your entry file
|
||||
"cwd": "${workspaceFolder}",
|
||||
"autoAttachChildProcesses": true,
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen",
|
||||
"sourceMaps": true,
|
||||
"env": {
|
||||
"NODE_ENV":"development",
|
||||
"TESTING_ON":"1"
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch Trace Warning",
|
||||
"program": "${workspaceFolder}/node_modules/nodemon/bin/nodemon.js",
|
||||
"restart": true,
|
||||
"runtimeExecutable": "node",
|
||||
"runtimeArgs": [
|
||||
"--trace-warnings" // Use "--inspect=0.0.0.0:9229" for remote debugging
|
||||
],
|
||||
"args": ["${workspaceFolder}/src/server/server.js"], // Replace with your entry file
|
||||
"cwd": "${workspaceFolder}",
|
||||
"autoAttachChildProcesses": true,
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen",
|
||||
"sourceMaps": true,
|
||||
"env": {
|
||||
"NODE_ENV":"development",
|
||||
"TESTING_ON":"1"
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "Server Debug",
|
||||
"request": "launch",
|
||||
"runtimeArgs": [
|
||||
@@ -12,6 +54,10 @@
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"env": {
|
||||
"NODE_ENV":"development",
|
||||
"TESTING_ON":"1"
|
||||
},
|
||||
"type": "node"
|
||||
},
|
||||
{
|
||||
|
||||
7
Dockerfile
Normal file
7
Dockerfile
Normal file
@@ -0,0 +1,7 @@
|
||||
FROM node:alpine
|
||||
WORKDIR /Users/suryapaolo/myproject/freeplanet_serverside
|
||||
COPY package*.json .
|
||||
RUN npm ci
|
||||
COPY . .
|
||||
#CMD ["npm", "start"]
|
||||
CMD ["npm", "run", "dev"]
|
||||
18
deploy_solo1.sh
Executable file
18
deploy_solo1.sh
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
source ./.env.production
|
||||
|
||||
msg="*** SERVER DI PRODUZIONE **** SEI SICURO DI INVIARE IL SINGOLO FILE GENERAL.JS - SUL SERVER DI PRODUZIONE ?? $SERVERDIR_WEBSITE (Y/N) ? "
|
||||
|
||||
if [ "$1" = "" ]; then
|
||||
read -p "$msg" risposta
|
||||
else
|
||||
echo $msg
|
||||
risposta=$1
|
||||
fi
|
||||
|
||||
if [[ $risposta == "Y" || $risposta == "y" ]]; then
|
||||
echo "Sincronizzazione di 1 FILE in corso..."
|
||||
rsync -avz -e 'ssh -p 8855' src/server/tools/general.js suryapaolo@servereng:/var/www/$SERVERDIR_WEBSITE/src/server/tools/general.js
|
||||
echo "Sincronizzazione TERMINATA - SERVER PRODUZIONE!"
|
||||
fi
|
||||
30
docker-compose.yml
Normal file
30
docker-compose.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
version: '3.9'
|
||||
|
||||
services:
|
||||
# mongoDB service
|
||||
mongo_db:
|
||||
container_name: db_container
|
||||
image: mongo:4.4
|
||||
restart: always
|
||||
ports:
|
||||
- 2717:27017
|
||||
volumes:
|
||||
- mongo_db:/data/db
|
||||
|
||||
# Node API service
|
||||
api:
|
||||
build: .
|
||||
ports:
|
||||
- 4000:3000
|
||||
volumes:
|
||||
- .:/Users/suryapaolo/myproject/freeplanet_serverside
|
||||
environment:
|
||||
PORT: 3000
|
||||
DOMAIN: mongodb://mongo_db:27017/
|
||||
DATABASE: test_FreePlanet
|
||||
UDB: paofreeplanet
|
||||
depends_on:
|
||||
- mongo_db
|
||||
|
||||
volumes:
|
||||
mongo_db: {}
|
||||
BIN
emails/.DS_Store
vendored
Normal file
BIN
emails/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -1,5 +1,6 @@
|
||||
p Ciao,
|
||||
p Ti avvisiamo che #{username} (#{name} #{surname}) ha appena cancellato la prenotazione per l'evento #{event}:
|
||||
span #{msgbooking}
|
||||
span #{participants}
|
||||
span #{participantsLunch}
|
||||
span #{participantsDinner}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
p Ciao,
|
||||
p Ti confermiamo che #{username} (#{name} #{surname}) ha appena inviato una richiesta di prenotazione per l'evento #{event}
|
||||
p #{msgbooking}
|
||||
p #{participants}
|
||||
p #{participantsLunch}
|
||||
p #{participantsDinner}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
p Ciao,
|
||||
p Ti confermiamo che #{username} (#{name} #{surname}) ha appena Modificato la sua prenotazione per l'evento #{event}
|
||||
p #{msgbooking}
|
||||
p #{participants}
|
||||
p #{participantsLunch}
|
||||
p #{participantsDinner}
|
||||
|
||||
BIN
emails/admin/registration/.DS_Store
vendored
Normal file
BIN
emails/admin/registration/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -1,5 +1,6 @@
|
||||
p Ciao #{name},
|
||||
p Ti confermiamo che la prenotazione per l'evento "#{event}" è stata cancellata.
|
||||
p #{msgbooking}
|
||||
p #{participants}
|
||||
p #{participantsLunch}
|
||||
p #{participantsDinner}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
p Ciao #{name},
|
||||
p Ti confermiamo che hai appena inviato una richiesta di prenotazione per l'evento #{event}
|
||||
p #{msgbooking}
|
||||
p #{participants}
|
||||
p #{participantsLunch}
|
||||
p #{participantsDinner}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
p Ciao #{name},
|
||||
p Ti confermiamo che hai modificato la prenotazione per l'evento #{event}
|
||||
p #{msgbooking}
|
||||
p #{participants}
|
||||
p #{participantsLunch}
|
||||
p #{participantsDinner}
|
||||
|
||||
68
filelog.txt
68
filelog.txt
@@ -25,3 +25,71 @@ Gio 05/01 ORE 19:28: USER [paoloar77]: vai al sito
|
||||
Gio 05/01 ORE 19:28: USER [paoloar77]: link da condividere
|
||||
|
||||
Gio 16/02 ORE 18:14: USER [paoloar77]: vai al sito
|
||||
|
||||
Mar 06/06 ORE 19:39: USER [paoloar77]: ciaooooooooooooooooo
|
||||
|
||||
Mar 06/06 ORE 19:54: USER [paoloar77]: dasjdalksjdasdklasjkldasjlkdjasl
|
||||
|
||||
Sab 17/06 ORE 20:03: USER [paoloar77]: pro v adsasdasdaksdas
|
||||
|
||||
Dom 18/06 ORE 19:22: USER [paoloar77]: /start inv
|
||||
|
||||
Dom 18/06 ORE 19:42: USER [paoloar77]: /start inv
|
||||
|
||||
Dom 18/06 ORE 19:58: USER [paoloar77]: /start inv
|
||||
|
||||
Dom 18/06 ORE 19:59: USER [paoloar77]: /start inv
|
||||
|
||||
Dom 18/06 ORE 19:59: USER [paoloar77]: /start inv
|
||||
|
||||
Ven 23/06 ORE 14:08: USER [paoloar77]: link da condividere
|
||||
|
||||
Sab 30/09 ORE 00:21: USER [SuryaArena]: vai al sito
|
||||
|
||||
Sab 30/09 ORE 00:32: USER [SuryaArena]: vai al sito
|
||||
|
||||
Gio 12/10 ORE 11:11: USER [paoloar77]: prova
|
||||
|
||||
Gio 12/10 ORE 11:48: USER [paoloar77]: prova
|
||||
|
||||
Gio 12/10 ORE 12:07: USER [SuryaArena]: prova
|
||||
|
||||
Gio 12/10 ORE 12:07: USER [SuryaArena]: prova
|
||||
|
||||
Gio 12/10 ORE 12:09: USER [SuryaArena]: prova
|
||||
|
||||
Gio 12/10 ORE 12:10: USER [SuryaArena]: prova
|
||||
|
||||
Gio 12/10 ORE 12:10: USER [SuryaArena]: prova
|
||||
|
||||
Gio 12/10 ORE 12:13: USER [SuryaArena]: prova
|
||||
|
||||
Gio 12/10 ORE 12:14: USER [SuryaArena]: prova
|
||||
|
||||
Gio 12/10 ORE 12:16: USER [SuryaArena]: prova
|
||||
|
||||
Gio 12/10 ORE 12:21: USER [SuryaArena]: prova
|
||||
|
||||
Gio 12/10 ORE 12:33: USER [paoloar77]: prova
|
||||
|
||||
Gio 12/10 ORE 12:33: USER [SuryaArena]: ciao
|
||||
|
||||
Gio 12/10 ORE 12:33: USER [SuryaArena]: prova
|
||||
|
||||
Gio 12/10 ORE 12:45: USER [SuryaArena]: bottone
|
||||
|
||||
Gio 12/10 ORE 14:49: USER [paoloar77]: bottone
|
||||
|
||||
Gio 12/10 ORE 14:49: USER [paoloar77]: bottone
|
||||
|
||||
Gio 12/10 ORE 14:49: USER [paoloar77]: bottone
|
||||
|
||||
Gio 12/10 ORE 14:52: USER [paoloar77]: bottone
|
||||
|
||||
Gio 12/10 ORE 14:57: USER [paoloar77]: bottone
|
||||
|
||||
Gio 12/10 ORE 15:06: USER [paoloar77]: bottone
|
||||
|
||||
Ven 13/10 ORE 11:05: USER [SuryaArena]: bottone
|
||||
|
||||
Ven 13/10 ORE 11:40: USER [SuryaArena]: bottone
|
||||
|
||||
27
logevents.txt
Normal file
27
logevents.txt
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
Mar 06/06 ORE 19:06: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena2 è stato Abilitato correttamente (da paoloar77)!
|
||||
Mar 06/06 ORE 19:07: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena2 è stato Abilitato correttamente (da paoloar77)!
|
||||
Mar 06/06 ORE 19:38: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena2 è stato Abilitato correttamente (da paoloar77)!
|
||||
Mar 06/06 ORE 19:39: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
ciaooooooooooooooooo
|
||||
Mar 06/06 ORE 19:49: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena2 è stato Abilitato correttamente (da paoloar77)!
|
||||
Mar 06/06 ORE 19:54: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
dasjdalksjdasdklasjkldasjlkdjasl
|
||||
Sab 17/06 ORE 20:03: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
pro v adsasdasdaksdas
|
||||
Dom 18/06 ORE 19:22: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
/start inv
|
||||
Ven 23/06 ORE 14:13: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena è stato Abilitato correttamente (da paoloar77)!
|
||||
Dom 25/06 ORE 16:11: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena è stato Abilitato correttamente (da paoloar77)!
|
||||
Ven 29/09 ORE 23:18: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena è stato Abilitato correttamente (da paoloar77)!
|
||||
Mar 03/10 ORE 22:49: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena è stato Abilitato correttamente (da paoloar77)!
|
||||
Sab 04/11 ORE 15:17: 🤖: Da Sùrya (Paolo) undefined (paoloar77):
|
||||
✅ SuryaArena è stato Abilitato correttamente (da paoloar77)!
|
||||
94
logtrans.txt
94
logtrans.txt
@@ -4,4 +4,96 @@ Lun 06/02 ORE 23:15: Inviate Monete da paoloar77 a surya1977 1 RISTEST [caus
|
||||
Lun 06/02 ORE 23:17: Inviate Monete da paoloar77 a surya1977 1 RISTEST [causale: ] [Saldo paoloar77: -52 RISTEST] [Saldo surya1977: 7 RISTEST]
|
||||
Dom 12/03 ORE 13:35: Inviate Monete da paoloar77 a 1 RIS [causale: ] [Saldo paoloar77: 3 RIS] [Saldo : 2 RIS]
|
||||
Mer 15/03 ORE 22:15: Inviate Monete da pontiUmani (paoloar77) a paoloar77 1 RIS [causale: ] [Saldo pontiUmani (paoloar77): 1 RIS] [Saldo paoloar77: 4 RIS]
|
||||
Mer 15/03 ORE 22:37: Inviate Monete da pontiUmani (paoloar77) a surya1977 1 RIS [causale: ] [Saldo pontiUmani (paoloar77): 0 RIS] [Saldo surya1977: 1 RIS]
|
||||
Mer 15/03 ORE 22:37: Inviate Monete da pontiUmani (paoloar77) a surya1977 1 RIS [causale: ] [Saldo pontiUmani (paoloar77): 0 RIS] [Saldo surya1977: 1 RIS]
|
||||
Ven 28/04 ORE 01:33: Inviate Monete da surya1977 a risotest 1 RISTEST [causale: ] [Saldo surya1977: 0 RISTEST] [Saldo risotest: 9.5 RISTEST]
|
||||
Gio 01/06 ORE 12:22: Inviate Monete da paoloar77 a surya1977 1 RIS [causale: ] [Saldo paoloar77: -2 RIS] [Saldo surya1977: 1 RIS]
|
||||
Gio 01/06 ORE 12:25: Inviate Monete da paoloar77 a surya1977 2 RIS [causale: ] [Saldo paoloar77: -4 RIS] [Saldo surya1977: 3 RIS]
|
||||
Gio 01/06 ORE 12:31: Inviate Monete da paoloar77 a surya1977 4 RIS [causale: ] [Saldo paoloar77: -8 RIS] [Saldo surya1977: 7 RIS]
|
||||
Gio 01/06 ORE 17:26: Inviate Monete da paoloar77 a surya1977 1 RIS [causale: ] [Saldo paoloar77: -9 RIS] [Saldo surya1977: 8 RIS]
|
||||
Gio 01/06 ORE 17:41: Inviate Monete da paoloar77 a surya1977 1 RIS [causale: ] [Saldo paoloar77: -10 RIS] [Saldo surya1977: 9 RIS]
|
||||
Ven 02/06 ORE 19:29: Inviate Monete da paoloar77 a 2 RIS [causale: ] [Saldo paoloar77: 8 RIS] [Saldo : -261 RIS]
|
||||
Ven 02/06 ORE 19:31: Inviate Monete da paoloar77 a pontiUmani 4 RIS [causale: ] [Saldo paoloar77: 0 RIS] [Saldo pontiUmani: -253 RIS]
|
||||
Lun 26/06 ORE 23:23: [<b>Circuito RIS Ragusa</b>]: Inviate Monete da risragusa (paoloar77) a paogruppo2 300 RIS [causale: aaa]
|
||||
Saldi:
|
||||
risragusa (paoloar77): -300 RIS]
|
||||
paogruppo2: 300 RIS]
|
||||
Lun 26/06 ORE 23:27: [<b>Circuito RIS Ragusa</b>]: Inviate Monete da paoloar77 a paogruppo2 20 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -20 RIS]
|
||||
paogruppo2: 320 RIS]
|
||||
Sab 30/09 ORE 13:32: [<b>Circuito RIS Bologna</b>]: Inviate Monete da SuryaArena a paoloar77 1 RIS [causale: aaa]
|
||||
Saldi:
|
||||
SuryaArena: -1 RIS]
|
||||
paoloar77: 11 RIS]
|
||||
Lun 09/10 ORE 09:04: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -2 RIS]
|
||||
SuryaArena2: 1 RIS]
|
||||
Lun 09/10 ORE 09:21: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -3 RIS]
|
||||
SuryaArena2: 2 RIS]
|
||||
Lun 09/10 ORE 10:25: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -4 RIS]
|
||||
SuryaArena2: 3 RIS]
|
||||
Lun 09/10 ORE 10:26: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -5 RIS]
|
||||
SuryaArena2: 4 RIS]
|
||||
Lun 09/10 ORE 23:26: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -2 RIS]
|
||||
SuryaArena2: 1 RIS]
|
||||
Lun 09/10 ORE 23:36: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -3 RIS]
|
||||
SuryaArena2: 2 RIS]
|
||||
Lun 09/10 ORE 23:36: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -4 RIS]
|
||||
SuryaArena2: 3 RIS]
|
||||
Mar 10/10 ORE 00:04: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -5 RIS]
|
||||
SuryaArena2: 4 RIS]
|
||||
Mar 10/10 ORE 00:21: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -6 RIS]
|
||||
SuryaArena2: 5 RIS]
|
||||
Mar 10/10 ORE 00:34: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -7 RIS]
|
||||
SuryaArena2: 6 RIS]
|
||||
Mar 10/10 ORE 22:47: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a PaoTEST1 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -8 RIS]
|
||||
PaoTEST1: 1 RIS]
|
||||
Mar 10/10 ORE 22:49: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a PaoTEST1 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -9 RIS]
|
||||
PaoTEST1: 2 RIS]
|
||||
Mar 10/10 ORE 23:08: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a PaoTEST1 2 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -11 RIS]
|
||||
PaoTEST1: 4 RIS]
|
||||
Mar 10/10 ORE 23:13: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a PaoTEST1 3 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -14 RIS]
|
||||
PaoTEST1: 7 RIS]
|
||||
Mar 10/10 ORE 23:22: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a PaoTEST1 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -15 RIS]
|
||||
PaoTEST1: 8 RIS]
|
||||
Mer 11/10 ORE 22:33: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a PaoTEST1 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -16 RIS]
|
||||
PaoTEST1: 9 RIS]
|
||||
Gio 12/10 ORE 08:05: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a PaoTEST1 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -17 RIS]
|
||||
PaoTEST1: 10 RIS]
|
||||
Gio 12/10 ORE 08:06: [<b>Circuito RIS Rimini</b>]: Inviate Monete da paoloar77 a SuryaArena2 1 RIS [causale: ]
|
||||
Saldi:
|
||||
paoloar77: -18 RIS]
|
||||
SuryaArena2: 7 RIS]
|
||||
@@ -10,91 +10,345 @@ let aggregation = [
|
||||
{
|
||||
$match: {
|
||||
idapp: "13",
|
||||
},
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
date_updated: -1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$addFields: {
|
||||
myId1: {
|
||||
$toObjectId: "$userId",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
localField: "myId1",
|
||||
foreignField: "_id",
|
||||
as: "user",
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
"$user",
|
||||
0,
|
||||
],
|
||||
},
|
||||
"$$ROOT",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
recGood: 1,
|
||||
sectorGood: 1,
|
||||
idSectorGood: 1,
|
||||
idGood: 1,
|
||||
mygood: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
"profile.username_telegram": 1,
|
||||
"profile.favorite": 1,
|
||||
"profile.bookmark": 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
comune: 1,
|
||||
mycities: 1,
|
||||
"profile.img": 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.qualifica": 1,
|
||||
"profile.resid_province": 1,
|
||||
"profile.resid_card": 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "goods",
|
||||
localField: "idGood",
|
||||
foreignField: "_id",
|
||||
as: "recGood",
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
"$recGood",
|
||||
0,
|
||||
],
|
||||
},
|
||||
"$$ROOT",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
recGood: 1,
|
||||
sectorGood: 1,
|
||||
idSectorGood: 1,
|
||||
idGood: 1,
|
||||
mygood: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
"profile.username_telegram": 1,
|
||||
"profile.favorite": 1,
|
||||
"profile.bookmark": 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
comune: 1,
|
||||
mycities: 1,
|
||||
"profile.img": 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.qualifica": 1,
|
||||
"profile.resid_province": 1,
|
||||
"profile.resid_card": 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "sectorgoods",
|
||||
localField: "idSectorGood",
|
||||
foreignField: "_id",
|
||||
as: "sectorGood",
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
"$sectorGood",
|
||||
0,
|
||||
],
|
||||
},
|
||||
"$$ROOT",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
recGood: 1,
|
||||
sectorGood: 1,
|
||||
idSectorGood: 1,
|
||||
idGood: 1,
|
||||
mygood: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
"profile.username_telegram": 1,
|
||||
"profile.favorite": 1,
|
||||
"profile.bookmark": 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
comune: 1,
|
||||
mycities: 1,
|
||||
"profile.img": 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.qualifica": 1,
|
||||
"profile.resid_province": 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "cities",
|
||||
localField: "idCity",
|
||||
foreignField: "_id",
|
||||
as: "mycities",
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
"$mycities",
|
||||
0,
|
||||
],
|
||||
},
|
||||
"$$ROOT",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
recGood: 1,
|
||||
sectorGood: 1,
|
||||
idSectorGood: 1,
|
||||
idGood: 1,
|
||||
mygood: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
"profile.username_telegram": 1,
|
||||
"profile.favorite": 1,
|
||||
"profile.bookmark": 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
comune: 1,
|
||||
mycities: 1,
|
||||
"profile.img": 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.qualifica": 1,
|
||||
"profile.resid_province": 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
$or: [
|
||||
{
|
||||
deleted: {
|
||||
$exists: false,
|
||||
},
|
||||
$and: [
|
||||
{
|
||||
"profile.mygroups": {
|
||||
$elemMatch: {
|
||||
groupname: {
|
||||
$in: [
|
||||
"000017",
|
||||
"risoprova",
|
||||
"VillaggiamoItalia",
|
||||
"Terraw",
|
||||
"RisoBenevento",
|
||||
"111",
|
||||
"gruppodefaultriso",
|
||||
"pontiUmani",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
pub_to_share: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
deleted: {
|
||||
$exists: true,
|
||||
$eq: false,
|
||||
},
|
||||
$or: [
|
||||
{
|
||||
pub_to_share: {
|
||||
$exists: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
pub_to_share: {
|
||||
$exists: true,
|
||||
$eq: 0,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
$and: [
|
||||
{
|
||||
"mycities.reg": "EMR",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: "$aportador_solidario",
|
||||
_id: null,
|
||||
count: {
|
||||
$sum: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$match: { "count": { $gte: 2 } }
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
count: -1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
let: {
|
||||
username: "$_id",
|
||||
idapp: "13",
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{
|
||||
$eq: [
|
||||
"$$username",
|
||||
"$username",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$$idapp",
|
||||
"$idapp",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
as: "user",
|
||||
},
|
||||
},
|
||||
{ $unwind: "$user" },
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [ "$user", "$$ROOT" ],
|
||||
results: {
|
||||
$push: "$$ROOT",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
count: 1,
|
||||
aportador_solidario: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
idapp: 1,
|
||||
"profile.img": 1,
|
||||
rows: {
|
||||
$slice: [
|
||||
"$results",
|
||||
0,
|
||||
10,
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
db.users.aggregate(aggregation);
|
||||
db.myskills.aggregate(aggregation);
|
||||
|
||||
|
||||
432
mongodb/Favorite.mongodb
Normal file
432
mongodb/Favorite.mongodb
Normal file
@@ -0,0 +1,432 @@
|
||||
use('test_FreePlanet');
|
||||
|
||||
let aggregation = [
|
||||
{
|
||||
$match: {
|
||||
idapp: "13",
|
||||
},
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
date_updated: -1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
let: {
|
||||
tab: 1,
|
||||
id: "$_id",
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$unwind: "$profile.favorite",
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{
|
||||
$eq: [
|
||||
"$profile.favorite.id",
|
||||
"$$id",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$profile.favorite.tab",
|
||||
"$$tab",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$idapp",
|
||||
"13",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{ $project: { username: 1, _id: 0 } },
|
||||
],
|
||||
as: "myfav",
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
let: {
|
||||
tab: 1,
|
||||
id: "$_id",
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$unwind: "$profile.bookmark",
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{
|
||||
$eq: [
|
||||
"$profile.bookmark.id",
|
||||
"$$id",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$profile.bookmark.tab",
|
||||
"$$tab",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
as: "mybook",
|
||||
},
|
||||
},
|
||||
{
|
||||
$addFields: {
|
||||
myId1: {
|
||||
$toObjectId: "$userId",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
localField: "myId1",
|
||||
foreignField: "_id",
|
||||
as: "user",
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
"$user",
|
||||
0,
|
||||
],
|
||||
},
|
||||
"$$ROOT",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
recSkill: 1,
|
||||
sector: 1,
|
||||
idSector: 1,
|
||||
idSkill: 1,
|
||||
myskill: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
"profile.username_telegram": 1,
|
||||
"profile.favorite": 1,
|
||||
"profile.bookmark": 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
comune: 1,
|
||||
mycities: 1,
|
||||
"profile.img": 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.qualifica": 1,
|
||||
"profile.resid_province": 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
myfav: 1,
|
||||
mybook: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "skills",
|
||||
localField: "idSkill",
|
||||
foreignField: "_id",
|
||||
as: "recSkill",
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
"$recSkill",
|
||||
0,
|
||||
],
|
||||
},
|
||||
"$$ROOT",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
recSkill: 1,
|
||||
sector: 1,
|
||||
idSector: 1,
|
||||
idSkill: 1,
|
||||
myskill: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
"profile.username_telegram": 1,
|
||||
"profile.favorite": 1,
|
||||
"profile.bookmark": 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
comune: 1,
|
||||
mycities: 1,
|
||||
"profile.img": 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.qualifica": 1,
|
||||
"profile.resid_province": 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
myfav: 1,
|
||||
mybook: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "sectors",
|
||||
localField: "idSector",
|
||||
foreignField: "_id",
|
||||
as: "sector",
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
"$sector",
|
||||
0,
|
||||
],
|
||||
},
|
||||
"$$ROOT",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
recSkill: 1,
|
||||
sector: 1,
|
||||
idSector: 1,
|
||||
idSkill: 1,
|
||||
myskill: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
"profile.username_telegram": 1,
|
||||
"profile.favorite": 1,
|
||||
"profile.bookmark": 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
comune: 1,
|
||||
mycities: 1,
|
||||
"profile.img": 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.qualifica": 1,
|
||||
"profile.resid_province": 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
myfav: 1,
|
||||
mybook: 1,
|
||||
myseen: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "cities",
|
||||
localField: "idCity",
|
||||
foreignField: "_id",
|
||||
as: "mycities",
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
"$mycities",
|
||||
0,
|
||||
],
|
||||
},
|
||||
"$$ROOT",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
recSkill: 1,
|
||||
sector: 1,
|
||||
idSector: 1,
|
||||
idSkill: 1,
|
||||
myskill: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
"profile.username_telegram": 1,
|
||||
"profile.favorite": 1,
|
||||
"profile.bookmark": 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
comune: 1,
|
||||
mycities: 1,
|
||||
"profile.img": 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.qualifica": 1,
|
||||
"profile.resid_province": 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
myfav: 1,
|
||||
mybook: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
$or: [
|
||||
{
|
||||
$and: [
|
||||
{
|
||||
"profile.mygroups": {
|
||||
$elemMatch: {
|
||||
groupname: {
|
||||
$in: [
|
||||
"000017",
|
||||
"risoprova",
|
||||
"VillaggiamoItalia",
|
||||
"Terraw",
|
||||
"RisoBenevento",
|
||||
"111",
|
||||
"gruppodefaultriso",
|
||||
"pontiUmani",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
pub_to_share: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
$or: [
|
||||
{
|
||||
pub_to_share: {
|
||||
$exists: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
pub_to_share: {
|
||||
$exists: true,
|
||||
$eq: 0,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
$and: [
|
||||
{
|
||||
"mycities.reg": "EMR",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
count: {
|
||||
$sum: 1,
|
||||
},
|
||||
results: {
|
||||
$push: "$$ROOT",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
count: 1,
|
||||
rows: {
|
||||
$slice: [
|
||||
"$results",
|
||||
0,
|
||||
10,
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
db.myskills.aggregate(aggregation);
|
||||
|
||||
203
mongodb/Members.mongodb
Normal file
203
mongodb/Members.mongodb
Normal file
@@ -0,0 +1,203 @@
|
||||
use('test_FreePlanet');
|
||||
|
||||
let aggregation = [
|
||||
{
|
||||
$match: {
|
||||
idapp: "13",
|
||||
"profile.mycircuits": {
|
||||
$elemMatch: {
|
||||
circuitname: {
|
||||
$eq: "Circuito RIS Bologna",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "circuits",
|
||||
as: "circuit",
|
||||
let: {
|
||||
circuitname: "Circuito RIS Bologna",
|
||||
idapp: "$idapp",
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{
|
||||
$eq: [
|
||||
"$name",
|
||||
"$$circuitname",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$idapp",
|
||||
"$$idapp",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$circuit",
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
date_reg: 1,
|
||||
profile: 1,
|
||||
idapp: 1,
|
||||
"circuit.name": 1,
|
||||
"circuit._id": 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "accounts",
|
||||
as: "account",
|
||||
let: {
|
||||
username: "$username",
|
||||
idapp: "$idapp",
|
||||
circuitId: "$circuit._id",
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{
|
||||
$eq: [
|
||||
"$$username",
|
||||
"$username",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$$idapp",
|
||||
"$idapp",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$$circuitId",
|
||||
"$circuitId",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$account",
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
idapp: "13",
|
||||
},
|
||||
},
|
||||
{
|
||||
$addFields: {
|
||||
myId1: {
|
||||
$toObjectId: "$userId",
|
||||
},
|
||||
namecomplete: {
|
||||
$concat: [
|
||||
{
|
||||
$toLower: "$name",
|
||||
},
|
||||
{
|
||||
$toLower: "$surname",
|
||||
},
|
||||
{ $toLower: "$username" },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
localField: "myId1",
|
||||
foreignField: "_id",
|
||||
as: "user",
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
"$user",
|
||||
0,
|
||||
],
|
||||
},
|
||||
"$$ROOT",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
"profile.img": 1,
|
||||
"profile.mycircuits": 1,
|
||||
"profile.qualifica": 1,
|
||||
"profile.resid_province": 1,
|
||||
"account._id": 1,
|
||||
"account.saldo": 1,
|
||||
"account.fidoConcesso": 1,
|
||||
"account.qta_maxConcessa": 1,
|
||||
"account.totTransato": 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
namecomplete: 1,
|
||||
date_reg: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
date_reg: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
count: {
|
||||
$sum: 1,
|
||||
},
|
||||
results: {
|
||||
$push: "$$ROOT",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
count: 1,
|
||||
rows: {
|
||||
$slice: [
|
||||
"$results",
|
||||
1,
|
||||
15,
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
db.users.aggregate(aggregation);
|
||||
|
||||
352
mongodb/MySkills.mongodb
Normal file
352
mongodb/MySkills.mongodb
Normal file
@@ -0,0 +1,352 @@
|
||||
// MongoDB Playground
|
||||
// To disable this template go to Settings | MongoDB | Use Default Template For Playground.
|
||||
// Make sure you are connected to enable completions and to be able to run a playground.
|
||||
// Use Ctrl+Space inside a snippet or a string literal to trigger completions.
|
||||
|
||||
// Select the database to use.
|
||||
use('test_FreePlanet');
|
||||
|
||||
let aggregation = [
|
||||
{
|
||||
$match: {
|
||||
idapp: "13",
|
||||
},
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
date_updated: -1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$addFields: {
|
||||
myId1: {
|
||||
$toObjectId: "$userId",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
localField: "myId1",
|
||||
foreignField: "_id",
|
||||
as: "user",
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
"$user",
|
||||
0,
|
||||
],
|
||||
},
|
||||
"$$ROOT",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
recGood: 1,
|
||||
sectorGood: 1,
|
||||
idSectorGood: 1,
|
||||
idGood: 1,
|
||||
mygood: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
"profile.username_telegram": 1,
|
||||
"profile.favorite": 1,
|
||||
"profile.bookmark": 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
comune: 1,
|
||||
mycities: 1,
|
||||
"profile.img": 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.qualifica": 1,
|
||||
"profile.resid_province": 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "goods",
|
||||
localField: "idGood",
|
||||
foreignField: "_id",
|
||||
as: "recGood",
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
"$recGood",
|
||||
0,
|
||||
],
|
||||
},
|
||||
"$$ROOT",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
recGood: 1,
|
||||
sectorGood: 1,
|
||||
idSectorGood: 1,
|
||||
idGood: 1,
|
||||
mygood: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
"profile.username_telegram": 1,
|
||||
"profile.favorite": 1,
|
||||
"profile.bookmark": 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
comune: 1,
|
||||
mycities: 1,
|
||||
"profile.img": 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.qualifica": 1,
|
||||
"profile.resid_province": 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "sectorgoods",
|
||||
localField: "idSectorGood",
|
||||
foreignField: "_id",
|
||||
as: "sectorGood",
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
"$sectorGood",
|
||||
0,
|
||||
],
|
||||
},
|
||||
"$$ROOT",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
recGood: 1,
|
||||
sectorGood: 1,
|
||||
idSectorGood: 1,
|
||||
idGood: 1,
|
||||
mygood: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
"profile.username_telegram": 1,
|
||||
"profile.favorite": 1,
|
||||
"profile.bookmark": 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
comune: 1,
|
||||
mycities: 1,
|
||||
"profile.img": 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.qualifica": 1,
|
||||
"profile.resid_province": 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "cities",
|
||||
localField: "idCity",
|
||||
foreignField: "_id",
|
||||
as: "mycities",
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
"$mycities",
|
||||
0,
|
||||
],
|
||||
},
|
||||
"$$ROOT",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
recGood: 1,
|
||||
sectorGood: 1,
|
||||
idSectorGood: 1,
|
||||
idGood: 1,
|
||||
mygood: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
"profile.username_telegram": 1,
|
||||
"profile.favorite": 1,
|
||||
"profile.bookmark": 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
comune: 1,
|
||||
mycities: 1,
|
||||
"profile.img": 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.qualifica": 1,
|
||||
"profile.resid_province": 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
$or: [
|
||||
{
|
||||
$and: [
|
||||
{
|
||||
"profile.mygroups": {
|
||||
$elemMatch: {
|
||||
groupname: {
|
||||
$in: [
|
||||
"000017",
|
||||
"risoprova",
|
||||
"VillaggiamoItalia",
|
||||
"Terraw",
|
||||
"RisoBenevento",
|
||||
"111",
|
||||
"gruppodefaultriso",
|
||||
"pontiUmani",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
pub_to_share: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
$or: [
|
||||
{
|
||||
pub_to_share: {
|
||||
$exists: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
pub_to_share: {
|
||||
$exists: true,
|
||||
$eq: 0,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
$and: [
|
||||
{
|
||||
"mycities.reg": "EMR",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
count: {
|
||||
$sum: 1,
|
||||
},
|
||||
results: {
|
||||
$push: "$$ROOT",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
count: 1,
|
||||
rows: {
|
||||
$slice: [
|
||||
"$results",
|
||||
0,
|
||||
10,
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
db.myskills.aggregate(aggregation);
|
||||
|
||||
@@ -278,3 +278,11 @@ if (test) {
|
||||
// Use toArray() to exhaust the cursor to return the whole result set.
|
||||
// You can use hasNext()/next() to iterate through the cursor page by page.
|
||||
db.users.aggregate(aggregation);
|
||||
|
||||
|
||||
|
||||
db.getCollection('myskills').deleteMany({ '_id': { $lte: 10000 }})
|
||||
db.getCollection('mygoods').deleteMany({ '_id': { $lte: 10000 }})
|
||||
db.getCollection('mybachecas').deleteMany({ '_id': { $lte: 10000 }})
|
||||
db.getCollection('myhosps').deleteMany({ '_id': { $lte: 10000 }})
|
||||
db.getCollection('mygroups').deleteMany({ '_id': { $lte: 10000 }})
|
||||
23
mongodb/favorite.mongodb.js
Normal file
23
mongodb/favorite.mongodb.js
Normal file
@@ -0,0 +1,23 @@
|
||||
use('test_FreePlanet');
|
||||
|
||||
let aggregation = [
|
||||
{
|
||||
$match: {
|
||||
idapp: "13",
|
||||
"profile.favorite": {
|
||||
$elemMatch:
|
||||
{ id: '10256', tab: 4 }
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
$group:
|
||||
{
|
||||
_id: null,
|
||||
count: { $sum: 1 },
|
||||
}
|
||||
},
|
||||
{ $project: { _id: 0 } }
|
||||
];
|
||||
|
||||
db.users.aggregate(aggregation);
|
||||
17
package.json
17
package.json
@@ -4,7 +4,8 @@
|
||||
"description": "freeplanet serverside",
|
||||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
"start": "NODE_ENV=development nodemon src/server/server.js",
|
||||
"start": "node src/server/server.js",
|
||||
"dev": "NODE_ENV=development nodemon src/server/server.js",
|
||||
"build": "gulp build",
|
||||
"watch": "gulp watch",
|
||||
"test": "export NODE_ENV=development || SET NODE_ENV=development && mocha src/server/**/*.test.js",
|
||||
@@ -13,7 +14,7 @@
|
||||
"test-watch": "nodemon --exec 'npm test'"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^16.14.0"
|
||||
"node": "^16.19.0"
|
||||
},
|
||||
"author": "Paolo Arena",
|
||||
"license": "MIT",
|
||||
@@ -35,8 +36,8 @@
|
||||
"i18n": "^0.15.0",
|
||||
"image-downloader": "^4.3.0",
|
||||
"internet-available": "^1.0.0",
|
||||
"jade": "^1.11.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"jade": "^1.9.2",
|
||||
"jsonwebtoken": "^9.0.1",
|
||||
"lodash": "^4.17.21",
|
||||
"mongodb": "^4.4.1",
|
||||
"mongoose": "^5.13.15",
|
||||
@@ -53,7 +54,7 @@
|
||||
"pug": "^3.0.2",
|
||||
"rate-limiter-flexible": "^2.3.9",
|
||||
"save": "^2.5.0",
|
||||
"sharp": "0.30.0",
|
||||
"sharp": "^0.30.7",
|
||||
"superagent": "^8.0.0",
|
||||
"url-parse": "^1.5.10",
|
||||
"validator": "^13.7.0",
|
||||
@@ -63,15 +64,15 @@
|
||||
"devDependencies": {
|
||||
"browser-sync": "^2.27.10",
|
||||
"expect": "^29.0.2",
|
||||
"gulp": "^4.0.2",
|
||||
"gulp-inline-css": "^4.0.0",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-inline-css": "^2.0.0",
|
||||
"gulp-pug": "^5.0.0",
|
||||
"gulp-rename": "^2.0.0",
|
||||
"gulp-replace": "^1.1.3",
|
||||
"gulp-sass": "^5.1.0",
|
||||
"jest": "^29.0.2",
|
||||
"mocha": "^10.0.0",
|
||||
"nodemon": "^2.0.19",
|
||||
"nodemon": "^3.0.1",
|
||||
"supertest": "^6.2.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ const tools = require('../tools/general');
|
||||
|
||||
// still in app.js
|
||||
const node_env = process.env.NODE_ENV || 'production';
|
||||
console.log('node_env=', node_env);
|
||||
|
||||
var file = `.env.${node_env}`;
|
||||
|
||||
|
||||
@@ -18,7 +20,10 @@ require('dotenv').config({ path: file });
|
||||
|
||||
process.env.DATABASE = process.env.DATABASE || 'FreePlanet';
|
||||
|
||||
console.log('process.env.DOMAIN:', process.env.DOMAIN);
|
||||
process.env.MONGODB_URI = process.env.DOMAIN + process.env.DATABASE;
|
||||
console.log('process.env.MONGODB_URI:', process.env.MONGODB_URI);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -44,6 +44,9 @@ const db = mongoose.connection;
|
||||
|
||||
// mongoose.connect(process.env.MONGODB_URI + '?authSource=admin', { options })
|
||||
// console.log(' -> PASSAGGIO PARAMETRI MONGOOSE')
|
||||
console.log('Node Version ' + process.version);
|
||||
console.log('Mongoose Version ' + mongoose.version);
|
||||
console.log('Connessione a ' + process.env.MONGODB_URI + ' in corso...');
|
||||
mongoose.connect(process.env.MONGODB_URI, options);
|
||||
|
||||
db.on('error', console.error.bind(console, 'connection error:'));
|
||||
|
||||
@@ -3,8 +3,15 @@
|
||||
"Hello %s": "Ciao %s",
|
||||
"Good: %s": "Bene: %s",
|
||||
"Service: %s": "Servizio: %s",
|
||||
"<strong>%s</strong> new Good: %s": "<strong>%s</strong> nuovo Bene: %s",
|
||||
"<strong>%s</strong> new Service: %s": "<strong>%s</strong> nuovo Servizio: %s",
|
||||
"NEW_GOOD": "❇️ <strong>%s</strong> ha aggiunto un nuovo Bene: \n<strong>%s</strong>",
|
||||
"NEW_SERVICE": "❇️ <strong>%s</strong> ha aggiunto un nuovo Servizio: \n<strong>%s</strong>",
|
||||
"NEW_HOSP": "❇️ <strong>%s</strong> ha aggiunto una nuova Ospitalità: \n<strong>%s</strong>",
|
||||
"NEW_EVENT": "❇️ <strong>%s</strong> ha aggiunto un nuovo Evento: \n%s\n<strong>%s</strong>\n%s",
|
||||
"NEW_EVENT_TELEGRAM": "%s\n\n❇️ <strong>%s</strong>\n\n%s\n\n%s",
|
||||
"ADDED_FROM": "\n\n<i>(Evento aggiunto da <strong>%s</strong>)</i>",
|
||||
"CONTRIB": "\n💠 Contributo richiesto: %s",
|
||||
"ORGANIZED_BY": "\n<i>Organizzato da <strong>%s</strong></i>",
|
||||
"SHOW_POST": "👉🏻 vedi post su RISO",
|
||||
"OPEN PAGE": "<em>APRI la APP RISO oppure visita riso.app</em>",
|
||||
"<strong>%s</strong> asked you for Friendship": "<strong>%s</strong> ti ha chiesto l'Amicizia",
|
||||
"<strong>%s</strong> accepted your Friendship": "<strong>%s</strong> ha accettato l'Amicizia",
|
||||
@@ -12,6 +19,8 @@
|
||||
"✅ %s accepted your Friendship request !": "✅ %s ha accettato la tua richiesta di Amicizia !",
|
||||
"✅ You have accepted %s' Friendship request!": "✅ Hai accettato la richiesta di Amicizia di %s !",
|
||||
"HANDSHAKE_SET": "<strong>%s</strong> ha comunicato che ti conosce personalmente e ha fiducia in te.",
|
||||
"HANDSHAKE_CONFIRMED": "🤝 Hai contraccambiato la fiducia in <strong>%s</strong>!",
|
||||
"HANDSHAKE_ACCEPTED": "🤝 <strong>%s</strong> ha contraccambiato la stretta di mano (fiducia) !",
|
||||
"GROUPS_ACCEPTED": "✅ Sei stato accettato a far parte del Gruppo %s (da parte di %s)",
|
||||
"GROUPS_REFUSED": "❌ Ti è stato rifiutato l'accesso da %s a far parte del Gruppo %s. Se pensi sia un'errore, contatta l'amministratore del Gruppo.",
|
||||
"GROUPS_REMOVED": "❌ l'utente %s è stato rimosso del Gruppo %s (da parte di %s)",
|
||||
@@ -34,57 +43,69 @@
|
||||
"FRIEND_UNBLOCKED_TO_ME": "Sei stato riattivato da %s",
|
||||
"FRIEND_UNBLOCKED": "E' stato riattivato %s da %s.",
|
||||
"FRIEND_UNBLOCKED_YOU": "Hai riattivato %s.",
|
||||
"CIRCUIT_ACCEPT_NEWENTRY": "❇️👥 🧍♂️ Accetta Ingresso nel Circuito %s:",
|
||||
"CIRCUIT_ACCEPT_NEWENTRY_BYGROUP": "❇️👥 🧍♂️ Accetta Ingresso nel Circuito il gruppo %s:",
|
||||
"CIRCUIT_REQUEST_TO_ENTER": "%s ha chiesto di entrare nel circuito %s",
|
||||
"CIRCUIT_REQUEST_TO_ENTER_WITH_GROUP": "il gruppo %s ha chiesto di entrare nel circuito %s",
|
||||
"CIRCUIT_ACCEPT_NEWENTRY": "❇️👥 🧍♂️ Abilita fido a %s nel '%s':",
|
||||
"CIRCUIT_ACCEPT_NEWENTRY_BYGROUP": "❇️👥 🧍♂️ Abilita fido nel Circuito al gruppo %s:",
|
||||
"CIRCUIT_OPEN_RISITALIA": "Apri il Circuito RIS Italia e chiedi di entrare",
|
||||
"CIRCUIT_REQUEST_TO_ENTER": "%s è entrato nel %s (con %s iscritti) ed è in attesa di essere abilitato al Fido (è stato invitato da %s)",
|
||||
"CIRCUIT_ADMINS": "Gli amministratori del circuito sono %s:\n%s",
|
||||
"CIRCUIT_WHERE_IS_PRESENT": "\nAttualmente è presente in: %s",
|
||||
"CIRCUIT_REQUEST_TO_ENTER_WITH_GROUP": "il gruppo %s ha chiesto di entrare nel %s (con %s iscritti)",
|
||||
"CIRCUIT_CREATED": "✅ %s ha creato un nuovo Circuito chiamato %s",
|
||||
"CIRCUIT_REQUEST": "Richiesta di entrare nel Circuito %s da parte di %s",
|
||||
"CIRCUIT_ADDED_ADMIN": "E' stato aggiunto %s come Amministratore del circuito %s da parte di %s",
|
||||
"CIRCUIT_ADDED_ADMIN_YOU": "Sei stato aggiunto come Amministratore del circuito %s da parte di %s",
|
||||
"CIRCUIT_REMOVED_ADMIN": "E' stato rimosso l'incarico di Amministratore a %s del circuito %s da parte di %s",
|
||||
"CIRCUIT_REMOVED_ADMIN_YOU": "Ti è stato rimosso l'incarico di Amministratore del circuito %s da parte di %s",
|
||||
"RICHIESTA_BLOCCO_CIRCUIT": "Richiesta di bloccare il Circuito %s da parte di %s",
|
||||
"CIRCUIT_ELIMINATO": "Il circuito %s è stato eliminato da parte di %s",
|
||||
"ACCETTATO_NOTIFICA_ADMINS_CIRCUIT": "✅ l'utente %s è stato accettato a far parte del Circuito %s (da parte di %s)",
|
||||
"ACCETTATO_NOTIFICA_ADMINS_CIRCUIT_MYGROUP": "✅ il Conto Collettivo %s è stato accettato a far parte del Circuito %s (da parte di %s)",
|
||||
"CIRCUIT_ACCEPTED": "✅ Sei stato accettato da %s a far parte del Circuito %s.\nApri la APP e clicca in alto a destra sull'icona delle monete, oppure clicca qui: %s",
|
||||
"CIRCUIT_ACCEPTED_YOU": "✅ Hai accettato %s a far parte del Circuito %s",
|
||||
"CIRCUIT_REFUSED": "❌ Ti è stato rifiutato l'accesso da %s a far parte del Circuito %s. Se pensi sia un'errore, contatta l'amministratore del Circuito.",
|
||||
"CIRCUIT_REMOVED": "❌ l'utente %s è stato rimosso del Circuito %s (da parte di %s)",
|
||||
"CIRCUIT_REFUSED_TO_ME": "All'utente %s gli è stato rifiutato l'accesso a far parte del Circuito %s (da parte di %s).",
|
||||
"CIRCUIT_REFUSED_TO_MYGROUP": "Al Conto Collettivo %s gli è stato rifiutato l'accesso a far parte del Circuito %s (da parte di %s).",
|
||||
"CIRCUIT_EXIT_USER": "❌ l'utente %s è uscito dal Circuito %s",
|
||||
"CIRCUIT_EXIT_USER_TO_ME": "❌ Sei uscito dal Circuito %s",
|
||||
"CIRCUIT_REMOVED_TO_ME": "❌ Sei stato rimosso dal Circuito %s (da parte di %s)",
|
||||
"CIRCUIT_SENDCOINSREQ": "%s ti sta inviando <strong>%s %s</strong>.",
|
||||
"CIRCUIT_REQUEST": "Richiesta di entrare nel %s da parte di %s",
|
||||
"CIRCUIT_ADDED_ADMIN": "E' stato aggiunto %s come Amministratore del %s da parte di %s",
|
||||
"CIRCUIT_ADDED_ADMIN_YOU": "%s sei stato aggiunto come Amministratore del %s da parte di %s",
|
||||
"CIRCUIT_REMOVED_ADMIN": "E' stato rimosso l'incarico di Amministratore a %s del %s da parte di %s",
|
||||
"CIRCUIT_REMOVED_ADMIN_YOU": "%s ti è stato rimosso l'incarico di Amministratore del %s da parte di %s",
|
||||
"RICHIESTA_BLOCCO_CIRCUIT": "Richiesta di bloccare il %s da parte di %s",
|
||||
"CIRCUIT_ELIMINATO": "Il %s è stato eliminato da parte di %s",
|
||||
"FIDO_IMPOSTATO_ADMINS_CIRCUIT": "✅ l'utente %s è stato abilitato al Fido (%s RIS) sul '%s' (da parte di %s)",
|
||||
"FIDO_IMPOSTATO_ADMINS_CIRCUIT_MYGROUP": "✅ il Conto di Gruppo %s è stato abilitato al Fido fino a -%s sul '%s' (da parte di %s)",
|
||||
"ACCETTATO_NOTIFICA_ADMINS_CIRCUIT": "✅ l'utente %s è stato accettato a far parte del '%s' (da parte di %s)",
|
||||
"ACCETTATO_NOTIFICA_ADMINS_CIRCUIT_MYGROUP": "✅ il Conto di Gruppo %s è stato accettato a far parte del '%s' (da parte di %s)",
|
||||
"CIRCUIT_ACCEPTED": "✅ Sei stato accettato da %s a far parte del %s.\nApri la APP e clicca in alto a destra sull'icona delle monete, oppure clicca qui: %s",
|
||||
"FIDO_IMPOSTATO": "✅ Ti è stata attivata la possibilità di utilizzare il fido (Fiducia Concessa) fino a %s RIS da %s sul '%s'.",
|
||||
"CIRCUIT_ACCEPTED_YOU": "✅ Hai accettato %s a far parte del '%s'",
|
||||
"CIRCUIT_REFUSED": "❌ Ti è stato rifiutato l'accesso da %s a far parte del '%s'. Se pensi sia un'errore, contatta l'amministratore del Circuito.",
|
||||
"CIRCUIT_REMOVED": "❌ l'utente %s è stato rimosso del %s (da parte di %s)",
|
||||
"CIRCUIT_REFUSED_TO_ME": "All'utente %s gli è stato rifiutato l'accesso a far parte del '%s' (da parte di %s).",
|
||||
"CIRCUIT_REFUSED_TO_MYGROUP": "Al Conto Collettivo %s gli è stato rifiutato l'accesso a far parte del '%s' (da parte di %s).",
|
||||
"CIRCUIT_EXIT_USER": "❌ l'utente %s è uscito dal '%s'",
|
||||
"CIRCUIT_EXIT_USER_TO_ME": "❌ Sei uscito dal '%s'",
|
||||
"CIRCUIT_REMOVED_TO_ME": "❌ Sei stato rimosso dal '%s' (da parte di %s)",
|
||||
"CIRCUIT_SENDCOINSREQ": "%s ti sta inviando <strong>%s %s</strong> sul '%s'.",
|
||||
"COMUNITARIO": "Comunitario",
|
||||
"COLLETTIVO": "Collettivo",
|
||||
"CIRCUIT_SENDCOINSREQ_GROUP": "%s sta inviando <strong>%s %s</strong> al Conto %s '%s'.",
|
||||
"CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_USER": "il conto %s '%s' (%s) sta inviando <strong>%s %s</strong> a %s.",
|
||||
"CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_YOU": "il conto %s '%s' (%s) ti sta inviando <strong>%s %s</strong>",
|
||||
"CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_GROUP": "il conto %s '%s' (%s) sta inviando <strong>%s %s</strong> al conto %s '%s'.",
|
||||
"CIRCUIT_SENDCOINSREQ_TO_ME": "Stai inviando <strong>%s %s</strong> a %s. \nIl destinatario deve accettare la transazione.",
|
||||
"CIRCUIT_SENDCOINSREQ_TO_GROUP": "Stai inviando <strong>%s %s</strong> al Conto %s '%s'. \nIl destinatario deve accettare la transazione.",
|
||||
"ID_CIRCUIT_COINS_ACCEPTED_FROM_GROUP_TO_YOU": "<strong>%s %s</strong> accettati dal Conto %s '%s' (%s).",
|
||||
|
||||
"ID_CIRCUIT_COINS_ACCEPTED_FROM_GROUP_TO_GROUP": "il conto %s '%s' (%s) ha accettato <strong>%s %s</strong> dal conto %s '%s' (%s).",
|
||||
|
||||
"ID_CIRCUIT_COINS_ACCEPTED_FROM_ME_TO_GROUP": "il conto %s '%s' (%s) ha accettato <strong>%s %s</strong> da %s.",
|
||||
"ID_CIRCUIT_COINS_ACCEPTED_FROM_ME_TO_YOU": "<strong>%s %s</strong> accettati da %s.",
|
||||
"ID_CIRCUIT_COINS_ACCEPTED": "<strong>%s %s</strong> accettati da %s.",
|
||||
"SALDO_UPDATE": "[Saldo <strong>%s %s</strong>]",
|
||||
"SALDO_UPDATE_WHO": "[Saldo %s <strong>%s %s</strong>]",
|
||||
"ID_CIRCUIT_COINS_ACCEPTED_TO_ME": "<strong>%s %s</strong> sono stati accettati da %s.",
|
||||
"ID_CIRCUIT_COINS_REFUSED": "%s %s rifiutati da %s.",
|
||||
"ID_CIRCUIT_COINS_REFUSED_TO_ME": "%s %s rifiutati da %s.",
|
||||
"COLLETTIVO": "Gruppo",
|
||||
"CIRCUIT_SENDCOINSREQ_GROUP": "%s sta inviando <strong>%s %s</strong> al Conto %s '%s' sul '%s'.",
|
||||
"CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_USER": "il conto %s '%s' (%s) sta inviando <strong>%s %s</strong> a %s sul '%s'.",
|
||||
"CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_YOU": "il conto %s '%s' (%s) ti sta inviando <strong>%s %s</strong> sul '%s'",
|
||||
"CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_GROUP": "il conto %s '%s' (%s) sta inviando <strong>%s %s</strong> al conto %s '%s' sul '%s'.",
|
||||
"CIRCUIT_SENDCOINSREQ_TO_ME": "Stai inviando <strong>%s %s</strong> a %s sul '%s'. \nIl destinatario deve accettare la transazione.",
|
||||
"CIRCUIT_SENDCOINSREQ_TO_GROUP": "Stai inviando <strong>%s %s</strong> al Conto %s '%s' sul '%s'. \nIl destinatario deve accettare la transazione.",
|
||||
"ID_CIRCUIT_COINS_ACCEPTED_FROM_GROUP_TO_YOU": "<strong>%s %s</strong> accettati dal Conto %s '%s' sul '%s' (%s) .",
|
||||
"ID_CIRCUIT_COINS_ACCEPTED_FROM_GROUP_TO_GROUP": "il conto %s '%s' (%s) ha accettato <strong>%s %s</strong> dal conto %s '%s' sul '%s' (%s).",
|
||||
"ID_CIRCUIT_COINS_ACCEPTED_FROM_ME_TO_GROUP": "il conto %s '%s' (%s) ha accettato <strong>%s %s</strong> da %s sul '%s'.",
|
||||
"ID_CIRCUIT_COINS_ACCEPTED_FROM_ME_TO_YOU": "<strong>%s %s</strong> accettati da %s sul '%s'.",
|
||||
"ID_CIRCUIT_COINS_ACCEPTED": "<strong>%s %s</strong> accettati da %s sul '%s'.",
|
||||
"SALDO_UPDATE": "[Saldo <strong>%s %s</strong> sul '%s']",
|
||||
"SALDO_UPDATE_WHO": "[Saldo %s <strong>%s %s</strong> sul '%s']",
|
||||
"ID_CIRCUIT_COINS_ACCEPTED_TO_ME": "<strong>%s %s</strong> sono stati accettati da %s sul '%s'.",
|
||||
"ID_CIRCUIT_COINS_REFUSED": "%s %s rifiutati da %s sul '%s'.",
|
||||
"ID_CIRCUIT_COINS_REFUSED_TO_ME": "%s %s rifiutati da %s sul '%s'.",
|
||||
"CIRCUIT_AMOUNT_EXCEED_FIDO": "L'importo supera la quantità massima concessa per %s",
|
||||
"CIRCUIT_AMOUNT_EXCEED_QTAMAX": "L'importo supera la quantità massima che il destinatario (%s) può accumulare",
|
||||
"CIRCUIT_COINS_ALREADY_PROCESSED": "La richiesta è stata già processata. Stato %s",
|
||||
"STATUS_SENT": "Inviato",
|
||||
"STATUS_REFUSED": "Rifiutato",
|
||||
"SALDO_VARIATO": "[Circuito %s] l'utente %s ha variato il Saldo di %s da %s a %s %s",
|
||||
"FIDOCONCESSO_VARIATO": "[Circuito %s] l'utente %s ha variato il Fido Concesso di %s da %s a %s %s",
|
||||
"QTAMAX_VARIATO": "[Circuito %s] l'utente %s ha variato la quantità massima concessa di %s da %s a %s %s",
|
||||
"SALDO_VARIATO": "[%s] l'utente %s ha variato il Saldo di %s da %s a %s %s",
|
||||
"FIDOCONCESSO_VARIATO": "[%s] l'utente %s ha variato il Fido Concesso di %s da %s a %s %s",
|
||||
"QTAMAX_VARIATO": "[%s] l'utente %s ha variato la quantità massima concessa di %s da %s a %s %s",
|
||||
"SET_FAVORITE": "%s ha messo 'Mi Piace' al tuo post: %s",
|
||||
"SET_FAVORITE_OTHERS": "%s e altre %s persone hanno messo 'Mi Piace' al tuo post: %s",
|
||||
"EVENT_SEND_MSG": "%s ha mandato un messaggio sull'evento %s: \n%s",
|
||||
"SET_ATTEND": "%s ha detto che Parteciperà all'evento: %s",
|
||||
"SET_ATTEND_OTHERS": "%s e altre %s persone hanno detto che Parteciperanno all'evento: %s",
|
||||
"DATEDAYONLY": "%s dalle %s alle %s",
|
||||
"DATE_2DAYS": "%s dalle %s fino a %s alle %s",
|
||||
"SENDMSG_ENTRA_IN_RISO_ITALIA": "Ciao %s!<br>%s che appartiene al <em>%s</em> vuole inviarti dei RIS. Per poterli ricevere dovete entrambi utilizzare il <strong>Circuito RIS Italia</strong>.",
|
||||
"CLICCA_QUI": "CLICCA QUI"
|
||||
}
|
||||
@@ -56,12 +56,23 @@ const AccountSchema = new Schema({
|
||||
},
|
||||
importo_iniziale: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
saldo: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
totTransato: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
saldo_pend: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
totTransato_pend: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
regulation_ok: {
|
||||
type: Boolean,
|
||||
@@ -138,7 +149,7 @@ AccountSchema.statics.calcTotCircolante = async function (idapp, circuitId) {
|
||||
{ $group: { _id: null, count: { $sum: '$saldo' } } }
|
||||
];
|
||||
|
||||
ris = await Account.aggregate(aggr1);
|
||||
const ris = await Account.aggregate(aggr1);
|
||||
|
||||
return ris ? ris[0].count : 0;
|
||||
|
||||
@@ -147,23 +158,69 @@ AccountSchema.statics.calcTotCircolante = async function (idapp, circuitId) {
|
||||
}
|
||||
|
||||
};
|
||||
AccountSchema.methods.addtoSaldoSave = async function (amount) {
|
||||
const account = this;
|
||||
AccountSchema.methods.calcPending = async function (mittente) {
|
||||
try {
|
||||
const account = this;
|
||||
|
||||
if (account) {
|
||||
account.saldo = account.saldo + amount;
|
||||
if (!account.totTransato) {
|
||||
account.totTransato = 0;
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
// *** Calc Pending Transactions ***
|
||||
|
||||
const circuit = await Circuit.getCircuitById(account.circuitId);
|
||||
if (circuit) {
|
||||
let prec_saldo_pend = account.saldo_pend;
|
||||
let prec_totTransato_pend = account.totTransato_pend;
|
||||
let transatopending = 0;
|
||||
|
||||
if (mittente) {
|
||||
let pendingtransactionsMittente = await SendNotif.getSumPendingTransactionsMittente(account.idapp, account.username, circuit.name, account.groupname);
|
||||
let saldopendingMitt = pendingtransactionsMittente.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
|
||||
transatopending = pendingtransactionsMittente.reduce((sum, rec) => sum + Math.abs(rec.extrarec.qty), 0);
|
||||
|
||||
account.saldo_pend = account.saldo - saldopendingMitt;
|
||||
} else {
|
||||
// let pendingtransactionsDest = await SendNotif.getSumPendingTransactionsMittente(account.idapp, account.username, circuit.name, account.groupname);
|
||||
|
||||
// let saldopendingDest = pendingtransactionsDest.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
|
||||
// transatopending = pendingtransactionsDest.reduce((sum, rec) => sum + Math.abs(rec.extrarec.qty), 0);
|
||||
|
||||
// account.saldo_pend = account.saldo + saldopendingDest;
|
||||
account.saldo_pend = account.saldo;
|
||||
}
|
||||
account.totTransato_pend = account.totTransato + transatopending;
|
||||
|
||||
if (prec_saldo_pend !== account.saldo_pend || prec_totTransato_pend !== account.totTransato_pend) {
|
||||
|
||||
const myaccountupdate = {
|
||||
saldo_pend: account.saldo_pend,
|
||||
totTransato_pend: account.totTransato_pend,
|
||||
};
|
||||
|
||||
// Update Record
|
||||
return await Account.findByIdAndUpdate(account.id,
|
||||
{
|
||||
$set: myaccountupdate
|
||||
}).then((ris) => {
|
||||
console.log('calcPending', ris);
|
||||
}).catch((err) => {
|
||||
console.error('calcPending', err);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
account.totTransato += Math.abs(amount);
|
||||
account.date_updated = new Date();
|
||||
return await account.save();
|
||||
|
||||
|
||||
// -----
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
AccountSchema.statics.addtoSaldo = async function (myaccount, amount) {
|
||||
AccountSchema.statics.addtoSaldo = async function (myaccount, amount, mitt) {
|
||||
const Account = this;
|
||||
|
||||
try {
|
||||
@@ -181,10 +238,16 @@ AccountSchema.statics.addtoSaldo = async function (myaccount, amount) {
|
||||
myaccountupdate.totTransato = myaccount.totTransato;
|
||||
myaccountupdate.date_updated = myaccount.date_updated;
|
||||
|
||||
return await Account.updateOne({ _id: myaccount.id },
|
||||
const ris = await Account.updateOne({ _id: myaccount.id },
|
||||
{
|
||||
$set: myaccountupdate
|
||||
});
|
||||
|
||||
|
||||
await myaccount.calcPending(mitt);
|
||||
|
||||
return ris;
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('error', e);
|
||||
@@ -195,13 +258,14 @@ AccountSchema.statics.addtoSaldo = async function (myaccount, amount) {
|
||||
|
||||
AccountSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
this.date_created = new Date();
|
||||
if (!this.date_created)
|
||||
this.date_created = new Date();
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, createifnotexist, groupname = '', contocom = "") {
|
||||
AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, createifnotexist, confido, groupname = '', contocom = "") {
|
||||
const Account = this;
|
||||
|
||||
try {
|
||||
@@ -233,15 +297,18 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
myaccount = new Account({
|
||||
_id: new ObjectID().toString(),
|
||||
idapp,
|
||||
username,
|
||||
username: (!groupname && !contocom) ? username : '',
|
||||
groupname,
|
||||
contocom,
|
||||
circuitId: mycircuit._id,
|
||||
deperibile: false,
|
||||
importo_iniziale: 0,
|
||||
saldo: 0,
|
||||
saldo_pend: 0,
|
||||
fidoConcesso: 0,
|
||||
qta_maxConcessa: 0,
|
||||
totTransato: 0,
|
||||
totTransato_pend: 0,
|
||||
});
|
||||
|
||||
if (contocom) {
|
||||
@@ -262,6 +329,9 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
}
|
||||
}
|
||||
|
||||
if (!confido) {
|
||||
myaccount.fidoConcesso = 0;
|
||||
}
|
||||
|
||||
return await myaccount.save();
|
||||
}
|
||||
@@ -276,14 +346,52 @@ AccountSchema.statics.getAccountByUsernameAndCircuitId = async function (idapp,
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.createAccount = async function (idapp, username, circuitName, groupname = '', contocom = '') {
|
||||
AccountSchema.statics.isExistAccountByUsernameAndCircuitId = async function (idapp, username, circuitId, groupname = '', contocom = "") {
|
||||
const Account = this;
|
||||
|
||||
try {
|
||||
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
if (username === undefined)
|
||||
return false;
|
||||
|
||||
let myquery = {
|
||||
idapp,
|
||||
circuitId,
|
||||
};
|
||||
|
||||
if (groupname) {
|
||||
myquery.groupname = groupname;
|
||||
} else if (contocom) {
|
||||
myquery.contocom = contocom;
|
||||
} else {
|
||||
myquery.username = username;
|
||||
}
|
||||
|
||||
let mycircuit = await Circuit.getCircuitById(circuitId);
|
||||
|
||||
if (mycircuit) {
|
||||
let myaccount = await Account.findOne(myquery);
|
||||
return !!myaccount
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
} catch (e) {
|
||||
console.error('error', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.createAccount = async function (idapp, username, circuitName, confido, groupname = '', contocom = '') {
|
||||
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
try {
|
||||
mycircuit = await Circuit.findOne({ name: circuitName }, { _id: 1 });
|
||||
if (mycircuit) {
|
||||
return await Account.getAccountByUsernameAndCircuitId(idapp, username, mycircuit._id, true, groupname, contocom);
|
||||
return await Account.getAccountByUsernameAndCircuitId(idapp, username, mycircuit._id, true, confido, groupname, contocom);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -295,6 +403,7 @@ AccountSchema.statics.createAccount = async function (idapp, username, circuitNa
|
||||
};
|
||||
|
||||
AccountSchema.statics.getUserAccounts = async function (idapp, username) {
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
try {
|
||||
let aggr1 = [
|
||||
@@ -326,42 +435,64 @@ AccountSchema.statics.getUserAccounts = async function (idapp, username) {
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{ $eq: ['$idapp', '$$idapp'] },
|
||||
{ $eq: ['$typedir', '$$typedir'] },
|
||||
{ $eq: ['$typeid', '$$typeid'] },
|
||||
{ $eq: ['$status', 0] },
|
||||
{ $eq: ['$sender', '$$username'] },
|
||||
{ $eq: ['$idapp', '$$idapp'] },
|
||||
{ $eq: ['$extrarec.circuitname', '$$circuitname'] },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$group:
|
||||
{ _id: "$extrarec.notifIdToUpdate", result: { $first: "$$ROOT" } }
|
||||
},
|
||||
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
ris = await this.aggregate(aggr1);
|
||||
const ris = await this.aggregate(aggr1);
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
// console.log('1 - INIZIA getUserAccounts ')
|
||||
// console.log(aggr1);
|
||||
|
||||
if (ris) {
|
||||
/* if (ris) {
|
||||
for (const account of ris) {
|
||||
const pendingtransactions = await SendNotif.getSumPendingTransactions(idapp, username, account.circuit.name);
|
||||
const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
|
||||
account.saldo -= saldopending;
|
||||
try {
|
||||
//++OTTIMIZZARE QUESTA PARTE ! (CON UNA QUERY...)
|
||||
// console.log(' 1B - PENDIND... ')
|
||||
|
||||
let pendingtransactions = await SendNotif.getSumPendingTransactions(idapp, username, account.circuit.name);
|
||||
let saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
|
||||
if (saldopending !== 0) {
|
||||
account.saldo -= saldopending;
|
||||
account.totTransato = account.totTransato || 0;
|
||||
}
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.error('getUserAccounts 1) ', e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
return ris;
|
||||
} catch (e) {
|
||||
console.error('e', e);
|
||||
console.error('getUserAccounts', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
|
||||
|
||||
if (!groupname) {
|
||||
return [];
|
||||
}
|
||||
try {
|
||||
let aggr1 = [
|
||||
{
|
||||
@@ -402,22 +533,16 @@ AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$group:
|
||||
{ _id: "$extrarec.notifIdToUpdate", result: { $first: "$$ROOT" } }
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
ris = await this.aggregate(aggr1);
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
if (ris) {
|
||||
for (const account of ris) {
|
||||
const pendingtransactions = await SendNotif.getSumPendingTransactions(idapp, '', account.circuit.name, groupname);
|
||||
const saldopending = pendingtransactions.reduce((sum, rec) => sum + rec.extrarec.qty, 0);
|
||||
account.saldo -= saldopending;
|
||||
}
|
||||
}
|
||||
const ris = await this.aggregate(aggr1);
|
||||
|
||||
return ris;
|
||||
} catch (e) {
|
||||
@@ -430,7 +555,7 @@ AccountSchema.statics.getGroupAccounts = async function (idapp, groupname) {
|
||||
AccountSchema.statics.SetMinMaxCollettivi = async function (idapp, valmin, valmax) {
|
||||
const Account = this;
|
||||
|
||||
ris = await Account.updateMany({ idapp, groupname: { "$nin": [null, ""] } },
|
||||
const ris = await Account.updateMany({ idapp, groupname: { "$nin": [null, ""] } },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
@@ -445,7 +570,7 @@ AccountSchema.statics.SetMinMaxCollettivi = async function (idapp, valmin, valma
|
||||
AccountSchema.statics.SetMinMaxComunitari = async function (idapp, valmin, valmax) {
|
||||
const Account = this;
|
||||
|
||||
ris = await Account.updateMany({ idapp, contocom: { "$nin": [null, ""] } },
|
||||
const ris = await Account.updateMany({ idapp, contocom: { "$nin": [null, ""] } },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
@@ -457,18 +582,121 @@ AccountSchema.statics.SetMinMaxComunitari = async function (idapp, valmin, valma
|
||||
};
|
||||
|
||||
// Imposta a tutti i Conti Personali, i seguenti minimi e massimi
|
||||
AccountSchema.statics.SetMinMaxPersonali = async function (idapp, valmin, valmax) {
|
||||
AccountSchema.statics.SetMinMaxPersonali = async function (idapp, fidoConcesso, qta_maxConcessa, circuitId) {
|
||||
const Account = this;
|
||||
|
||||
ris = await Account.updateMany({ idapp, username: { "$nin": [null, ""] } },
|
||||
{
|
||||
$set:
|
||||
if (circuitId) {
|
||||
const ris = await Account.updateMany({ idapp, circuitId, fidoConcesso: { $gt: 0 }, username: { "$nin": [null, ""] } },
|
||||
{
|
||||
fidoConcesso: valmin,
|
||||
qta_maxConcessa: valmax,
|
||||
}
|
||||
});
|
||||
$set:
|
||||
{
|
||||
fidoConcesso,
|
||||
qta_maxConcessa,
|
||||
}
|
||||
});
|
||||
|
||||
// Se aggiorno questi dati, allora devo aggiornare anche gli account del RIS Nazionale
|
||||
await Account.updateAccountCircuitoNazionaleByLimiti(idapp, circuitId, fidoConcesso, qta_maxConcessa);
|
||||
|
||||
} else {
|
||||
const ris = await Account.updateMany({ idapp, fidoConcesso: { $gt: 0 }, username: { "$nin": [null, ""] } },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
fidoConcesso,
|
||||
qta_maxConcessa,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.updateFido = async function (idapp, username, groupname, circuitId, fido) {
|
||||
|
||||
let paramstoupdate = {
|
||||
fidoConcesso: fido,
|
||||
};
|
||||
let risult = null;
|
||||
if (groupname)
|
||||
risult = await Account.updateOne({ idapp, circuitId, groupname }, { $set: paramstoupdate });
|
||||
else
|
||||
risult = await Account.updateOne({ idapp, username, circuitId }, { $set: paramstoupdate });
|
||||
|
||||
return risult;
|
||||
};
|
||||
|
||||
AccountSchema.statics.updateQtaMax = async function (idapp, username, groupname, circuitId, qtamax) {
|
||||
|
||||
let paramstoupdate = {
|
||||
qta_maxConcessa: qtamax,
|
||||
};
|
||||
let risult = null;
|
||||
if (groupname)
|
||||
risult = await Account.updateOne({ idapp, circuitId, groupname }, { $set: paramstoupdate });
|
||||
else
|
||||
risult = await Account.updateOne({ idapp, username, circuitId }, { $set: paramstoupdate });
|
||||
|
||||
return risult;
|
||||
};
|
||||
|
||||
AccountSchema.statics.getAccountsCircuitiNazionali = async function (idapp) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
const circuit = await Circuit.find({ idapp, showAlways: true });
|
||||
|
||||
return Account.find({ idapp, circuitId: circuit.id });
|
||||
};
|
||||
|
||||
AccountSchema.statics.updateAccountCircuitoNazionaleByLimiti = async function (idapp, circuitId, fidoConcesso, qta_maxConcessa) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
try {
|
||||
const accounts = await this.getAccountsCircuitiNazionali(idapp);
|
||||
|
||||
for (const account of accounts) {
|
||||
const circuitId = account.circuitId;
|
||||
const circuit = await Circuit.findOne({ _id: circuitId });
|
||||
if (circuit) {
|
||||
let fido = 0;
|
||||
let qtamax = 0;
|
||||
|
||||
if (account.groupname) {
|
||||
fido = circuit.fido_scoperto_default_grp * shared_consts.CIRCUIT_CFG.MULT_FIDO_GROUP;
|
||||
qtamax = circuit.qta_max_default_grp * shared_consts.CIRCUIT_CFG.MULT_FIDO_GROUP;
|
||||
} else {
|
||||
fido = circuit.fido_scoperto_default * shared_consts.CIRCUIT_CFG.MULT_FIDO_USER;
|
||||
qtamax = circuit.qta_max_default * shared_consts.CIRCUIT_CFG.MULT_FIDO_USER;
|
||||
}
|
||||
|
||||
let paramstoupdate = {
|
||||
fidoConcesso: fido,
|
||||
qta_maxConcessa: qtamax,
|
||||
};
|
||||
|
||||
risult = await Account.updateOne({ _id: account.id }, { $set: paramstoupdate });
|
||||
}
|
||||
}
|
||||
return risult;
|
||||
} catch (e) {
|
||||
console.error('updateAccountCircuitoNazionaleByLimiti', e);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
AccountSchema.statics.canEditAccountAdmins = async function (username, id) {
|
||||
const account = await Account.findOne({ _id: id }).lean();
|
||||
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
if (account) {
|
||||
const circuit = await Circuit.findOne({ _id: account.circuitId }).lean();
|
||||
if (circuit) {
|
||||
return circuit.admins.findIndex((admin) => admin.username === username) >= 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
AccountSchema.statics.addToPeopleOfMyAccount = async function (idapp, username, circuitId, person_username, perm) {
|
||||
@@ -489,11 +717,28 @@ AccountSchema.statics.addToPeopleOfMyAccount = async function (idapp, username,
|
||||
|
||||
// Rimuovi dagli Admin del Account
|
||||
AccountSchema.statics.removeAdminOfAccount = async function (idapp, username, circuitId, person_username, perm) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
return await Circuit.updateOne({ idapp, username, circuitId },
|
||||
{ $pull: { people: { username: { $in: [person_username] } } } });
|
||||
};
|
||||
|
||||
// Rimuovi l'account
|
||||
AccountSchema.statics.removeAccount = async function (accountId) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
return await Circuit.deleteOne({ _id: accountId});
|
||||
};
|
||||
|
||||
AccountSchema.statics.updateSaldoAndTransato_AllAccounts = async function (idapp) {
|
||||
|
||||
const recaccounts = await Account.find({ idapp });
|
||||
|
||||
for (const account of recaccounts) {
|
||||
await account.calcPending();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const Account = mongoose.model('Account', AccountSchema);
|
||||
|
||||
|
||||
@@ -20,6 +20,12 @@ const bookingSchema = new Schema({
|
||||
userId: {
|
||||
type: String,
|
||||
},
|
||||
username: {
|
||||
type: String,
|
||||
},
|
||||
tableType: {
|
||||
type: Number,
|
||||
},
|
||||
id_bookedevent: {
|
||||
type: String,
|
||||
},
|
||||
|
||||
@@ -57,6 +57,10 @@ const CircuitSchema = new Schema({
|
||||
{
|
||||
type: String,
|
||||
},
|
||||
card: // Punti cardinali
|
||||
{
|
||||
type: String,
|
||||
},
|
||||
pub_to_share: {
|
||||
type: Number, // PUB_TO_SHARE_ALL, PUB_TO_SHARE_ONLY_TABLE_FOLLOW
|
||||
},
|
||||
@@ -80,6 +84,9 @@ const CircuitSchema = new Schema({
|
||||
totCircolante: {
|
||||
type: Number,
|
||||
},
|
||||
showAlways: {
|
||||
type: Boolean,
|
||||
},
|
||||
totTransato: {
|
||||
type: Number,
|
||||
},
|
||||
@@ -212,6 +219,10 @@ const CircuitSchema = new Schema({
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
showAlways: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
status: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
@@ -276,12 +287,14 @@ CircuitSchema.statics.getWhatToShow = function (idapp, username) {
|
||||
fido_scoperto_default_grp: 1,
|
||||
qta_max_default_grp: 1,
|
||||
deperimento: 1,
|
||||
showAlways: 1,
|
||||
transactionsEnabled: 1,
|
||||
status: 1,
|
||||
valuta_per_euro: 1,
|
||||
symbol: 1,
|
||||
idCity: 1,
|
||||
strProv: 1,
|
||||
card: 1,
|
||||
link_group: 1,
|
||||
pub_to_share: 1,
|
||||
visibility: 1,
|
||||
@@ -331,6 +344,7 @@ CircuitSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
|
||||
longdescr: 1,
|
||||
regulation: 1,
|
||||
numMembers: 1,
|
||||
showAlways: 1,
|
||||
systemUserId: 1,
|
||||
founderUserId: 1,
|
||||
nome_valuta: 1,
|
||||
@@ -345,6 +359,7 @@ CircuitSchema.statics.getWhatToShow_Unknown = function (idapp, username) {
|
||||
color: 1,
|
||||
idCity: 1,
|
||||
strProv: 1,
|
||||
card: 1,
|
||||
link_group: 1,
|
||||
pub_to_share: 1,
|
||||
visibility: 1,
|
||||
@@ -469,13 +484,40 @@ CircuitSchema.statics.getCircuitByName = async function (idapp, name) {
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getCircuitByProvince = async function (idapp, strProv) {
|
||||
CircuitSchema.statics.getCircuitIdByName = async function (idapp, name) {
|
||||
|
||||
const myfind = {
|
||||
idapp,
|
||||
strProv,
|
||||
name,
|
||||
};
|
||||
|
||||
try {
|
||||
const circuit = await Circuit.findOne(myfind);
|
||||
return (!!circuit ? circuit._id : 0);
|
||||
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getCircuitByProvinceAndCard = async function (idapp, strProv, card) {
|
||||
|
||||
let myfind = {};
|
||||
|
||||
if (card) {
|
||||
myfind = {
|
||||
idapp,
|
||||
strProv,
|
||||
card
|
||||
};
|
||||
} else {
|
||||
myfind = {
|
||||
idapp,
|
||||
strProv,
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
return await Circuit.findOne(myfind);
|
||||
|
||||
@@ -505,59 +547,6 @@ CircuitSchema.statics.deleteCircuit = async function (idapp, usernameOrig, name)
|
||||
return await Circuit.findOneAndRemove({ idapp, name });
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getUserCircuits = async function (idapp, username) {
|
||||
|
||||
try {
|
||||
let aggr1 = [
|
||||
{
|
||||
$match: {
|
||||
idapp, username,
|
||||
$or: [
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'circuits',
|
||||
localField: 'circuitId',
|
||||
foreignField: '_id',
|
||||
as: 'circuit',
|
||||
},
|
||||
},
|
||||
{
|
||||
'$replaceRoot': {
|
||||
'newRoot': {
|
||||
'$mergeObjects': [
|
||||
{
|
||||
'$arrayElemAt': [
|
||||
'$circuit',
|
||||
0,
|
||||
],
|
||||
},
|
||||
'$$ROOT',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
/*
|
||||
{
|
||||
$project: {
|
||||
"circuit.name": 1,
|
||||
},
|
||||
},
|
||||
|
||||
*/
|
||||
];
|
||||
|
||||
ris = await this.aggregate(aggr1);
|
||||
|
||||
return ris;
|
||||
} catch (e) {
|
||||
console.error('e', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getUsersSingleCircuit = async function (idapp, username, circuitname, circuitId) {
|
||||
|
||||
@@ -658,6 +647,8 @@ CircuitSchema.statics.getCircolanteSingolaTransaz = function (accountorigTable,
|
||||
|
||||
CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig, extrarec) {
|
||||
|
||||
const { User } = require('../models/user');
|
||||
|
||||
let ris = {
|
||||
result: false,
|
||||
cansend: true,
|
||||
@@ -676,8 +667,30 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
|
||||
if (circuittable) {
|
||||
const myqty = Math.abs(extrarec.qty);
|
||||
|
||||
const accountdestTable = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, circuittable._id, true, extrarec.groupdest, extrarec.contoComDest);
|
||||
const accountorigTable = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, circuittable._id, true, extrarec.grouporig, extrarec.contoComOrig);
|
||||
const esisteDest = await Account.isExistAccountByUsernameAndCircuitId(idapp, extrarec.dest, circuittable._id, extrarec.groupdest, extrarec.contoComDest);
|
||||
|
||||
if (!esisteDest) {
|
||||
// Fallo entrare anche sul Circuito (oltre ad aver creato l'Account).
|
||||
await User.addCircuitToUser(idapp, usernameOrig, extrarec.circuitname, false, extrarec.groupdest, extrarec.contoComDest);
|
||||
}
|
||||
if (extrarec.dest) {
|
||||
const foundIfAlreadyCircuit = await User.ifAlreadyInCircuit(idapp, extrarec.dest, extrarec.circuitname);
|
||||
if (!foundIfAlreadyCircuit) {
|
||||
update = {
|
||||
$push: {
|
||||
'profile.mycircuits': {
|
||||
circuitname: extrarec.circuitname,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
};
|
||||
const ris = await User.updateOne({ idapp, username: extrarec.dest }, update);
|
||||
}
|
||||
}
|
||||
|
||||
const accountdestTable = await Account.getAccountByUsernameAndCircuitId(idapp, extrarec.dest, circuittable._id, true, false, extrarec.groupdest, extrarec.contoComDest);
|
||||
const accountorigTable = await Account.getAccountByUsernameAndCircuitId(idapp, usernameOrig, circuittable._id, true, true, extrarec.grouporig, extrarec.contoComOrig);
|
||||
|
||||
|
||||
const circolantePrec = this.getCircolanteSingolaTransaz(accountorigTable, accountdestTable);
|
||||
|
||||
@@ -687,7 +700,7 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
|
||||
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_FIDO', usernameOrig);
|
||||
}
|
||||
|
||||
if (accountdestTable.saldo + myqty > accountorigTable.qta_maxConcessa) {
|
||||
if (accountdestTable.saldo + myqty > accountdestTable.qta_maxConcessa) {
|
||||
ris.cansend = false;
|
||||
ris.errormsg = i18n.__('CIRCUIT_AMOUNT_EXCEED_QTAMAX', extrarec.dest);
|
||||
}
|
||||
@@ -723,10 +736,11 @@ CircuitSchema.statics.sendCoins = async function (onlycheck, idapp, usernameOrig
|
||||
if (extrarec.contoComOrig) {
|
||||
orig = extrarec.contoComOrig + ' (' + usernameOrig + ')'
|
||||
}
|
||||
let dest = (extrarec.dest ? extrarec.dest : '') + (extrarec.groupDest ? extrarec.groupDest : '') + (extrarec.contoComDest ? extrarec.contoComDest : '');
|
||||
let dest = (extrarec.dest ? extrarec.dest : '') + (extrarec.groupdest ? extrarec.groupdest : '') + (extrarec.contoComDest ? extrarec.contoComDest : '');
|
||||
|
||||
ris.result = true;
|
||||
let msg = 'Inviate Monete da ' + orig + ' a ' + dest + ' ' + myqty + ' ' + circuittable.symbol + ' [causale: ' + extrarec.causal + `] [Saldo ${orig}: ` + extrarec.saldoOrig + ' ' + circuittable.symbol + '] ' + ` [Saldo ${dest}: ` + extrarec.saldoDest + ' ' + circuittable.symbol + ']';
|
||||
let msg = '[<b>' + circuittable.name + '</b>]: Inviate Monete da ' + orig + ' a ' + dest + ' ' + myqty + ' ' + circuittable.symbol + ' [causale: ' + extrarec.causal +
|
||||
`]\nSaldi:\n${orig}: ` + extrarec.saldoOrig + ' ' + circuittable.symbol + '] ' + `\n${dest}: ` + extrarec.saldoDest + ' ' + circuittable.symbol + ']';
|
||||
console.log(msg);
|
||||
|
||||
ris.useraccounts = await Account.getUserAccounts(idapp, usernameOrig);
|
||||
@@ -817,7 +831,13 @@ CircuitSchema.statics.updateData = async function (idapp, circuitname) {
|
||||
|
||||
const ris = await User.aggregate(aggr1);
|
||||
|
||||
let numMembers = ris ? ris[0].count : 0;
|
||||
let numMembers = 0;
|
||||
try {
|
||||
numMembers = ris && tools.isArray(ris) ? ris[0].count : 0;
|
||||
} catch (e) {
|
||||
|
||||
};
|
||||
|
||||
|
||||
let paramstoupdate = {
|
||||
numMembers: numMembers,
|
||||
@@ -890,67 +910,90 @@ CircuitSchema.statics.setstrProvByIdCityCircuits = async function (idapp) {
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, valmax) {
|
||||
|
||||
ris = await Circuit.updateMany({ idapp, contocom: { "$nin": [null, ""] } },
|
||||
CircuitSchema.statics.AbilitaTuttiCircuiti = async function (idapp) {
|
||||
|
||||
const ris = await Circuit.updateMany({ idapp },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
fido_scoperto_default: valmin,
|
||||
qta_max_default: valmax,
|
||||
transactionsEnabled: true
|
||||
}
|
||||
});
|
||||
|
||||
return ris;
|
||||
};
|
||||
|
||||
CircuitSchema.statics.AzzeraRegolamentiTuttiCircuiti = async function (idapp) {
|
||||
|
||||
const ris = await Circuit.updateMany({ idapp },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
regulation: '',
|
||||
}
|
||||
});
|
||||
|
||||
return ris;
|
||||
};
|
||||
|
||||
// Imposta a tutti i Conti Personali, i seguenti minimi e massimi
|
||||
CircuitSchema.statics.SetDefMinMaxPersonali = async function (idapp, valmin, valmax) {
|
||||
CircuitSchema.statics.SetDefMinMaxPersonali = async function (idapp, valmin, valmax, circuitId) {
|
||||
|
||||
ris = await Circuit.updateMany({ idapp },
|
||||
{
|
||||
$set:
|
||||
if (circuitId) {
|
||||
const ris = await Circuit.updateOne({ _id: circuitId },
|
||||
{
|
||||
fido_scoperto_default: valmin,
|
||||
qta_max_default: valmax,
|
||||
}
|
||||
});
|
||||
$set:
|
||||
{
|
||||
fido_scoperto_default: valmin,
|
||||
qta_max_default: valmax,
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
const ris = await Circuit.updateMany({ idapp },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
fido_scoperto_default: valmin,
|
||||
qta_max_default: valmax,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Imposta a tutti i Conti Collettivi, i seguenti minimi e massimi
|
||||
CircuitSchema.statics.replaceAllCircuits = async function (idapp) {
|
||||
CircuitSchema.statics.getCircuitMyProvince = async function (idapp, username) {
|
||||
const { User } = require('../models/user');
|
||||
|
||||
const globalTables = require('../tools/globalTables');
|
||||
const myuser = await User.getUserByUsername(idapp, username);
|
||||
|
||||
const arrcircuit = await Circuit.find({ idapp }).lean();
|
||||
try {
|
||||
const circuit = await this.getCircuitByProvinceAndCard(idapp, myuser.profile.resid_province, myuser.profile.resid_card);
|
||||
|
||||
let num = 0;
|
||||
for (const circuit of arrcircuit) {
|
||||
if (circuit.strProv) {
|
||||
let nomeprovincia = await Province.getStrProvinceByProv(circuit.strProv);
|
||||
let newname = 'Circuito RIS ' + nomeprovincia;
|
||||
|
||||
if (newname !== circuit.name) {
|
||||
ris = await globalTables.ReplaceCircuitName(idapp, circuit.name, newname);
|
||||
|
||||
if (ris)
|
||||
num++;
|
||||
if (circuit) {
|
||||
if (await User.ifAlreadyInCircuit(idapp, username, circuit.name)) {
|
||||
return circuit.name;
|
||||
}
|
||||
}
|
||||
|
||||
return '[nessun Circuito]';
|
||||
|
||||
} catch (e) {
|
||||
console.error('Error', e);
|
||||
}
|
||||
|
||||
console.log('*** Replaced Circuits ', num);
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, province) {
|
||||
// Imposta a tutti i Conti Collettivi, i seguenti minimi e massimi
|
||||
CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, province, card) {
|
||||
const { User } = require('../models/user');
|
||||
|
||||
const useradmin = tools.USER_ADMIN_CIRCUITS;
|
||||
|
||||
let myrec = null;
|
||||
try {
|
||||
const circuit = await this.getCircuitByProvince(idapp, province);
|
||||
const circuit = await this.getCircuitByProvinceAndCard(idapp, province, card);
|
||||
|
||||
const nomeprovincia = await Province.getStrProvinceByProv(province);
|
||||
|
||||
@@ -960,11 +1003,12 @@ CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, prov
|
||||
name: 'Circuito RIS ' + nomeprovincia,
|
||||
path: 'ris' + tools.convertSpaces_ToUScore(nomeprovincia.toLowerCase()),
|
||||
strProv: province,
|
||||
card,
|
||||
photos: [],
|
||||
admins: [],
|
||||
color: '#ff5500',
|
||||
deperimento: false,
|
||||
transactionsEnabled: false,
|
||||
showAlways: false,
|
||||
transactionsEnabled: true, // Abilita cmq il circuito dall'inizio
|
||||
status: shared_consts.CIRCUIT_STATUS.FASE1_CREAZIONE_GRUPPO,
|
||||
symbol: 'RIS',
|
||||
fido_scoperto_default: 100,
|
||||
@@ -1006,17 +1050,173 @@ CircuitSchema.statics.createCircuitIfNotExist = async function (req, idapp, prov
|
||||
return myrec;
|
||||
|
||||
};
|
||||
CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, valmax) {
|
||||
|
||||
ris = await Circuit.updateMany({ idapp },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
fido_scoperto_default_grp: valmin,
|
||||
qta_max_default_grp: valmax,
|
||||
CircuitSchema.statics.getListAdmins = async function (idapp, circuitname) {
|
||||
|
||||
let arr = await Circuit.findOne({
|
||||
idapp,
|
||||
name: circuitname,
|
||||
$or: [
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, { admins: 1 }).lean();
|
||||
|
||||
let mystr = '';
|
||||
|
||||
if (arr) {
|
||||
for (const admin of arr.admins) {
|
||||
mystr += await tools.getAhref(admin.username, await tools.getLinkUserTelegram(idapp, admin.username)) + ', ';
|
||||
}
|
||||
}
|
||||
|
||||
return { str: mystr, num: arr ? arr.admins.length : 0 };
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.isAdminCircuit = async function (idapp, circuitname, username) {
|
||||
|
||||
let arr = await Circuit.findOne({
|
||||
idapp,
|
||||
name: circuitname,
|
||||
$or: [
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}, { admins: 1 }).lean();
|
||||
|
||||
if (arr) {
|
||||
for (const admin of arr.admins) {
|
||||
if (admin.username === username)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.getListCircuitsByUsername = async function (idapp, username, groupname) {
|
||||
|
||||
let mystr = '';
|
||||
const { User } = require('../models/user');
|
||||
const myuser = await User.getUserByUsername(idapp, username);
|
||||
|
||||
const useraccounts = await Account.getUserAccounts(idapp, username);
|
||||
const groupsaccounts = await Account.getGroupAccounts(idapp, groupname);
|
||||
|
||||
|
||||
|
||||
for (let account of useraccounts) {
|
||||
if (myuser.profile.mycircuits.find((rec) => (rec.circuitname === account.circuit.name))) {
|
||||
if (account.groupname === '') {
|
||||
mystr += '\n👉🏻 ' + account.circuit.name + '\n';
|
||||
mystr += ' [Saldo: ' + account.saldo + ' RIS, ';
|
||||
mystr += ' Fido: ' + account.fidoConcesso + ' RIS, ';
|
||||
mystr += ' Transato: ' + account.totTransato + ' RIS]';
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (let account of groupsaccounts) {
|
||||
if (myuser.profile.mycircuits.find((rec) => (rec.circuitname === account.circuit.name))) {
|
||||
mystr += '\n GRUPPO: 👉🏻 <b>' + account.groupname + '</b> in ' + account.circuit.name + '\n';
|
||||
mystr += ' [Saldo: ' + account.saldo + ' RIS, ';
|
||||
mystr += ' Fido: ' + account.fidoConcesso + ' RIS, ';
|
||||
mystr += ' Transato: ' + account.totTransato + ' RIS]';
|
||||
}
|
||||
}
|
||||
|
||||
if (!mystr) {
|
||||
mystr = '[Nessun Circuito]';
|
||||
}
|
||||
|
||||
return mystr;
|
||||
|
||||
};
|
||||
|
||||
CircuitSchema.statics.SetDefMinMaxCollettivi = async function (idapp, valmin, valmax, circuitId) {
|
||||
|
||||
if (circuitId) {
|
||||
const ris = await Circuit.updateOne({ _id: circuitId },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
fido_scoperto_default_grp: valmin,
|
||||
qta_max_default_grp: valmax,
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const ris = await Circuit.updateMany({ idapp },
|
||||
{
|
||||
$set:
|
||||
{
|
||||
fido_scoperto_default_grp: valmin,
|
||||
qta_max_default_grp: valmax,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
CircuitSchema.statics.setFido = async function (idapp, username, circuitName, groupname) {
|
||||
|
||||
mycircuit = await Circuit.findOne({ idapp, name: circuitName });
|
||||
if (mycircuit) {
|
||||
const circuitId = mycircuit._id;
|
||||
let account = null;
|
||||
let fido = 0;
|
||||
let qtamax = 0;
|
||||
|
||||
if (mycircuit.showAlways) {
|
||||
|
||||
const { User } = require('../models/user');
|
||||
|
||||
const myuser = await User.getUserByUsername(idapp, username);
|
||||
|
||||
// Se è il circuito Nazionale, allora prende i valori dal proprio Circuito Locale:
|
||||
const accountsuser = await Account.getUserAccounts(idapp, username);
|
||||
if (accountsuser) {
|
||||
// Se lo trovo della mia provincia, prendo quello
|
||||
account = accountsuser.find((account) => account.circuit.strProv === myuser.profile.resid_province && account.circuit.card === myuser.profile.resid_card)
|
||||
if (!account && accountsuser.length > 0) {
|
||||
// Se non lo trovo, prendo il primo in cui sono entrato !
|
||||
account = accountsuser[0];
|
||||
}
|
||||
if (account && account.circuit) {
|
||||
if (groupname) {
|
||||
qtamax = account.circuit.qta_max_default_grp * shared_consts.CIRCUIT_CFG.MULT_FIDO_GROUP;
|
||||
fido = account.circuit.fido_scoperto_default_grp * shared_consts.CIRCUIT_CFG.MULT_FIDO_GROUP;
|
||||
} else {
|
||||
qtamax = account.circuit.qta_max_default * shared_consts.CIRCUIT_CFG.MULT_FIDO_USER;
|
||||
fido = account.circuit.fido_scoperto_default * shared_consts.CIRCUIT_CFG.MULT_FIDO_USER;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Se non ho Circuiti locali, non applico il Fido !
|
||||
return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
account = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, true, true, groupname, '');
|
||||
if (groupname)
|
||||
fido = mycircuit.fido_scoperto_default_grp;
|
||||
else
|
||||
fido = mycircuit.fido_scoperto_default;
|
||||
}
|
||||
|
||||
if (account) {
|
||||
if (qtamax > 0) {
|
||||
await Account.updateQtaMax(idapp, username, groupname, circuitId, qtamax);
|
||||
}
|
||||
|
||||
const ris = await Account.updateFido(idapp, username, groupname, circuitId, fido);
|
||||
if (ris) {
|
||||
return { qta_maxConcessa: qtamax, fidoConcesso: fido };
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const Circuit = mongoose.model('Circuit', CircuitSchema);
|
||||
|
||||
@@ -77,6 +77,17 @@ CitySchema.statics.getProvinceByIdCity = async function(idcity) {
|
||||
return '';
|
||||
}
|
||||
|
||||
CitySchema.statics.getCircuitNameBystrProv = async function(strProv) {
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
const myrec = await Circuit.findOne({strProv}).lean();
|
||||
if (myrec) {
|
||||
return myrec.name;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
CitySchema.statics.getRegionByIdCity = async function(idcity) {
|
||||
const myrec = await City.findOne({_id: idcity}).lean();
|
||||
if (myrec) {
|
||||
|
||||
@@ -47,9 +47,11 @@ const MovementSchema = new Schema({
|
||||
},
|
||||
causal: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
residual: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
expiringDate: {
|
||||
type: Date,
|
||||
@@ -111,9 +113,9 @@ MovementSchema.statics.addMov = async function (idapp, accountFromIdTable, accou
|
||||
|
||||
if (mymov) {
|
||||
// Update saldo dell'Account
|
||||
await Account.addtoSaldo(accountToIdTable, amount);
|
||||
await Account.addtoSaldo(accountToIdTable, amount, true);
|
||||
|
||||
await Account.addtoSaldo(accountFromIdTable, -amount);
|
||||
await Account.addtoSaldo(accountFromIdTable, -amount, false);
|
||||
|
||||
return mymov;
|
||||
}
|
||||
@@ -128,7 +130,7 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username
|
||||
if (!circuitId) {
|
||||
return [];
|
||||
}
|
||||
const myaccount = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, false, groupname, contocom);
|
||||
const myaccount = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, false, true, groupname, contocom);
|
||||
|
||||
if (myaccount) {
|
||||
|
||||
@@ -206,6 +208,7 @@ MovementSchema.statics.getQueryMovsByCircuitId = async function (idapp, username
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
$lookup: {
|
||||
from: 'circuits',
|
||||
@@ -678,7 +681,6 @@ MovementSchema.statics.checkIfCoinsAlreadySent = async function (notifId) {
|
||||
|
||||
try {
|
||||
const rec = await MyMovement.findOne({ notifId }, { _id: 1 });
|
||||
|
||||
return !!rec;
|
||||
|
||||
} catch (e) {
|
||||
|
||||
@@ -7,6 +7,11 @@ mongoose.level = 'F';
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const { Reaction } = require('./reaction');
|
||||
|
||||
const tableModel = shared_consts.TABLES_MYBACHECAS;
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
@@ -14,92 +19,112 @@ mongoose.plugin(schema => {
|
||||
});
|
||||
|
||||
const MyBachecaSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
idSector: {
|
||||
type: Number,
|
||||
},
|
||||
idSkill: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
idStatusSkill: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
idContribType: [
|
||||
{
|
||||
...{
|
||||
_id: {
|
||||
type: String,
|
||||
}],
|
||||
idCity: [
|
||||
{
|
||||
default: function () {
|
||||
return new ObjectID().toString();
|
||||
},
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
groupname: { type: String },
|
||||
idSector: {
|
||||
type: Number,
|
||||
}],
|
||||
dateTimeStart: {
|
||||
type: Date,
|
||||
},
|
||||
dateTimeEnd: {
|
||||
type: Date,
|
||||
},
|
||||
numLevel: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
adType: {
|
||||
type: Number,
|
||||
},
|
||||
photos: [
|
||||
{
|
||||
imagefile: {
|
||||
},
|
||||
idSkill: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
idStatusSkill: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
idContribType: [
|
||||
{
|
||||
type: String,
|
||||
},
|
||||
alt: {
|
||||
type: String,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
}],
|
||||
note: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
//**ADDFIELD_MYBACHECAS
|
||||
website: {
|
||||
type: String,
|
||||
},
|
||||
date_created: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
},
|
||||
date_updated: {
|
||||
type: Date,
|
||||
}],
|
||||
idCity: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
dateTimeStart: {
|
||||
type: Date,
|
||||
},
|
||||
dateTimeEnd: {
|
||||
type: Date,
|
||||
},
|
||||
organisedBy: {
|
||||
type: String
|
||||
},
|
||||
contact_phone: {
|
||||
type: String
|
||||
},
|
||||
contact_telegram: {
|
||||
type: String
|
||||
},
|
||||
address: {
|
||||
type: String,
|
||||
},
|
||||
min_partecip: {
|
||||
type: Number,
|
||||
},
|
||||
max_partecip: {
|
||||
type: Number,
|
||||
},
|
||||
link_maplocation: {
|
||||
type: String,
|
||||
},
|
||||
contribstr: {
|
||||
type: String,
|
||||
},
|
||||
numLevel: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
adType: {
|
||||
type: Number,
|
||||
},
|
||||
photos: [
|
||||
{
|
||||
imagefile: {
|
||||
type: String,
|
||||
},
|
||||
alt: {
|
||||
type: String,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
}],
|
||||
note: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
//**ADDFIELD_MYBACHECAS
|
||||
website: {
|
||||
type: String,
|
||||
},
|
||||
date_created: {
|
||||
type: Date,
|
||||
},
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
},
|
||||
...Reaction.getFieldsForReactions()
|
||||
});
|
||||
|
||||
MyBachecaSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await MyBacheca.findOne().limit(1).sort({ _id: -1 });
|
||||
if (!!myrec) {
|
||||
if (myrec._doc._id === 0)
|
||||
this._id = 1;
|
||||
else
|
||||
this._id = myrec._doc._id + 1;
|
||||
|
||||
} else {
|
||||
this._id = 1;
|
||||
}
|
||||
|
||||
this.date_created = new Date();
|
||||
if (!this.date_created)
|
||||
this.date_created = new Date();
|
||||
}
|
||||
|
||||
next();
|
||||
@@ -144,37 +169,7 @@ MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
lk_FF: '_id',
|
||||
lk_as: 'user',
|
||||
af_objId_tab: 'myId',
|
||||
lk_proj: {
|
||||
idSkill: 1,
|
||||
idSubSkill: 1,
|
||||
MyBacheca: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
dateTimeStart: 1,
|
||||
dateTimeEnd: 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
//**ADDFIELD_MYBACHECAS
|
||||
website: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
},
|
||||
lk_proj: shared_consts.getProjectForAll({}, tableModel),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -186,28 +181,24 @@ MyBachecaSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
const MyBacheca = this;
|
||||
|
||||
const query = [
|
||||
|
||||
let myparsid = {
|
||||
'_id': id,
|
||||
idapp,
|
||||
};
|
||||
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$and': [
|
||||
{
|
||||
'_id': parseInt(id),
|
||||
},
|
||||
],
|
||||
$match:
|
||||
myparsid,
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
desc: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
'$match': {
|
||||
'idapp': idapp,
|
||||
},
|
||||
},
|
||||
{
|
||||
'$sort': {
|
||||
'desc': 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
'$addFields': {
|
||||
$addFields: {
|
||||
'myId1': {
|
||||
'$toObjectId': '$userId',
|
||||
},
|
||||
@@ -237,39 +228,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recSkill': 1,
|
||||
'sector': 1,
|
||||
'idSector': 1,
|
||||
'idSkill': 1,
|
||||
'idSubSkill': 1,
|
||||
'idStatusSkill': 1,
|
||||
'idContribType': 1,
|
||||
dateTimeStart: 1,
|
||||
dateTimeEnd: 1,
|
||||
'idCity': 1,
|
||||
pub_to_share: 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MYBACHECAS
|
||||
'descr': 1,
|
||||
'date_created': 1,
|
||||
'date_updated': 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
'$project': shared_consts.getProjectForAll({}, tableModel),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
@@ -295,39 +254,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recSkill': 1,
|
||||
'sector': 1,
|
||||
'idSector': 1,
|
||||
'idSkill': 1,
|
||||
'idSubSkill': 1,
|
||||
'idStatusSkill': 1,
|
||||
'idContribType': 1,
|
||||
dateTimeStart: 1,
|
||||
dateTimeEnd: 1,
|
||||
'idCity': 1,
|
||||
pub_to_share: 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MYBACHECAS
|
||||
'descr': 1,
|
||||
'date_created': 1,
|
||||
'date_updated': 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
'$project': shared_consts.getProjectForAll({}, tableModel),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
@@ -353,40 +280,22 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recSkill': 1,
|
||||
'sector': 1,
|
||||
'idSector': 1,
|
||||
'idSkill': 1,
|
||||
'idSubSkill': 1,
|
||||
'idStatusSkill': 1,
|
||||
'idContribType': 1,
|
||||
dateTimeStart: 1,
|
||||
dateTimeEnd: 1,
|
||||
'idCity': 1,
|
||||
pub_to_share: 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MYBACHECAS
|
||||
'descr': 1,
|
||||
'date_created': 1,
|
||||
'date_updated': 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
$lookup: {
|
||||
'from': 'mygroups',
|
||||
'localField': 'groupname',
|
||||
'foreignField': 'groupname',
|
||||
'as': 'mygrp',
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: {
|
||||
path: '$mygrp',
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': shared_consts.getProjectForAll({}, tableModel),
|
||||
},
|
||||
/*{
|
||||
'$lookup': {
|
||||
'from': 'subskills',
|
||||
@@ -411,39 +320,7 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recSkill': 1,
|
||||
'sector': 1,
|
||||
'idSector': 1,
|
||||
'idSkill': 1,
|
||||
// 'idSubSkill': 1,
|
||||
'idStatusSkill': 1,
|
||||
'idContribType': 1,
|
||||
dateTimeStart: 1,
|
||||
dateTimeEnd: 1,
|
||||
'idCity': 1,
|
||||
pub_to_share: 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MYBACHECAS
|
||||
'descr': 1,
|
||||
'date_created': 1,
|
||||
'date_updated': 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
'$project': shared_consts.getProjectForAll({}, tableModel),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
@@ -468,48 +345,29 @@ MyBachecaSchema.statics.getMyRecById = function (idapp, id) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recSkill': 1,
|
||||
'sector': 1,
|
||||
'idSector': 1,
|
||||
'idSkill': 1,
|
||||
// 'idSubSkill': 1,
|
||||
'idStatusSkill': 1,
|
||||
'idContribType': 1,
|
||||
dateTimeStart: 1,
|
||||
dateTimeEnd: 1,
|
||||
'idCity': 1,
|
||||
pub_to_share: 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MYBACHECAS
|
||||
'descr': 1,
|
||||
'date_created': 1,
|
||||
'date_updated': 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
try {
|
||||
let numtab = tools.getNumTabByTable(shared_consts.TABLES_MYBACHECAS);
|
||||
|
||||
let objadd = tools.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
|
||||
query = [...query, ...objadd.query];
|
||||
|
||||
const toadd = {
|
||||
$project: shared_consts.getProjectForAll(objadd.proj, tableModel),
|
||||
};
|
||||
|
||||
query = [...query, { ...toadd }];
|
||||
} catch (e) {
|
||||
console.error('e', e);
|
||||
}
|
||||
|
||||
return MyBacheca.aggregate(query).then((rec) => {
|
||||
return rec ? rec[0] : null;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
MyBachecaSchema.statics.getCompleteRecord = function (idapp, id) {
|
||||
const MyBacheca = this;
|
||||
|
||||
|
||||
@@ -143,6 +143,7 @@ const MyElemSchema = new Schema({
|
||||
anim: animation,
|
||||
active: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
class: {
|
||||
type: String,
|
||||
|
||||
@@ -6,7 +6,11 @@ mongoose.level = 'F';
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
const { Reaction } = require('./reaction');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
@@ -14,104 +18,96 @@ mongoose.plugin(schema => {
|
||||
});
|
||||
|
||||
const MyGoodSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
userId: {type: Schema.Types.ObjectId, ref: 'User'},
|
||||
idSectorGood: {
|
||||
type: Number,
|
||||
},
|
||||
idGood: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
idShipping: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
|
||||
idContribType: [
|
||||
{
|
||||
...{
|
||||
_id: {
|
||||
type: String,
|
||||
}],
|
||||
idCity: [
|
||||
{
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
idSectorGood: {
|
||||
type: Number,
|
||||
},
|
||||
idGood: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
idShipping: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
|
||||
idContribType: [
|
||||
{
|
||||
type: String,
|
||||
}],
|
||||
idCity: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
pub_to_share: {
|
||||
type: Number, // PUB_TO_SHARE_ALL, PUB_TO_SHARE_ONLY_TABLE_FOLLOW
|
||||
},
|
||||
numLevel: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
adType: {
|
||||
type: Number,
|
||||
},
|
||||
otherfilters: [{
|
||||
type: Number,
|
||||
}],
|
||||
pub_to_share: {
|
||||
type: Number, // PUB_TO_SHARE_ALL, PUB_TO_SHARE_ONLY_TABLE_FOLLOW
|
||||
},
|
||||
numLevel: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
adType: {
|
||||
type: Number,
|
||||
},
|
||||
otherfilters: [{
|
||||
type: Number,
|
||||
}],
|
||||
photos: [
|
||||
{
|
||||
imagefile: {
|
||||
type: String,
|
||||
},
|
||||
alt: {
|
||||
type: String,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
}],
|
||||
note: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
//**ADDFIELD_MyGood
|
||||
website: {
|
||||
type: String,
|
||||
},
|
||||
date_created: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
},
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
photos: [
|
||||
{
|
||||
imagefile: {
|
||||
type: String,
|
||||
},
|
||||
alt: {
|
||||
type: String,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
}],
|
||||
note: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
//**ADDFIELD_MyGood
|
||||
website: {
|
||||
type: String,
|
||||
},
|
||||
date_created: {
|
||||
type: Date,
|
||||
},
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
},
|
||||
...Reaction.getFieldsForReactions()
|
||||
});
|
||||
|
||||
MyGoodSchema.pre('save', async function(next) {
|
||||
MyGoodSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await MyGood.findOne().limit(1).sort({_id: -1});
|
||||
if (!!myrec) {
|
||||
if (myrec._doc._id === 0)
|
||||
this._id = 1;
|
||||
else
|
||||
this._id = myrec._doc._id + 1;
|
||||
|
||||
} else {
|
||||
this._id = 1;
|
||||
}
|
||||
|
||||
this.date_created = new Date();
|
||||
if (!this.date_created)
|
||||
this.date_created = new Date();
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
MyGoodSchema.statics.findAllIdApp = async function(idapp) {
|
||||
MyGoodSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const MyGood = this;
|
||||
|
||||
const query = [
|
||||
{$match: {idapp}},
|
||||
{$sort: {descr: 1}},
|
||||
{ $match: { idapp } },
|
||||
{ $sort: { descr: 1 } },
|
||||
];
|
||||
|
||||
return await MyGood.aggregate(query).then((arrrec) => {
|
||||
@@ -120,21 +116,21 @@ MyGoodSchema.statics.findAllIdApp = async function(idapp) {
|
||||
|
||||
};
|
||||
|
||||
MyGoodSchema.statics.getFieldsForSearch = function() {
|
||||
MyGoodSchema.statics.getFieldsForSearch = function () {
|
||||
return [];
|
||||
};
|
||||
|
||||
MyGoodSchema.statics.getFieldsLastForSearch = function() {
|
||||
MyGoodSchema.statics.getFieldsLastForSearch = function () {
|
||||
return [
|
||||
{field: 'note', type: tools.FieldType.string},
|
||||
{field: 'descr', type: tools.FieldType.string},
|
||||
{field: 'recGood.descr', type: tools.FieldType.string},
|
||||
{field: 'MyGood.descr', type: tools.FieldType.string},
|
||||
{ field: 'note', type: tools.FieldType.string },
|
||||
{ field: 'descr', type: tools.FieldType.string },
|
||||
{ field: 'recGood.descr', type: tools.FieldType.string },
|
||||
{ field: 'MyGood.descr', type: tools.FieldType.string },
|
||||
];
|
||||
};
|
||||
|
||||
|
||||
MyGoodSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
MyGoodSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
params.fieldsearch_last = this.getFieldsLastForSearch();
|
||||
|
||||
@@ -145,60 +141,27 @@ MyGoodSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
lk_FF: '_id',
|
||||
lk_as: 'user',
|
||||
af_objId_tab: 'myId',
|
||||
lk_proj: {
|
||||
idGood: 1,
|
||||
idShipping: 1,
|
||||
MyGood: 1,
|
||||
idStatusGood: 1,
|
||||
idContribType: 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
otherfilters: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MyGood
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
lk_proj: this.getProject(),
|
||||
},
|
||||
};
|
||||
|
||||
params = {...params, ...otherparams};
|
||||
params = { ...params, ...otherparams };
|
||||
|
||||
return tools.executeQueryTable(this, idapp, params, user);
|
||||
};
|
||||
|
||||
MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
MyGoodSchema.statics.getMyRecById = function (idapp, idGood) {
|
||||
const MyGood = this;
|
||||
|
||||
const query = [
|
||||
let myparsid = {
|
||||
'_id': idGood,
|
||||
idapp,
|
||||
};
|
||||
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$and': [
|
||||
{
|
||||
'_id': parseInt(idGood),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
'$match': {
|
||||
'idapp': idapp,
|
||||
},
|
||||
'$match':
|
||||
myparsid,
|
||||
},
|
||||
{
|
||||
'$sort': {
|
||||
@@ -236,38 +199,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recGood': 1,
|
||||
'sectorGood': 1,
|
||||
'idSectorGood': 1,
|
||||
'idGood': 1,
|
||||
'idShipping': 1,
|
||||
'idStatusGood': 1,
|
||||
'idContribType': 1,
|
||||
'idCity': 1,
|
||||
pub_to_share: 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
otherfilters: 1,
|
||||
'photos': 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MyGood
|
||||
'descr': 1,
|
||||
'date_created': 1,
|
||||
'date_updated': 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
$project: this.getProject(),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
@@ -293,38 +225,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recGood': 1,
|
||||
'sectorGood': 1,
|
||||
'idSectorGood': 1,
|
||||
'idGood': 1,
|
||||
'idShipping': 1,
|
||||
'idStatusGood': 1,
|
||||
'idContribType': 1,
|
||||
'idCity': 1,
|
||||
pub_to_share: 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
otherfilters: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MyGood
|
||||
'descr': 1,
|
||||
'date_created': 1,
|
||||
'date_updated': 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
$project: this.getProject(),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
@@ -351,38 +252,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recGood': 1,
|
||||
'sectorGood': 1,
|
||||
'idSectorGood': 1,
|
||||
'idGood': 1,
|
||||
'idShipping': 1,
|
||||
'idStatusGood': 1,
|
||||
'idContribType': 1,
|
||||
'idCity': 1,
|
||||
pub_to_share: 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
otherfilters: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MyGood
|
||||
'descr': 1,
|
||||
'date_created': 1,
|
||||
'date_updated': 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
$project: this.getProject(),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
@@ -408,38 +278,7 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recGood': 1,
|
||||
'sectorGood': 1,
|
||||
'idSectorGood': 1,
|
||||
'idGood': 1,
|
||||
'idShipping': 1,
|
||||
'idStatusGood': 1,
|
||||
'idContribType': 1,
|
||||
'idCity': 1,
|
||||
pub_to_share: 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
otherfilters: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MyGood
|
||||
'descr': 1,
|
||||
'date_created': 1,
|
||||
'date_updated': 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
$project: this.getProject(),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
@@ -464,55 +303,49 @@ MyGoodSchema.statics.getMyRecById = function(idapp, idGood) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recGood': 1,
|
||||
'sectorGood': 1,
|
||||
'idSectorGood': 1,
|
||||
'idGood': 1,
|
||||
'idShipping': 1,
|
||||
'idStatusGood': 1,
|
||||
'idContribType': 1,
|
||||
'idCity': 1,
|
||||
pub_to_share: 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
otherfilters: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MyGood
|
||||
'descr': 1,
|
||||
'date_created': 1,
|
||||
'date_updated': 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
let numtab = tools.getNumTabByTable(shared_consts.TABLES_MYGOODS);
|
||||
|
||||
const objadd = tools.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
|
||||
query = [...query, ...objadd.query];
|
||||
|
||||
const toadd = {
|
||||
$project: this.getProject(objadd.proj),
|
||||
};
|
||||
|
||||
query = [...query, { ...toadd }];
|
||||
|
||||
return MyGood.aggregate(query).then((rec) => {
|
||||
return rec ? rec[0] : null;
|
||||
});
|
||||
};
|
||||
|
||||
MyGoodSchema.statics.getCompleteRecord = function(idapp, id) {
|
||||
MyGoodSchema.statics.getCompleteRecord = function (idapp, id) {
|
||||
const MyGood = this;
|
||||
|
||||
return MyGood.getMyRecById(idapp, id);
|
||||
|
||||
};
|
||||
|
||||
MyGoodSchema.statics.getProject = function () {
|
||||
let proj = {
|
||||
'recGood': 1,
|
||||
'sectorGood': 1,
|
||||
'idSectorGood': 1,
|
||||
'idGood': 1,
|
||||
'idShipping': 1,
|
||||
'idStatusGood': 1,
|
||||
//**ADDFIELD_MYGOOD
|
||||
|
||||
};
|
||||
|
||||
const proj_add = shared_consts.getProjectForAll()
|
||||
|
||||
return Object.assign({}, proj, proj_add);
|
||||
|
||||
}
|
||||
|
||||
const MyGood = mongoose.model('MyGood', MyGoodSchema);
|
||||
|
||||
module.exports = {MyGood};
|
||||
module.exports = { MyGood };
|
||||
|
||||
@@ -15,7 +15,10 @@ mongoose.plugin(schema => {
|
||||
|
||||
const MyGroupSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
type: String,
|
||||
default: function () {
|
||||
return new ObjectID().toString();
|
||||
},
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
@@ -144,18 +147,8 @@ MyGroupSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
|
||||
MyGroupSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await MyGroup.findOne().limit(1).sort({ _id: -1 });
|
||||
if (!!myrec) {
|
||||
if (myrec._doc._id === 0)
|
||||
this._id = 1;
|
||||
else
|
||||
this._id = myrec._doc._id + 1;
|
||||
|
||||
} else {
|
||||
this._id = 1;
|
||||
}
|
||||
|
||||
this.date_created = new Date();
|
||||
if (!this.date_created)
|
||||
this.date_created = new Date();
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
@@ -6,7 +6,10 @@ mongoose.level = 'F';
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
const { Reaction } = require('./reaction');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
@@ -14,109 +17,101 @@ mongoose.plugin(schema => {
|
||||
});
|
||||
|
||||
const MyHospSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
userId: {type: Schema.Types.ObjectId, ref: 'User'},
|
||||
visibile: {
|
||||
type: Boolean
|
||||
},
|
||||
typeHosp: { // scambio casa / ospitalità
|
||||
type: Number,
|
||||
},
|
||||
numMaxPeopleHosp: {
|
||||
type: Number,
|
||||
},
|
||||
accomodation: [
|
||||
{
|
||||
type: { // Letto matrimoniale / letto singolo / divano-letto / almaca / a terra sul tappeto (per sacco a pelo) / culla
|
||||
type: Number,
|
||||
},
|
||||
location: { // in camera privata / in camera condivisa / in soggiorno / in camper / in tenda / in giardino / all'aperto
|
||||
type: Number,
|
||||
},
|
||||
num: {
|
||||
type: Number,
|
||||
},
|
||||
}],
|
||||
preferences: [ // Accetto bambini, Accetto cani, Accetto gatti, E' consentito fumare in casa, Accessibile con sedia a rotelle
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
photos: [
|
||||
{
|
||||
imagefile: {
|
||||
type: String,
|
||||
},
|
||||
alt: {
|
||||
type: String,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
}],
|
||||
idContribType: [
|
||||
{
|
||||
...{
|
||||
_id: {
|
||||
type: String,
|
||||
}],
|
||||
idCity: [
|
||||
{
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
visibile: {
|
||||
type: Boolean
|
||||
},
|
||||
typeHosp: { // scambio casa / ospitalità
|
||||
type: Number,
|
||||
}],
|
||||
pub_to_share: {
|
||||
type: Number, // PUB_TO_SHARE_ALL, PUB_TO_SHARE_ONLY_TABLE_FOLLOW
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
note: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
website: {
|
||||
type: String,
|
||||
},
|
||||
link_maplocation: {
|
||||
type: String,
|
||||
},
|
||||
date_created: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
},
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
numMaxPeopleHosp: {
|
||||
type: Number,
|
||||
},
|
||||
accomodation: [
|
||||
{
|
||||
type: { // Letto matrimoniale / letto singolo / divano-letto / almaca / a terra sul tappeto (per sacco a pelo) / culla
|
||||
type: Number,
|
||||
},
|
||||
location: { // in camera privata / in camera condivisa / in soggiorno / in camper / in tenda / in giardino / all'aperto
|
||||
type: Number,
|
||||
},
|
||||
num: {
|
||||
type: Number,
|
||||
},
|
||||
}],
|
||||
preferences: [ // Accetto bambini, Accetto cani, Accetto gatti, E' consentito fumare in casa, Accessibile con sedia a rotelle
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
photos: [
|
||||
{
|
||||
imagefile: {
|
||||
type: String,
|
||||
},
|
||||
alt: {
|
||||
type: String,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
}],
|
||||
idContribType: [
|
||||
{
|
||||
type: String,
|
||||
}],
|
||||
idCity: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
pub_to_share: {
|
||||
type: Number, // PUB_TO_SHARE_ALL, PUB_TO_SHARE_ONLY_TABLE_FOLLOW
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
note: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
website: {
|
||||
type: String,
|
||||
},
|
||||
link_maplocation: {
|
||||
type: String,
|
||||
},
|
||||
date_created: {
|
||||
type: Date,
|
||||
},
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
},
|
||||
...Reaction.getFieldsForReactions()
|
||||
});
|
||||
|
||||
MyHospSchema.pre('save', async function(next) {
|
||||
MyHospSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await MyHosp.findOne().limit(1).sort({_id: -1});
|
||||
if (!!myrec) {
|
||||
if (myrec._doc._id === 0)
|
||||
this._id = 1;
|
||||
else
|
||||
this._id = myrec._doc._id + 1;
|
||||
|
||||
} else {
|
||||
this._id = 1;
|
||||
}
|
||||
|
||||
this.date_created = new Date();
|
||||
if (!this.date_created)
|
||||
this.date_created = new Date();
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
MyHospSchema.statics.findAllIdApp = async function(idapp) {
|
||||
MyHospSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const MyHosp = this;
|
||||
|
||||
const query = [
|
||||
{$match: {idapp}},
|
||||
{$sort: {descr: 1}},
|
||||
{ $match: { idapp } },
|
||||
{ $sort: { descr: 1 } },
|
||||
];
|
||||
|
||||
return await MyHosp.aggregate(query).then((arrrec) => {
|
||||
@@ -125,18 +120,18 @@ MyHospSchema.statics.findAllIdApp = async function(idapp) {
|
||||
|
||||
};
|
||||
|
||||
MyHospSchema.statics.getFieldsForSearch = function() {
|
||||
MyHospSchema.statics.getFieldsForSearch = function () {
|
||||
return [];
|
||||
};
|
||||
|
||||
MyHospSchema.statics.getFieldsLastForSearch = function() {
|
||||
MyHospSchema.statics.getFieldsLastForSearch = function () {
|
||||
return [
|
||||
{field: 'descr', type: tools.FieldType.string},
|
||||
{field: 'note', type: tools.FieldType.string},
|
||||
{ field: 'descr', type: tools.FieldType.string },
|
||||
{ field: 'note', type: tools.FieldType.string },
|
||||
];
|
||||
};
|
||||
|
||||
MyHospSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
MyHospSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
params.fieldsearch_last = this.getFieldsLastForSearch();
|
||||
|
||||
@@ -147,59 +142,24 @@ MyHospSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
lk_FF: '_id',
|
||||
lk_as: 'user',
|
||||
af_objId_tab: 'myId',
|
||||
lk_proj: {
|
||||
visibile: 1,
|
||||
typeHosp: 1,
|
||||
numMaxPeopleHosp: 1,
|
||||
accomodation: 1,
|
||||
preferences: 1,
|
||||
photos: 1,
|
||||
idContribType: 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
link_maplocation: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
'mycities': 1,
|
||||
reported: 1,
|
||||
},
|
||||
lk_proj: this.getProject(),
|
||||
},
|
||||
};
|
||||
|
||||
params = {...params, ...otherparams};
|
||||
params = { ...params, ...otherparams };
|
||||
|
||||
return tools.executeQueryTable(this, idapp, params, user);
|
||||
};
|
||||
|
||||
MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
MyHospSchema.statics.getMyRecById = function (idapp, id) {
|
||||
const MyHosp = this;
|
||||
|
||||
const query = [
|
||||
const myparsid = { '_id': id, idapp };
|
||||
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$and': [
|
||||
{
|
||||
'_id': parseInt(id),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
'$match': {
|
||||
'idapp': idapp,
|
||||
},
|
||||
'$match':
|
||||
myparsid,
|
||||
},
|
||||
{
|
||||
'$sort': {
|
||||
@@ -237,34 +197,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
visibile: 1,
|
||||
typeHosp: 1,
|
||||
numMaxPeopleHosp: 1,
|
||||
accomodation: 1,
|
||||
preferences: 1,
|
||||
photos: 1,
|
||||
idContribType: 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
link_maplocation: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
$project: this.getProject(),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
@@ -290,34 +223,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
visibile: 1,
|
||||
typeHosp: 1,
|
||||
numMaxPeopleHosp: 1,
|
||||
accomodation: 1,
|
||||
preferences: 1,
|
||||
photos: 1,
|
||||
idContribType: 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
link_maplocation: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
$project: this.getProject(),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
@@ -343,34 +249,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
visibile: 1,
|
||||
typeHosp: 1,
|
||||
numMaxPeopleHosp: 1,
|
||||
accomodation: 1,
|
||||
preferences: 1,
|
||||
photos: 1,
|
||||
idContribType: 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
link_maplocation: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
$project: this.getProject(),
|
||||
},
|
||||
/*{
|
||||
'$lookup': {
|
||||
@@ -396,34 +275,7 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
visibile: 1,
|
||||
typeHosp: 1,
|
||||
numMaxPeopleHosp: 1,
|
||||
accomodation: 1,
|
||||
preferences: 1,
|
||||
photos: 1,
|
||||
idContribType: 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
link_maplocation: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
$project: this.getProject(),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
@@ -448,50 +300,52 @@ MyHospSchema.statics.getMyRecById = function(idapp, id) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
visibile: 1,
|
||||
typeHosp: 1,
|
||||
numMaxPeopleHosp: 1,
|
||||
accomodation: 1,
|
||||
preferences: 1,
|
||||
photos: 1,
|
||||
idContribType: 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
link_maplocation: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
let numtab = tools.getNumTabByTable(shared_consts.TABLES_MYHOSPS);
|
||||
|
||||
const objadd = tools.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
|
||||
query = [...query, ...objadd.query];
|
||||
|
||||
const toadd = {
|
||||
$project: this.getProject(objadd.proj),
|
||||
};
|
||||
|
||||
query = [...query, { ...toadd }];
|
||||
|
||||
return MyHosp.aggregate(query).then((rec) => {
|
||||
return rec ? rec[0] : null;
|
||||
});
|
||||
};
|
||||
|
||||
MyHospSchema.statics.getCompleteRecord = function(idapp, id) {
|
||||
MyHospSchema.statics.getCompleteRecord = function (idapp, id) {
|
||||
const MyHosp = this;
|
||||
|
||||
return MyHosp.getMyRecById(idapp, id);
|
||||
|
||||
};
|
||||
|
||||
MyHospSchema.statics.getProject = function () {
|
||||
let proj = {
|
||||
visibile: 1,
|
||||
typeHosp: 1,
|
||||
numMaxPeopleHosp: 1,
|
||||
accomodation: 1,
|
||||
preferences: 1,
|
||||
photos: 1,
|
||||
website: 1,
|
||||
link_maplocation: 1,
|
||||
//**ADDFIELD_MYHOSP
|
||||
|
||||
};
|
||||
|
||||
const proj_add = shared_consts.getProjectForAll()
|
||||
|
||||
return Object.assign({}, proj, proj_add);
|
||||
|
||||
}
|
||||
|
||||
|
||||
const MyHosp = mongoose.model('MyHosp', MyHospSchema);
|
||||
|
||||
module.exports = {MyHosp};
|
||||
module.exports = { MyHosp };
|
||||
|
||||
@@ -6,115 +6,118 @@ mongoose.level = 'F';
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
const { Reaction } = require('./reaction');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true;
|
||||
});
|
||||
|
||||
const MySkillSchema = new Schema({
|
||||
_id: {
|
||||
type: Number,
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
userId: {type: Schema.Types.ObjectId, ref: 'User'},
|
||||
idSector: {
|
||||
type: Number,
|
||||
},
|
||||
idSkill: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
/*idSubSkill: [
|
||||
{
|
||||
type: Number,
|
||||
default: 0,
|
||||
}],
|
||||
const MySkillSchema = new Schema(
|
||||
{
|
||||
...{
|
||||
_id: {
|
||||
type: String,
|
||||
default: function () {
|
||||
return new ObjectID().toString();
|
||||
},
|
||||
},
|
||||
idapp: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
idSector: {
|
||||
type: Number,
|
||||
},
|
||||
idSkill: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
/*idSubSkill: [
|
||||
{
|
||||
type: Number,
|
||||
default: 0,
|
||||
}],
|
||||
|
||||
*/
|
||||
idStatusSkill: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
idContribType: [
|
||||
{
|
||||
type: String,
|
||||
}],
|
||||
idCity: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
pub_to_share: {
|
||||
type: Number, // PUB_TO_SHARE_ALL, PUB_TO_SHARE_ONLY_TABLE_FOLLOW
|
||||
},
|
||||
numLevel: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
adType: {
|
||||
type: Number,
|
||||
},
|
||||
photos: [
|
||||
{
|
||||
imagefile: {
|
||||
type: String,
|
||||
},
|
||||
alt: {
|
||||
type: String,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
}],
|
||||
note: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
//**ADDFIELD_MYSKILL
|
||||
website: {
|
||||
type: String,
|
||||
},
|
||||
date_created: {
|
||||
type: Date,
|
||||
},
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
},
|
||||
...Reaction.getFieldsForReactions()
|
||||
}, { strict: false });
|
||||
|
||||
*/
|
||||
idStatusSkill: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
idContribType: [
|
||||
{
|
||||
type: String,
|
||||
}],
|
||||
idCity: [
|
||||
{
|
||||
type: Number,
|
||||
}],
|
||||
pub_to_share: {
|
||||
type: Number, // PUB_TO_SHARE_ALL, PUB_TO_SHARE_ONLY_TABLE_FOLLOW
|
||||
},
|
||||
numLevel: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
adType: {
|
||||
type: Number,
|
||||
},
|
||||
photos: [
|
||||
{
|
||||
imagefile: {
|
||||
type: String,
|
||||
},
|
||||
alt: {
|
||||
type: String,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
}],
|
||||
note: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
descr: {
|
||||
type: String,
|
||||
},
|
||||
//**ADDFIELD_MYSKILL
|
||||
website: {
|
||||
type: String,
|
||||
},
|
||||
date_created: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
},
|
||||
date_updated: {
|
||||
type: Date,
|
||||
},
|
||||
});
|
||||
MySkillSchema.index({ 'idapp': 1 });
|
||||
|
||||
MySkillSchema.pre('save', async function(next) {
|
||||
|
||||
MySkillSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await MySkill.findOne().limit(1).sort({_id: -1});
|
||||
if (!!myrec) {
|
||||
if (myrec._doc._id === 0)
|
||||
this._id = 1;
|
||||
else
|
||||
this._id = myrec._doc._id + 1;
|
||||
|
||||
} else {
|
||||
this._id = 1;
|
||||
}
|
||||
|
||||
this.date_created = new Date();
|
||||
if (!this.date_created)
|
||||
this.date_created = new Date();
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
MySkillSchema.statics.findAllIdApp = async function(idapp) {
|
||||
MySkillSchema.statics.findAllIdApp = async function (idapp) {
|
||||
const MySkill = this;
|
||||
|
||||
const query = [
|
||||
{$match: {idapp}},
|
||||
{$sort: {descr: 1}},
|
||||
{ $match: { idapp } },
|
||||
{ $sort: { descr: 1 } },
|
||||
];
|
||||
|
||||
return await MySkill.aggregate(query).then((arrrec) => {
|
||||
@@ -123,20 +126,20 @@ MySkillSchema.statics.findAllIdApp = async function(idapp) {
|
||||
|
||||
};
|
||||
|
||||
MySkillSchema.statics.getFieldsForSearch = function() {
|
||||
MySkillSchema.statics.getFieldsForSearch = function () {
|
||||
return [];
|
||||
};
|
||||
|
||||
MySkillSchema.statics.getFieldsLastForSearch = function() {
|
||||
MySkillSchema.statics.getFieldsLastForSearch = function () {
|
||||
return [
|
||||
{field: 'note', type: tools.FieldType.string},
|
||||
{field: 'descr', type: tools.FieldType.string},
|
||||
{field: 'recSkill.descr', type: tools.FieldType.string},
|
||||
{field: 'myskill.descr', type: tools.FieldType.string},
|
||||
{ field: 'note', type: tools.FieldType.string },
|
||||
{ field: 'descr', type: tools.FieldType.string },
|
||||
{ field: 'recSkill.descr', type: tools.FieldType.string },
|
||||
{ field: 'myskill.descr', type: tools.FieldType.string },
|
||||
];
|
||||
};
|
||||
|
||||
MySkillSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
MySkillSchema.statics.executeQueryTable = function (idapp, params, user) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
params.fieldsearch_last = this.getFieldsLastForSearch();
|
||||
|
||||
@@ -147,58 +150,22 @@ MySkillSchema.statics.executeQueryTable = function(idapp, params, user) {
|
||||
lk_FF: '_id',
|
||||
lk_as: 'user',
|
||||
af_objId_tab: 'myId',
|
||||
lk_proj: {
|
||||
idSkill: 1,
|
||||
// idSubSkill: 1,
|
||||
myskill: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MYSKILL
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
lasttimeonline: 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
lk_proj: this.getProject(),
|
||||
},
|
||||
};
|
||||
|
||||
params = {...params, ...otherparams};
|
||||
params = { ...params, ...otherparams };
|
||||
|
||||
return tools.executeQueryTable(this, idapp, params, user);
|
||||
};
|
||||
|
||||
MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
MySkillSchema.statics.getMyRecById = function (idapp, idSkill) {
|
||||
const MySkill = this;
|
||||
|
||||
const query = [
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$and': [
|
||||
{
|
||||
'_id': parseInt(idSkill),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
'$match': {
|
||||
'idapp': idapp,
|
||||
'_id': idSkill, idapp
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -237,37 +204,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recSkill': 1,
|
||||
'sector': 1,
|
||||
'idSector': 1,
|
||||
'idSkill': 1,
|
||||
// 'idSubSkill': 1,
|
||||
'idStatusSkill': 1,
|
||||
'idContribType': 1,
|
||||
'idCity': 1,
|
||||
pub_to_share: 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
'photos': 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MYSKILL
|
||||
'descr': 1,
|
||||
'date_created': 1,
|
||||
'date_updated': 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
$project: this.getProject(),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
@@ -293,37 +230,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recSkill': 1,
|
||||
'sector': 1,
|
||||
'idSector': 1,
|
||||
'idSkill': 1,
|
||||
// 'idSubSkill': 1,
|
||||
'idStatusSkill': 1,
|
||||
'idContribType': 1,
|
||||
'idCity': 1,
|
||||
pub_to_share: 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MYSKILL
|
||||
'descr': 1,
|
||||
'date_created': 1,
|
||||
'date_updated': 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
$project: this.getProject(),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
@@ -349,37 +256,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recSkill': 1,
|
||||
'sector': 1,
|
||||
'idSector': 1,
|
||||
'idSkill': 1,
|
||||
//'idSubSkill': 1,
|
||||
'idStatusSkill': 1,
|
||||
'idContribType': 1,
|
||||
'idCity': 1,
|
||||
pub_to_share: 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MYSKILL
|
||||
'descr': 1,
|
||||
'date_created': 1,
|
||||
'date_updated': 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
$project: this.getProject(),
|
||||
},
|
||||
/*{
|
||||
'$lookup': {
|
||||
@@ -407,37 +284,7 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recSkill': 1,
|
||||
'sector': 1,
|
||||
'idSector': 1,
|
||||
'idSkill': 1,
|
||||
// 'idSubSkill': 1,
|
||||
'idStatusSkill': 1,
|
||||
'idContribType': 1,
|
||||
'idCity': 1,
|
||||
pub_to_share: 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MYSKILL
|
||||
'descr': 1,
|
||||
'date_created': 1,
|
||||
'date_updated': 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
$project: this.getProject(),
|
||||
},
|
||||
{
|
||||
'$lookup': {
|
||||
@@ -462,47 +309,43 @@ MySkillSchema.statics.getMyRecById = function(idapp, idSkill) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
'$project': {
|
||||
'recSkill': 1,
|
||||
'sector': 1,
|
||||
'idSector': 1,
|
||||
'idSkill': 1,
|
||||
// 'idSubSkill': 1,
|
||||
'idStatusSkill': 1,
|
||||
'idContribType': 1,
|
||||
'idCity': 1,
|
||||
pub_to_share: 1,
|
||||
'numLevel': 1,
|
||||
adType: 1,
|
||||
'photos': 1,
|
||||
'note': 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MYSKILL
|
||||
'descr': 1,
|
||||
'date_created': 1,
|
||||
'date_updated': 1,
|
||||
'userId': 1,
|
||||
'username': 1,
|
||||
'name': 1,
|
||||
'surname': 1,
|
||||
'comune': 1,
|
||||
'mycities': 1,
|
||||
'profile.img': 1,
|
||||
"profile.mygroups": 1,
|
||||
"profile.mycircuits": 1,
|
||||
'profile.qualifica': 1,
|
||||
reported: 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
let numtab = tools.getNumTabByTable(shared_consts.TABLES_MYSKILLS);
|
||||
|
||||
const objadd = tools.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
|
||||
query = [...query, ...objadd.query];
|
||||
|
||||
const toadd = {
|
||||
$project: this.getProject(objadd.proj),
|
||||
};
|
||||
|
||||
query = [...query, { ...toadd }];
|
||||
|
||||
return MySkill.aggregate(query).then((rec) => {
|
||||
return rec ? rec[0] : null;
|
||||
});
|
||||
};
|
||||
|
||||
MySkillSchema.statics.getCompleteRecord = function(idapp, id) {
|
||||
MySkillSchema.statics.getProject = function (proj_add2) {
|
||||
let proj = {
|
||||
recSkill: 1,
|
||||
sector: 1,
|
||||
idSector: 1,
|
||||
idSkill: 1,
|
||||
idStatusSkill: 1,
|
||||
website: 1,
|
||||
'numLevel': 1,
|
||||
//**ADDFIELD_MYSKILL
|
||||
};
|
||||
|
||||
const proj_add = shared_consts.getProjectForAll(proj_add2)
|
||||
|
||||
return Object.assign({}, proj, proj_add);
|
||||
|
||||
}
|
||||
|
||||
MySkillSchema.statics.getCompleteRecord = function (idapp, id) {
|
||||
const MySkill = this;
|
||||
|
||||
return MySkill.getMyRecById(idapp, id);
|
||||
@@ -511,4 +354,4 @@ MySkillSchema.statics.getCompleteRecord = function(idapp, id) {
|
||||
|
||||
const MySkill = mongoose.model('MySkill', MySkillSchema);
|
||||
|
||||
module.exports = {MySkill};
|
||||
module.exports = { MySkill };
|
||||
|
||||
@@ -20,12 +20,12 @@ const PermissionSchema = new Schema({
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
},{ _id : false });
|
||||
}, { _id: false });
|
||||
|
||||
|
||||
PermissionSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await Permission.findOne().limit(1).sort({_id:-1});
|
||||
const myrec = await Permission.findOne().limit(1).sort({ _id: -1 });
|
||||
if (!!myrec) {
|
||||
if (myrec._doc._id === 0)
|
||||
this._id = 1;
|
||||
@@ -48,7 +48,7 @@ PermissionSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
PermissionSchema.statics.findAllIdApp = async function () {
|
||||
const Permission = this;
|
||||
|
||||
const myfind = { };
|
||||
const myfind = {};
|
||||
|
||||
return await Permission.find(myfind, (err, arrrec) => {
|
||||
return arrrec
|
||||
|
||||
@@ -35,8 +35,32 @@ const ProvinceSchema = new Schema({
|
||||
link_grp: {
|
||||
type: String,
|
||||
},
|
||||
card : {
|
||||
type: String,
|
||||
},
|
||||
|
||||
link_telegram: {
|
||||
type: String,
|
||||
},
|
||||
}, { _id : false });
|
||||
|
||||
ProvinceSchema.pre('save', async function (next) {
|
||||
if (this.isNew) {
|
||||
const myrec = await Province.findOne().limit(1).sort({_id:-1});
|
||||
if (!!myrec) {
|
||||
if (myrec._doc._id === 0)
|
||||
this._id = 1;
|
||||
else
|
||||
this._id = myrec._doc._id + 1;
|
||||
|
||||
} else {
|
||||
this._id = 1;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
ProvinceSchema.statics.getRegionByStrProvince = async function(strprovince) {
|
||||
const myrec = await Province.findOne({prov: strprovince}).lean();
|
||||
if (myrec) {
|
||||
|
||||
436
src/server/models/reaction.js
Executable file
436
src/server/models/reaction.js
Executable file
@@ -0,0 +1,436 @@
|
||||
const mongoose = require('mongoose').set('debug', false)
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const i18n = require('i18n');
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const reactionSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
userId: {
|
||||
type: String,
|
||||
},
|
||||
username: {
|
||||
type: String,
|
||||
},
|
||||
idrec: {
|
||||
type: String,
|
||||
},
|
||||
tab: {
|
||||
type: Number,
|
||||
},
|
||||
fav: {
|
||||
type: Boolean,
|
||||
},
|
||||
book: {
|
||||
type: Boolean,
|
||||
},
|
||||
seen: {
|
||||
type: Boolean,
|
||||
},
|
||||
attend: {
|
||||
type: Boolean,
|
||||
},
|
||||
});
|
||||
|
||||
reactionSchema.statics.getFieldsForReactions = function () {
|
||||
let reactionsField = {
|
||||
numseen: {
|
||||
type: Number,
|
||||
},
|
||||
numbook: {
|
||||
type: Number,
|
||||
},
|
||||
numfav: {
|
||||
type: Number,
|
||||
},
|
||||
numattend: {
|
||||
type: Number,
|
||||
},
|
||||
};
|
||||
|
||||
return reactionsField;
|
||||
};
|
||||
|
||||
reactionSchema.statics.getReactionsCounts = async function (mytable, idapp, idrec, numtab) {
|
||||
|
||||
let query = [];
|
||||
|
||||
try {
|
||||
|
||||
query =
|
||||
[
|
||||
{
|
||||
$match: {
|
||||
_id: idrec,
|
||||
},
|
||||
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "reactions",
|
||||
let: {
|
||||
tab: numtab,
|
||||
id: '$_id',
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{ $eq: ['$idrec', idrec] },
|
||||
{ $eq: ['$tab', numtab] },
|
||||
{ $eq: ['$idapp', idapp] },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: "$idrec",
|
||||
numseen: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$seen", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
},
|
||||
numfav: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$fav", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
},
|
||||
numbook: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$book", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
},
|
||||
numattend: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$attend", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
as: 'myreact',
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
$unwind: {
|
||||
path: "$myreact",
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
const ris = await mytable.aggregate(query);
|
||||
|
||||
return ris ? ris[0]: null;
|
||||
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
reactionSchema.statics.updateReactionsCounts = async function () {
|
||||
|
||||
const globalTables = require('../tools/globalTables');
|
||||
|
||||
console.log('INIZIO - updateReactionsCounts');
|
||||
|
||||
try {
|
||||
|
||||
for (const tablestr of shared_consts.TABLES_REACTIONS) {
|
||||
const numtab = tools.getNumTabByTable(tablestr);
|
||||
const mytable = globalTables.getTableByTableName(tablestr);
|
||||
|
||||
const arrrec = await mytable.find({});
|
||||
|
||||
console.log(' updateReactionsCounts tabella', tablestr);
|
||||
|
||||
for (const rec of arrrec) {
|
||||
// Calcola
|
||||
const ris = await Reaction.getReactionsCounts(mytable, idapp, rec._id, numtab);
|
||||
|
||||
if (ris && ris.myreact) {
|
||||
|
||||
risupdate = await mytable.updateOne({ _id: rec._id }, {
|
||||
$set: {
|
||||
numseen: ris.myreact.numseen | 0,
|
||||
numfav: ris.myreact.numfav | 0,
|
||||
numbook: ris.myreact.numbook | 0,
|
||||
numattend: ris.myreact.numattend | 0,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
console.log('FINE - updateReactionsCounts');
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
;
|
||||
|
||||
reactionSchema.statics.getFieldsForSearch = function () {
|
||||
return [
|
||||
{ field: 'username', type: tools.FieldType.string }];
|
||||
};
|
||||
|
||||
reactionSchema.statics.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, 0, params);
|
||||
};
|
||||
|
||||
reactionSchema.statics.calcReactions = async function (idapp, id, tab) {
|
||||
|
||||
try {
|
||||
let myquerycountreaction = [
|
||||
{
|
||||
$match: {
|
||||
idapp,
|
||||
idrec: id,
|
||||
tab,
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
numseen: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$seen", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
},
|
||||
numfav: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$fav", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
},
|
||||
numbook: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$book", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
},
|
||||
numattend: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$attend", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
return await Reaction.aggregate(myquerycountreaction)
|
||||
.then((ris) => {
|
||||
return ris ? ris[0] : null;
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Aggiungo il Favorite
|
||||
reactionSchema.statics.addFavorite = async function (req, idapp, username, id, tab) {
|
||||
|
||||
let ris = null;
|
||||
|
||||
try {
|
||||
let ok = false;
|
||||
|
||||
const myrec = await Reaction.findOne({ idrec: id, idapp, username });
|
||||
if (!myrec) {
|
||||
const myrec = new Reaction({ idrec: id, idapp, userId: req.user.id, username, tab, fav: true });
|
||||
ris = await myrec.save();
|
||||
ok = ris ? 1 : 0;
|
||||
} else {
|
||||
ris = await Reaction.updateOne({ idrec: id, idapp, username }, {
|
||||
$set: {
|
||||
fav: true,
|
||||
}
|
||||
})
|
||||
ok = ris.ok;
|
||||
}
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
const globalTables = require('../tools/globalTables');
|
||||
|
||||
// Invia una Notifica al Destinatario
|
||||
const recObjCreator = await globalTables.getUserCreatorByNumTabAndId(idapp, id, tab);
|
||||
|
||||
if (recObjCreator) {
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest: recObjCreator.username, recObjCreator, username_action: req.user.username }, false, shared_consts.TypeNotifs.TYPEDIR_FAVORITE,
|
||||
shared_consts.TypeNotifs.ID_FAVORITE_ADDED);
|
||||
|
||||
}
|
||||
|
||||
return { ris, ok };
|
||||
|
||||
} catch (e) {
|
||||
console.error('Err addFavorite', e);
|
||||
return { ris: null, ok: 0 };
|
||||
}
|
||||
};
|
||||
|
||||
// Aggiungo il Seen
|
||||
reactionSchema.statics.addSeen = async function (req, idapp, username, id, tab) {
|
||||
|
||||
const myrec = await Reaction.findOne({ idrec: id, idapp, username });
|
||||
if (!myrec) {
|
||||
const myrec = new Reaction({ idrec: id, idapp, userId: req.user.id, username, tab, seen: true });
|
||||
return await myrec.save()
|
||||
.then((ris) => {
|
||||
// console.log('salvato proj!');
|
||||
return { ris, ok: ris ? 1 : 0 };
|
||||
})
|
||||
.catch(err => {
|
||||
console.log("Error addSeen", err.message);
|
||||
});
|
||||
} else {
|
||||
return Reaction.updateOne({ _id: myrec._id }, {
|
||||
$set: {
|
||||
seen: true,
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
// Aggiungo il Bookmark
|
||||
reactionSchema.statics.addBookmark = async function (req, idapp, username, id, tab) {
|
||||
|
||||
const myrec = await Reaction.findOne({ idrec: id, idapp, username });
|
||||
if (!myrec) {
|
||||
const myrec = new Reaction({ idrec: id, idapp, userId: req.user.id, username, tab, book: true });
|
||||
return await myrec.save()
|
||||
.then((ris) => {
|
||||
return { ris, ok: ris ? 1 : 0 };
|
||||
})
|
||||
.catch(err => {
|
||||
console.log("Error addBookmark", err.message);
|
||||
});
|
||||
} else {
|
||||
return Reaction.updateOne({ _id: myrec._id }, {
|
||||
$set: {
|
||||
book: true,
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
// Aggiungo il Attend
|
||||
reactionSchema.statics.addAttend = async function (req, idapp, username, id, tab) {
|
||||
|
||||
const myrec = await Reaction.findOne({ idrec: id, idapp, username });
|
||||
if (!myrec) {
|
||||
const myrec = new Reaction({ idrec: id, idapp, userId: req.user.id, username, tab, attend: true });
|
||||
return await myrec.save()
|
||||
.then((ris) => {
|
||||
return { ris, ok: ris ? 1 : 0 };
|
||||
})
|
||||
.catch(err => {
|
||||
console.log("Error addAttend", err.message);
|
||||
});
|
||||
} else {
|
||||
return Reaction.updateOne({ _id: myrec._id }, {
|
||||
$set: {
|
||||
attend: true,
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
// Rimuovo il Favorite
|
||||
reactionSchema.statics.removeFavorite = async function (
|
||||
idapp, username, id, tab) {
|
||||
|
||||
const myrec = await Reaction.findOne({ idrec: id, idapp, username });
|
||||
if (myrec) {
|
||||
return Reaction.updateOne({ _id: myrec._id }, {
|
||||
$set: {
|
||||
fav: false,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
};
|
||||
|
||||
// Rimuovo il Bookmark
|
||||
reactionSchema.statics.removeBookmark = async function (
|
||||
idapp, username, id, tab) {
|
||||
|
||||
const myrec = await Reaction.findOne({ idrec: id, idapp, username });
|
||||
if (myrec) {
|
||||
return Reaction.updateOne({ _id: myrec._id }, {
|
||||
$set: {
|
||||
book: false,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
};
|
||||
|
||||
const Reaction = mongoose.model('Reaction', reactionSchema);
|
||||
|
||||
module.exports = { Reaction };
|
||||
45
src/server/models/search.js
Executable file
45
src/server/models/search.js
Executable file
@@ -0,0 +1,45 @@
|
||||
const mongoose = require('mongoose').set('debug', false)
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const searchSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
userId: {
|
||||
type: String,
|
||||
},
|
||||
text: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
searchSchema.statics.findAllByUserIdAndIdApp = function (userId, idapp, sall) {
|
||||
const Search = this;
|
||||
|
||||
let myfind = {};
|
||||
if (sall === '1')
|
||||
myfind = { idapp };
|
||||
else
|
||||
myfind = { userId, idapp };
|
||||
|
||||
return Search.find(myfind, (err, arrsearch) => {
|
||||
return arrsearch
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const Search = mongoose.model('Search', searchSchema);
|
||||
|
||||
module.exports = { Search };
|
||||
@@ -17,14 +17,14 @@ const sendmsgSchema = new Schema({
|
||||
},
|
||||
source: {
|
||||
page: { type: String },
|
||||
event_id: { type: String }
|
||||
event_id: { type: String },
|
||||
infoevent: { type: String }
|
||||
},
|
||||
origin: {
|
||||
username: { type: String },
|
||||
type: String,
|
||||
},
|
||||
dest: {
|
||||
idapp: { type: String, },
|
||||
username: { type: String },
|
||||
type: String,
|
||||
},
|
||||
message: {
|
||||
type: String,
|
||||
@@ -54,7 +54,7 @@ sendmsgSchema.statics.findAllMsgByUsernameIdAndIdApp = function (username, lastd
|
||||
|
||||
return SendMsg.find({
|
||||
$and: [
|
||||
{ $or: [ { 'dest.username': username }, { 'origin.username': username },] },
|
||||
{ $or: [ { 'dest': username }, { 'origin': username },] },
|
||||
{ 'datemsg': {$gt: new Date(lastdataread)} },
|
||||
{ idapp }
|
||||
]
|
||||
@@ -73,14 +73,14 @@ sendmsgSchema.statics.findLastGroupByUserIdAndIdApp = function (userId, username
|
||||
return SendMsg.aggregate([
|
||||
{
|
||||
$match: {
|
||||
$or: [{ 'origin.username': username }, { 'dest.username': username }, { idapp }],
|
||||
$or: [{ 'origin': username }, { 'dest': username }, { idapp }],
|
||||
$and: [{ idapp }]
|
||||
}
|
||||
},
|
||||
{
|
||||
$group:
|
||||
{
|
||||
_id: "$dest.username",
|
||||
_id: "$dest",
|
||||
message: { $last: "$message" },
|
||||
datemsg: { $last: "$datemsg" },
|
||||
dest: { $last: "$dest" },
|
||||
|
||||
@@ -22,18 +22,22 @@ mongoose.plugin(schema => {
|
||||
const sendNotifSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
index: true,
|
||||
},
|
||||
typedir: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
index: true,
|
||||
},
|
||||
typeid: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
index: true,
|
||||
},
|
||||
sender: { // mittente
|
||||
type: String,
|
||||
default: '',
|
||||
index: true,
|
||||
},
|
||||
dest: {
|
||||
type: String,
|
||||
@@ -66,6 +70,7 @@ const sendNotifSchema = new Schema({
|
||||
status: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
index: true,
|
||||
},
|
||||
typesend: {
|
||||
type: Number,
|
||||
@@ -96,8 +101,25 @@ const sendNotifSchema = new Schema({
|
||||
options: {
|
||||
type: Array,
|
||||
},
|
||||
textaddTelegram: {
|
||||
type: String,
|
||||
},
|
||||
textcontent_Telegram: {
|
||||
type: String,
|
||||
},
|
||||
linkaddTelegram: {
|
||||
type: String,
|
||||
}
|
||||
});
|
||||
|
||||
sendNotifSchema.index({ idapp: 1 });
|
||||
sendNotifSchema.index({ typedir: 1 });
|
||||
sendNotifSchema.index({ typeid: 1 });
|
||||
sendNotifSchema.index({ sender: 1 });
|
||||
|
||||
sendNotifSchema.index({ idapp: 1, typedir: 1, typeid: 1, status: 1, sender: 1 });
|
||||
|
||||
|
||||
sendNotifSchema.statics.setNotifAsRead = function (idapp, username, idnotif) {
|
||||
const SendNotif = this;
|
||||
|
||||
@@ -139,7 +161,7 @@ sendNotifSchema.statics.getRecNotif = function (id) {
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, lastdataread, idapp) {
|
||||
sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, lastdataread, idapp, limitrecord) {
|
||||
const SendNotif = this;
|
||||
|
||||
if (!lastdataread)
|
||||
@@ -151,7 +173,7 @@ sendNotifSchema.statics.findAllNotifByUsernameIdAndIdApp = function (username, l
|
||||
{ 'dest': username },
|
||||
{ 'datenotif': { $gt: new Date(lastdataread) } },
|
||||
],
|
||||
}).lean().sort({ datenotif: -1 }).then(async (arrnotif) => {
|
||||
}).lean().limit(limitrecord).sort({ datenotif: -1 }).then(async (arrnotif) => {
|
||||
// console.log('arrnotif', arrnotif.length);
|
||||
|
||||
return this.compileOtherFields(arrnotif);
|
||||
@@ -166,11 +188,15 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
|
||||
const numchars = 80;
|
||||
let newdescr = '';
|
||||
let newdescrtelegram = '';
|
||||
let mydescr = '';
|
||||
let myidrec = '';
|
||||
let sender = recnotif.sender;
|
||||
let sender = recnotif.sender ? recnotif.sender : '';
|
||||
let tag = '';
|
||||
|
||||
const { Circuit } = require('../models/circuit');
|
||||
const { User } = require('../models/user');
|
||||
|
||||
try {
|
||||
if (recnotif.myrectableorig) {
|
||||
myidrec = recnotif.myrectableorig._id;
|
||||
@@ -179,14 +205,44 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
|
||||
if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_BACHECA) {
|
||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD) {
|
||||
newdescr = i18n.__('<strong>%s</strong> new Good: %s', userorig, mydescr);
|
||||
recnotif.openUrl = '/mygood/' + myidrec;
|
||||
newdescr = i18n.__('NEW_GOOD', userorig, mydescr);
|
||||
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYGOODS, true) + myidrec;
|
||||
tag = 'newgood';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE) {
|
||||
newdescr = i18n.__('<strong>%s</strong> new Service: %s', userorig, mydescr);
|
||||
recnotif.openUrl = '/myservice/' + myidrec;
|
||||
newdescr = i18n.__('NEW_SERVICE', userorig, mydescr);
|
||||
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYSKILLS, true) + myidrec;
|
||||
tag = 'newservice';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_BACHECA_NEW_HOSP) {
|
||||
newdescr = i18n.__('NEW_HOSP', userorig, mydescr);
|
||||
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYHOSPS, true) + myidrec;
|
||||
tag = 'newhosp';
|
||||
}
|
||||
recnotif.linkaddTelegram = 'Vedi annuncio';
|
||||
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_EVENTS) {
|
||||
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TABLES_MYBACHECAS, true) + myidrec;
|
||||
tag = 'newevent';
|
||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_EVENTS_NEW_REC) {
|
||||
let eventobj = await tools.getEventForTelegram(recnotif.myrectableorig, mydescr, userorig);
|
||||
newdescr = eventobj.newdescr;
|
||||
newdescrtelegram = eventobj.newdescrtelegram;
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_EVENTS_SEND_MSG) {
|
||||
newdescr = i18n.__('EVENT_SEND_MSG', userorig, recnotif.title, recnotif.msg);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_EVENTS_ATTEND) {
|
||||
// ++ Controlla se esiste già
|
||||
let esitegia = recnotif.paramsObj.recObjCreator.exist; // ++
|
||||
|
||||
if (esitegia)
|
||||
newdescr = i18n.__('SET_ATTEND_OTHERS', recnotif.paramsObj.username_action, recnotif.paramsObj.recObjCreator.numattend - 1, recnotif.paramsObj.recObjCreator.descr);
|
||||
else
|
||||
newdescr = i18n.__('SET_ATTEND', recnotif.paramsObj.username_action, recnotif.paramsObj.recObjCreator.descr);
|
||||
|
||||
recnotif.openUrl = shared_consts.getDirectoryByTable(recnotif.paramsObj.recObjCreator.table, true) + recnotif.paramsObj.recObjCreator.id;
|
||||
tag = 'attend';
|
||||
|
||||
}
|
||||
recnotif.textcontent_Telegram = newdescrtelegram;
|
||||
recnotif.linkaddTelegram = i18n.__('SHOW_POST');
|
||||
|
||||
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
|
||||
recnotif.openUrl = '/my/' + sender;
|
||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_FRIENDS_NEW_REC) {
|
||||
@@ -222,7 +278,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
}
|
||||
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
|
||||
tag = 'group';
|
||||
recnotif.openUrl = '/grp/' + recnotif.paramsObj.groupnameDest;
|
||||
recnotif.openUrl = shared_consts.getDirectoryByTable('mygroups', true) + recnotif.paramsObj.groupnameDest;
|
||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_NEW_REC) {
|
||||
newdescr = i18n.__('GROUP_CREATED', sender, recnotif.paramsObj.groupnameDest);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_GROUP_ACCEPTED) {
|
||||
@@ -280,11 +336,17 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
}
|
||||
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS) {
|
||||
tag = 'circuit';
|
||||
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path;
|
||||
strtipocontoOrig = recnotif.paramsObj.extrarec.contoComOrig ? i18n.__('COMUNITARIO') : i18n.__('COLLETTIVO');
|
||||
strtipocontoDest = recnotif.paramsObj.extrarec.contoComDest ? i18n.__('COMUNITARIO') : i18n.__('COLLETTIVO');
|
||||
let groupOComorig = recnotif.paramsObj.extrarec.contoComOrig ? recnotif.paramsObj.extrarec.contoComOrig : recnotif.paramsObj.extrarec.grouporig;
|
||||
let groupOComdest = recnotif.paramsObj.extrarec.contoComDest ? recnotif.paramsObj.extrarec.contoComDest : recnotif.paramsObj.extrarec.groupdest;
|
||||
let strtipocontoDest = '';
|
||||
let strtipocontoOrig = '';
|
||||
let groupOComorig = '';
|
||||
let groupOComdest = '';
|
||||
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TAB_MYCIRCUITS, true) + recnotif.paramsObj.path;
|
||||
if (recnotif.paramsObj.extrarec) {
|
||||
strtipocontoOrig = recnotif.paramsObj.extrarec.contoComOrig ? i18n.__('COMUNITARIO') : i18n.__('COLLETTIVO');
|
||||
strtipocontoDest = recnotif.paramsObj.extrarec.contoComDest ? i18n.__('COMUNITARIO') : i18n.__('COLLETTIVO');
|
||||
groupOComorig = recnotif.paramsObj.extrarec.contoComOrig ? recnotif.paramsObj.extrarec.contoComOrig : recnotif.paramsObj.extrarec.grouporig;
|
||||
groupOComdest = recnotif.paramsObj.extrarec.contoComDest ? recnotif.paramsObj.extrarec.contoComDest : recnotif.paramsObj.extrarec.groupdest;
|
||||
}
|
||||
let myorig = '';
|
||||
let mydest = '';
|
||||
let destinatario = '';
|
||||
@@ -292,6 +354,8 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
let symbol = '';
|
||||
let username_action = '';
|
||||
let username_mittente = '';
|
||||
let circuitname = '';
|
||||
let numuserincircuit = 0;
|
||||
try {
|
||||
username_action = recnotif.paramsObj.username_action
|
||||
username_mittente = recnotif.paramsObj.sender ? recnotif.paramsObj.sender : username_action
|
||||
@@ -300,15 +364,35 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
destinatario = recnotif.paramsObj.extrarec.dest ? recnotif.paramsObj.extrarec.dest : (recnotif.paramsObj.extrarec.groupdest ? recnotif.paramsObj.extrarec.groupdest : recnotif.paramsObj.extrarec.contoComDest);
|
||||
qty = recnotif.paramsObj.extrarec && recnotif.paramsObj.extrarec.qty ? recnotif.paramsObj.extrarec.qty.toString() : '';
|
||||
symbol = recnotif.paramsObj.extrarec ? recnotif.paramsObj.extrarec.symbol : '';
|
||||
circuitname = recnotif.paramsObj.circuitnameDest;
|
||||
numuserincircuit = await User.countUsersInCircuit(recnotif.idapp, circuitname);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
recnotif.textaddTelegram = '';
|
||||
|
||||
if (groupOComdest) {
|
||||
destinatario += ' (' + username_mittente + ')'
|
||||
}
|
||||
|
||||
if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC) {
|
||||
newdescr = i18n.__('CIRCUIT_CREATED', sender, recnotif.paramsObj.circuitnameDest);
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SETFIDO) {
|
||||
if (recnotif.paramsObj.isAdmin) {
|
||||
if (recnotif.extrarec.groupname) {
|
||||
newdescr = i18n.__('FIDO_IMPOSTATO_ADMINS_CIRCUIT_MYGROUP', recnotif.extrarec.groupname, -recnotif.paramsObj.extrarec.fidoConcesso, recnotif.paramsObj.circuitnameDest,
|
||||
username_action);
|
||||
} else {
|
||||
newdescr = i18n.__('FIDO_IMPOSTATO_ADMINS_CIRCUIT', sender, -recnotif.paramsObj.extrarec.fidoConcesso, recnotif.paramsObj.circuitnameDest,
|
||||
username_action);
|
||||
}
|
||||
|
||||
recnotif.openUrl = '/my/' + sender;
|
||||
} else {
|
||||
newdescr = i18n.__('FIDO_IMPOSTATO', -recnotif.paramsObj.extrarec.fidoConcesso, username_action, recnotif.paramsObj.circuitnameDest);
|
||||
}
|
||||
tag = 'setfido';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ACCEPTED) {
|
||||
if (recnotif.paramsObj.isAdmin) {
|
||||
if (recnotif.extrarec.groupname) {
|
||||
@@ -351,13 +435,20 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
}
|
||||
tag = 'refcircuit';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER) {
|
||||
|
||||
aportador_solidario = await User.getAportadorSolidarioByUsername(recnotif.idapp, sender);
|
||||
if (recnotif.extrarec.groupname) {
|
||||
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER_WITH_GROUP', recnotif.extrarec.groupname, recnotif.paramsObj.circuitnameDest,
|
||||
recnotif.paramsObj.singleadmin_username);
|
||||
numuserincircuit, recnotif.paramsObj.singleadmin_username);
|
||||
|
||||
} else {
|
||||
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', sender, recnotif.paramsObj.circuitnameDest,
|
||||
recnotif.paramsObj.singleadmin_username);
|
||||
newdescr = i18n.__('CIRCUIT_REQUEST_TO_ENTER', sender, '<strong>' + recnotif.paramsObj.circuitnameDest + '</strong>', numuserincircuit, aportador_solidario);
|
||||
|
||||
}
|
||||
const myadmins = await Circuit.getListAdmins(recnotif.idapp, recnotif.paramsObj.circuitnameDest);
|
||||
recnotif.textaddTelegram += '\n' + i18n.__('CIRCUIT_ADMINS', myadmins.num, myadmins.str);
|
||||
recnotif.textaddTelegram += '\n' + i18n.__('CIRCUIT_WHERE_IS_PRESENT', await Circuit.getListCircuitsByUsername(recnotif.idapp, sender, recnotif.extrarec.groupname));
|
||||
|
||||
tag = 'reqcircuits';
|
||||
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_DELETE_USER) {
|
||||
@@ -365,7 +456,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
tag = 'deletecircuit';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_ADDED_ADMIN) {
|
||||
if (sender === recnotif.paramsObj.usernameDest) {
|
||||
newdescr = i18n.__('CIRCUIT_ADDED_ADMIN_YOU', recnotif.paramsObj.circuitnameDest, username_action);
|
||||
newdescr = i18n.__('CIRCUIT_ADDED_ADMIN_YOU', recnotif.paramsObj.usernameDest, recnotif.paramsObj.circuitnameDest, username_action);
|
||||
} else {
|
||||
newdescr = i18n.__('CIRCUIT_ADDED_ADMIN', sender, recnotif.paramsObj.circuitnameDest, username_action);
|
||||
recnotif.openUrl = '/my/' + sender;
|
||||
@@ -373,7 +464,7 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
tag = 'addadmingrp';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED_ADMIN) {
|
||||
if (sender === recnotif.paramsObj.usernameDest) {
|
||||
newdescr = i18n.__('CIRCUIT_REMOVED_ADMIN_YOU', recnotif.paramsObj.circuitnameDest, username_action);
|
||||
newdescr = i18n.__('CIRCUIT_REMOVED_ADMIN_YOU', recnotif.paramsObj.usernameDest, recnotif.paramsObj.circuitnameDest, username_action);
|
||||
} else {
|
||||
newdescr = i18n.__('CIRCUIT_REMOVED_ADMIN', sender, recnotif.paramsObj.circuitnameDest, username_action);
|
||||
recnotif.openUrl = '/my/' + sender;
|
||||
@@ -382,56 +473,56 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ) {
|
||||
if (groupOComdest) {
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_GROUP', tools.getAhref(username_action, await tools.getLinkUserTelegram(recnotif.idapp, username_action)), qty,
|
||||
symbol, strtipocontoDest, groupOComdest);
|
||||
symbol, strtipocontoDest, groupOComdest, circuitname);
|
||||
} else if (groupOComorig && (sender === recnotif.paramsObj.usernameDest)) {
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_YOU', strtipocontoOrig, groupOComorig, username_action, qty, symbol, recnotif.paramsObj.extrarec.dest);
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_YOU', strtipocontoOrig, groupOComorig, username_action, qty, symbol, recnotif.paramsObj.extrarec.dest, circuitname);
|
||||
} else if (groupOComorig) {
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_USER', strtipocontoOrig, groupOComorig, username_action, qty, symbol, recnotif.paramsObj.extrarec.dest);
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_USER', strtipocontoOrig, groupOComorig, username_action, qty, symbol, recnotif.paramsObj.extrarec.dest, circuitname);
|
||||
} else {
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ', tools.getAhref(username_action, await tools.getLinkUserTelegram(recnotif.idapp, username_action)), qty,
|
||||
symbol);
|
||||
symbol, circuitname);
|
||||
}
|
||||
|
||||
tag = 'sendcoin';
|
||||
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path; //++Todo: dove lo mando ?
|
||||
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TAB_MYCIRCUITS, true) + recnotif.paramsObj.path; //++Todo: dove lo mando ?
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ_SENT) {
|
||||
|
||||
if (myorig) {
|
||||
if (groupOComdest) {
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_GROUP', strtipocontoOrig, myorig, username_action, qty, symbol, strtipocontoDest, groupOComdest);
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_GROUP', strtipocontoOrig, myorig, username_action, qty, symbol, strtipocontoDest, groupOComdest, circuitname);
|
||||
} else {
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_USER', strtipocontoOrig, myorig, username_action, qty, symbol, mydest);
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_FROM_GROUP_TO_USER', strtipocontoOrig, myorig, username_action, qty, symbol, mydest, circuitname);
|
||||
}
|
||||
} else {
|
||||
if (groupOComdest) {
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_TO_GROUP', qty, symbol, strtipocontoDest, groupOComdest);
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_TO_GROUP', qty, symbol, strtipocontoDest, groupOComdest, circuitname);
|
||||
} else {
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_TO_ME', qty, symbol, mydest);
|
||||
newdescr = i18n.__('CIRCUIT_SENDCOINSREQ_TO_ME', qty, symbol, mydest, circuitname);
|
||||
}
|
||||
}
|
||||
|
||||
tag = 'sendcoin';
|
||||
recnotif.openUrl = '/circuit/' + recnotif.paramsObj.path; //++Todo: dove lo mando ?
|
||||
recnotif.openUrl = shared_consts.getDirectoryByTable(shared_consts.TAB_MYCIRCUITS, true) + recnotif.paramsObj.path; //++Todo: dove lo mando ?
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_ACCEPTED) {
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED', qty, symbol,
|
||||
username_action) + `\n` + i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoDest, symbol);
|
||||
username_action, circuitname) + `\n` + i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoDest, symbol, circuitname);
|
||||
|
||||
if (myorig) {
|
||||
if (groupOComdest) {
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED_FROM_GROUP_TO_GROUP', strtipocontoDest, myorig, username_action, qty, symbol, strtipocontoDest, groupOComdest, username_mittente) + `\n`
|
||||
+ i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoDest, symbol);
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED_FROM_GROUP_TO_GROUP', strtipocontoDest, myorig, username_action, qty, symbol, strtipocontoDest, groupOComdest, circuitname, username_mittente) + `\n`
|
||||
+ i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoDest, symbol, circuitname);
|
||||
|
||||
} else {
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED_FROM_GROUP_TO_YOU', qty, symbol, strtipocontoOrig, myorig, username_action)
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED_FROM_GROUP_TO_YOU', qty, symbol, strtipocontoOrig, myorig, circuitname, username_action)
|
||||
+ `\n` + i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoDest, symbol);
|
||||
}
|
||||
} else {
|
||||
if (groupOComdest) {
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED_FROM_ME_TO_GROUP', strtipocontoDest, groupOComdest, username_action, qty, symbol, username_mittente)
|
||||
+ `\n` + i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoDest, symbol);
|
||||
+ `\n` + i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoDest, symbol, circuitname);
|
||||
} else {
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED_FROM_ME_TO_YOU', qty, symbol, username_action)
|
||||
+ `\n` + i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoDest, symbol);
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED_FROM_ME_TO_YOU', qty, symbol, username_action, circuitname)
|
||||
+ `\n` + i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoDest, symbol, circuitname);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,22 +531,35 @@ sendNotifSchema.statics.getDescrAndLinkByRecNotif = async function (recnotif, us
|
||||
if (!destinatario) {
|
||||
destinatario = username_action
|
||||
}
|
||||
let saldostr = i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoOrig, symbol);
|
||||
let saldostr = i18n.__('SALDO_UPDATE', recnotif.paramsObj.extrarec.saldoOrig, symbol, circuitname);
|
||||
if (groupOComorig) {
|
||||
saldostr = i18n.__('SALDO_UPDATE_WHO', groupOComorig, recnotif.paramsObj.extrarec.saldoOrig, symbol);
|
||||
saldostr = i18n.__('SALDO_UPDATE_WHO', groupOComorig, recnotif.paramsObj.extrarec.saldoOrig, symbol, circuitname);
|
||||
}
|
||||
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED_TO_ME', qty, symbol, destinatario)
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_ACCEPTED_TO_ME', qty, symbol, destinatario, circuitname)
|
||||
+ `\n` + saldostr;
|
||||
tag = 'sendcoin';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_REFUSED) {
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_REFUSED', qty, symbol, username_action);
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_REFUSED', qty, symbol, username_action, circuitname);
|
||||
tag = 'sendcoin';
|
||||
} else if (recnotif.typeid === shared_consts.TypeNotifs.ID_CIRCUIT_COINS_REFUSED_SENT) {
|
||||
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_REFUSED_TO_ME', qty, symbol, destinatario);
|
||||
newdescr = i18n.__('ID_CIRCUIT_COINS_REFUSED_TO_ME', qty, symbol, destinatario, circuitname);
|
||||
tag = 'sendcoin';
|
||||
}
|
||||
} else if (recnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FAVORITE) {
|
||||
// ++ Controlla se esiste già
|
||||
let esitegia = recnotif.paramsObj.recObjCreator.exist; // ++
|
||||
|
||||
if (esitegia)
|
||||
newdescr = i18n.__('SET_FAVORITE_OTHERS', recnotif.paramsObj.username_action, recnotif.paramsObj.recObjCreator.numfav - 1, recnotif.paramsObj.recObjCreator.descr);
|
||||
else
|
||||
newdescr = i18n.__('SET_FAVORITE', recnotif.paramsObj.username_action, recnotif.paramsObj.recObjCreator.descr);
|
||||
|
||||
tag = 'favorite';
|
||||
|
||||
recnotif.openUrl = shared_consts.getDirectoryByTable(recnotif.paramsObj.recObjCreator.table, true) + recnotif.paramsObj.recObjCreator.id;
|
||||
recnotif.linkaddTelegram = i18n.__('SHOW_POST');
|
||||
}
|
||||
|
||||
recnotif.tag = recnotif.tag ? recnotif.tag : tag;
|
||||
@@ -531,6 +635,8 @@ sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res,
|
||||
|
||||
// console.log('myrecout._id', myrecout._id.toString());
|
||||
|
||||
let risnotif = null;
|
||||
|
||||
if (save) {
|
||||
let res = null;
|
||||
try {
|
||||
@@ -541,7 +647,10 @@ sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res,
|
||||
const myrecread = await SendNotif.findById(idobj).lean();
|
||||
// console.log('myrecread._id', myrecread._id.toString());
|
||||
|
||||
return await globalTables.sendNotif(myrecread.typedir, myrecread.typeid, res, idapp, user ? user : req.user, myrecread);
|
||||
if (myrecread)
|
||||
risnotif = await globalTables.sendNotif(myrecread.typedir, myrecread.typeid, res, idapp, user ? user : req.user, myrecread);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
@@ -550,9 +659,12 @@ sendNotifSchema.statics.saveAndSendNotif = async function (myrecnotif, req, res,
|
||||
}
|
||||
|
||||
} else {
|
||||
return await globalTables.sendNotif(myrecout.typedir, myrecout.typeid, res, idapp, user ? user : req.user, myrecout);
|
||||
risnotif = await globalTables.sendNotif(myrecout.typedir, myrecout.typeid, res, idapp, user ? user : req.user, myrecout);
|
||||
}
|
||||
|
||||
|
||||
return risnotif;
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.updateStatusAndDescr = async function (myrecnotif, onlysave, userorig) {
|
||||
@@ -569,10 +681,10 @@ sendNotifSchema.statics.updateStatusAndDescr = async function (myrecnotif, onlys
|
||||
let typeidsearch = 0;
|
||||
let dest = '';
|
||||
|
||||
let sender = myrecnotif.sender;
|
||||
let newdest = myrecnotif.dest;
|
||||
let sendergroup = myrecnotif.sendergroup;
|
||||
let newdestgroup = myrecnotif.destgroup;
|
||||
let sender = myrecnotif.sender ? myrecnotif.sender : '';
|
||||
let newdest = myrecnotif.dest ? myrecnotif.dest : '';
|
||||
let sendergroup = myrecnotif.sendergroup ? myrecnotif.sendergroup : '';
|
||||
let newdestgroup = myrecnotif.destgroup ? myrecnotif.destgroup : '';
|
||||
|
||||
// Controllare se devo modificare un Notif già esistente !
|
||||
if (myrecnotif.typedir === shared_consts.TypeNotifs.TYPEDIR_FRIENDS) {
|
||||
@@ -811,9 +923,11 @@ sendNotifSchema.statics.createNewNotification = async function (req, res, params
|
||||
myrecnotif.idrec = rec._id;
|
||||
}
|
||||
|
||||
|
||||
myrecnotif.typedir = typedir;
|
||||
myrecnotif.typeid = typeid;
|
||||
|
||||
|
||||
await SendNotif.sendToTheDestinations(myrecnotif, req, res);
|
||||
|
||||
return true;
|
||||
@@ -854,6 +968,7 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
|
||||
// Send only to the destination to reach:
|
||||
const userlist = await User.find({
|
||||
idapp: myrecnotifpass.idapp,
|
||||
// username: 'SuryaArena2', //TOGLIERE
|
||||
$or: [
|
||||
{ deleted: { $exists: false } },
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
@@ -864,6 +979,9 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
|
||||
lang: 1,
|
||||
username: 1,
|
||||
'profile.notifs': 1,
|
||||
'profile.mycircuits': 1,
|
||||
'profile.resid_province': 1,
|
||||
'profile.resid_card': 1,
|
||||
'profile.notif_idCities': 1,
|
||||
'profile.notif_provinces': 1,
|
||||
'profile.notif_regions': 1,
|
||||
@@ -871,30 +989,39 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
|
||||
'profile.notif_sector_goods': 1,
|
||||
}).lean();
|
||||
|
||||
let arrcircuits = [];
|
||||
let arrprovinces = [];
|
||||
let arrregions = [];
|
||||
let idSector = 0;
|
||||
|
||||
const mytable = globalTables.getTableByTableName(myrecnotifpass.tablerec);
|
||||
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) ||
|
||||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
||||
if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_BACHECA || myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_EVENTS) {
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) ||
|
||||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
||||
|
||||
const myrectableorig = await mytable.findOne({ _id: myrecnotifpass.idrec }).lean();
|
||||
if (myrectableorig) {
|
||||
for (const city of myrectableorig.idCity) {
|
||||
arrprovinces.push(await City.getProvinceByIdCity(city));
|
||||
arrregions.push(await City.getRegionByIdCity(city));
|
||||
if (myrecnotifpass.idrec && myrecnotifpass.idrec !== '0') {
|
||||
// const myrectableorig = await mytable.findOne({ _id: myrecnotifpass.idrec }).lean();
|
||||
const myrectableorig = await mytable.getCompleteRecord(myrecnotifpass.idapp, myrecnotifpass.idrec);
|
||||
if (myrectableorig) {
|
||||
for (const city of myrectableorig.idCity) {
|
||||
const prov = await City.getProvinceByIdCity(city);
|
||||
arrprovinces.push(await City.getProvinceByIdCity(city));
|
||||
arrregions.push(await City.getRegionByIdCity(city));
|
||||
arrcircuits.push(await City.getCircuitNameBystrProv(prov));
|
||||
}
|
||||
|
||||
|
||||
if (myrecnotifpass.tablerec === shared_consts.TABLES_MYGOODS) {
|
||||
idSector = myrectableorig.idSectorGood;
|
||||
} else {
|
||||
idSector = myrectableorig.idSector;
|
||||
}
|
||||
|
||||
}
|
||||
myrecnotifpass.myrectableorig = myrectableorig;
|
||||
}
|
||||
|
||||
if (myrecnotifpass.tablerec === shared_consts.TABLES_MYGOODS) {
|
||||
idSector = myrectableorig.idSectorGood;
|
||||
} else {
|
||||
idSector = myrectableorig.idSector;
|
||||
}
|
||||
|
||||
}
|
||||
myrecnotifpass.myrectableorig = myrectableorig;
|
||||
}
|
||||
|
||||
myrecnotifpass = await this.getDescrAndLinkByRecNotif(myrecnotifpass, req.user.username);
|
||||
@@ -902,48 +1029,86 @@ sendNotifSchema.statics.sendToTheDestinations = async function (myrecnotifpass,
|
||||
|
||||
for (const user of userlist) {
|
||||
|
||||
const mycircuits = user.profile.mycircuits;
|
||||
|
||||
if (user.profile && user.profile.notifs) {
|
||||
const usernotifprofile = user.profile.notifs.find((notif) => notif.dir === myrecnotifpass.typedir);
|
||||
|
||||
let send = false;
|
||||
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec) ||
|
||||
shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
||||
// Estrai la Città, la Provincia e la regione.
|
||||
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_PROVINCE) &&
|
||||
user.profile.notif_provinces && user.profile.notif_provinces.some(r => arrprovinces.indexOf(r) >= 0)) {
|
||||
send = true;
|
||||
}
|
||||
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_REGION) &&
|
||||
user.profile.notif_regions && user.profile.notif_regions.some(r => arrregions.indexOf(r) >= 0)) {
|
||||
send = true;
|
||||
}
|
||||
|
||||
if (idSector && usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_SECTOR)) {
|
||||
// Controlla se è del settore selezionato
|
||||
if (myrecnotifpass.tablerec === shared_consts.TABLES_MYGOODS) {
|
||||
if (user.profile.notif_sector_goods) {
|
||||
send = send && (user.profile.notif_sector_goods.includes(idSector));
|
||||
}
|
||||
} else if (user.profile.notif_sectors) {
|
||||
send = send && (user.profile.notif_sectors.includes(idSector));
|
||||
if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_EVENTS) {
|
||||
if (myrecnotifpass.tablerec === shared_consts.TABLES_MYBACHECAS) {
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.TypeNotifs.ID_EVENTS_ATTEND)) {
|
||||
send = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (shared_consts.TABLES_GROUPS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.GroupsNotifs.STATUS_GROUPS_NEW)) {
|
||||
send = true;
|
||||
if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_FAVORITE) {
|
||||
if (shared_consts.TABLES_FAVORITE_BOOKMARK.includes(myrecnotifpass.tablerec)) {
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.TypeNotifs.ID_FAVORITE_ADDED)) {
|
||||
send = true;
|
||||
}
|
||||
}
|
||||
} else if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_BACHECA
|
||||
|| myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_EVENTS
|
||||
|| myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS
|
||||
) {
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(myrecnotifpass.tablerec)
|
||||
|| shared_consts.TABLES_EVENTS_NOTIFICATION.includes(myrecnotifpass.tablerec)
|
||||
|| shared_consts.TABLES_GROUPS_NOTIFICATION.includes(myrecnotifpass.tablerec)
|
||||
) {
|
||||
// Estrai la Città, la Provincia e la regione.
|
||||
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_YOUR_PROVINCE) &&
|
||||
user.profile.resid_province && arrprovinces.indexOf(user.profile.resid_province) >= 0) {
|
||||
send = true;
|
||||
}
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_PROVINCE) &&
|
||||
user.profile.notif_provinces && user.profile.notif_provinces.some(r => arrprovinces.indexOf(r) >= 0)) {
|
||||
send = true;
|
||||
}
|
||||
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_REGION) &&
|
||||
user.profile.notif_regions && user.profile.notif_regions.some(r => arrregions.indexOf(r) >= 0)) {
|
||||
send = true;
|
||||
}
|
||||
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_MY_RIS_CIRCUIT) &&
|
||||
user.profile.mycircuits && user.profile.mycircuits.some(r => arrcircuits.indexOf(r.circuitname) >= 0)) {
|
||||
send = true;
|
||||
}
|
||||
|
||||
if (idSector && usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.UsersNotif.NEW_ADV_SECTOR)) {
|
||||
// Controlla se è del settore selezionato
|
||||
if (myrecnotifpass.tablerec === shared_consts.TABLES_MYGOODS) {
|
||||
if (user.profile.notif_sector_goods) {
|
||||
send = send && (user.profile.notif_sector_goods.includes(idSector));
|
||||
}
|
||||
} else if (user.profile.notif_sectors) {
|
||||
send = send && (user.profile.notif_sectors.includes(idSector));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/*} else if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_GROUPS) {
|
||||
if (shared_consts.TABLES_GROUPS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.GroupsNotifs.STATUS_GROUPS_NEW)) {
|
||||
send = true;
|
||||
}
|
||||
}
|
||||
} else if (myrecnotifpass.typedir === shared_consts.TypeNotifs.TYPEDIR_CIRCUITS) {
|
||||
if (shared_consts.TABLES_CIRCUITS_NOTIFICATION.includes(myrecnotifpass.tablerec)) {
|
||||
if (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.CircuitsNotif.STATUS_NEW)) {
|
||||
send = true;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
if (send) {
|
||||
let myrecnotif = new SendNotif(myrecnotifpass);
|
||||
myrecnotif.dest = user.username;
|
||||
return await SendNotif.saveAndSendNotif(myrecnotif, req, res, user);
|
||||
await SendNotif.saveAndSendNotif(myrecnotif, req, res, user);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -977,7 +1142,8 @@ sendNotifSchema.statics.sendToSingleUserDest = async function (myrecnotif, req,
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.getSumPendingTransactions = async function (idapp, username, circuitname, groupname) {
|
||||
|
||||
sendNotifSchema.statics.getSumPendingTransactionsMittente = async function (idapp, username, circuitname, groupname) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
@@ -999,6 +1165,60 @@ sendNotifSchema.statics.getSumPendingTransactions = async function (idapp, usern
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.getSumPendingTransactionsDest = async function (idapp, username, circuitname, groupname) {
|
||||
const SendNotif = this;
|
||||
|
||||
try {
|
||||
const query = {
|
||||
idapp,
|
||||
sender: username,
|
||||
sendergroup: groupname,
|
||||
typedir: shared_consts.TypeNotifs.TYPEDIR_CIRCUITS,
|
||||
typeid: shared_consts.TypeNotifs.ID_CIRCUIT_SENDCOINSREQ,
|
||||
status: 0,
|
||||
'extrarec.circuitname': circuitname,
|
||||
'extrarec.dest': username,
|
||||
'extrarec.groupdest': groupname,
|
||||
};
|
||||
|
||||
return await SendNotif.find(query).lean();
|
||||
|
||||
} catch (e) {
|
||||
console.error('e', e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
sendNotifSchema.statics.updatePendingTransactions = async function (recnotif) {
|
||||
|
||||
const { Circuit } = require('../models/circuit');
|
||||
const { Account } = require('../models/account');
|
||||
|
||||
try {
|
||||
if (recnotif && recnotif.extrarec && recnotif.extrarec.circuitname) {
|
||||
|
||||
const circuit = await Circuit.getCircuitByName(recnotif.idapp, recnotif.extrarec.circuitname);
|
||||
|
||||
const accountdestTable = await Account.getAccountByUsernameAndCircuitId(recnotif.idapp, recnotif.extrarec.dest, circuit._id, true, false, recnotif.extrarec.groupdest, recnotif.extrarec.contoComDest);
|
||||
const accountorigTable = await Account.getAccountByUsernameAndCircuitId(recnotif.idapp, recnotif.sender, circuit._id, true, true, recnotif.extrarec.grouporig, recnotif.extrarec.contoComOrig);
|
||||
|
||||
if (accountdestTable)
|
||||
await accountdestTable.calcPending(false);
|
||||
if (accountorigTable)
|
||||
await accountorigTable.calcPending(true);
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
sendNotifSchema.statics.checkIfAlreadyExist = async function (idapp, tag, idpost, numtab) {
|
||||
|
||||
};
|
||||
|
||||
const SendNotif = mongoose.model('SendNotif', sendNotifSchema);
|
||||
|
||||
module.exports = { SendNotif: SendNotif };
|
||||
|
||||
@@ -62,6 +62,12 @@ const SiteSchema = new Schema({
|
||||
telegram_key_test: {
|
||||
type: String,
|
||||
},
|
||||
teleg_cfg: {
|
||||
type: String,
|
||||
},
|
||||
teleg_cfg_test: {
|
||||
type: String,
|
||||
},
|
||||
telegram_bot_name_test: {
|
||||
type: String,
|
||||
},
|
||||
@@ -122,6 +128,7 @@ const SiteSchema = new Schema({
|
||||
enableRegMultiChoice: { type: Boolean },
|
||||
enableDebugOn: { type: Boolean },
|
||||
enabledRegNeedTelegram: { type: Boolean },
|
||||
showViewEventi: { type: Boolean },
|
||||
showViewGroups: { type: Boolean },
|
||||
showViewCircuits: { type: Boolean },
|
||||
showViewUsers: { type: Boolean },
|
||||
@@ -225,6 +232,7 @@ module.exports.findAllIdApp = async function (idapp) {
|
||||
rec.email_pwd = '';
|
||||
rec.telegram_key = '';
|
||||
rec.telegram_key_test = '';
|
||||
// rec.confsite = {};
|
||||
|
||||
return rec;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ const { Graduatoria } = require('../models/graduatoria');
|
||||
// const {NavePersistente} = require('../models/navepersistente');
|
||||
// const { ExtraList } = require('../models/extralist');
|
||||
|
||||
|
||||
const { Reaction } = require('../models/reaction');
|
||||
|
||||
const { MyGroup } = require('../models/mygroup');
|
||||
const { Circuit } = require('../models/circuit');
|
||||
|
||||
@@ -41,7 +44,7 @@ const UserSchema = new mongoose.Schema({
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: true,
|
||||
// required: true,
|
||||
trim: true,
|
||||
minlength: 1,
|
||||
unique: false,
|
||||
@@ -438,6 +441,10 @@ const UserSchema = new mongoose.Schema({
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
resid_card: {
|
||||
type: String,
|
||||
trim: true,
|
||||
},
|
||||
stepTutorial: {
|
||||
type: Number,
|
||||
},
|
||||
@@ -447,12 +454,47 @@ const UserSchema = new mongoose.Schema({
|
||||
noCircuit: {
|
||||
type: Boolean,
|
||||
},
|
||||
noCircIta: {
|
||||
type: Boolean,
|
||||
},
|
||||
noFoto: {
|
||||
type: Boolean,
|
||||
}
|
||||
},
|
||||
seen: [
|
||||
{
|
||||
_id: false,
|
||||
id: { type: String },
|
||||
tab: { type: Number },
|
||||
},
|
||||
],
|
||||
bookmark: [
|
||||
{
|
||||
_id: false,
|
||||
id: { type: String },
|
||||
tab: { type: Number },
|
||||
},
|
||||
],
|
||||
favorite: [
|
||||
{
|
||||
_id: false,
|
||||
id: { type: String },
|
||||
tab: { type: Number },
|
||||
},
|
||||
],
|
||||
attend: [
|
||||
{
|
||||
_id: false,
|
||||
id: { type: String },
|
||||
tab: { type: Number },
|
||||
num: { type: Number },
|
||||
},
|
||||
],
|
||||
version: { type: Number },
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
UserSchema.methods.toJSON = function () {
|
||||
const user = this;
|
||||
const userObject = user.toObject();
|
||||
@@ -1498,7 +1540,7 @@ UserSchema.statics.getUserById = function (idapp, id) {
|
||||
UserSchema.statics.getUserByUsername = function (idapp, username) {
|
||||
const User = this;
|
||||
|
||||
return User.findne({
|
||||
return User.findOne({
|
||||
idapp,
|
||||
username,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
@@ -1585,6 +1627,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
|
||||
'profile.born_province': 1,
|
||||
'profile.born_country': 1,
|
||||
'profile.resid_province': 1,
|
||||
'profile.resid_card': 1,
|
||||
'profile.calc': 1,
|
||||
'profile.handshake': 1,
|
||||
'profile.friends': 1,
|
||||
@@ -1629,6 +1672,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
|
||||
'profile.born_province': 1,
|
||||
'profile.born_country': 1,
|
||||
'profile.resid_province': 1,
|
||||
'profile.resid_card': 1,
|
||||
'profile.calc': 1,
|
||||
'profile.handshake': 1,
|
||||
'profile.friends': 1,
|
||||
@@ -1674,6 +1718,7 @@ UserSchema.statics.getUserProfileByUsername = async function (
|
||||
'profile.born_province': 1,
|
||||
'profile.born_country': 1,
|
||||
'profile.resid_province': 1,
|
||||
'profile.resid_card': 1,
|
||||
'profile.calc': 1,
|
||||
'profile.handshake': 1,
|
||||
'profile.friends': 1,
|
||||
@@ -1856,11 +1901,80 @@ UserSchema.statics.removeFromMyGroups = async function (
|
||||
return await User.updateOne({ idapp, username },
|
||||
{ $pull: { 'profile.mygroups': { groupname: { $in: [groupnameDest] } } } });
|
||||
};
|
||||
// Rimuovo il Gruppo
|
||||
|
||||
// Rimuovo il Circuito
|
||||
UserSchema.statics.removeFromCircuits = async function (idapp, username, circuitname) {
|
||||
return await User.updateOne({ idapp, username },
|
||||
|
||||
// Elimina la richiesta (se esiste):
|
||||
update = { $pull: { req_users: { username: { $in: [username] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
const ris = await User.updateOne({ idapp, username },
|
||||
{ $pull: { 'profile.mycircuits': { circuitname: { $in: [circuitname] } } } });
|
||||
|
||||
|
||||
const circuitId = await Circuit.getCircuitIdByName(idapp, circuitname);
|
||||
let remove = false;
|
||||
|
||||
// Se il mio account non è stato utilizzato, allora lo cancello anche questo
|
||||
const myaccount = await Account.getAccountByUsernameAndCircuitId(idapp, username, circuitId, false, false, '', '');
|
||||
if (myaccount && myaccount.totTransato === 0) {
|
||||
remove = true;
|
||||
} else {
|
||||
remove = true;
|
||||
}
|
||||
|
||||
if (remove) {
|
||||
await Account.removeAccount(myaccount._id);
|
||||
}
|
||||
|
||||
return ris;
|
||||
};
|
||||
|
||||
// Aggiungo il Circuito
|
||||
UserSchema.statics.addCircuitToUser = async function (idapp, usernameOrig, circuitname, confido, groupname, contocom) {
|
||||
|
||||
let ris = null;
|
||||
|
||||
if (groupname) {
|
||||
|
||||
ris = await MyGroup.addCircuitFromGroup(idapp, groupname, circuitname);
|
||||
|
||||
// Elimina la richiesta:
|
||||
update = { $pull: { req_groups: { groupname: { $in: [groupname] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
// Elimina eventualmente se era bloccato:
|
||||
update = { $pull: { refused_groups: { groupname: { $in: [groupname] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
} else {
|
||||
|
||||
let update = {
|
||||
$push: {
|
||||
'profile.mycircuits': {
|
||||
circuitname,
|
||||
date: new Date(),
|
||||
},
|
||||
},
|
||||
};
|
||||
ris = await User.updateOne({ idapp, username: usernameOrig }, update);
|
||||
|
||||
if (confido) {
|
||||
// Elimina la richiesta:
|
||||
update = { $pull: { req_users: { username: { $in: [usernameOrig] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
}
|
||||
|
||||
// Elimina eventualmente se era bloccato:
|
||||
update = { $pull: { refused_users: { username: { $in: [usernameOrig] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
}
|
||||
|
||||
await Account.createAccount(idapp, usernameOrig, circuitname, confido, groupname, contocom);
|
||||
|
||||
return ris;
|
||||
};
|
||||
|
||||
// Rimuovo il Gruppo per Tutti gli Utenti
|
||||
@@ -1882,6 +1996,57 @@ UserSchema.statics.removeReqFriend = async function (
|
||||
{ $pull: { 'profile.req_friends': { username: { $in: [usernameDest] } } } });
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Aggiungo il Partecipa
|
||||
UserSchema.statics.addAttend = async function (
|
||||
req, idapp, username, id, tab, num) {
|
||||
const ris = await User.updateOne({ idapp, username },
|
||||
{ $push: { 'profile.attend': { id, tab, num } } });
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
const globalTables = require('../tools/globalTables');
|
||||
|
||||
// Invia una Notifica al Destinatario
|
||||
const recObjCreator = await globalTables.getUserCreatorByNumTabAndId(idapp, id, tab);
|
||||
|
||||
if (recObjCreator) {
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest: recObjCreator.username, recObjCreator, username_action: req.user.username }, false,
|
||||
shared_consts.TypeNotifs.TYPEDIR_EVENTS,
|
||||
shared_consts.TypeNotifs.ID_EVENTS_ATTEND);
|
||||
|
||||
}
|
||||
|
||||
return ris;
|
||||
};
|
||||
// Rimuovo il Bookmark
|
||||
UserSchema.statics.removeBookmark = async function (
|
||||
idapp, username, id, tab) {
|
||||
return await User.updateOne({ idapp, username },
|
||||
{ $pull: { 'profile.bookmark': { id: { $in: [id] }, tab } } });
|
||||
};
|
||||
|
||||
// Aggiungo il Bookmark
|
||||
UserSchema.statics.addBookmark = async function (
|
||||
idapp, username, id, tab) {
|
||||
return await User.updateOne({ idapp, username },
|
||||
{ $push: { 'profile.bookmark': { id, tab } } });
|
||||
};
|
||||
// Rimuovo il Partecipa
|
||||
UserSchema.statics.removeAttend = async function (
|
||||
idapp, username, id, tab) {
|
||||
return await User.updateOne({ idapp, username },
|
||||
{ $pull: { 'profile.attend': { id: { $in: [id] }, tab } } });
|
||||
};
|
||||
|
||||
// Aggiungo il Bookmark
|
||||
UserSchema.statics.addSeen = async function (
|
||||
idapp, username, id, tab) {
|
||||
return await User.updateOne({ idapp, username },
|
||||
{ $push: { 'profile.seen': { id, tab } } });
|
||||
};
|
||||
|
||||
UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, usernameDest, cmd, value, disablenotif) {
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
@@ -1991,7 +2156,7 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
//}
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.SETHANDSHAKE) {
|
||||
// Aggiungo la Stretta di mano a lui
|
||||
const foundIfAlreadyFriend = await User.findOne({
|
||||
const foundIfAlreadyHandshake = await User.findOne({
|
||||
idapp,
|
||||
username: usernameDest,
|
||||
'profile.handshake': {
|
||||
@@ -2001,7 +2166,7 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
|
||||
let rec = null;
|
||||
|
||||
if (!foundIfAlreadyFriend) {
|
||||
if (!foundIfAlreadyHandshake) {
|
||||
update = {
|
||||
$push: {
|
||||
'profile.handshake': {
|
||||
@@ -2012,12 +2177,34 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
};
|
||||
rec = await User.updateOne({ idapp, username: usernameDest }, update);
|
||||
|
||||
if (!disablenotif) {
|
||||
// Send a notification to the DESTINATION HANDSHAKE !
|
||||
let req = tools.getReqByPar(idapp, usernameOrig);
|
||||
await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest }, true, shared_consts.TypeNotifs.TYPEDIR_HANDSHAKE,
|
||||
shared_consts.TypeNotifs.ID_HANDSHAKE_ACCEPTED);
|
||||
tools.sendNotificationByUsername(idapp, usernameDest, cmd, true, usernameOrig);
|
||||
let req = tools.getReqByPar(idapp, usernameOrig);
|
||||
|
||||
if (rec) {
|
||||
try {
|
||||
if (!disablenotif) {
|
||||
const userDest = await User.getRecLangAndIdByUsername(idapp, usernameDest);
|
||||
const user = await User.getRecLangAndIdByUsername(idapp, usernameOrig);
|
||||
const already_stretta = await User.isMyHandShake(idapp, usernameDest, usernameOrig);
|
||||
const msgDest = i18n.__({ phrase: 'HANDSHAKE_CONFIRMED', locale: userDest.lang }, usernameDest);
|
||||
let phrase = 'HANDSHAKE_SET';
|
||||
if (already_stretta) {
|
||||
phrase = 'HANDSHAKE_ACCEPTED';
|
||||
}
|
||||
|
||||
const msgOrig = i18n.__({ phrase, locale: user.lang }, usernameOrig);
|
||||
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameOrig, msgDest);
|
||||
await telegrambot.sendMsgTelegram(idapp, usernameDest, msgOrig);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Notification : ', e);
|
||||
}
|
||||
}
|
||||
|
||||
// Send a notification to the DESTINATION HANDSHAKE !
|
||||
// await SendNotif.createNewNotifToSingleUser(req, null, { usernameDest }, false, shared_consts.TypeNotifs.TYPEDIR_HANDSHAKE,
|
||||
// shared_consts.TypeNotifs.ID_HANDSHAKE_ACCEPTED);
|
||||
}
|
||||
|
||||
const userprofile = await User.getInfoFriendByUsername(idapp, usernameDest);
|
||||
@@ -2169,6 +2356,86 @@ UserSchema.statics.setFriendsCmd = async function (req, idapp, usernameOrig, use
|
||||
return ris;
|
||||
};
|
||||
|
||||
UserSchema.statics.sendCmd = async function (req, idapp, usernameOrig, usernameDest, cmd, value, disablenotif) {
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
const cl = telegrambot.getclTelegByidapp(idapp);
|
||||
|
||||
if (!req) {
|
||||
req = tools.getReqByPar(idapp, usernameOrig);
|
||||
}
|
||||
|
||||
const myuser = await User.getUserByUsername(idapp, usernameOrig);
|
||||
const recuserDest = await User.getUserByUsername(idapp, usernameDest);
|
||||
|
||||
const langdest = recuserDest.lang;
|
||||
const telegid = recuserDest.profile.teleg_id;
|
||||
|
||||
let userId = recuserDest._id;
|
||||
let title = tools.getNomeAppByIdApp(idapp);
|
||||
let keyb = null;
|
||||
let descr = '';
|
||||
|
||||
let send_notif = false;
|
||||
let send_msgTelegramBot = false;
|
||||
let actions = [];
|
||||
let popupOnApp = '';
|
||||
|
||||
let ris = null;
|
||||
|
||||
try {
|
||||
if (cmd === shared_consts.CallFunz.ENTRA_RIS_ITALIA) {
|
||||
mycircuitOrig = await Circuit.getCircuitMyProvince(idapp, usernameOrig);
|
||||
descr = i18n.__({ phrase: 'SENDMSG_ENTRA_IN_RISO_ITALIA', locale: langdest }, usernameDest, usernameOrig, mycircuitOrig);
|
||||
msgtelegram = descr;
|
||||
|
||||
openUrl = '/circuit/ris_italia';
|
||||
bottone = i18n.__({ phrase: 'CIRCUIT_OPEN_RISITALIA', locale: langdest });
|
||||
tag = 'risitalia';
|
||||
|
||||
send_notif = true;
|
||||
send_msgTelegramBot = true;
|
||||
|
||||
keyb = cl.getInlineKeyboard(langdest, [
|
||||
{
|
||||
text: bottone,
|
||||
url: tools.getHostByIdApp(idapp) + openUrl,
|
||||
// callback_data: InlineConferma.RISPOSTA_SI + myfunc + tools.SEP + myuser.username + tools.SEP + '' + tools.SEP + '' + tools.SEP +
|
||||
// groupid,
|
||||
},
|
||||
]);
|
||||
|
||||
popupOnApp = 'Messaggio inviato al destinatario';
|
||||
|
||||
}
|
||||
|
||||
if (send_notif) {
|
||||
// SEND PUSH NOTIFICATION
|
||||
await tools.sendNotificationToUser(userId, title, descr, openUrl, '', tag, actions);
|
||||
}
|
||||
|
||||
// Invia Msg
|
||||
if (send_msgTelegramBot && msgtelegram) {
|
||||
await telegrambot.local_sendMsgTelegramByIdTelegram(idapp, telegid, msgtelegram, undefined, undefined, true, keyb);
|
||||
}
|
||||
|
||||
const userprofile = await User.getInfoFriendByUsername(idapp, usernameDest);
|
||||
const myuser = await User.getInfoFriendByUsername(idapp, usernameOrig);
|
||||
|
||||
ris = { userprofile, myuser, popupOnApp, result: true };
|
||||
|
||||
} catch (e) {
|
||||
popupOnApp = e;
|
||||
ris = { popupOnApp };
|
||||
console.error('Error sendCmd: ', e);
|
||||
}
|
||||
|
||||
return ris;
|
||||
};
|
||||
|
||||
UserSchema.statics.ifAlreadyInGroup = async function (idapp, usernameOrig, groupnameDest) {
|
||||
|
||||
// Controllo se è stato già inserito
|
||||
@@ -2399,7 +2666,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
const mycirc = await Circuit.findOne({ idapp, name: circuitname });
|
||||
if (mycirc) {
|
||||
// Il Conto Comunitario prende il nome del circuito !
|
||||
await Account.createAccount(idapp, '', circuitname, '', mycirc.path);
|
||||
await Account.createAccount(idapp, '', circuitname, true, '', mycirc.path);
|
||||
}
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.SET) {
|
||||
@@ -2407,18 +2674,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
const foundIfCircuitInGroup = await MyGroup.ifCircuitAlreadyInGroup(idapp, groupname, circuitname);
|
||||
|
||||
if (!foundIfCircuitInGroup) {
|
||||
ris = await MyGroup.addCircuitFromGroup(idapp, groupname, circuitname);
|
||||
|
||||
// Elimina la richiesta:
|
||||
update = { $pull: { req_groups: { groupname: { $in: [groupname] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
// Elimina eventualmente se era bloccato:
|
||||
update = { $pull: { refused_groups: { groupname: { $in: [groupname] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
await Account.createAccount(idapp, '', circuitname, groupname);
|
||||
|
||||
ris = await this.addCircuitToUser(idapp, usernameOrig, circuitname, true, groupname);
|
||||
|
||||
} else {
|
||||
ris = false;
|
||||
@@ -2430,7 +2686,6 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, value, true, username_action, extrarec);
|
||||
outres.result = await Circuit.getInfoCircuitByName(idapp, circuitname);
|
||||
}
|
||||
|
||||
} else {
|
||||
const foundIfAlreadyCircuit = await this.ifAlreadyInCircuit(idapp, usernameOrig, circuitname);
|
||||
|
||||
@@ -2445,10 +2700,6 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
};
|
||||
ris = await User.updateOne({ idapp, username: usernameOrig }, update);
|
||||
|
||||
// Elimina la richiesta:
|
||||
update = { $pull: { req_users: { username: { $in: [usernameOrig] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
// Elimina eventualmente se era bloccato:
|
||||
update = { $pull: { refused_users: { username: { $in: [usernameOrig] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
@@ -2467,6 +2718,29 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
outres.result = await Circuit.getInfoCircuitByName(idapp, circuitname);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.SETFIDO) {
|
||||
|
||||
ris = await Circuit.setFido(idapp, usernameOrig, circuitname, groupname);
|
||||
if (ris) {
|
||||
|
||||
extrarec.fidoConcesso = ris.fidoConcesso;
|
||||
extrarec.qta_maxConcessa = ris.qta_maxConcessa;
|
||||
|
||||
// Elimina la richiesta:
|
||||
update = { $pull: { req_users: { username: { $in: [usernameOrig] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
await Circuit.updateData(idapp, circuitname)
|
||||
if (ris) {
|
||||
// Invia una notifica alla persona e agli Admin
|
||||
tools.sendNotificationByCircuit(idapp, usernameOrig, circuitname, cmd, value, true, username_action, extrarec);
|
||||
outres.result = await Circuit.getInfoCircuitByName(idapp, circuitname);
|
||||
}
|
||||
} else {
|
||||
// errore !?
|
||||
}
|
||||
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REQ) {
|
||||
|
||||
if (groupname) {
|
||||
@@ -2480,6 +2754,9 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
});
|
||||
|
||||
if (value) {
|
||||
|
||||
ris = await this.addCircuitToUser(idapp, usernameOrig, circuitname, false, groupname, '');
|
||||
|
||||
if (!foundIfAlreadyAskCircuit) {
|
||||
update = {
|
||||
$push: {
|
||||
@@ -2506,7 +2783,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
}
|
||||
|
||||
} else {
|
||||
// Aggiungo la richiesta di Gruppo a me
|
||||
// Aggiungo la richiesta di Circuito a me
|
||||
const foundIfAlreadyAskCircuit = await Circuit.findOne({
|
||||
idapp,
|
||||
name: circuitname,
|
||||
@@ -2516,6 +2793,9 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
});
|
||||
|
||||
if (value) {
|
||||
// Aggiungi intanto l'utente al Circuito (senza fido)
|
||||
ris = await this.addCircuitToUser(idapp, usernameOrig, circuitname, false);
|
||||
|
||||
if (!foundIfAlreadyAskCircuit) {
|
||||
update = {
|
||||
$push: {
|
||||
@@ -2525,6 +2805,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
},
|
||||
},
|
||||
};
|
||||
// Aggiungi la richiesta per ottenere il fido
|
||||
ris = await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
}
|
||||
@@ -2547,6 +2828,10 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVE_FROM_MYLIST) {
|
||||
|
||||
if (groupname) {
|
||||
// Elimina la richiesta:
|
||||
update = { $pull: { req_groups: { groupname: { $in: [groupname] } } } };
|
||||
await Circuit.updateOne({ idapp, name: circuitname }, update);
|
||||
|
||||
outres.result = await MyGroup.removeCircuitFromGroup(idapp, groupname, circuitname); // Rimuovo l'Amicizia da me
|
||||
} else {
|
||||
|
||||
@@ -2669,7 +2954,7 @@ UserSchema.statics.setCircuitCmd = async function (idapp, usernameOrig, circuitn
|
||||
}
|
||||
|
||||
outres.recnotif = await SendNotif.getRecNotif(extrarec.notifId);
|
||||
outres.arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username_action, extrarec.lastdr, idapp);
|
||||
outres.arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username_action, extrarec.lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER);
|
||||
|
||||
} else {
|
||||
outres.cansend = false;
|
||||
@@ -2728,6 +3013,7 @@ function getWhatToShow(idapp, username) {
|
||||
'profile.born_province': 1,
|
||||
'profile.born_country': 1,
|
||||
'profile.resid_province': 1,
|
||||
'profile.resid_card': 1,
|
||||
'profile.calc': 1,
|
||||
email: 1,
|
||||
date_reg: 1,
|
||||
@@ -2752,10 +3038,15 @@ function getWhatToShow_Unknown(idapp, username) {
|
||||
'profile.born_province': 1,
|
||||
'profile.born_country': 1,
|
||||
'profile.resid_province': 1,
|
||||
'profile.resid_card': 1,
|
||||
'profile.calc': 1,
|
||||
date_reg: 1,
|
||||
'profile.handshake': 1,
|
||||
'profile.friends': 1,
|
||||
'profile.favorite': 1,
|
||||
'profile.bookmark': 1,
|
||||
'profile.attend': 1,
|
||||
'profile.seen': 1,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2774,6 +3065,7 @@ UserSchema.statics.getWhatToShow_IfFriends = async function (idapp, username) {
|
||||
'profile.born_province': 1,
|
||||
'profile.born_country': 1,
|
||||
'profile.resid_province': 1,
|
||||
'profile.resid_card': 1,
|
||||
'profile.calc': 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
@@ -2782,6 +3074,10 @@ UserSchema.statics.getWhatToShow_IfFriends = async function (idapp, username) {
|
||||
groups: 1,
|
||||
'profile.handshake': 1,
|
||||
'profile.friends': 1,
|
||||
'profile.favorite': 1,
|
||||
'profile.bookmark': 1,
|
||||
'profile.attend': 1,
|
||||
'profile.seen': 1,
|
||||
};
|
||||
|
||||
};
|
||||
@@ -2932,27 +3228,34 @@ UserSchema.statics.UserByIdTelegram = async function (idapp, teleg_id) {
|
||||
const User = this;
|
||||
|
||||
return await User.findOne({
|
||||
idapp, 'profile.teleg_id': teleg_id,
|
||||
idapp,
|
||||
'profile.teleg_id': teleg_id,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
}).lean().then((rec) => {
|
||||
}).lean().then(async (rec) => {
|
||||
if (!rec) {
|
||||
// Cerca se esiste in quello salvato in precedenza:
|
||||
const recold = await User.findOne({
|
||||
idapp,
|
||||
'profile.teleg_id_old': teleg_id
|
||||
}).lean();
|
||||
if (recold && recold.profile.teleg_id_old === teleg_id) {
|
||||
// Riaggiorna l'ID perché è ritornato sulla chat!
|
||||
await User.SetTelegramIdSuccess(idapp, recold._id, recold.profile.teleg_id_old);
|
||||
|
||||
rec = await User.findOne({
|
||||
idapp,
|
||||
'profile.teleg_id': teleg_id,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
}).lean();
|
||||
}
|
||||
|
||||
}
|
||||
return (!!rec) ? rec : null;
|
||||
}).catch((e) => {
|
||||
console.error('UserExistByIdTelegram', e);
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.UsersByIdTelegram = async function (idapp, teleg_id) {
|
||||
const User = this;
|
||||
|
||||
return await User.find({
|
||||
idapp, 'profile.teleg_id': teleg_id,
|
||||
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
|
||||
}).lean().then((rec) => {
|
||||
return (!!rec) ? rec : null;
|
||||
}).catch((e) => {
|
||||
console.error('UserExistByIdTelegram', e);
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.setPicProfile = async function (idapp, username, imgpic) {
|
||||
const User = this;
|
||||
@@ -3118,7 +3421,9 @@ UserSchema.statics.SetTelegramWasBlocked = async function (idapp, teleg_id) {
|
||||
'profile.teleg_id': 0,
|
||||
};
|
||||
|
||||
if (tools.sulServer()) {
|
||||
|
||||
// if (tools.sulServer()) {
|
||||
if (true) {
|
||||
|
||||
const ris = await User.findOneAndUpdate({
|
||||
idapp,
|
||||
@@ -3219,8 +3524,8 @@ UserSchema.statics.getNameSurnameById = async function (idapp, userId) {
|
||||
|
||||
UserSchema.statics.getusersManagers = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
return await User.find({ idapp, 'profile.manage_telegram': true },
|
||||
// Int32 mongodb 6.0
|
||||
return await User.find({ idapp, 'profile.manage_telegram': true, perm: { $bitsAnySet: 0b010 } },
|
||||
{ username: 1, 'profile.teleg_id': 1, perm: 1 }).then((arrrec) => {
|
||||
return (!!arrrec) ? arrrec : null;
|
||||
}).catch((e) => {
|
||||
@@ -3228,6 +3533,19 @@ UserSchema.statics.getusersManagers = async function (idapp) {
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getusersAdmin = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
// Int32 mongodb 6.0
|
||||
|
||||
return await User.find({ idapp, 'profile.manage_telegram': true, perm: { $bitsAnySet: 0b001 } },
|
||||
{ username: 1, 'profile.teleg_id': 1, perm: 1 }).then((arrrec) => {
|
||||
return (!!arrrec) ? arrrec : null;
|
||||
}).catch((e) => {
|
||||
console.error('getusersAdmin', e);
|
||||
});
|
||||
};
|
||||
|
||||
UserSchema.statics.getusersRespList = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
@@ -3310,7 +3628,7 @@ UserSchema.statics.isManagerByIdTeleg = async function (idapp, idtelegram) {
|
||||
}, { 'profile.teleg_id': 1 }).then((rec) => {
|
||||
return (!!rec && rec.profile.teleg_id === idtelegram);
|
||||
}).catch((e) => {
|
||||
console.error('getusersManagers', e);
|
||||
console.error('isManagerByIdTeleg', e);
|
||||
return false;
|
||||
});
|
||||
};
|
||||
@@ -3758,7 +4076,7 @@ UserSchema.statics.getUsersDreams = async function (idapp) {
|
||||
UserSchema.statics.getLastUsers = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_USERS', 5);
|
||||
const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_N_USERS', 10);
|
||||
|
||||
return await User.find(
|
||||
{
|
||||
@@ -3786,7 +4104,7 @@ UserSchema.statics.getLastUsers = async function (idapp) {
|
||||
UserSchema.statics.getLastOnlineUsers = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_ONLINE_USERS', 10);
|
||||
const lastn = await Settings.getValDbSettings(idapp, 'SHOW_LAST_ONLINE_USERS', 20);
|
||||
|
||||
return await User.find(
|
||||
{
|
||||
@@ -3893,6 +4211,7 @@ UserSchema.statics.calculateStat = async function (idapp, username) {
|
||||
const { MyGood } = require('../models/mygood');
|
||||
const { MyBacheca } = require('../models/mybacheca');
|
||||
const { MyGroup } = require('../models/mygroup');
|
||||
const globalTables = require('../tools/globalTables');
|
||||
|
||||
const numUsersReg = await User.countDocuments(
|
||||
{
|
||||
@@ -3904,8 +4223,6 @@ UserSchema.statics.calculateStat = async function (idapp, username) {
|
||||
|
||||
let numByTab = {};
|
||||
|
||||
const globalTables = require('../tools/globalTables');
|
||||
|
||||
for (let table of shared_consts.TABLES_VISU_STAT_IN_HOME) {
|
||||
let mytable = globalTables.getTableByTableName(table);
|
||||
if (mytable) {
|
||||
@@ -4329,7 +4646,7 @@ UserSchema.statics.calcnumRegUntilDay = async function (idapp) {
|
||||
UserSchema.statics.calcRegDaily = async function (idapp) {
|
||||
const User = this;
|
||||
|
||||
return await User.aggregate(User.getUsersRegDaily(idapp, 60)).then(ris => {
|
||||
return await User.aggregate(User.getUsersRegDaily(idapp, 90)).then(ris => {
|
||||
// console.table(ris);
|
||||
return ris;
|
||||
});
|
||||
@@ -4346,11 +4663,18 @@ UserSchema.statics.calcRegWeekly = async function (idapp) {
|
||||
|
||||
if (tools.INITDB_FIRSTIME) {
|
||||
console.log(' createIndex User Index...');
|
||||
|
||||
UserSchema.index({ userId: 1 });
|
||||
UserSchema.index({ 'idapp': 1 });
|
||||
|
||||
|
||||
// UserSchema.index({ username: 'text', name: 'text', surname: 'text', email: 'text' });
|
||||
// UserSchema.index({ name: 'name' });
|
||||
// UserSchema.index({ name: 1 });
|
||||
// UserSchema.index({ surname: 1 });
|
||||
// ter
|
||||
|
||||
tools.INITDB_FIRSTIME = false;
|
||||
}
|
||||
|
||||
UserSchema.statics.getUsernameByIndex = async function (idapp, index) {
|
||||
@@ -4622,17 +4946,28 @@ UserSchema.statics.getExtraInfoByUsername = async function (idapp, username) {
|
||||
return myuser.profile;
|
||||
|
||||
};
|
||||
UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave) {
|
||||
UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave, version) {
|
||||
|
||||
try {
|
||||
// tools.startTimeLog('addExtraInfo')
|
||||
|
||||
try {
|
||||
if (recUserSave && recUser.profile && recUser.profile.notifs && recUser.profile.notifs.length <= 0) {
|
||||
recUser.profile.notifs = shared_consts.DEFAULT_NOTIFS_USER;
|
||||
await recUserSave.save();
|
||||
if (version) {
|
||||
let versattualeuser = 0;
|
||||
if (!recUser.profile.version) {
|
||||
recUser.version = 0;
|
||||
versattualeuser = 0;
|
||||
} else {
|
||||
versattualeuser = recUser.profile.version;
|
||||
}
|
||||
|
||||
// versattualeuser = 0; // TOGLIERE!
|
||||
|
||||
if (versattualeuser < version) {
|
||||
// Aggiornamento versione
|
||||
recUser = await User.updateVersion(versattualeuser, recUser);
|
||||
|
||||
await User.findOneAndUpdate({ _id: recUser._id }, { $set: { 'profile.version': version } });
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Err addExtraInfo notifs ', e);
|
||||
}
|
||||
|
||||
const listSentMyRequestFriends = await User.find({
|
||||
@@ -4687,6 +5022,8 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave) {
|
||||
{ deleted: { $exists: true, $eq: false } }],
|
||||
}).lean();
|
||||
|
||||
recUser.profile.reaction = await Reaction.find({ idapp, username: recUser.username }).lean();
|
||||
|
||||
recUser.profile.manage_mygroups = listManageGroups
|
||||
? listManageGroups
|
||||
: [];
|
||||
@@ -4711,6 +5048,7 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave) {
|
||||
|
||||
recUser.profile.calc = await User.calcOtherByUser(idapp, recUser._id);
|
||||
|
||||
// tools.endTimeLog('addExtraInfo')
|
||||
|
||||
return recUser;
|
||||
|
||||
@@ -4721,6 +5059,179 @@ UserSchema.statics.addExtraInfo = async function (idapp, recUser, recUserSave) {
|
||||
return recUser;
|
||||
};
|
||||
|
||||
addRecordReaction = async function (arr, fields, fieldtoset) {
|
||||
let newrecord = {};
|
||||
|
||||
try {
|
||||
|
||||
if (tools.isArray(arr)) {
|
||||
for (let myrec of arr) {
|
||||
if (myrec.id) {
|
||||
let myfields = { ...{ idrec: myrec.id }, ...fields };
|
||||
newrecord = await Reaction.findOne(myfields)
|
||||
|
||||
if (!newrecord) {
|
||||
newrecord = new Reaction(myfields);
|
||||
// console.log('Nuovo Record: ', newrecord._doc);
|
||||
}
|
||||
|
||||
newrecord[fieldtoset] = true;
|
||||
|
||||
await newrecord.save();
|
||||
|
||||
let newrecfound = await Reaction.findOne(myfields)
|
||||
}
|
||||
// if (newrecfound)
|
||||
// console.log('trovato')
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
UserSchema.statics.moverecordsFavorite = async function (tab) {
|
||||
const { MySkill } = require('../models/myskill');
|
||||
const { MyGood } = require('../models/mygood');
|
||||
|
||||
console.log('INIZIO - moverecordsFavorite tab', tab);
|
||||
|
||||
const arrusers = await User.find({ idapp: '13' }).lean();
|
||||
|
||||
let index = 0;
|
||||
try {
|
||||
|
||||
|
||||
let index = 0;
|
||||
let totali = 0;
|
||||
for (let user of arrusers) {
|
||||
|
||||
if (user.profile) {
|
||||
let arrfav = user.profile.favorite;
|
||||
let arrseen = user.profile.seen;
|
||||
let arrbookmark = user.profile.bookmark;
|
||||
let arrattend = user.profile.attend;
|
||||
|
||||
totali++;
|
||||
|
||||
if (arrfav || arrseen) {
|
||||
console.log('utente n.', index, 'su', totali, user.username);
|
||||
index++;
|
||||
|
||||
let fields = {
|
||||
idapp: user.idapp,
|
||||
userId: user._id,
|
||||
username: user.username,
|
||||
tab
|
||||
};
|
||||
|
||||
await addRecordReaction(arrfav, fields, 'fav');
|
||||
await addRecordReaction(arrseen, fields, 'seen');
|
||||
await addRecordReaction(arrbookmark, fields, 'book:');
|
||||
await addRecordReaction(arrattend, fields, 'attend');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
|
||||
console.log('fine moverecordsFavorite');
|
||||
|
||||
};
|
||||
|
||||
UserSchema.statics.removerecordsFavorite = async function () {
|
||||
// Rimuovi i record del vecchio schema
|
||||
const attivacanc = true;
|
||||
|
||||
if (attivacanc) {
|
||||
const queryfind = { idapp: '13' };
|
||||
await User.findOneAndUpdate(queryfind, {
|
||||
$set:
|
||||
{
|
||||
'profile.favorite': [],
|
||||
'profile.bookmark': [],
|
||||
'profile.attend': [],
|
||||
'profile.seen': []
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
UserSchema.statics.updateVersion = async function (userversion, recUser) {
|
||||
|
||||
const { MySkill } = require('../models/myskill');
|
||||
const { MyGood } = require('../models/mygood');
|
||||
const { City } = require('../models/city');
|
||||
|
||||
if (userversion < 604) {
|
||||
if (!recUser.profile.notifs || recUser.profile.notifs.length === 0) {
|
||||
recUser.profile.notifs = shared_consts.DEFAULT_NOTIFS_USER;
|
||||
}
|
||||
|
||||
const recfavoriteNotif = recUser.profile.notifs.find((rec) => rec.dir === shared_consts.TypeNotifs.TYPEDIR_FAVORITE);
|
||||
if (!recfavoriteNotif) {
|
||||
recUser.profile.notifs.push({ dir: shared_consts.TypeNotifs.TYPEDIR_FAVORITE, value: shared_consts.TypeNotifs.ID_FAVORITE_ADDED })
|
||||
}
|
||||
|
||||
const recAttendNotif = recUser.profile.notifs.find((rec) => rec.dir === shared_consts.TypeNotifs.TYPEDIR_EVENTS);
|
||||
if (recAttendNotif) {
|
||||
if (!tools.isBitActive(recAttendNotif.value, shared_consts.TypeNotifs.ID_EVENTS_ATTEND)) {
|
||||
recAttendNotif.value = tools.SetBit(recAttendNotif.value, shared_consts.TypeNotifs.ID_EVENTS_ATTEND);
|
||||
}
|
||||
|
||||
for (let i = 0; i < recUser.profile.notifs.length; i++) {
|
||||
if (recUser.profile.notifs[i].dir === shared_consts.TypeNotifs.TYPEDIR_EVENTS)
|
||||
recUser.profile.notifs[i].value = recAttendNotif.value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Imposta la provincia, se non l'ho messa, in base al bene o servizio che hai messo.
|
||||
if (!recUser.profile.resid_province) {
|
||||
let resid_province = '';
|
||||
const firstrec = await MySkill.findOne({ userId: recUser._id }).lean();
|
||||
if (firstrec && firstrec.idCity && firstrec.idCity.length > 0) {
|
||||
resid_province = await City.getProvinceByIdCity(firstrec.idCity[0]);
|
||||
} else {
|
||||
const firstrec = await MyGood.findOne({ userId: recUser._id }).lean();
|
||||
if (firstrec && firstrec.idCity && firstrec.idCity.length === 1) {
|
||||
resid_province = await City.getProvinceByIdCity(firstrec.idCity[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (resid_province) {
|
||||
await User.findOneAndUpdate({ _id: recUser._id }, { $set: { 'profile.resid_province': resid_province } });
|
||||
}
|
||||
}
|
||||
|
||||
let recmybach = recUser.profile.notifs.find((rec) => rec.dir === shared_consts.TypeNotifs.TYPEDIR_BACHECA);
|
||||
if (!tools.isBitActive(recmybach.value, shared_consts.UsersNotif.NEW_ADV_YOUR_PROVINCE)) {
|
||||
recmybach.value = tools.SetBit(recmybach.value, shared_consts.UsersNotif.NEW_ADV_YOUR_PROVINCE);
|
||||
for (let i = 0; i < recUser.profile.notifs.length; i++) {
|
||||
if (recUser.profile.notifs[i].dir === shared_consts.TypeNotifs.TYPEDIR_BACHECA)
|
||||
recUser.profile.notifs[i].value = recmybach.value;
|
||||
}
|
||||
}
|
||||
|
||||
await User.findOneAndUpdate({ _id: recUser._id }, { $set: { 'profile.notifs': recUser.profile.notifs } });
|
||||
}
|
||||
|
||||
if (userversion < 1016) {
|
||||
|
||||
}
|
||||
|
||||
return recUser;
|
||||
};
|
||||
|
||||
UserSchema.statics.calcOtherByUser = async function (idapp, userId) {
|
||||
|
||||
const { MySkill } = require('../models/myskill');
|
||||
@@ -4805,6 +5316,7 @@ UserSchema.statics.createNewSubRecord = async function (idapp, req) {
|
||||
return rec;
|
||||
};
|
||||
|
||||
|
||||
const User = mongoose.model('User', UserSchema);
|
||||
|
||||
class Hero {
|
||||
@@ -4819,6 +5331,45 @@ class Hero {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { User, Hero };
|
||||
const FuncUsers = {
|
||||
createRegistration_withTelegram(userdata) {
|
||||
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
try {
|
||||
// Cerca se esiste già
|
||||
const user = new User(userdata);
|
||||
|
||||
user.verified_email = false;
|
||||
user.lasttimeonline = new Date();
|
||||
user.date_reg = new Date();
|
||||
|
||||
return user.save().then(async () => {
|
||||
return User.findByUsername(user.idapp, user.username, false).
|
||||
then(async (usertrovato) => {
|
||||
|
||||
const numutenti = await User.getNumUsers(user.idapp);
|
||||
|
||||
let msg = '++ Nuovo Entrato: [' + numutenti + '] ' + user.username + ' ' + user.name + ' ' + user.surname;
|
||||
|
||||
await telegrambot.sendMsgTelegramToTheManagers(user.idapp, msg);
|
||||
|
||||
return telegrambot.askConfirmationUser(user.idapp, shared_consts.CallFunz.REGISTRATION, user, '', '', '', '');
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.error(e.message);
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
module.exports = {
|
||||
User, Hero, FuncUsers
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -89298,5 +89298,16 @@ module.exports = {
|
||||
abitanti: '',
|
||||
country: 'ONL',
|
||||
},
|
||||
{
|
||||
_id: 8120,
|
||||
istat: '',
|
||||
comune: 'Italia',
|
||||
prov: 'ITA',
|
||||
reg: 'ITA',
|
||||
pref: '',
|
||||
cap: '',
|
||||
abitanti: '',
|
||||
country: 'ITA',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -62,5 +62,13 @@ module.exports = {
|
||||
{_id: 60, idSectorGood: [17], descr: 'Per Imbiancare'},
|
||||
{_id: 61, idSectorGood: [17], descr: 'Giardinaggio'},
|
||||
{_id: 62, idSectorGood: [17], descr: 'Falegnameria'},
|
||||
{_id: 63, idSectorGood: [7], descr: 'Pane'},
|
||||
{_id: 64, idSectorGood: [7], descr: 'Pasta'},
|
||||
{_id: 65, idSectorGood: [7], descr: 'Formaggi'},
|
||||
{_id: 66, idSectorGood: [7], descr: 'Olio'},
|
||||
{_id: 67, idSectorGood: [7], descr: 'Fervida'},
|
||||
{_id: 68, idSectorGood: [7], descr: 'Fermentati'},
|
||||
{_id: 69, idSectorGood: [7], descr: 'Marmellate'},
|
||||
{_id: 70, idSectorGood: [7], descr: 'Salse'},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -1,124 +1,126 @@
|
||||
module.exports = {
|
||||
list: [
|
||||
{_id: 1, reg: 'SIC', prov: 'AG', descr: 'Agrigento', link_grp: 'https://t.me/c/1614195634/562?thread=553'},
|
||||
{_id: 2, reg: 'PIE', prov: 'AL', descr: 'Alessandria', link_grp: 'https://t.me/c/1614195634/513?thread=504'},
|
||||
{_id: 3, reg: 'MAR', prov: 'AN', descr: 'Ancona', link_grp: 'https://t.me/c/1614195634/450?thread=446'},
|
||||
{_id: 4, reg: 'VDA', prov: 'AO', descr: 'Aosta', link_grp: 'https://t.me/c/1614195634/521?thread=520'},
|
||||
{_id: 5, reg: 'TOS', prov: 'AR', descr: 'Arezzo', link_grp: 'https://t.me/c/1614195634/583?thread=572'},
|
||||
{_id: 6, reg: 'MAR', prov: 'AP', descr: 'Ascoli Piceno', link_grp: 'https://t.me/c/1614195634/451?thread=447'},
|
||||
{_id: 7, reg: 'PIE', prov: 'AT', descr: 'Asti', link_grp: 'https://t.me/c/1614195634/514?thread=505'},
|
||||
{_id: 8, reg: 'CAM', prov: 'AV', descr: 'Avellino', link_grp: 'https://t.me/c/1614195634/413?thread=409'},
|
||||
{_id: 9, reg: 'PUG', prov: 'BA', descr: 'Bari', link_grp: 'https://t.me/c/1614195634/534?thread=528'},
|
||||
{_id: 10, reg: 'PUG', prov: 'BT', descr: 'Barletta-Andria-Trani', link_grp: 'https://t.me/c/1614195634/535?thread=529'},
|
||||
{_id: 11, reg: 'VEN', prov: 'BL', descr: 'Belluno', link_grp: 'https://t.me/c/1614195634/608?thread=599'},
|
||||
{_id: 12, reg: 'CAM', prov: 'BN', descr: 'Benevento', link_grp: 'https://t.me/c/1614195634/415?thread=411'},
|
||||
{_id: 13, reg: 'LOM', prov: 'BG', descr: 'Bergamo', link_grp: 'https://t.me/c/1614195634/491?thread=477'},
|
||||
{_id: 14, reg: 'PIE', prov: 'BI', descr: 'Biella', link_grp: 'https://t.me/c/1614195634/515?thread=506'},
|
||||
{_id: 15, reg: 'EMR', prov: 'BO', descr: 'Bologna', link_grp: 'https://t.me/c/1614195634/428?thread=419'},
|
||||
{_id: 16, reg: 'TAA', prov: 'BZ', descr: 'Bolzano', link_grp: 'https://t.me/c/1614195634/596?thread=594'},
|
||||
{_id: 17, reg: 'LOM', prov: 'BS', descr: 'Brescia', link_grp: 'https://t.me/c/1614195634/490?thread=478'},
|
||||
{_id: 18, reg: 'PUG', prov: 'BR', descr: 'Brindisi', link_grp: 'https://t.me/c/1614195634/536?thread=530'},
|
||||
{_id: 19, reg: 'SAR', prov: 'CA', descr: 'Cagliari', link_grp: 'https://t.me/c/1614195634/546?thread=541'},
|
||||
{_id: 20, reg: 'SIC', prov: 'CL', descr: 'Caltanissetta', link_grp: 'https://t.me/c/1614195634/563?thread=554'},
|
||||
{_id: 21, reg: 'MOL', prov: 'CB', descr: 'Campobasso', link_grp: 'https://t.me/c/1614195634/398?thread=396'},
|
||||
{_id: 22, reg: 'SAR', prov: 'CI', descr: 'Carbonia-Iglesias', link_grp: ''},
|
||||
{_id: 23, reg: 'CAM', prov: 'CE', descr: 'Caserta', link_grp: 'https://t.me/c/1614195634/414?thread=410'},
|
||||
{_id: 24, reg: 'SIC', prov: 'CT', descr: 'Catania', link_grp: 'https://t.me/c/1614195634/564?thread=555'},
|
||||
{_id: 25, reg: 'CAL', prov: 'CZ', descr: 'Catanzaro', link_grp: 'https://t.me/c/1614195634/378?thread=377'},
|
||||
{_id: 26, reg: 'ABR', prov: 'CH', descr: 'Chieti', link_grp: 'https://t.me/c/1614195634/366?thread=365'},
|
||||
{_id: 27, reg: 'LOM', prov: 'CO', descr: 'Como', link_grp: 'https://t.me/c/1614195634/492?thread=479'},
|
||||
{_id: 28, reg: 'CAL', prov: 'CS', descr: 'Cosenza', link_grp: 'https://t.me/c/1614195634/381?thread=379'},
|
||||
{_id: 29, reg: 'LOM', prov: 'CR', descr: 'Cremona', link_grp: 'https://t.me/c/1614195634/493?thread=480'},
|
||||
{_id: 30, reg: 'CAL', prov: 'KR', descr: 'Crotone', link_grp: 'https://t.me/c/1614195634/382?thread=380'},
|
||||
{_id: 31, reg: 'PIE', prov: 'CN', descr: 'Cuneo', link_grp: 'https://t.me/c/1614195634/516?thread=507'},
|
||||
{_id: 32, reg: 'SIC', prov: 'EN', descr: 'Enna', link_grp: 'https://t.me/c/1614195634/565?thread=556'},
|
||||
{_id: 33, reg: 'MAR', prov: 'FM', descr: 'Fermo', link_grp: 'https://t.me/c/1614195634/453?thread=448'},
|
||||
{_id: 34, reg: 'EMR', prov: 'FE', descr: 'Ferrara', link_grp: 'https://t.me/c/1614195634/429?thread=420'},
|
||||
{_id: 35, reg: 'TOS', prov: 'FI', descr: 'Firenze', link_grp: 'https://t.me/c/1614195634/584?thread=573'},
|
||||
{_id: 36, reg: 'PUG', prov: 'FG', descr: 'Foggia', link_grp: 'https://t.me/c/1614195634/537?thread=531'},
|
||||
{_id: 37, reg: 'EMR', prov: 'FC', descr: 'Forli-Cesena', link_grp: 'https://t.me/c/1614195634/430?thread=421'},
|
||||
{_id: 38, reg: 'LAZ', prov: 'FR', descr: 'Frosinone', link_grp: 'https://t.me/c/1614195634/48?thread=44'},
|
||||
{_id: 39, reg: 'LIG', prov: 'GE', descr: 'Genova', link_grp: 'https://t.me/c/1614195634/392?thread=388'},
|
||||
{_id: 40, reg: 'FVG', prov: 'GO', descr: 'Gorizia', link_grp: 'https://t.me/c/1614195634/469?thread=465'},
|
||||
{_id: 41, reg: 'TOS', prov: 'GR', descr: 'Grosseto', link_grp: 'https://t.me/c/1614195634/585?thread=574'},
|
||||
{_id: 42, reg: 'LIG', prov: 'IM', descr: 'Imperia', link_grp: 'https://t.me/c/1614195634/393?thread=389'},
|
||||
{_id: 43, reg: 'MOL', prov: 'IS', descr: 'Isernia', link_grp: 'https://t.me/c/1614195634/399?thread=397'},
|
||||
{_id: 44, reg: 'LIG', prov: 'SP', descr: 'La Spezia', link_grp: 'https://t.me/c/1614195634/394?thread=390'},
|
||||
{_id: 45, reg: 'ABR', prov: 'AQ', descr: 'L\'Aquila', link_grp: 'https://t.me/c/1614195634/364?thread=363'},
|
||||
{_id: 46, reg: 'LAZ', prov: 'LT', descr: 'Latina', link_grp: 'https://t.me/c/1614195634/60?thread=46'},
|
||||
{_id: 47, reg: 'PUG', prov: 'LE', descr: 'Lecce', link_grp: 'https://t.me/c/1614195634/538?thread=532'},
|
||||
{_id: 48, reg: 'LOM', prov: 'LC', descr: 'Lecco', link_grp: 'https://t.me/c/1614195634/494?thread=482'},
|
||||
{_id: 49, reg: 'TOS', prov: 'LI', descr: 'Livorno', link_grp: 'https://t.me/c/1614195634/586?thread=575'},
|
||||
{_id: 50, reg: 'LOM', prov: 'LO', descr: 'Lodi', link_grp: 'https://t.me/c/1614195634/495?thread=483'},
|
||||
{_id: 51, reg: 'TOS', prov: 'LU', descr: 'Lucca', link_grp: 'https://t.me/c/1614195634/587?thread=576'},
|
||||
{_id: 52, reg: 'MAR', prov: 'MC', descr: 'Macerata', link_grp: 'https://t.me/c/1614195634/300?thread=162'},
|
||||
{_id: 53, reg: 'LOM', prov: 'MN', descr: 'Mantova', link_grp: 'https://t.me/c/1614195634/497?thread=484'},
|
||||
{_id: 54, reg: 'TOS', prov: 'MS', descr: 'Massa-Carrara', link_grp: 'https://t.me/c/1614195634/588?thread=577'},
|
||||
{_id: 55, reg: 'BAS', prov: 'MT', descr: 'Matera', link_grp: 'https://t.me/c/1614195634/374?thread=373'},
|
||||
{_id: 56, reg: 'SIC', prov: 'ME', descr: 'Messina', link_grp: 'https://t.me/c/1614195634/566?thread=557'},
|
||||
{_id: 57, reg: 'LOM', prov: 'MI', descr: 'Milano', link_grp: 'https://t.me/c/1614195634/214?thread=173'},
|
||||
{_id: 58, reg: 'EMR', prov: 'MO', descr: 'Modena', link_grp: 'https://t.me/c/1614195634/431?thread=422'},
|
||||
{_id: 59, reg: 'LOM', prov: 'MB', descr: 'Monza e della Brianza', link_grp: 'https://t.me/c/1614195634/498?thread=485'},
|
||||
{_id: 60, reg: 'CAM', prov: 'NA', descr: 'Napoli', link_grp: 'https://t.me/c/1614195634/407?thread=406'},
|
||||
{_id: 61, reg: 'PIE', prov: 'NO', descr: 'Novara', link_grp: 'https://t.me/c/1614195634/517?thread=508'},
|
||||
{_id: 62, reg: 'SAR', prov: 'NU', descr: 'Nuoro', link_grp: 'https://t.me/c/1614195634/548?thread=542'},
|
||||
{_id: 63, reg: 'SAR', prov: 'OT', descr: 'Olbia-Tempio', link_grp: ''},
|
||||
{_id: 64, reg: 'SAR', prov: 'OR', descr: 'Oristano', link_grp: 'https://t.me/c/1614195634/550?thread=543'},
|
||||
{_id: 65, reg: 'VEN', prov: 'PD', descr: 'Padova', link_grp: 'https://t.me/c/1614195634/610?thread=600'},
|
||||
{_id: 66, reg: 'SIC', prov: 'PA', descr: 'Palermo', link_grp: 'https://t.me/c/1614195634/568?thread=558'},
|
||||
{_id: 67, reg: 'EMR', prov: 'PR', descr: 'Parma', link_grp: 'https://t.me/c/1614195634/432?thread=423'},
|
||||
{_id: 68, reg: 'LOM', prov: 'PV', descr: 'Pavia', link_grp: 'https://t.me/c/1614195634/499?thread=486'},
|
||||
{_id: 69, reg: 'UMB', prov: 'PG', descr: 'Perugia', link_grp: 'https://t.me/c/1614195634/403?thread=401'},
|
||||
{_id: 70, reg: 'MAR', prov: 'PU', descr: 'Pesaro e Urbino', link_grp: 'https://t.me/c/1614195634/454?thread=449'},
|
||||
{_id: 71, reg: 'ABR', prov: 'PE', descr: 'Pescara', link_grp: 'https://t.me/c/1614195634/368?thread=367'},
|
||||
{_id: 72, reg: 'EMR', prov: 'PC', descr: 'Piacenza', link_grp: 'https://t.me/c/1614195634/433?thread=424'},
|
||||
{_id: 73, reg: 'TOS', prov: 'PI', descr: 'Pisa', link_grp: 'https://t.me/c/1614195634/589?thread=578'},
|
||||
{_id: 74, reg: 'TOS', prov: 'PT', descr: 'Pistoia', link_grp: 'https://t.me/c/1614195634/590?thread=579'},
|
||||
{_id: 75, reg: 'FVG', prov: 'PN', descr: 'Pordenone', link_grp: 'https://t.me/c/1614195634/470?thread=466'},
|
||||
{_id: 76, reg: 'BAS', prov: 'PZ', descr: 'Potenza', link_grp: 'https://t.me/c/1614195634/376?thread=375'},
|
||||
{_id: 77, reg: 'TOS', prov: 'PO', descr: 'Prato', link_grp: 'https://t.me/c/1614195634/591?thread=580'},
|
||||
{_id: 78, reg: 'SIC', prov: 'RG', descr: 'Ragusa', link_grp: 'https://t.me/c/1614195634/569?thread=559'},
|
||||
{_id: 79, reg: 'EMR', prov: 'RA', descr: 'Ravenna', link_grp: 'https://t.me/c/1614195634/434?thread=425'},
|
||||
{_id: 80, reg: 'CAL', prov: 'RC', descr: 'Reggio Calabria', link_grp: 'https://t.me/c/1614195634/385?thread=383'},
|
||||
{_id: 81, reg: 'EMR', prov: 'RE', descr: 'Reggio Emilia', link_grp: 'https://t.me/c/1614195634/435?thread=426'},
|
||||
{_id: 82, reg: 'LAZ', prov: 'RI', descr: 'Rieti', link_grp: 'https://t.me/c/1614195634/61?thread=45'},
|
||||
{_id: 83, reg: 'EMR', prov: 'RN', descr: 'Rimini', link_grp: 'https://t.me/c/1614195634/436?thread=https://t.me/c/1614195634/64?thread=57427'},
|
||||
{_id: 84, reg: 'LAZ', prov: 'RM', descr: 'Roma', link_grp: ''},
|
||||
{_id: 85, reg: 'VEN', prov: 'RO', descr: 'Rovigo', link_grp: 'https://t.me/c/1614195634/611?thread=601'},
|
||||
{_id: 86, reg: 'CAM', prov: 'SA', descr: 'Salerno', link_grp: 'https://t.me/c/1614195634/416?thread=412'},
|
||||
{_id: 87, reg: 'SAR', prov: 'VS', descr: 'Medio Campidano', link_grp: ''},
|
||||
{_id: 88, reg: 'SAR', prov: 'SS', descr: 'Sassari', link_grp: 'https://t.me/c/1614195634/551?thread=544'},
|
||||
{_id: 89, reg: 'LIG', prov: 'SV', descr: 'Savona', link_grp: 'https://t.me/c/1614195634/395?thread=391'},
|
||||
{_id: 90, reg: 'TOS', prov: 'SI', descr: 'Siena', link_grp: 'https://t.me/c/1614195634/592?thread=581'},
|
||||
{_id: 91, reg: 'SIC', prov: 'SR', descr: 'Siracusa', link_grp: 'https://t.me/c/1614195634/570?thread=560'},
|
||||
{_id: 92, reg: 'LOM', prov: 'SO', descr: 'Sondrio', link_grp: 'https://t.me/c/1614195634/500?thread=487'},
|
||||
{_id: 93, reg: 'PUG', prov: 'TA', descr: 'Taranto', link_grp: 'https://t.me/c/1614195634/539?thread=533'},
|
||||
{_id: 94, reg: 'ABR', prov: 'TE', descr: 'Teramo', link_grp: 'https://t.me/c/1614195634/370?thread=369'},
|
||||
{_id: 95, reg: 'UMB', prov: 'TR', descr: 'Terni', link_grp: 'https://t.me/c/1614195634/404?thread=402'},
|
||||
{_id: 96, reg: 'PIE', prov: 'TO', descr: 'Torino', link_grp: 'https://t.me/c/1614195634/518?thread=509'},
|
||||
{_id: 97, reg: 'SAR', prov: 'OG', descr: 'Ogliastra', link_grp: ''},
|
||||
{_id: 98, reg: 'SIC', prov: 'TP', descr: 'Trapani', link_grp: 'https://t.me/c/1614195634/571?thread=561'},
|
||||
{_id: 99, reg: 'TAA', prov: 'TN', descr: 'Trento', link_grp: 'https://t.me/c/1614195634/597?thread=595'},
|
||||
{_id: 100, reg: 'VEN', prov: 'TV', descr: 'Treviso', link_grp: 'https://t.me/c/1614195634/612?thread=602'},
|
||||
{_id: 101, reg: 'FVG', prov: 'TS', descr: 'Trieste', link_grp: 'https://t.me/c/1614195634/471?thread=467'},
|
||||
{_id: 102, reg: 'FVG', prov: 'UD', descr: 'Udine', link_grp: 'https://t.me/c/1614195634/472?thread=468'},
|
||||
{_id: 103, reg: 'LOM', prov: 'VA', descr: 'Varese', link_grp: 'https://t.me/c/1614195634/501?thread=488'},
|
||||
{_id: 104, reg: 'VEN', prov: 'VE', descr: 'Venezia', link_grp: 'https://t.me/c/1614195634/613?thread=603'},
|
||||
{_id: 105, reg: 'PIE', prov: 'VB', descr: 'Verbano-Cusio-Ossola', link_grp: 'https://t.me/c/1614195634/519?thread=510 '},
|
||||
{_id: 106, reg: 'PIE', prov: 'VC', descr: 'Vercelli', link_grp: 'https://t.me/c/1614195634/512?thread=511'},
|
||||
{_id: 107, reg: 'VEN', prov: 'VR', descr: 'Verona', link_grp: 'https://t.me/c/1614195634/614?thread=604'},
|
||||
{_id: 108, reg: 'CAL', prov: 'VV', descr: 'Vibo Valentia', link_grp: 'https://t.me/c/1614195634/386?thread=384'},
|
||||
{_id: 109, reg: 'VEN', prov: 'VI', descr: 'Vicenza', link_grp: 'https://t.me/c/1614195634/615?thread=605'},
|
||||
{_id: 110, reg: 'LAZ', prov: 'VT', descr: 'Viterbo', link_grp: 'https://t.me/c/1614195634/76?thread=74'},
|
||||
{_id: 111, reg: 'RSM', prov: 'RSM', descr: 'Repubblica di San Marino', link_grp: 'https://t.me/+HSdNurm0IXY1MGI0'},
|
||||
{_id: 112, reg: 'EST', prov: 'EST', descr: 'Estero', link_grp: ''},
|
||||
{_id: 113, reg: 'ONL', prov: 'ONL', descr: 'On Line', link_grp: ''},
|
||||
{_id: 114, reg: 'LAZ', prov: 'RM', descr: 'Roma Nord-Est', link_grp: 'https://t.me/c/1614195634/64?thread=57'},
|
||||
{_id: 115, reg: 'LAZ', prov: 'RM', descr: 'Roma Sud-Est', link_grp: 'https://t.me/c/1614195634/65?thread=58'},
|
||||
{_id: 116, reg: 'LAZ', prov: 'RM', descr: 'Roma Nord', link_grp: 'https://t.me/c/1614195634/75?thread=73'},
|
||||
{_id: 117, reg: 'LAZ', prov: 'RM', descr: 'Roma Nord-Ovest', link_grp: 'https://t.me/c/1614195634/62?thread=47'},
|
||||
{_id: 118, reg: 'LAZ', prov: 'RM', descr: 'Roma Sud e Litorale', link_grp: 'https://t.me/c/1614195634/67?thread=43'},
|
||||
{_id: 119, reg: 'PUG', prov: 'VAL', descr: 'Valle D\'Itria', link_grp: 'https://t.me/progettoriso/7016?thread=7015'},
|
||||
{_id: 120, reg: 'SAR', prov: 'SUS', descr: 'Sud Sardegna', link_grp: 'https://t.me/c/1614195634/552?thread=545'},
|
||||
{_id: 1, reg: 'SIC', prov: 'AG', descr: 'Agrigento', link_grp: 'https://t.me/c/1614195634/562?thread=553', link_telegram: ''},
|
||||
{_id: 2, reg: 'PIE', prov: 'AL', descr: 'Alessandria', link_grp: 'https://t.me/c/1614195634/513?thread=504', link_telegram: ''},
|
||||
{_id: 3, reg: 'MAR', prov: 'AN', descr: 'Ancona', link_grp: 'https://t.me/c/1614195634/450?thread=446', link_telegram: ''},
|
||||
{_id: 4, reg: 'VDA', prov: 'AO', descr: 'Aosta', link_grp: 'https://t.me/c/1614195634/521?thread=520', link_telegram: ''},
|
||||
{_id: 5, reg: 'TOS', prov: 'AR', descr: 'Arezzo', link_grp: 'https://t.me/c/1614195634/583?thread=572', link_telegram: ''},
|
||||
{_id: 6, reg: 'MAR', prov: 'AP', descr: 'Ascoli Piceno', link_grp: 'https://t.me/c/1614195634/451?thread=447', link_telegram: ''},
|
||||
{_id: 7, reg: 'PIE', prov: 'AT', descr: 'Asti', link_grp: 'https://t.me/c/1614195634/514?thread=505', link_telegram: ''},
|
||||
{_id: 8, reg: 'CAM', prov: 'AV', descr: 'Avellino', link_grp: 'https://t.me/c/1614195634/413?thread=409', link_telegram: ''},
|
||||
{_id: 9, reg: 'PUG', prov: 'BA', descr: 'Bari', link_grp: 'https://t.me/c/1614195634/534?thread=528', link_telegram: ''},
|
||||
{_id: 10, reg: 'PUG', prov: 'BT', descr: 'Barletta-Andria-Trani', link_grp: 'https://t.me/c/1614195634/535?thread=529', link_telegram: ''},
|
||||
{_id: 11, reg: 'VEN', prov: 'BL', descr: 'Belluno', link_grp: 'https://t.me/c/1614195634/608?thread=599', link_telegram: ''},
|
||||
{_id: 12, reg: 'CAM', prov: 'BN', descr: 'Benevento', link_grp: 'https://t.me/c/1614195634/415?thread=411', link_telegram: ''},
|
||||
{_id: 13, reg: 'LOM', prov: 'BG', descr: 'Bergamo', link_grp: 'https://t.me/c/1614195634/491?thread=477', link_telegram: ''},
|
||||
{_id: 14, reg: 'PIE', prov: 'BI', descr: 'Biella', link_grp: 'https://t.me/c/1614195634/515?thread=506', link_telegram: ''},
|
||||
{_id: 15, reg: 'EMR', prov: 'BO', descr: 'Bologna', link_grp: 'https://t.me/c/1614195634/428?thread=419', link_telegram: ''},
|
||||
{_id: 16, reg: 'TAA', prov: 'BZ', descr: 'Bolzano', link_grp: 'https://t.me/c/1614195634/596?thread=594', link_telegram: ''},
|
||||
{_id: 17, reg: 'LOM', prov: 'BS', descr: 'Brescia', link_grp: 'https://t.me/c/1614195634/490?thread=478', link_telegram: ''},
|
||||
{_id: 18, reg: 'PUG', prov: 'BR', descr: 'Brindisi', link_grp: 'https://t.me/c/1614195634/536?thread=530', link_telegram: ''},
|
||||
{_id: 19, reg: 'SAR', prov: 'CA', descr: 'Cagliari', link_grp: 'https://t.me/c/1614195634/546?thread=541', link_telegram: ''},
|
||||
{_id: 20, reg: 'SIC', prov: 'CL', descr: 'Caltanissetta', link_grp: 'https://t.me/c/1614195634/563?thread=554', link_telegram: ''},
|
||||
{_id: 21, reg: 'MOL', prov: 'CB', descr: 'Campobasso', link_grp: 'https://t.me/c/1614195634/398?thread=396', link_telegram: ''},
|
||||
{_id: 22, reg: 'SAR', prov: 'CI', descr: 'Carbonia-Iglesias', link_grp: '', link_telegram: ''},
|
||||
{_id: 23, reg: 'CAM', prov: 'CE', descr: 'Caserta', link_grp: 'https://t.me/c/1614195634/414?thread=410', link_telegram: ''},
|
||||
{_id: 24, reg: 'SIC', prov: 'CT', descr: 'Catania', link_grp: 'https://t.me/c/1614195634/564?thread=555', link_telegram: ''},
|
||||
{_id: 25, reg: 'CAL', prov: 'CZ', descr: 'Catanzaro', link_grp: 'https://t.me/c/1614195634/378?thread=377', link_telegram: ''},
|
||||
{_id: 26, reg: 'ABR', prov: 'CH', descr: 'Chieti', link_grp: 'https://t.me/c/1614195634/366?thread=365', link_telegram: ''},
|
||||
{_id: 27, reg: 'LOM', prov: 'CO', descr: 'Como', link_grp: 'https://t.me/c/1614195634/492?thread=479', link_telegram: ''},
|
||||
{_id: 28, reg: 'CAL', prov: 'CS', descr: 'Cosenza', link_grp: 'https://t.me/c/1614195634/381?thread=379', link_telegram: ''},
|
||||
{_id: 29, reg: 'LOM', prov: 'CR', descr: 'Cremona', link_grp: 'https://t.me/c/1614195634/493?thread=480', link_telegram: ''},
|
||||
{_id: 30, reg: 'CAL', prov: 'KR', descr: 'Crotone', link_grp: 'https://t.me/c/1614195634/382?thread=380', link_telegram: ''},
|
||||
{_id: 31, reg: 'PIE', prov: 'CN', descr: 'Cuneo', link_grp: 'https://t.me/c/1614195634/516?thread=507', link_telegram: ''},
|
||||
{_id: 32, reg: 'SIC', prov: 'EN', descr: 'Enna', link_grp: 'https://t.me/c/1614195634/565?thread=556', link_telegram: ''},
|
||||
{_id: 33, reg: 'MAR', prov: 'FM', descr: 'Fermo', link_grp: 'https://t.me/c/1614195634/453?thread=448', link_telegram: ''},
|
||||
{_id: 34, reg: 'EMR', prov: 'FE', descr: 'Ferrara', link_grp: 'https://t.me/c/1614195634/429?thread=420', link_telegram: ''},
|
||||
{_id: 35, reg: 'TOS', prov: 'FI', descr: 'Firenze', link_grp: 'https://t.me/c/1614195634/584?thread=573', link_telegram: ''},
|
||||
{_id: 36, reg: 'PUG', prov: 'FG', descr: 'Foggia', link_grp: 'https://t.me/c/1614195634/537?thread=531', link_telegram: ''},
|
||||
{_id: 37, reg: 'EMR', prov: 'FC', descr: 'Forli-Cesena', link_grp: 'https://t.me/c/1614195634/430?thread=421', link_telegram: ''},
|
||||
{_id: 38, reg: 'LAZ', prov: 'FR', descr: 'Frosinone', link_grp: 'https://t.me/c/1614195634/48?thread=44', link_telegram: ''},
|
||||
{_id: 39, reg: 'LIG', prov: 'GE', descr: 'Genova', link_grp: 'https://t.me/c/1614195634/392?thread=388', link_telegram: ''},
|
||||
{_id: 40, reg: 'FVG', prov: 'GO', descr: 'Gorizia', link_grp: 'https://t.me/c/1614195634/469?thread=465', link_telegram: ''},
|
||||
{_id: 41, reg: 'TOS', prov: 'GR', descr: 'Grosseto', link_grp: 'https://t.me/c/1614195634/585?thread=574', link_telegram: ''},
|
||||
{_id: 42, reg: 'LIG', prov: 'IM', descr: 'Imperia', link_grp: 'https://t.me/c/1614195634/393?thread=389', link_telegram: ''},
|
||||
{_id: 43, reg: 'MOL', prov: 'IS', descr: 'Isernia', link_grp: 'https://t.me/c/1614195634/399?thread=397', link_telegram: ''},
|
||||
{_id: 44, reg: 'LIG', prov: 'SP', descr: 'La Spezia', link_grp: 'https://t.me/c/1614195634/394?thread=390', link_telegram: ''},
|
||||
{_id: 45, reg: 'ABR', prov: 'AQ', descr: 'L\'Aquila', link_grp: 'https://t.me/c/1614195634/364?thread=363', link_telegram: ''},
|
||||
{_id: 46, reg: 'LAZ', prov: 'LT', descr: 'Latina', link_grp: 'https://t.me/c/1614195634/60?thread=46', link_telegram: ''},
|
||||
{_id: 47, reg: 'PUG', prov: 'LE', descr: 'Lecce', link_grp: 'https://t.me/c/1614195634/538?thread=532', link_telegram: ''},
|
||||
{_id: 48, reg: 'LOM', prov: 'LC', descr: 'Lecco', link_grp: 'https://t.me/c/1614195634/494?thread=482', link_telegram: ''},
|
||||
{_id: 49, reg: 'TOS', prov: 'LI', descr: 'Livorno', link_grp: 'https://t.me/c/1614195634/586?thread=575', link_telegram: ''},
|
||||
{_id: 50, reg: 'LOM', prov: 'LO', descr: 'Lodi', link_grp: 'https://t.me/c/1614195634/495?thread=483', link_telegram: ''},
|
||||
{_id: 51, reg: 'TOS', prov: 'LU', descr: 'Lucca', link_grp: 'https://t.me/c/1614195634/587?thread=576', link_telegram: ''},
|
||||
{_id: 52, reg: 'MAR', prov: 'MC', descr: 'Macerata', link_grp: 'https://t.me/c/1614195634/300?thread=162', link_telegram: ''},
|
||||
{_id: 53, reg: 'LOM', prov: 'MN', descr: 'Mantova', link_grp: 'https://t.me/c/1614195634/497?thread=484', link_telegram: ''},
|
||||
{_id: 54, reg: 'TOS', prov: 'MS', descr: 'Massa-Carrara', link_grp: 'https://t.me/c/1614195634/588?thread=577', link_telegram: ''},
|
||||
{_id: 55, reg: 'BAS', prov: 'MT', descr: 'Matera', link_grp: 'https://t.me/c/1614195634/374?thread=373', link_telegram: ''},
|
||||
{_id: 56, reg: 'SIC', prov: 'ME', descr: 'Messina', link_grp: 'https://t.me/c/1614195634/566?thread=557', link_telegram: ''},
|
||||
{_id: 57, reg: 'LOM', prov: 'MI', descr: 'Milano', link_grp: 'https://t.me/c/1614195634/214?thread=173', link_telegram: ''},
|
||||
{_id: 58, reg: 'EMR', prov: 'MO', descr: 'Modena', link_grp: 'https://t.me/c/1614195634/431?thread=422', link_telegram: ''},
|
||||
{_id: 59, reg: 'LOM', prov: 'MB', descr: 'Monza e della Brianza', link_grp: 'https://t.me/c/1614195634/498?thread=485', link_telegram: ''},
|
||||
{_id: 60, reg: 'CAM', prov: 'NA', descr: 'Napoli', link_grp: 'https://t.me/c/1614195634/407?thread=406', link_telegram: ''},
|
||||
{_id: 61, reg: 'PIE', prov: 'NO', descr: 'Novara', link_grp: 'https://t.me/c/1614195634/517?thread=508', link_telegram: ''},
|
||||
{_id: 62, reg: 'SAR', prov: 'NU', descr: 'Nuoro', link_grp: 'https://t.me/c/1614195634/548?thread=542', link_telegram: ''},
|
||||
{_id: 63, reg: 'SAR', prov: 'OT', descr: 'Olbia-Tempio', link_grp: '', link_telegram: ''},
|
||||
{_id: 64, reg: 'SAR', prov: 'OR', descr: 'Oristano', link_grp: 'https://t.me/c/1614195634/550?thread=543', link_telegram: ''},
|
||||
{_id: 65, reg: 'VEN', prov: 'PD', descr: 'Padova', link_grp: 'https://t.me/c/1614195634/610?thread=600', link_telegram: ''},
|
||||
{_id: 66, reg: 'SIC', prov: 'PA', descr: 'Palermo', link_grp: 'https://t.me/c/1614195634/568?thread=558', link_telegram: ''},
|
||||
{_id: 67, reg: 'EMR', prov: 'PR', descr: 'Parma', link_grp: 'https://t.me/c/1614195634/432?thread=423', link_telegram: ''},
|
||||
{_id: 68, reg: 'LOM', prov: 'PV', descr: 'Pavia', link_grp: 'https://t.me/c/1614195634/499?thread=486', link_telegram: ''},
|
||||
{_id: 69, reg: 'UMB', prov: 'PG', descr: 'Perugia', link_grp: 'https://t.me/c/1614195634/403?thread=401', link_telegram: ''},
|
||||
{_id: 70, reg: 'MAR', prov: 'PU', descr: 'Pesaro e Urbino', link_grp: 'https://t.me/c/1614195634/454?thread=449', link_telegram: ''},
|
||||
{_id: 71, reg: 'ABR', prov: 'PE', descr: 'Pescara', link_grp: 'https://t.me/c/1614195634/368?thread=367', link_telegram: ''},
|
||||
{_id: 72, reg: 'EMR', prov: 'PC', descr: 'Piacenza', link_grp: 'https://t.me/c/1614195634/433?thread=424', link_telegram: ''},
|
||||
{_id: 73, reg: 'TOS', prov: 'PI', descr: 'Pisa', link_grp: 'https://t.me/c/1614195634/589?thread=578', link_telegram: ''},
|
||||
{_id: 74, reg: 'TOS', prov: 'PT', descr: 'Pistoia', link_grp: 'https://t.me/c/1614195634/590?thread=579', link_telegram: ''},
|
||||
{_id: 75, reg: 'FVG', prov: 'PN', descr: 'Pordenone', link_grp: 'https://t.me/c/1614195634/470?thread=466', link_telegram: ''},
|
||||
{_id: 76, reg: 'BAS', prov: 'PZ', descr: 'Potenza', link_grp: 'https://t.me/c/1614195634/376?thread=375', link_telegram: ''},
|
||||
{_id: 77, reg: 'TOS', prov: 'PO', descr: 'Prato', link_grp: 'https://t.me/c/1614195634/591?thread=580', link_telegram: ''},
|
||||
{_id: 78, reg: 'SIC', prov: 'RG', descr: 'Ragusa', link_grp: 'https://t.me/c/1614195634/569?thread=559', link_telegram: ''},
|
||||
{_id: 79, reg: 'EMR', prov: 'RA', descr: 'Ravenna', link_grp: 'https://t.me/c/1614195634/434?thread=425', link_telegram: ''},
|
||||
{_id: 80, reg: 'CAL', prov: 'RC', descr: 'Reggio Calabria', link_grp: 'https://t.me/c/1614195634/385?thread=383', link_telegram: ''},
|
||||
{_id: 81, reg: 'EMR', prov: 'RE', descr: 'Reggio Emilia', link_grp: 'https://t.me/c/1614195634/435?thread=426', link_telegram: ''},
|
||||
{_id: 82, reg: 'LAZ', prov: 'RI', descr: 'Rieti', link_grp: 'https://t.me/c/1614195634/61?thread=45', link_telegram: ''},
|
||||
{_id: 83, reg: 'EMR', prov: 'RN', descr: 'Rimini', link_grp: 'https://t.me/c/1614195634/436?thread=https://t.me/c/1614195634/64?thread=57427', link_telegram: ''},
|
||||
{_id: 84, reg: 'LAZ', prov: 'RM', descr: 'Roma', link_grp: '', link_telegram: ''},
|
||||
{_id: 85, reg: 'VEN', prov: 'RO', descr: 'Rovigo', link_grp: 'https://t.me/c/1614195634/611?thread=601', link_telegram: ''},
|
||||
{_id: 86, reg: 'CAM', prov: 'SA', descr: 'Salerno', link_grp: 'https://t.me/c/1614195634/416?thread=412', link_telegram: ''},
|
||||
{_id: 87, reg: 'SAR', prov: 'VS', descr: 'Medio Campidano', link_grp: '', link_telegram: ''},
|
||||
{_id: 88, reg: 'SAR', prov: 'SS', descr: 'Sassari', link_grp: 'https://t.me/c/1614195634/551?thread=544', link_telegram: ''},
|
||||
{_id: 89, reg: 'LIG', prov: 'SV', descr: 'Savona', link_grp: 'https://t.me/c/1614195634/395?thread=391', link_telegram: ''},
|
||||
{_id: 90, reg: 'TOS', prov: 'SI', descr: 'Siena', link_grp: 'https://t.me/c/1614195634/592?thread=581', link_telegram: ''},
|
||||
{_id: 91, reg: 'SIC', prov: 'SR', descr: 'Siracusa', link_grp: 'https://t.me/c/1614195634/570?thread=560', link_telegram: ''},
|
||||
{_id: 92, reg: 'LOM', prov: 'SO', descr: 'Sondrio', link_grp: 'https://t.me/c/1614195634/500?thread=487', link_telegram: ''},
|
||||
{_id: 93, reg: 'PUG', prov: 'TA', descr: 'Taranto', link_grp: 'https://t.me/c/1614195634/539?thread=533', link_telegram: ''},
|
||||
{_id: 94, reg: 'ABR', prov: 'TE', descr: 'Teramo', link_grp: 'https://t.me/c/1614195634/370?thread=369', link_telegram: ''},
|
||||
{_id: 95, reg: 'UMB', prov: 'TR', descr: 'Terni', link_grp: 'https://t.me/c/1614195634/404?thread=402', link_telegram: ''},
|
||||
{_id: 96, reg: 'PIE', prov: 'TO', descr: 'Torino', link_grp: 'https://t.me/c/1614195634/518?thread=509', link_telegram: ''},
|
||||
{_id: 97, reg: 'SAR', prov: 'OG', descr: 'Ogliastra', link_grp: '', link_telegram: ''},
|
||||
{_id: 98, reg: 'SIC', prov: 'TP', descr: 'Trapani', link_grp: 'https://t.me/c/1614195634/571?thread=561', link_telegram: ''},
|
||||
{_id: 99, reg: 'TAA', prov: 'TN', descr: 'Trento', link_grp: 'https://t.me/c/1614195634/597?thread=595', link_telegram: ''},
|
||||
{_id: 100, reg: 'VEN', prov: 'TV', descr: 'Treviso', link_grp: 'https://t.me/c/1614195634/612?thread=602', link_telegram: ''},
|
||||
{_id: 101, reg: 'FVG', prov: 'TS', descr: 'Trieste', link_grp: 'https://t.me/c/1614195634/471?thread=467', link_telegram: ''},
|
||||
{_id: 102, reg: 'FVG', prov: 'UD', descr: 'Udine', link_grp: 'https://t.me/c/1614195634/472?thread=468', link_telegram: ''},
|
||||
{_id: 103, reg: 'LOM', prov: 'VA', descr: 'Varese', link_grp: 'https://t.me/c/1614195634/501?thread=488', link_telegram: ''},
|
||||
{_id: 104, reg: 'VEN', prov: 'VE', descr: 'Venezia', link_grp: 'https://t.me/c/1614195634/613?thread=603', link_telegram: ''},
|
||||
{_id: 105, reg: 'PIE', prov: 'VB', descr: 'Verbano-Cusio-Ossola', link_grp: 'https://t.me/c/1614195634/519?thread=510 ', link_telegram: ''},
|
||||
{_id: 106, reg: 'PIE', prov: 'VC', descr: 'Vercelli', link_grp: 'https://t.me/c/1614195634/512?thread=511', link_telegram: ''},
|
||||
{_id: 107, reg: 'VEN', prov: 'VR', descr: 'Verona', link_grp: 'https://t.me/c/1614195634/614?thread=604', link_telegram: ''},
|
||||
{_id: 108, reg: 'CAL', prov: 'VV', descr: 'Vibo Valentia', link_grp: 'https://t.me/c/1614195634/386?thread=384', link_telegram: ''},
|
||||
{_id: 109, reg: 'VEN', prov: 'VI', descr: 'Vicenza', link_grp: 'https://t.me/c/1614195634/615?thread=605', link_telegram: ''},
|
||||
{_id: 110, reg: 'LAZ', prov: 'VT', descr: 'Viterbo', link_grp: 'https://t.me/c/1614195634/76?thread=74', link_telegram: ''},
|
||||
{_id: 111, reg: 'RSM', prov: 'RSM', descr: 'Repubblica di San Marino', link_grp: 'https://t.me/+HSdNurm0IXY1MGI0', link_telegram: ''},
|
||||
{_id: 112, reg: 'EST', prov: 'EST', descr: 'Estero', link_grp: '', link_telegram: ''},
|
||||
{_id: 113, reg: 'ONL', prov: 'ONL', descr: 'On Line', link_grp: '', link_telegram: ''},
|
||||
{_id: 114, reg: 'LAZ', prov: 'RM', descr: 'Roma Nord-Est', card: 'NORD-EST', link_grp: 'https://t.me/c/1614195634/64?thread=57', link_telegram: ''},
|
||||
{_id: 115, reg: 'LAZ', prov: 'RM', descr: 'Roma Sud-Est', card: 'SUD-EST', link_grp: 'https://t.me/c/1614195634/65?thread=58', link_telegram: ''},
|
||||
{_id: 116, reg: 'LAZ', prov: 'RM', descr: 'Roma Nord', card: 'NORD', link_grp: 'https://t.me/c/1614195634/75?thread=73', link_telegram: ''},
|
||||
{_id: 117, reg: 'LAZ', prov: 'RM', descr: 'Roma Nord-Ovest', card: 'NORD-OVEST', link_grp: 'https://t.me/c/1614195634/62?thread=47', link_telegram: ''},
|
||||
{_id: 118, reg: 'LAZ', prov: 'RM', descr: 'Roma Sud e Litorale', card: 'SUD', link_grp: 'https://t.me/c/1614195634/67?thread=43', link_telegram: ''},
|
||||
{_id: 119, reg: 'PUG', prov: 'VAL', descr: 'Valle D\'Itria', link_grp: 'https://t.me/progettoriso/7016?thread=7015', link_telegram: ''},
|
||||
{_id: 120, reg: 'SAR', prov: 'SUS', descr: 'Sud Sardegna', link_grp: 'https://t.me/c/1614195634/552?thread=545', link_telegram: ''},
|
||||
{_id: 121, reg: 'ITA', prov: 'ITA', descr: 'Italia', link_grp: '', link_telegram: ''},
|
||||
{_id: 122, reg: 'LOM', prov: 'MI', card: 'EST', descr: 'Milano Est', link_grp: '', link_telegram: ''},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -42,7 +42,7 @@ module.exports = {
|
||||
{_id: 40, idSector: [7], descr: 'Muratore'},
|
||||
{_id: 41, idSector: [7], descr: 'Imbianchino'},
|
||||
{_id: 42, idSector: [7], descr: 'Elettricista - TV'},
|
||||
{_id: 43, idSector: [7], descr: 'Falegname e restauro'},
|
||||
{_id: 43, idSector: [7], descr: 'Falegname'},
|
||||
{_id: 44, idSector: [7], descr: 'Fabbro'},
|
||||
{_id: 45, idSector: [7], descr: 'Arredamento'},
|
||||
{_id: 46, idSector: [7], descr: 'Idraulico'},
|
||||
@@ -122,7 +122,10 @@ module.exports = {
|
||||
{_id: 127, idSector: [1], descr: 'Stanza in affitto'},
|
||||
{_id: 128, idSector: [1], descr: 'Stanza in condivisione'},
|
||||
{_id: 129, idSector: [3], descr: 'Home Restaurant'},
|
||||
{_id: 130, idSector: [7], descr: 'Pompe di calore'},
|
||||
{_id: 131, idSector: [7], descr: 'Impianti Fotovoltaici'},
|
||||
{_id: 130, idSector: [7], descr: 'Pannelli Solari'},
|
||||
{_id: 131, idSector: [7], descr: 'Pompe di calore'},
|
||||
{_id: 132, idSector: [7], descr: 'Impianti Fotovoltaici'},
|
||||
{_id: 133, idSector: [7], descr: 'Restauro'},
|
||||
{_id: 134, idSector: [7], descr: 'Altro'},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -78,7 +78,7 @@ router.delete('/:id/:notify/:idapp', authenticate, (req, res) => {
|
||||
const id = req.params.id;
|
||||
const notify = req.params.notify;
|
||||
const idapp = req.params.idapp;
|
||||
|
||||
|
||||
Booking.findByIdAndRemove(id).then((recbooking) => {
|
||||
if (!recbooking) {
|
||||
return res.status(404).send();
|
||||
|
||||
@@ -5,6 +5,8 @@ const tools = require('../tools/general');
|
||||
|
||||
const server_constants = require('../tools/server_constants');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
@@ -19,11 +21,17 @@ const { ObjectID } = require('mongodb');
|
||||
|
||||
async function getCircuitRecAdminsInfo(idapp, data) {
|
||||
|
||||
if (data && data.admins) {
|
||||
for (const admin of data.admins) {
|
||||
const myuser = await User.findOne({ idapp, username: admin.username }, { 'profile.img': 1 }).lean();
|
||||
admin.profile = { img: myuser.profile.img };
|
||||
try {
|
||||
if (data && data.admins) {
|
||||
for (const admin of data.admins) {
|
||||
const myuser = await User.findOne({ idapp, username: admin.username }, { 'profile.img': 1 }).lean();
|
||||
if (myuser && myuser.profile)
|
||||
admin.profile = { img: myuser.profile.img };
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return data;
|
||||
}
|
||||
|
||||
return data;
|
||||
@@ -73,10 +81,11 @@ router.post('/load', authenticate, async (req, res) => {
|
||||
}
|
||||
|
||||
if (data) {
|
||||
data.account = await Account.getAccountByUsernameAndCircuitId(idapp, '', data._id, false, '', data.path);
|
||||
data.account = await Account.getAccountByUsernameAndCircuitId(idapp, '', data._id, false, false, '', data.path);
|
||||
}
|
||||
|
||||
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp);
|
||||
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(req.user.username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER);
|
||||
/// E' QUIIII !!!!
|
||||
const useraccounts = await Account.getUserAccounts(idapp, req.user.username);
|
||||
|
||||
await User.setLastCircuitOpened(idapp, req.user.username, path);
|
||||
|
||||
@@ -270,6 +270,7 @@ router.get('/test1', authenticate_noerror, async (req, res) => {
|
||||
router.post('/settable', authenticate, async (req, res) => {
|
||||
const params = req.body;
|
||||
const mytable = globalTables.getTableByTableName(params.table);
|
||||
|
||||
let mydata = req.body.data;
|
||||
let extrarec = {};
|
||||
if (mydata && mydata.hasOwnProperty('extrarec')) {
|
||||
@@ -277,6 +278,11 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
delete mydata['extrarec'];
|
||||
}
|
||||
|
||||
if (mydata === undefined) {
|
||||
console.error('MYDATA VUOTO !');
|
||||
return res.status(400).send('Mydata VUOTO');
|
||||
}
|
||||
|
||||
const fieldsvalue = { 'ALL': 1 };
|
||||
|
||||
mydata.idapp = req.user.idapp;
|
||||
@@ -354,7 +360,7 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
|
||||
const mytablestrutt = globalTables.getTableByTableName(params.table);
|
||||
|
||||
if (mydata['_id'] !== undefined && mydata['_id'] !== 0) {
|
||||
if (mydata['_id'] !== undefined && mydata['_id'] !== 0 && mydata['_id'] !== '') {
|
||||
mytablerec.isNew = false;
|
||||
}
|
||||
|
||||
@@ -364,7 +370,7 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
} else if (params.table === 'hours') {
|
||||
|
||||
} else {
|
||||
if ((mydata['_id'] === undefined || mydata['_id'] === '' || (mytablerec.isNew && mydata['_id'] === 0)) && (mytablerec._id === undefined)) {
|
||||
if ((mydata['_id'] === undefined || mydata['_id'] === '' || (mytablerec.isNew && mydata['_id'] === 0)) && (mytablerec._id === undefined || mytablerec._id === '0')) {
|
||||
mytablerec._id = new ObjectID();
|
||||
mydata._id = new ObjectID();
|
||||
}
|
||||
@@ -413,8 +419,22 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
resolve(mytablerec._id && mytable.findById(mytablerec._id))
|
||||
});
|
||||
|
||||
// Controlla se esiste già questo record:
|
||||
if (shared_consts.TABLES_FIELDS_DESCR_AND_CITY_AND_USER.includes(params.table)) {
|
||||
if (mytablerec.isNew) {
|
||||
const trovatoDuplicato = await mytable.findOne({ idapp: mytablerec.idapp, descr: mytablerec.descr, idCity: mytablerec.idCity, userId: mytablerec.userId }).lean();
|
||||
if (trovatoDuplicato) {
|
||||
// trovatoDuplicato
|
||||
return res.status(200).send({ code: server_constants.RIS_CODE_REC_DUPLICATED_DESCR_CITY_USER, msg: '' });
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return await myPromise
|
||||
.then(async (doupdate) => {
|
||||
|
||||
if (doupdate)
|
||||
return mytable.updateOne({ _id: mytablerec._id }, mydata, { new: true })
|
||||
else
|
||||
@@ -448,9 +468,12 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
|
||||
if (shared_consts.TABLES_ADV_NOTIFICATION.includes(params.table)) {
|
||||
typedir = shared_consts.TypeNotifs.TYPEDIR_BACHECA;
|
||||
typeid = (params.table === shared_consts.TABLES_MYGOODS)
|
||||
? shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD
|
||||
: shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE;
|
||||
if (params.table === shared_consts.TABLES_MYGOODS)
|
||||
typeid = shared_consts.TypeNotifs.ID_BACHECA_NEW_GOOD
|
||||
else if (params.table === shared_consts.TABLES_MYSKILLS)
|
||||
typeid = shared_consts.TypeNotifs.ID_BACHECA_NEW_SERVICE
|
||||
else if (params.table === shared_consts.TABLES_MYHOSPS)
|
||||
typeid = shared_consts.TypeNotifs.ID_BACHECA_NEW_HOSP
|
||||
setnotif = true;
|
||||
}
|
||||
|
||||
@@ -466,16 +489,18 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
groupnameDest = myrec ? myrec.groupname : '';
|
||||
setnotif = true;
|
||||
}
|
||||
if (shared_consts.TABLES_CIRCUITS_NOTIFICATION.includes(params.table)) {
|
||||
/*if (shared_consts.TABLES_CIRCUITS_NOTIFICATION.includes(params.table)) {
|
||||
typedir = shared_consts.TypeNotifs.TYPEDIR_CIRCUITS;
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_NEW_REC;
|
||||
circuitnameDest = myrec ? myrec.name : '';
|
||||
setnotif = (myrec.visibility === 0); // Not send a notification to others if the Circuit is HIDDEN or PRIVATE
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
if (setnotif) {
|
||||
await SendNotif.createNewNotification(req, res, { groupnameDest, circuitnameDest }, params.table, myrec, typedir, typeid);
|
||||
const myreq = { ...req };
|
||||
const myres = { ...res };
|
||||
SendNotif.createNewNotification(myreq, myres, { groupnameDest, circuitnameDest }, params.table, myrec, typedir, typeid);
|
||||
}
|
||||
|
||||
if (params.table === 'circuits') {
|
||||
@@ -589,7 +614,7 @@ router.post('/gettable', authenticate, (req, res) => {
|
||||
const params = req.body;
|
||||
let idapp = req.user ? req.user.idapp : params.idapp;
|
||||
const mytable = globalTables.getTableByTableName(params.table);
|
||||
// console.log('mytable', mytable);
|
||||
//console.log('mytable', mytable);
|
||||
if (!mytable) {
|
||||
console.log(`Table ${params.table} not found`);
|
||||
return res.status(400).send({});
|
||||
@@ -601,7 +626,9 @@ router.post('/gettable', authenticate, (req, res) => {
|
||||
User.setOnLine(req.user.idapp, req.user.username);
|
||||
}
|
||||
|
||||
|
||||
return mytable.executeQueryTable(idapp, params, req.user).then(ris => {
|
||||
// console.log('ris=', ris);
|
||||
return res.send(ris);
|
||||
|
||||
}).catch((e) => {
|
||||
@@ -780,13 +807,17 @@ router.patch('/chval', authenticate, async (req, res) => {
|
||||
const fieldsvalue = mydata.fieldsvalue;
|
||||
const unset = mydata.unset;
|
||||
|
||||
const { Account } = require('../models/account');
|
||||
|
||||
// tools.mylogshow('PATCH CHVAL: ', id, fieldsvalue);
|
||||
|
||||
// If I change my record...
|
||||
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
||||
if (((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) &&
|
||||
!User.isEditor(req.user.perm) && !User.isFacilitatore(req.user.perm)) &&
|
||||
(req.user._id.toString() !== id) &&
|
||||
!tools.ModificheConsentite(mydata.table, fieldsvalue)) {
|
||||
(!tools.ModificheConsentite(mydata.table, fieldsvalue)))
|
||||
&& !((mydata.table === 'accounts') && await Account.canEditAccountAdmins(req.user.username, mydata.id))
|
||||
) {
|
||||
// If without permissions, exit
|
||||
return res.status(404).
|
||||
send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
|
||||
@@ -921,8 +952,9 @@ router.patch('/chval', authenticate, async (req, res) => {
|
||||
if (mydata.table === 'users') {
|
||||
|
||||
if ('profile.resid_province' in fieldsvalue) {
|
||||
const card = fieldsvalue.hasOwnProperty('profile.resid_card') ? fieldsvalue['profile.resid_card'] : '';
|
||||
// Controlla se esiste il Circuito di questa provincia, se non esiste lo crea!
|
||||
await Circuit.createCircuitIfNotExist(req, idapp, fieldsvalue['profile.resid_province']);
|
||||
await Circuit.createCircuitIfNotExist(req, idapp, fieldsvalue['profile.resid_province'], card);
|
||||
}
|
||||
|
||||
if (camporequisiti) {
|
||||
@@ -1249,11 +1281,11 @@ router.post('/duprec/:table/:id', authenticate, async (req, res) => {
|
||||
send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
|
||||
}
|
||||
|
||||
if (!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) {
|
||||
/* if (!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm)) {
|
||||
// If without permissions, exit
|
||||
return res.status(404).
|
||||
send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
|
||||
}
|
||||
} */
|
||||
|
||||
return await mytable.findById(id).then(async (mydata) => {
|
||||
|
||||
@@ -1346,6 +1378,9 @@ function load(req, res, version) {
|
||||
|
||||
const permissions = Permission.findAllIdApp();
|
||||
|
||||
// const versionstr = User....
|
||||
// let version = tools.getVersionint(versionstr);
|
||||
|
||||
let newstosent = Promise.resolve([]);
|
||||
let mailinglist = Promise.resolve([]);
|
||||
let mypage;
|
||||
@@ -1406,7 +1441,7 @@ function load(req, res, version) {
|
||||
let myuserextra = null;
|
||||
if (req.user) {
|
||||
// askedfriends = User.getAskedFriendsByUsername(idapp, req.user.username);
|
||||
myuserextra = User.addExtraInfo(idapp, req.user._doc, req.user);
|
||||
myuserextra = User.addExtraInfo(idapp, req.user._doc, req.user, version);
|
||||
}
|
||||
|
||||
return Promise.all([
|
||||
@@ -1849,10 +1884,14 @@ function deleteFile(req, res, version) {
|
||||
const relativefile = req.query.filename;
|
||||
const idapp = req.user.idapp;
|
||||
|
||||
if (!relativefile || relativefile.endsWith('/')) {
|
||||
res.send({ code: server_constants.RIS_CODE_OK, msg: '' });
|
||||
}
|
||||
|
||||
try {
|
||||
let dirmain = '';
|
||||
if (version > 0) {
|
||||
if (tools.sulServer() !== 1) {
|
||||
if (!tools.sulServer()) {
|
||||
dirmain = '/public';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,60 +5,76 @@ const router = express.Router();
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
|
||||
var server_constants = require('../tools/server_constants');
|
||||
|
||||
var {authenticate, auth_default} = require('../middleware/authenticate');
|
||||
var { authenticate, authenticate_noerror, auth_default } = require('../middleware/authenticate');
|
||||
|
||||
var mongoose = require('mongoose').set('debug', false);
|
||||
const Subscription = mongoose.model('subscribers');
|
||||
|
||||
const _ = require('lodash');
|
||||
const {MyBacheca} = require('../models/mybacheca');
|
||||
var {User} = require('../models/user');
|
||||
const { MyBacheca } = require('../models/mybacheca');
|
||||
var { User } = require('../models/user');
|
||||
const { Reaction } = require('../models/reaction');
|
||||
|
||||
const globalTables = require('../tools/globalTables');
|
||||
|
||||
const {ObjectID} = require('mongodb');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
//GET orders
|
||||
router.post('/page', authenticate, function(req, res, next) {
|
||||
router.post('/page', authenticate_noerror, function (req, res, next) {
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
try {
|
||||
let table = req.body.table;
|
||||
let id = req.body.id;
|
||||
let idapp = req.body.idapp;
|
||||
|
||||
const username = req.user.username ? req.user.username : '';
|
||||
let username = ''
|
||||
if (req.user)
|
||||
username = req.user.username ? req.user.username : '';
|
||||
|
||||
// Check if ìs a Notif to read
|
||||
const idnotif = req.body.idnotif ? req.body.idnotif : '';
|
||||
SendNotif.setNotifAsRead(idapp, username, idnotif);
|
||||
if (username) {
|
||||
// Check if ìs a Notif to read
|
||||
const idnotif = req.body.idnotif ? req.body.idnotif : '';
|
||||
SendNotif.setNotifAsRead(idapp, username, idnotif);
|
||||
}
|
||||
|
||||
let mytable = null;
|
||||
if (shared_consts.TABLES_ENABLE_GETREC_BYID.includes(table)) {
|
||||
mytable = globalTables.getTableByTableName(table);
|
||||
}
|
||||
|
||||
|
||||
if (mytable) {
|
||||
|
||||
return mytable.getMyRecById(idapp, id).
|
||||
then((ris) => {
|
||||
then(async (ris) => {
|
||||
|
||||
if (ris) {
|
||||
res.send(ris);
|
||||
// Se è un record singolo di tipo Reaction,
|
||||
// allora gli devo passare anche le liste degli utenti :
|
||||
if (globalTables.isTableReaction(table)) {
|
||||
// ...
|
||||
// const myreaction = await Reaction.find({idapp, idrec: id}).lean();
|
||||
// ris.myreaction = myreaction;
|
||||
|
||||
} else {
|
||||
res.status(400).send();
|
||||
}
|
||||
}).catch((e) => {
|
||||
console.error('Err', e);
|
||||
res.status(400).send(e);
|
||||
})
|
||||
};
|
||||
|
||||
if (ris) {
|
||||
res.send(ris);
|
||||
|
||||
} else {
|
||||
res.status(400).send();
|
||||
}
|
||||
}).catch((e) => {
|
||||
console.error('Err', e);
|
||||
res.status(400).send(e);
|
||||
})
|
||||
|
||||
}
|
||||
}catch (e) {
|
||||
} catch (e) {
|
||||
console.error('/page', e);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ router.post('/load', authenticate, async (req, res) => {
|
||||
for (let i = 0; i < data.mycircuits.length; i++) {
|
||||
const mycirc = await Circuit.findOne({ idapp, name: data.mycircuits[i].circuitname }).lean();
|
||||
if (mycirc)
|
||||
data.mycircuits[i].account = await Account.getAccountByUsernameAndCircuitId(idapp, '', mycirc._id, true, groupname);
|
||||
data.mycircuits[i].account = await Account.getAccountByUsernameAndCircuitId(idapp, '', mycirc._id, true, true, groupname);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
127
src/server/router/reactions_router.js
Executable file
127
src/server/router/reactions_router.js
Executable file
@@ -0,0 +1,127 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const { Reaction } = require('../models/reaction');
|
||||
|
||||
const { User } = require('../models/user');
|
||||
|
||||
const Hours = require('../models/hours');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const sendemail = require('../sendemail');
|
||||
|
||||
const { Settings } = require('../models/settings');
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const server_constants = require('../tools/server_constants');
|
||||
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
const reg = require('../reg/registration');
|
||||
|
||||
const { authenticate, authenticate_noerror } = require('../middleware/authenticate');
|
||||
|
||||
const TypedError = require('../modules/ErrorHandler');
|
||||
const globalTables = require('../tools/globalTables');
|
||||
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
|
||||
router.post('/cmd', authenticate_noerror, async (req, res) => {
|
||||
|
||||
const mydata = req.body.mydata;
|
||||
const idapp = req.body.idapp;
|
||||
const cmd = req.body.cmd;
|
||||
const id = req.body.id;
|
||||
const tab = req.body.tab;
|
||||
const num = req.body.num;
|
||||
const value = req.body.value;
|
||||
|
||||
|
||||
try {
|
||||
const table = tools.getTableByNumTab(tab);
|
||||
const mytable = globalTables.getTableByTableName(table);
|
||||
let username = '';
|
||||
if (req.user) {
|
||||
username = req.user.username;
|
||||
} else {
|
||||
return res.send({ state: 0, record: null });
|
||||
}
|
||||
|
||||
let ris = null;
|
||||
let record = null;
|
||||
|
||||
const { User } = require('../models/user');
|
||||
|
||||
let objtoupdate = {};
|
||||
|
||||
if (cmd === shared_consts.CMD_REACTION.SET_FAVORITE) {
|
||||
if (tab) {
|
||||
if (value) {
|
||||
ris = await Reaction.addFavorite(req, idapp, username, id, tab);
|
||||
} else {
|
||||
ris = await Reaction.removeFavorite(idapp, username, id, tab);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (cmd === shared_consts.CMD_REACTION.SET_BOOKMARK) {
|
||||
if (tab) {
|
||||
if (value)
|
||||
ris = await Reaction.addBookmark(req, idapp, username, id, tab);
|
||||
else
|
||||
ris = await Reaction.removeBookmark(idapp, username, id, tab);
|
||||
|
||||
}
|
||||
} else if (cmd === shared_consts.CMD_REACTION.SET_ATTEND) {
|
||||
if (tab) {
|
||||
if (value)
|
||||
ris = await Reaction.addAttend(req, idapp, username, id, tab, num);
|
||||
else
|
||||
ris = await Reaction.removeAttend(idapp, username, id, tab);
|
||||
|
||||
}
|
||||
} else if (cmd === shared_consts.CMD_REACTION.SET_SEEN) {
|
||||
if (tab) {
|
||||
if (value) {
|
||||
ris = await Reaction.addSeen(req, idapp, username, id, tab);
|
||||
}
|
||||
const tabtofind = tools.getNumTabByTable('mybachecas');
|
||||
if (tab === tabtofind) {
|
||||
const { MyBacheca } = require('../models/mybacheca');
|
||||
record = await MyBacheca.getCompleteRecord(idapp, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let state = (value && ris && ris.ok === 1) ? 1 : ((!value && ris && ris.ok === 1) ? -1 : 0);
|
||||
|
||||
const risreac = await Reaction.calcReactions(idapp, id, tab);
|
||||
if (risreac) {
|
||||
delete risreac._id;
|
||||
objtoupdate = risreac;
|
||||
}
|
||||
|
||||
if (mytable) {
|
||||
ris = await mytable.updateOne({ _id: id }, {
|
||||
$set: objtoupdate,
|
||||
})
|
||||
}
|
||||
|
||||
return res.send({ state, record });
|
||||
|
||||
} catch (e) {
|
||||
res.status(400).send();
|
||||
res.send({ code: server_constants.RIS_CODE_ERR, msg: e, state: null, record: null });
|
||||
|
||||
console.log(e.message);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -10,7 +10,7 @@ const { User } = require('../models/user');
|
||||
const { Operator } = require('../models/operator');
|
||||
const { SendMsg } = require('../models/sendmsg');
|
||||
|
||||
const {SendNotif} = require('../models/sendnotif');
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
@@ -35,7 +35,7 @@ router.post('/', authenticate, (req, res) => {
|
||||
User.setOnLine(req.user.idapp, req.user.username);
|
||||
}
|
||||
|
||||
const check = tools.checkUserOk(myrecmsg.origin.username, req.user.username, res);
|
||||
const check = tools.checkUserOk(myrecmsg.origin, req.user.username, res);
|
||||
if (check.exit) return check.ret;
|
||||
|
||||
// console.log('fieldtochange', fieldtochange);
|
||||
@@ -49,26 +49,37 @@ router.post('/', authenticate, (req, res) => {
|
||||
|
||||
return SendMsg.findById(idobj)
|
||||
.then(async (recmsg) => {
|
||||
const myrecsend = new SendNotif(
|
||||
{
|
||||
title: recmsg.source.infoevent,
|
||||
sender: recmsg.origin,
|
||||
dest: recmsg.dest,
|
||||
openUrl: '',
|
||||
});
|
||||
// Add this field because I don't want to add into the database
|
||||
recmsg.source.infoevent = body.source.infoevent;
|
||||
// myrecsend.source.infoevent = body.source.infoevent;
|
||||
|
||||
recmsg.typedir = shared_consts.TypeNotifs.TYPEDIR_EVENTS;
|
||||
recmsg.typeid = shared_consts.TypeNotifs.ID_EVENTS_REMOVE_REC;
|
||||
myrecsend.typedir = shared_consts.TypeNotifs.TYPEDIR_EVENTS;
|
||||
myrecsend.typeid = shared_consts.TypeNotifs.ID_EVENTS_SEND_MSG;
|
||||
myrecsend.msg = recmsg.message;
|
||||
let myid = recmsg._id;
|
||||
// ##Todo !! DA SISTEMARE !!!
|
||||
return await SendNotif.saveAndSendNotif(recmsg, req, res).then((out) => {
|
||||
return await SendNotif.saveAndSendNotif(myrecsend, req, res).then((out) => {
|
||||
if (out)
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: recmsg._id });
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: myid });
|
||||
else
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, msg: '' });
|
||||
})
|
||||
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.log(e.message);
|
||||
console.error(e.message);
|
||||
// res.status(400).send(e);
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, msg: '' });
|
||||
// return res.send({ code: server_constants.RIS_CODE_ERR, msg: '' });
|
||||
})
|
||||
|
||||
let fine = '';
|
||||
|
||||
});
|
||||
|
||||
router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
|
||||
|
||||
@@ -144,7 +144,7 @@ router.get('/:username/:lastdataread/:idapp', authenticate, (req, res) => {
|
||||
return res.status(404).send({code: server_constants.RIS_CODE_NOT_MY_USERNAME});
|
||||
}
|
||||
|
||||
return SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp).then(async (arrnotif) => {
|
||||
return SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdataread, idapp, shared_consts.LIMIT_NOTIF_FOR_USER).then(async (arrnotif) => {
|
||||
// const wait = new Promise((resolve, reject) => {
|
||||
// setTimeout(() => {
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ router.post('/load', authenticate, async (req, res) => {
|
||||
for (let i = 0; i < data.mycircuits.length; i++) {
|
||||
const mycirc = await Circuit.findOne({ idapp, name: data.mycircuits[i].circuitname }).lean();
|
||||
if (mycirc)
|
||||
data.mycircuits[i].account = await Account.getAccountByUsernameAndCircuitId(idapp, '', mycirc._id, true, groupname);
|
||||
data.mycircuits[i].account = await Account.getAccountByUsernameAndCircuitId(idapp, '', mycirc._id, true, true, groupname);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@ const _ = require('lodash');
|
||||
|
||||
const reg = require('../reg/registration');
|
||||
|
||||
const { authenticate } = require('../middleware/authenticate');
|
||||
const { authenticate, authenticate_noerror } = require('../middleware/authenticate');
|
||||
|
||||
|
||||
const Cart = require('../models/cart');
|
||||
const CartClass = require('../modules/Cart');
|
||||
@@ -428,7 +429,7 @@ router.post('/receiveris', authenticate, (req, res) => {
|
||||
};
|
||||
});
|
||||
|
||||
router.post('/profile', (req, res) => {
|
||||
router.post('/profile', authenticate_noerror, (req, res) => {
|
||||
const usernameOrig = req.user ? req.user.username : '';
|
||||
const perm = req.user ? req.user.perm : tools.Perm.PERM_NONE;
|
||||
const username = req.body['username'];
|
||||
@@ -447,8 +448,16 @@ router.post('/profile', (req, res) => {
|
||||
then((ris) => {
|
||||
|
||||
return User.getFriendsByUsername(idapp, usernameOrig).
|
||||
then((friends) => {
|
||||
res.send({ user: ris, friends });
|
||||
then(async (friends) => {
|
||||
if (username === usernameOrig) {
|
||||
const userprofile = await User.getExtraInfoByUsername(idapp, username);
|
||||
ris.profile = userprofile;
|
||||
}
|
||||
|
||||
return { ris, friends };
|
||||
|
||||
}).then(tot => {
|
||||
return res.send({ user: tot.ris, friends: tot.friends });
|
||||
});
|
||||
|
||||
}).catch((e) => {
|
||||
@@ -705,6 +714,33 @@ router.post('/circuits', authenticate, (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/updatesaldo', authenticate, async (req, res) => {
|
||||
const username = req.user.username;
|
||||
idapp = req.body.idapp;
|
||||
locale = req.body.locale;
|
||||
circuitId = req.body.circuitId;
|
||||
groupname = req.body.groupname;
|
||||
const lastdr = req.body['lastdr'] ? req.body['lastdr'] : '';
|
||||
|
||||
try {
|
||||
const userprofile = await User.getExtraInfoByUsername(idapp, username);
|
||||
let ris = {
|
||||
userprofile
|
||||
}
|
||||
|
||||
const arrrecnotif = await SendNotif.findAllNotifByUsernameIdAndIdApp(username, lastdr, idapp, shared_consts.LIMIT_NOTIF_FOR_USER);
|
||||
|
||||
ris.arrrecnotif = arrrecnotif;
|
||||
|
||||
return res.send({ ris });
|
||||
|
||||
} catch (e) {
|
||||
tools.mylog('ERRORE IN updatesaldo: ' + e);
|
||||
res.status(400).send();
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
router.post('/friends/cmd', authenticate, async (req, res) => {
|
||||
const usernameLogged = req.user.username;
|
||||
const idapp = req.body.idapp;
|
||||
@@ -741,6 +777,29 @@ router.post('/friends/cmd', authenticate, async (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/sendcmd', authenticate, async (req, res) => {
|
||||
const usernameLogged = req.user.username;
|
||||
const idapp = req.body.idapp;
|
||||
const locale = req.body.locale;
|
||||
let usernameOrig = req.body.usernameOrig;
|
||||
let usernameDest = req.body.usernameDest;
|
||||
const cmd = req.body.cmd;
|
||||
const value = req.body.value;
|
||||
|
||||
usernameOrig = await User.getRealUsernameByUsername(idapp, usernameOrig);
|
||||
usernameDest = await User.getRealUsernameByUsername(idapp, usernameDest);
|
||||
|
||||
return User.sendCmd(req, idapp, usernameOrig, usernameDest, cmd, value).
|
||||
then((ris) => {
|
||||
res.send(ris);
|
||||
}).
|
||||
catch((e) => {
|
||||
tools.mylog('ERRORE IN sendcmd: ' + e.message);
|
||||
res.status(400).send();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
router.post('/groups/cmd', authenticate, (req, res) => {
|
||||
const usernameLogged = req.user.username;
|
||||
const idapp = req.body.idapp;
|
||||
@@ -813,6 +872,7 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
const populate = require('../populate/populate');
|
||||
|
||||
const globalTables = require('../tools/globalTables');
|
||||
const { Reaction } = require('../models/reaction');
|
||||
|
||||
let mystr = '';
|
||||
|
||||
@@ -1127,11 +1187,6 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
if (User.isAdmin(req.user.perm)) {
|
||||
ris = globalTables.replaceUsername(req.body.idapp, mydata.search_username, mydata.replace_username);
|
||||
}
|
||||
} else if (mydata.dbop === 'ReplaceCircuitName') {
|
||||
|
||||
if (User.isAdmin(req.user.perm)) {
|
||||
ris = globalTables.ReplaceCircuitName(req.body.idapp, mydata.search_username, mydata.replace_username);
|
||||
}
|
||||
|
||||
} else if (mydata.dbop === 'copyFrom1To14') {
|
||||
const idapporig = 1;
|
||||
@@ -1171,6 +1226,21 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
console.log('e', e);
|
||||
}
|
||||
|
||||
} else if (mydata.dbop === 'removeRecordsFav') {
|
||||
// Passa le tabelle da users sulle nuove tabelle:
|
||||
await User.removerecordsFavorite();
|
||||
|
||||
} else if (mydata.dbop === 'updateReactionsCounts') {
|
||||
await Reaction.updateReactionsCounts();
|
||||
|
||||
} else if (mydata.dbop === 'newRecordsFav') {
|
||||
// Passa le tabelle da users sulle nuove tabelle:
|
||||
await User.moverecordsFavorite(1);
|
||||
await User.moverecordsFavorite(2);
|
||||
await User.moverecordsFavorite(3);
|
||||
await User.moverecordsFavorite(4);
|
||||
await User.moverecordsFavorite(5);
|
||||
|
||||
} else if (mydata.dbop === 'emptyTabCatServiziBeni') {
|
||||
|
||||
const { Sector } = require('../models/sector');
|
||||
@@ -1246,6 +1316,48 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
await City.remove({});
|
||||
await Province.remove({});
|
||||
|
||||
} else if (mydata.dbop === 'ConvTablesFromIntToString') {
|
||||
|
||||
const { MySkill } = require('../models/myskill');
|
||||
const { MyBacheca } = require('../models/mybacheca');
|
||||
const { MyHosp } = require('../models/myhosp');
|
||||
const { MyGood } = require('../models/mygood');
|
||||
const { MyGroup } = require('../models/mygroup');
|
||||
|
||||
console.log('INIZIO - Conversioni');
|
||||
// 'myskills',
|
||||
// 'mybachecas',
|
||||
// 'myhosps',
|
||||
// 'mygoods',
|
||||
// 'mygroups'
|
||||
|
||||
await ConvertiDaIntAStr(MySkill);
|
||||
await ConvertiDaIntAStr(MyBacheca);
|
||||
await ConvertiDaIntAStr(MyHosp);
|
||||
await ConvertiDaIntAStr(MyGood);
|
||||
await ConvertiDaIntAStr(MyGroup);
|
||||
|
||||
console.log('FINE - Conversioni');
|
||||
|
||||
} else if (mydata.dbop === 'Removeinteger') {
|
||||
|
||||
const { MySkill } = require('../models/myskill');
|
||||
const { MyBacheca } = require('../models/mybacheca');
|
||||
const { MyHosp } = require('../models/myhosp');
|
||||
const { MyGood } = require('../models/mygood');
|
||||
const { MyGroup } = require('../models/mygroup');
|
||||
|
||||
console.log('INIZIO - Rimozione');
|
||||
|
||||
await RimuoviInteri(MySkill);
|
||||
await RimuoviInteri(MyBacheca);
|
||||
await RimuoviInteri(MyHosp);
|
||||
await RimuoviInteri(MyGood);
|
||||
await RimuoviInteri(MyGroup);
|
||||
|
||||
console.log('FINE - Rimozione');
|
||||
|
||||
|
||||
} else if (mydata.dbop === 'createAllCircuits') {
|
||||
const { Province } = require('../models/province');
|
||||
|
||||
@@ -1256,7 +1368,11 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
|
||||
} else if (mydata.dbop === 'ImpostaMinMaxPersonali') {
|
||||
|
||||
await Account.SetMinMaxPersonali(idapp, mydata.valmin, mydata.valmax);
|
||||
await Account.SetMinMaxPersonali(idapp, mydata.valmin, mydata.valmax, '');
|
||||
|
||||
} else if (mydata.dbop === 'ImpostaMinMaxPersonaliCircuito') {
|
||||
|
||||
await Account.SetMinMaxPersonali(idapp, mydata.valmin, mydata.valmax, mydata.circuitId);
|
||||
|
||||
} else if (mydata.dbop === 'ImpostaMinMaxComunitari') {
|
||||
|
||||
@@ -1268,20 +1384,28 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
|
||||
} else if (mydata.dbop === 'ImpostaDefMinMaxPersonali') {
|
||||
|
||||
await Circuit.SetDefMinMaxPersonali(idapp, mydata.valmin, mydata.valmax);
|
||||
await Circuit.SetDefMinMaxPersonali(idapp, mydata.valmin, mydata.valmax, mydata.circuitId);
|
||||
|
||||
} else if (mydata.dbop === 'ImpostaDefMinMaxCollettivi') {
|
||||
|
||||
await Circuit.SetDefMinMaxCollettivi(idapp, mydata.valmin, mydata.valmax);
|
||||
await Circuit.SetDefMinMaxCollettivi(idapp, mydata.valmin, mydata.valmax, mydata.circuitId);
|
||||
|
||||
} else if (mydata.dbop === 'ReplaceAllCircuits') {
|
||||
} else if (mydata.dbop === 'AbilitaTuttiCircuiti') {
|
||||
|
||||
await Circuit.replaceAllCircuits(idapp);
|
||||
await Circuit.AbilitaTuttiCircuiti(idapp);
|
||||
|
||||
} else if (mydata.dbop === 'AzzeraRegolamentiTuttiCircuiti') {
|
||||
|
||||
await Circuit.AzzeraRegolamentiTuttiCircuiti(idapp);
|
||||
|
||||
} else if (mydata.dbop === 'setstrProvByIdCityCircuits') {
|
||||
|
||||
await Circuit.setstrProvByIdCityCircuits(idapp);
|
||||
|
||||
} else if (mydata.dbop === 'updateSaldoAndTransato_AllAccounts') {
|
||||
|
||||
await Account.updateSaldoAndTransato_AllAccounts(idapp);
|
||||
|
||||
/*} else if (mydata.dbop === 'visuNave') {
|
||||
mystr = await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col));
|
||||
|
||||
@@ -1318,6 +1442,77 @@ async function eseguiDbOp(idapp, mydata, locale, req, res) {
|
||||
}
|
||||
};
|
||||
|
||||
async function ConvertiDaIntAStr(mytable) {
|
||||
try {
|
||||
console.log('INIZIO - ConvertiDaIntAStr ', mytable.modelName);
|
||||
|
||||
return await mytable.find({ '_id': { $type: 16 } })
|
||||
.then(async (arr) => {
|
||||
console.log('num record ', arr.length)
|
||||
|
||||
let ind = 0;
|
||||
for (let x of arr) {
|
||||
|
||||
const idnew = x._id;
|
||||
|
||||
if (idnew < 10000) {
|
||||
|
||||
const idint = parseInt(x._id, 10) + 10000;
|
||||
|
||||
const myrec = new mytable(x._doc);
|
||||
|
||||
myrec._doc.date_created = x._doc.date_created;
|
||||
myrec._doc.date_updated = x._doc.date_updated;
|
||||
|
||||
if (!myrec._doc.date_updated) {
|
||||
if (myrec.hasOwnProperty('date_created'))
|
||||
myrec._doc.date_updated = myrec._doc.date_created;
|
||||
}
|
||||
if ((myrec.hasOwnProperty('date_updated') && !myrec._doc.date_created))
|
||||
myrec._doc.date_created = myrec._doc.date_updated;
|
||||
myrec._doc._id = idint + '';
|
||||
|
||||
let ris = await myrec.save((async function (err, doc) {
|
||||
if (doc) {
|
||||
ind++;
|
||||
//await mytable.findOneAndRemove({ _id: parseInt(doc._id, 10) });
|
||||
console.log('++Add (', ind, ')', doc._id);
|
||||
} else {
|
||||
const myid = parseInt(err.keyValue._id, 10) + 0;
|
||||
const canc = await mytable.findOneAndRemove({ _id: myid });
|
||||
if (canc)
|
||||
console.log('err', err.message, 'canc', canc._doc._id);
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
console.log('FINE - ConvertiDaIntAStr ', mytable.modelName);
|
||||
});
|
||||
|
||||
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
async function RimuoviInteri(mytable) {
|
||||
try {
|
||||
console.log('INIZIO - RimuoviInteri ', mytable.modelName);
|
||||
|
||||
const arr = await mytable.find({ '_id': { $lte: 10000 } })
|
||||
console.log(' search interi...', arr.length);
|
||||
|
||||
const ris = await mytable.deleteMany({ '_id': { $lte: 10000 } })
|
||||
|
||||
console.log('FINE - RimuoviInteri ', mytable.modelName, ris);
|
||||
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
async function eseguiDbOpUser(idapp, mydata, locale, req, res) {
|
||||
|
||||
let ris = await User.DbOp(idapp, mydata);
|
||||
@@ -1336,7 +1531,7 @@ async function eseguiDbOpUser(idapp, mydata, locale, req, res) {
|
||||
|
||||
for (const mycirc of allcirc) {
|
||||
// Il Conto Comunitario prende il nome del circuito !
|
||||
await Account.createAccount(idapp, '', mycirc.name, '', mycirc.path);
|
||||
await Account.createAccount(idapp, '', mycirc.name, true, '', mycirc.path);
|
||||
|
||||
}
|
||||
|
||||
@@ -1349,6 +1544,9 @@ async function eseguiDbOpUser(idapp, mydata, locale, req, res) {
|
||||
} else if (mydata.dbop === 'noCircuit') {
|
||||
await User.findOneAndUpdate({ _id: mydata._id },
|
||||
{ $set: { 'profile.noCircuit': mydata.value } });
|
||||
} else if (mydata.dbop === 'noCircIta') {
|
||||
await User.findOneAndUpdate({ _id: mydata._id },
|
||||
{ $set: { 'profile.noCircIta': mydata.value } });
|
||||
} else if (mydata.dbop === 'noFoto') {
|
||||
await User.findOneAndUpdate({ _id: mydata._id },
|
||||
{ $set: { 'profile.noFoto': mydata.value } });
|
||||
@@ -1436,4 +1634,5 @@ router.post('/mgt', authenticate, async (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -195,7 +195,7 @@ module.exports = {
|
||||
let aportador = mylocalsconf.aportador_solidario ? ' (da ' + mylocalsconf.aportador_solidario + ')' : '';
|
||||
|
||||
const numutenti = await User.getNumUsers(mylocalsconf.idapp);
|
||||
tools.sendNotifToAdmin('++ [' + numutenti + '] ' + nometot + aportador);
|
||||
tools.sendNotifToAdmin(mylocalsconf.idapp, true, '++Reg [' + numutenti + '] ' + nometot + aportador);
|
||||
}
|
||||
|
||||
// if (tools.isManagAndAdminDifferent(idapp)) {
|
||||
@@ -227,7 +227,7 @@ module.exports = {
|
||||
|
||||
await telegrambot.notifyIscrizioneToTelegram(telegrambot.phase.ISCRIZIONE_CONACREIS, mylocalsconf, 'MSG_ISCRITTO_CONACREIS');
|
||||
|
||||
tools.sendNotifToAdmin('Iscrizione Conacreis : ' + mylocalsconf.name + ' ' + mylocalsconf.surname + ' (' + mylocalsconf.username + ')');
|
||||
tools.sendNotifToAdmin(idapp, true, 'Iscrizione Conacreis : ' + mylocalsconf.name + ' ' + mylocalsconf.surname + ' (' + mylocalsconf.username + ')');
|
||||
|
||||
if (tools.isManagAndAdminDifferent(idapp)) {
|
||||
this.sendEmail_base('admin/iscrizione_conacreis/' + tools.LANGADMIN, tools.getManagerEmailByIdApp(idapp), mylocalsconf, '');
|
||||
@@ -260,7 +260,7 @@ module.exports = {
|
||||
|
||||
await telegrambot.notifyIscrizioneToTelegram(telegrambot.phase.ISCRIZIONE_ARCADEI, mylocalsconf, 'MSG_ISCRITTO_ARCADEI');
|
||||
|
||||
tools.sendNotifToAdmin('Iscrizione Arcadei : ' + mylocalsconf.name + ' ' + mylocalsconf.surname + ' (' + mylocalsconf.username + ')');
|
||||
tools.sendNotifToAdmin(idapp, true, 'Iscrizione Arcadei : ' + mylocalsconf.name + ' ' + mylocalsconf.surname + ' (' + mylocalsconf.username + ')');
|
||||
|
||||
if (tools.isManagAndAdminDifferent(idapp)) {
|
||||
this.sendEmail_base('admin/iscrizione_arcadei/' + tools.LANGADMIN, tools.getManagerEmailByIdApp(idapp), mylocalsconf, '');
|
||||
@@ -299,6 +299,7 @@ module.exports = {
|
||||
locale: lang,
|
||||
nomeapp: tools.getNomeAppByIdApp(idapp),
|
||||
emailto: emailto,
|
||||
msgbooking: '',
|
||||
participants: '',
|
||||
participantsLunch: '',
|
||||
participantsDinner: '',
|
||||
@@ -347,6 +348,10 @@ module.exports = {
|
||||
|
||||
msgtelegram += '\n';
|
||||
|
||||
if (recbooking.msgbooking) {
|
||||
mylocalsconf.msgbooking = 'Messaggio: ' + recbooking.msgbooking.toString()
|
||||
msgtelegram += mylocalsconf.msgbooking + '\n';
|
||||
}
|
||||
if (recbooking.numpeople > 0) {
|
||||
mylocalsconf.participants = recbooking.numpeople.toString() + ' ' + tools.getres__('partecipanti', res);
|
||||
msgtelegram += mylocalsconf.participants + '\n';
|
||||
|
||||
@@ -112,6 +112,7 @@ myLoad().then(ris => {
|
||||
const projects_router = require('./router/projects_router');
|
||||
const report_router = require('./router/report_router');
|
||||
const users_router = require('./router/users_router');
|
||||
const reactions_router = require('./router/reactions_router');
|
||||
const mygroups_router = require('./router/mygroups_router');
|
||||
const circuits_router = require('./router/circuits_router');
|
||||
const accounts_router = require('./router/accounts_router');
|
||||
@@ -177,6 +178,7 @@ myLoad().then(ris => {
|
||||
app.use('/test', test_router);
|
||||
app.use('/projects', projects_router);
|
||||
app.use('/users', users_router);
|
||||
app.use('/reactions', reactions_router);
|
||||
app.use('/mygroup', mygroups_router);
|
||||
app.use('/circuit', circuits_router);
|
||||
app.use('/account', accounts_router);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -132,6 +132,7 @@ const textlang = {
|
||||
'CREATO_NUOVO_GRUPPO': '✅ Hai appena creato un nuovo Gruppo chiamato %s',
|
||||
'ACCETTATO_NOTIFICA_ADMINS': '✅ l\'utente %s è stato accettato a far parte del Gruppo %s (da parte di %s)',
|
||||
'GROUP_REQUEST': 'Richiesta di entrare nel Gruppo %s da parte di %s',
|
||||
"CLICCA_QUI": "CLICCA QUI",
|
||||
},
|
||||
si: {},
|
||||
es: {
|
||||
@@ -416,7 +417,7 @@ module.exports = {
|
||||
AYNI: '7',
|
||||
CNM: '10',
|
||||
RISO: '13',
|
||||
ARCADEI: '15',
|
||||
FIOREDELLAVITA: '15',
|
||||
|
||||
HELP_CHAT: '',
|
||||
TYPECONF_ZOOM: 'zoom',
|
||||
@@ -678,7 +679,9 @@ module.exports = {
|
||||
return [
|
||||
'idapp',
|
||||
'userId',
|
||||
'username',
|
||||
'id_bookedevent',
|
||||
'tableType',
|
||||
'numpeople',
|
||||
'numpeopleLunch',
|
||||
'numpeopleDinner',
|
||||
@@ -883,7 +886,7 @@ module.exports = {
|
||||
};
|
||||
},
|
||||
|
||||
sendNotificationByUsername: async function (idapp, username, cmd, telegram, usernameOrig) {
|
||||
sendNotificationByUsername: async function (idapp, username, cmd, telegram, usernameOrig, recObjCreator) {
|
||||
|
||||
var { User } = require('../models/user');
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
@@ -904,6 +907,7 @@ module.exports = {
|
||||
let openUrl = '/';
|
||||
let tag = '';
|
||||
let actions = [];
|
||||
let domanda = '';
|
||||
if (cmd) {
|
||||
if (cmd === shared_consts.FRIENDSCMD.REQFRIEND) {
|
||||
descr = printf(this.get__('RICHIESTA_AMICIZIA', lang), usernameOrig);
|
||||
@@ -919,22 +923,12 @@ module.exports = {
|
||||
}
|
||||
|
||||
} else if (cmd === shared_consts.FRIENDSCMD.SETHANDSHAKE) {
|
||||
descr = printf(this.get__('RICHIESTA_HANDSHAKE', lang), usernameOrig);
|
||||
openUrl = '/my/' + usernameOrig;
|
||||
tag = 'reqhandshake';
|
||||
|
||||
const userrecDest = await User.getUserShortDataByUsername(idapp, usernameOrig);
|
||||
|
||||
const foundIfAlreadyHandShake = await User.isMyHandShake(idapp, username, usernameOrig);
|
||||
|
||||
if (userrecDest) {
|
||||
sendmynotif = false; // non lo rimandare 2 volte !
|
||||
if (!foundIfAlreadyHandShake) {
|
||||
// SEND TELEGRAM NOTIFICATION
|
||||
telegrambot.askConfirmationUserFriend(idapp, shared_consts.CallFunz.RICHIESTA_HANDSHAKE, userrecDest, username, usernameOrig);
|
||||
}
|
||||
const foundIfAlready = await User.isMyHandShake(idapp, username, usernameOrig);
|
||||
if (!foundIfAlready) {
|
||||
telegrambot.askConfirmationUserFriend(idapp, shared_consts.CallFunz.RICHIESTA_HANDSHAKE, userrecDest, username, usernameOrig);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -947,7 +941,7 @@ module.exports = {
|
||||
|
||||
const idtelegram = await User.TelegIdByUsername(idapp, username);
|
||||
|
||||
await telegrambot.sendMsgTelegramByIdTelegram(idapp, idtelegram, descr);
|
||||
await telegrambot.sendMsgTelegramByIdTelegram(idapp, idtelegram, descr + domanda, undefined, undefined, true, keyb);
|
||||
}
|
||||
|
||||
},
|
||||
@@ -1089,6 +1083,11 @@ module.exports = {
|
||||
let typeid = 0;
|
||||
let onlysave = false;
|
||||
let numuserincircuit = await User.countUsersInCircuit(idapp, circuitname);
|
||||
const mycircuit = await Circuit.findOne({ name: circuitname }).lean();
|
||||
if (mycircuit) {
|
||||
extrarec.fido_scoperto_default = mycircuit.fido_scoperto_default;
|
||||
extrarec.fido_scoperto_default_grp = mycircuit.fido_scoperto_default_grp;
|
||||
}
|
||||
|
||||
if (cmd) {
|
||||
if (cmd === shared_consts.CIRCUITCMD.SET) {
|
||||
@@ -1105,11 +1104,13 @@ module.exports = {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REQUEST_TO_ENTER;
|
||||
// paramsObj.options = MessageOptions.Notify_OnlyToNotifinApp + MessageOptions.Notify_ByBotTelegram;
|
||||
const myuserdata = await User.getUserShortDataByUsername(idapp, username_action);
|
||||
telegrambot.askConfirmationUser(idapp, shared_consts.CallFunz.RICHIESTA_CIRCUIT, myuserdata, usernameDest, circuitname,
|
||||
telegrambot.askConfirmationUser(idapp, shared_consts.CallFunz.RICHIESTA_FIDO, myuserdata, usernameDest, circuitname,
|
||||
myreccircuit._id, '', extrarec.groupname);
|
||||
onlysave = false;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.ADDADMIN) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_ADDED_ADMIN;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.SETFIDO) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_SETFIDO;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.REMOVEADMIN) {
|
||||
typeid = shared_consts.TypeNotifs.ID_CIRCUIT_REMOVED_ADMIN;
|
||||
} else if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ) {
|
||||
@@ -1284,13 +1285,13 @@ module.exports = {
|
||||
|
||||
let ris = false;
|
||||
let inviato = false;
|
||||
let arrris = [];
|
||||
|
||||
if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ || cmd === shared_consts.CIRCUITCMD.SENDCOINS_ACCEPT || cmd ===
|
||||
shared_consts.CIRCUITCMD.SENDCOINS_REFUSE) {
|
||||
|
||||
groupOrig = extrarec.grouporig
|
||||
|
||||
let arrris = [];
|
||||
let recnotif = null;
|
||||
|
||||
if (cmd === shared_consts.CIRCUITCMD.SENDCOINS_REQ) {
|
||||
@@ -1370,6 +1371,19 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (inviato) {
|
||||
if (arrris && arrris.length > 0) {
|
||||
for (const notif of arrris) {
|
||||
await SendNotif.updatePendingTransactions(notif);
|
||||
}
|
||||
} else {
|
||||
if (ris) {
|
||||
await SendNotif.updatePendingTransactions(ris.recnotif);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { ris: ris.recnotif, inviato };
|
||||
|
||||
} catch (e) {
|
||||
@@ -1433,31 +1447,42 @@ module.exports = {
|
||||
},
|
||||
*/
|
||||
|
||||
sendNotifToAdmin(title, msg, tag = '') {
|
||||
const { User } = require('../models/user');
|
||||
sendNotifToAdmin(idapp, alsotelegram, title, msg, tag = '') {
|
||||
try {
|
||||
const { User } = require('../models/user');
|
||||
|
||||
// console.log('nomeapp 1: ' , this.getNomeAppByIdApp(1));
|
||||
// console.log('nomeapp 2: ' , this.getNomeAppByIdApp(2));
|
||||
const queryadmins = { username: 'paoloar77', idapp };
|
||||
|
||||
User.find({ username: 'paoloar77', idapp: '1' }).then(async (arrusers) => {
|
||||
if (arrusers !== null) {
|
||||
for (const user of arrusers) {
|
||||
await this.sendNotificationToUser(user._id, title, msg, '/', '', tag, []).
|
||||
then(ris => {
|
||||
if (ris) {
|
||||
if (idapp === 0)
|
||||
idapp = '13';
|
||||
|
||||
} else {
|
||||
// already sent the error on calling sendNotificationToUser
|
||||
}
|
||||
});
|
||||
User.find(queryadmins).then(async (arrusers) => {
|
||||
if (arrusers !== null) {
|
||||
for (const user of arrusers) {
|
||||
if (alsotelegram) {
|
||||
this.sendMsgTelegramToAdmin(idapp, title + ' ' + msg);
|
||||
}
|
||||
|
||||
await this.sendNotificationToUser(user._id, title, msg, '/', '', tag, []).
|
||||
then(ris => {
|
||||
if (ris) {
|
||||
|
||||
} else {
|
||||
// already sent the error on calling sendNotificationToUser
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
checkUserOk(userpassed, userauth, res) {
|
||||
this.mylog('checkUserOk', userpassed, userauth);
|
||||
// this.mylog('checkUserOk', userpassed, userauth);
|
||||
if (String(userpassed) !== String(userauth)) {
|
||||
// I'm trying to write something not mine!
|
||||
this.mylog('I\'m trying to write something not mine!: userId = ', userpassed, 'req.user._id', userauth);
|
||||
@@ -1469,8 +1494,9 @@ module.exports = {
|
||||
} else {
|
||||
return {
|
||||
exit: true,
|
||||
ret: res.status(404).
|
||||
send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER }),
|
||||
ret: false,
|
||||
// ret: res.status(404).
|
||||
// send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER }),
|
||||
};
|
||||
}
|
||||
} else {
|
||||
@@ -1508,6 +1534,74 @@ module.exports = {
|
||||
return msg;
|
||||
},
|
||||
|
||||
htmlToTelegramText(html) {
|
||||
|
||||
try {
|
||||
const withMarkdown = html
|
||||
.replace(/<strong>(.*?)<\/strong>/g, '*$1*')
|
||||
.replace(/<b>(.*?)<\/b>/g, '*$1*')
|
||||
.replace(/<em>(.*?)<\/em>/g, '_$1_')
|
||||
.replace(/<u>(.*?)<\/u>/g, '__$1__');
|
||||
|
||||
// Remove other HTML tags
|
||||
const plainText = withMarkdown.replace(/<[^>]*>/g, '');
|
||||
|
||||
// Replace HTML entities with their equivalent Markdown or plain text representations
|
||||
const replacements = [
|
||||
{ pattern: /&/g, replacement: '&' },
|
||||
{ pattern: /</g, replacement: '<' },
|
||||
{ pattern: />/g, replacement: '>' },
|
||||
{ pattern: /"/g, replacement: '"' },
|
||||
{ pattern: /'/g, replacement: "'" },
|
||||
];
|
||||
|
||||
let telegramText = plainText;
|
||||
replacements.forEach((replacement) => {
|
||||
telegramText = telegramText.replace(replacement.pattern, replacement.replacement);
|
||||
});
|
||||
|
||||
return telegramText;
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
};
|
||||
|
||||
},
|
||||
|
||||
htmlToTelegramText(html) {
|
||||
|
||||
try {
|
||||
const withMarkdown = html
|
||||
.replace(/<strong>(.*?)<\/strong>/g, '*$1*')
|
||||
.replace(/<b>(.*?)<\/b>/g, '*$1*')
|
||||
.replace(/<em>(.*?)<\/em>/g, '_$1_')
|
||||
.replace(/<u>(.*?)<\/u>/g, '__$1__');
|
||||
|
||||
// Remove other HTML tags
|
||||
const plainText = withMarkdown.replace(/<[^>]*>/g, '');
|
||||
|
||||
// Replace HTML entities with their equivalent Markdown or plain text representations
|
||||
const replacements = [
|
||||
{ pattern: /&/g, replacement: '&' },
|
||||
{ pattern: /</g, replacement: '<' },
|
||||
{ pattern: />/g, replacement: '>' },
|
||||
{ pattern: /"/g, replacement: '"' },
|
||||
{ pattern: /'/g, replacement: "'" },
|
||||
];
|
||||
|
||||
let telegramText = plainText;
|
||||
replacements.forEach((replacement) => {
|
||||
telegramText = telegramText.replace(replacement.pattern, replacement.replacement);
|
||||
});
|
||||
|
||||
return telegramText;
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
};
|
||||
|
||||
},
|
||||
|
||||
convertTexttoHtml(myhtml) {
|
||||
// let msg = myhtml;
|
||||
// msg = msg.replace('\n', '<br>');
|
||||
@@ -1765,6 +1859,16 @@ module.exports = {
|
||||
return myquery;
|
||||
},
|
||||
|
||||
getNumTabByTable(table) {
|
||||
const myrec = shared_consts.MYTABS.find((rec) => rec.table === table)
|
||||
return myrec ? myrec.id : -1
|
||||
},
|
||||
|
||||
getTableByNumTab(numtab) {
|
||||
const myrec = shared_consts.MYTABS.find((rec) => rec.id === numtab)
|
||||
return myrec ? myrec.table : ''
|
||||
},
|
||||
|
||||
getGroupnameLookupPipeLine(params, proj) {
|
||||
|
||||
let myquery = [
|
||||
@@ -1796,7 +1900,50 @@ module.exports = {
|
||||
return myquery;
|
||||
},
|
||||
|
||||
getLookup: function (params, num, pass_proj) {
|
||||
getLookupStandardPipeline: function (params, num) {
|
||||
const query = [];
|
||||
|
||||
if (!params)
|
||||
return;
|
||||
|
||||
query.push(
|
||||
{
|
||||
$lookup: {
|
||||
from: params.lk_tab,
|
||||
let: { searchId: { $toObjectId: "$" + params.lk_LF } },
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{ $eq: ["$" + params.lk_FF, "$$searchId"] },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: params.lk_proj
|
||||
},
|
||||
],
|
||||
as: params.lk_as + num,
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
'$' + params.lk_as + num, 0],
|
||||
}, '$$ROOT'],
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
return query;
|
||||
},
|
||||
|
||||
getLookup: function (params, num, pass_proj, proj_add) {
|
||||
const query = [];
|
||||
|
||||
if (!params)
|
||||
@@ -1806,6 +1953,17 @@ module.exports = {
|
||||
if (params.af_objId_tab) {
|
||||
const myobj = {};
|
||||
myobj['myId' + num] = { '$toObjectId': '$' + params.lk_LF };
|
||||
|
||||
if (params.lk_tab === 'users') {
|
||||
myobj.namecomplete = {
|
||||
$concat: [
|
||||
{ $toLower: "$name" },
|
||||
{ $toLower: "$surname" },
|
||||
{ $toLower: "$username" },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
query.push(
|
||||
{ '$addFields': myobj },
|
||||
);
|
||||
@@ -1819,6 +1977,8 @@ module.exports = {
|
||||
if (!!pass_proj) {
|
||||
proj = pass_proj;
|
||||
}
|
||||
proj = Object.assign({}, proj, proj_add);
|
||||
|
||||
query.push(
|
||||
{
|
||||
$lookup: {
|
||||
@@ -1827,18 +1987,33 @@ module.exports = {
|
||||
foreignField: params.lk_FF, // field in the 'from' collection
|
||||
as: params.lk_as,
|
||||
},
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
'$' + params.lk_as, 0],
|
||||
}, '$$ROOT'],
|
||||
});
|
||||
if (params.unwind) {
|
||||
|
||||
query.push({
|
||||
$unwind: {
|
||||
path: '$' + params.lk_as,
|
||||
preserveNullAndEmptyArrays: true,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (!params.noarray) {
|
||||
query.push(
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
'$' + params.lk_as, 0],
|
||||
}, '$$ROOT'],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
query.push(
|
||||
{ $project: proj },
|
||||
);
|
||||
}
|
||||
@@ -1910,8 +2085,205 @@ module.exports = {
|
||||
return myquery;
|
||||
},
|
||||
|
||||
addNumFavoriteAndBookmarkToQuery(idapp, numtab) {
|
||||
|
||||
let query = [];
|
||||
|
||||
try {
|
||||
/*
|
||||
query =
|
||||
[
|
||||
{
|
||||
$lookup: {
|
||||
from: "reactions",
|
||||
let: {
|
||||
tab: numtab,
|
||||
id: '$_id',
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{ $eq: ['$idrec', '$$id'] },
|
||||
{ $eq: ['$tab', numtab] },
|
||||
{ $eq: ['$idapp', idapp] },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: "$idrec",
|
||||
numseen: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$seen", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
},
|
||||
numfav: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$fav", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
},
|
||||
numbook: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$book", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
as: 'myreact',
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
$unwind: {
|
||||
path: "$myreact",
|
||||
preserveNullAndEmptyArrays: true,
|
||||
},
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
if (true) {
|
||||
// RIMUOVI
|
||||
// query = {};
|
||||
}
|
||||
|
||||
if (true) {
|
||||
// RIMUOVI
|
||||
// query = {};
|
||||
}
|
||||
|
||||
if (Object.keys(query).length > 0) {
|
||||
const numtabbacheca = this.getNumTabByTable(shared_consts.TABLES_MYBACHECAS);
|
||||
if (numtab === numtabbacheca) {
|
||||
const queryadd = this.getQueryMyBacheca(idapp);
|
||||
query = [...query, ...queryadd];
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
proj = {
|
||||
numseen: 1,
|
||||
numfav: 1,
|
||||
numbook: 1,
|
||||
numattend: 1,
|
||||
};
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
return { query, proj };
|
||||
|
||||
},
|
||||
|
||||
getQueryMyBacheca: function (idapp) {
|
||||
|
||||
const arrquery = [{
|
||||
$lookup: {
|
||||
from: "bookings",
|
||||
let: {
|
||||
id: '$_id',
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{ $eq: ['$id_bookedevent', '$$id'] },
|
||||
{ $eq: ['$idapp', idapp] },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
id_bookedevent: 1,
|
||||
username: 1,
|
||||
numpeople: 1,
|
||||
numpeopleLunch: 1,
|
||||
numpeopleDinner: 1,
|
||||
infoevent: 1,
|
||||
msgbooking: 1,
|
||||
booked: 1,
|
||||
datebooked: 1,
|
||||
userId: 1,
|
||||
}
|
||||
},
|
||||
],
|
||||
as: 'mybookings',
|
||||
},
|
||||
},
|
||||
/**
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
localField: "myId1",
|
||||
foreignField: "_id",
|
||||
as: "user",
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
let: {
|
||||
myid: { $toObjectId: "$mybookings.userId" },
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{
|
||||
$eq: [
|
||||
"$_id",
|
||||
"$$myid",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$idapp",
|
||||
"13",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: { _id: 1, username: 1 },
|
||||
}
|
||||
],
|
||||
|
||||
as: "myuser",
|
||||
},
|
||||
}**/
|
||||
|
||||
];
|
||||
|
||||
return arrquery;
|
||||
|
||||
},
|
||||
|
||||
getQueryTable: async function (idapp, params, user) {
|
||||
|
||||
|
||||
const { Search } = require('../models/search');
|
||||
|
||||
if (typeof params.startRow !== 'number') {
|
||||
throw new Error('startRow must be number');
|
||||
} else if (typeof params.endRow !== 'number') {
|
||||
@@ -2103,10 +2475,10 @@ module.exports = {
|
||||
if (params.options) {
|
||||
if (this.isBitActive(params.options,
|
||||
shared_consts.OPTIONS_SEARCH_ONLY_FULL_WORDS)) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (params.filterextra) {
|
||||
if (params.filterextra.length > 0)
|
||||
query = [...query, ...params.filterextra]
|
||||
@@ -2124,14 +2496,6 @@ module.exports = {
|
||||
// console.log('QUERYMATCH', query[0].$match.or);
|
||||
// console.log('filter', params.filter);
|
||||
|
||||
if (params.sortBy) {
|
||||
// maybe we want to sort by blog title or something
|
||||
const mysort = { $sort: params.sortBy };
|
||||
// console.log('sortBy', params.sortBy);
|
||||
// console.table(mysort);
|
||||
query.push(mysort);
|
||||
}
|
||||
|
||||
let numrowend = params.endRow - params.startRow;
|
||||
if (numrowend < 0)
|
||||
numrowend = 1;
|
||||
@@ -2352,23 +2716,38 @@ module.exports = {
|
||||
query.push({ $unwind: params.unwind0 });
|
||||
}
|
||||
|
||||
const q1 = this.getLookup(params.lookup1, 1, proj);
|
||||
let objadd = { query: [], proj: {} };
|
||||
|
||||
let numtab = this.getNumTabByTable(params.table);
|
||||
|
||||
|
||||
const q1 = this.getLookup(params.lookup1, 1, proj, objadd.proj);
|
||||
if (q1) query = [...query, ...q1];
|
||||
|
||||
if (params.unwind1) {
|
||||
query.push({ $unwind: params.unwind1 });
|
||||
}
|
||||
|
||||
const q2 = this.getLookup(params.lookup2, 2, proj);
|
||||
if (params.lookupPipeline1) {
|
||||
const q1p = this.getLookupStandardPipeline(params.lookupPipeline1, 1);
|
||||
if (q1p) query = [...query, ...q1p];
|
||||
}
|
||||
|
||||
const q2 = this.getLookup(params.lookup2, 2, proj, objadd.proj);
|
||||
if (q2) query = [...query, ...q2];
|
||||
|
||||
const q3 = this.getLookup(params.lookup3, 3, proj);
|
||||
if (params.lookupPipeline2) {
|
||||
const q2p = this.getLookupStandardPipeline(params.lookupPipeline2, 2);
|
||||
if (q2p) query = [...query, ...q2p];
|
||||
}
|
||||
|
||||
const q3 = this.getLookup(params.lookup3, 3, proj, objadd.proj);
|
||||
if (q3) query = [...query, ...q3];
|
||||
|
||||
const q4 = this.getLookup(params.lookup4, 4, proj);
|
||||
const q4 = this.getLookup(params.lookup4, 4, proj, objadd.proj);
|
||||
if (q4) query = [...query, ...q4];
|
||||
|
||||
const q5 = this.getLookup(params.lookup5, 5, proj);
|
||||
const q5 = this.getLookup(params.lookup5, 5, proj, objadd.proj);
|
||||
if (q5) query = [...query, ...q5];
|
||||
|
||||
if (params.filtersearch2) {
|
||||
@@ -2377,6 +2756,7 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let filteradmin = false;
|
||||
if (params.filtercustom) {
|
||||
let condition = {};
|
||||
@@ -2480,12 +2860,19 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (params.filter && params.fieldsearch_last) {
|
||||
const querytemp = this.getFilterParam(params.filter,
|
||||
params.fieldsearch_last);
|
||||
if (querytemp) {
|
||||
query = [...query, ...querytemp];
|
||||
}
|
||||
|
||||
// Save the search:
|
||||
if (user._id) {
|
||||
const mysearch = new Search({ idapp, userId: user._id, text: params.filter });
|
||||
await mysearch.save();
|
||||
}
|
||||
}
|
||||
|
||||
if (params.table === 'mygroups' || params.table === 'circuits') {
|
||||
@@ -2514,12 +2901,27 @@ module.exports = {
|
||||
// }
|
||||
}
|
||||
|
||||
if (params.options && this.isBitActive(params.options,
|
||||
shared_consts.OPTIONS_ADD_COUNT_FAVORITE)) {
|
||||
// objadd = this.addNumFavoriteAndBookmarkToQuery(idapp, numtab);
|
||||
// if (Object.keys(objadd.query).length > 0)
|
||||
// query = [...query, ...objadd.query];
|
||||
}
|
||||
|
||||
} else {
|
||||
// VECCHIA VERSIONE
|
||||
const q1 = this.getLookup(params, 1);
|
||||
if (q1) query = [...query, ...q1];
|
||||
}
|
||||
|
||||
if (params.sortBy) {
|
||||
// maybe we want to sort by blog title or something
|
||||
const mysort = { $sort: params.sortBy };
|
||||
// console.log('sortBy', params.sortBy);
|
||||
// console.table(mysort);
|
||||
query.push(mysort);
|
||||
}
|
||||
|
||||
query.push(
|
||||
{
|
||||
$group: {
|
||||
@@ -2539,17 +2941,36 @@ module.exports = {
|
||||
},
|
||||
);
|
||||
|
||||
if (this.testing()) {
|
||||
console.log('query', query);
|
||||
}
|
||||
// console.log('query', query);
|
||||
|
||||
return query;
|
||||
|
||||
},
|
||||
|
||||
startTimeLog(name) {
|
||||
if (this.testing()) {
|
||||
console.log('inizio', name);
|
||||
console.time(name);
|
||||
}
|
||||
},
|
||||
|
||||
endTimeLog(name) {
|
||||
if (this.testing()) {
|
||||
console.log(' ... fine', name);
|
||||
console.timeEnd(name);
|
||||
}
|
||||
},
|
||||
|
||||
async executeQueryTable(mythistable, idapp, params, user) {
|
||||
let query = await this.getQueryTable(idapp, params, user);
|
||||
|
||||
try {
|
||||
// console.log('query', query);
|
||||
this.startTimeLog('Query 1');
|
||||
|
||||
const [ris] = await mythistable.aggregate(query);
|
||||
|
||||
if (ris) {
|
||||
@@ -2564,6 +2985,8 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
this.endTimeLog('Query 1');
|
||||
|
||||
// console.table(ris.rows);
|
||||
// console.log('ROW ', ris.count);
|
||||
return ({ count: ris.count, rows: ris.rows });
|
||||
@@ -2625,8 +3048,9 @@ module.exports = {
|
||||
},
|
||||
|
||||
SetBit(myval, bit) {
|
||||
myval = myval & bit;
|
||||
return myval;
|
||||
let myvalout = myval
|
||||
myvalout |= bit
|
||||
return myvalout
|
||||
},
|
||||
|
||||
async snooze(ms) {
|
||||
@@ -2880,6 +3304,19 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
getstrTime(mytimestamp) {
|
||||
// Create a Date object with your desired date
|
||||
const date = new Date(mytimestamp); // You can replace this with your specific date
|
||||
|
||||
// Get the hour and minute components from the date
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
|
||||
// Format the hour and minute components as HH:MM
|
||||
const formattedTime = `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
|
||||
return formattedTime
|
||||
},
|
||||
|
||||
getstrDateShort(mydate, lang) {
|
||||
if (mydate) {
|
||||
// console.log('getstrDate', mytimestamp)
|
||||
@@ -3626,7 +4063,7 @@ module.exports = {
|
||||
const linkuserprof = this.getHostByIdApp(idapp) + '/my/' +
|
||||
myuser.username;
|
||||
|
||||
msg = `<br>👉🏻 <a href="${linkuserprof}">${name}</a> (email: ${myuser.email})`;
|
||||
msg = `<br>👉🏻 <a href="${linkuserprof}">${name}</a><br>email: ${myuser.email}`;
|
||||
|
||||
let u_tg = myuser.profile && myuser.profile.hasOwnProperty('username_telegram') ? myuser.profile.username_telegram : usernametelegram;
|
||||
let name_tg = myuser.profile && myuser.profile.hasOwnProperty('firstname_telegram')
|
||||
@@ -3641,7 +4078,7 @@ module.exports = {
|
||||
namesurnametg = ` [${name_tg} ${surname_tg}]`;;
|
||||
|
||||
if (u_tg) {
|
||||
msg += `<br><br>https://t.me/${u_tg}`;
|
||||
msg += `<br><br>Apri chat 👉🏻 https://t.me/${u_tg}`;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('getUserInfoMsg', e);
|
||||
@@ -3657,8 +4094,7 @@ module.exports = {
|
||||
try {
|
||||
const name = myuser.username +
|
||||
(myuser.name ? ` (${myuser.name} ${myuser.surname})` : '');
|
||||
const linkuserprof = this.getHostByIdApp(idapp) + '/my/' +
|
||||
myuser.username;
|
||||
const linkuserprof = this.getLinkUserProfile(idapp, myuser.username);
|
||||
|
||||
let u_tg = myuser.profile && myuser.profile.hasOwnProperty('username_telegram') ? myuser.profile.username_telegram : usernametelegram;
|
||||
|
||||
@@ -3739,7 +4175,7 @@ module.exports = {
|
||||
},
|
||||
|
||||
updateQueryStringParameter(uri, key, value) {
|
||||
if (uri === '')
|
||||
if (uri === '' || !uri)
|
||||
return '';
|
||||
var re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
|
||||
var separator = uri.indexOf('?') !== -1 ? '&' : '?';
|
||||
@@ -3763,6 +4199,16 @@ module.exports = {
|
||||
|
||||
let myhost = this.getHostByIdApp(params.idapp);
|
||||
|
||||
if (params.textaddTelegram) {
|
||||
content = content + '\n' + params.textaddTelegram;
|
||||
}
|
||||
|
||||
if (params.linkaddTelegram) {
|
||||
if (params.openUrl)
|
||||
content = content + '\n' + '<a href="' + myhost + params.openUrl + '">' + params.linkaddTelegram + '</a>';
|
||||
}
|
||||
|
||||
|
||||
/*if (params.openUrl)
|
||||
content = content + '\n' + '<a href="' + myhost + params.openUrl + '">' + i18n.__('OPEN PAGE') + '</a>';
|
||||
|
||||
@@ -3776,4 +4222,87 @@ module.exports = {
|
||||
return `<a href='${link}'>${username}</a>`;
|
||||
},
|
||||
|
||||
|
||||
firstchars(value, numchars) {
|
||||
if (!value) {
|
||||
return ''
|
||||
}
|
||||
try {
|
||||
let mycar = value.substring(0, numchars)
|
||||
if (value.length > numchars)
|
||||
mycar += '...'
|
||||
return mycar
|
||||
} catch (e) {
|
||||
return value
|
||||
}
|
||||
},
|
||||
|
||||
replaceStringAtEnd(inputString, searchString, replacement) {
|
||||
// Create a regular expression that matches the searchString at the end of the inputString
|
||||
const regex = new RegExp(searchString + '$');
|
||||
|
||||
// Use the replace method with the regular expression to replace the string
|
||||
const result = inputString.replace(regex, replacement);
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
getstrDateTimeEvent(myevent) {
|
||||
let mystr = '';
|
||||
|
||||
// is same day?
|
||||
if (this.getstrDateShort(myevent.dateTimeStart) === this.getstrDateShort(myevent.dateTimeEnd)) {
|
||||
mystr = i18n.__('DATEDAYONLY', this.getstrDateLong(myevent.dateTimeStart), this.getstrTime(myevent.dateTimeStart),
|
||||
this.getstrTime(myevent.dateTimeEnd))
|
||||
} else {
|
||||
mystr = i18n.__('DATE_2DAYS', this.getstrDateLong(myevent.dateTimeStart), this.getstrTime(myevent.dateTimeStart),
|
||||
this.getstrDateLong(myevent.dateTimeEnd), this.getstrTime(myevent.dateTimeEnd))
|
||||
}
|
||||
|
||||
return '🗓 ' + mystr;
|
||||
},
|
||||
|
||||
getDoveStrByEvent(myrec) {
|
||||
let dove = '🏠 ';
|
||||
if (myrec.mycities && myrec.mycities.length > 0) {
|
||||
dove += myrec.mycities[0].comune + ' (' + myrec.mycities[0].prov + ')'
|
||||
}
|
||||
return dove;
|
||||
},
|
||||
|
||||
async getDescrEstesaStrByEvent(myrec) {
|
||||
let mystr = '';
|
||||
|
||||
mystr = await this.firstchars(this.replaceStringAtEnd(myrec.note, '</div>', ''), 400);
|
||||
if (mystr)
|
||||
mystr = 'ℹ️ ' + mystr
|
||||
return mystr;
|
||||
},
|
||||
|
||||
|
||||
async getEventForTelegram(myrec, mydescr, userorig) {
|
||||
try {
|
||||
let datastr = this.getstrDateTimeEvent(myrec);
|
||||
let dovestr = this.getDoveStrByEvent(myrec);
|
||||
let descrestesa = await this.getDescrEstesaStrByEvent(myrec);
|
||||
let organizedby = myrec.organisedBy;
|
||||
let contributo = myrec.contribstr;
|
||||
|
||||
let newdescr = i18n.__('NEW_EVENT', userorig, datastr, mydescr, dovestr);
|
||||
let newdescrtelegram = i18n.__('NEW_EVENT_TELEGRAM', datastr, mydescr, dovestr, descrestesa, userorig);
|
||||
if (organizedby) {
|
||||
newdescrtelegram += i18n.__('ORGANIZED_BY', organizedby);
|
||||
}
|
||||
if (contributo) {
|
||||
newdescrtelegram += i18n.__('CONTRIB', contributo);
|
||||
}
|
||||
newdescrtelegram += i18n.__('ADDED_FROM', userorig);
|
||||
|
||||
return { newdescr, newdescrtelegram }
|
||||
} catch (e) {
|
||||
console.error('Error', e);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
@@ -16,6 +16,7 @@ const { Booking } = require('../models/booking');
|
||||
const { Operator } = require('../models/operator');
|
||||
const { Where } = require('../models/where');
|
||||
const { MyEvent } = require('../models/myevent');
|
||||
const { Reaction } = require('../models/reaction');
|
||||
const { Contribtype } = require('../models/contribtype');
|
||||
const { PaymentType } = require('../models/paymenttype');
|
||||
const { Discipline } = require('../models/discipline');
|
||||
@@ -79,6 +80,10 @@ const shared_consts = require('./shared_nodejs');
|
||||
|
||||
module.exports = {
|
||||
|
||||
isTableReaction(tablename) {
|
||||
return shared_consts.TABLES_REACTIONS.includes(tablename);
|
||||
},
|
||||
|
||||
getTableByTableName(tablename) {
|
||||
|
||||
let mytable = '';
|
||||
@@ -210,6 +215,8 @@ module.exports = {
|
||||
mytable = Account;
|
||||
else if (tablename === 'movements')
|
||||
mytable = Movement;
|
||||
else if (tablename === 'reactions')
|
||||
mytable = Reaction;
|
||||
else if (shared_consts.TablePickup.includes(tablename))
|
||||
mytable = Pickup;
|
||||
//else if (shared_consts.TableCities.includes(tablename))
|
||||
@@ -227,6 +234,8 @@ module.exports = {
|
||||
|
||||
const sendemail = require('../sendemail');
|
||||
|
||||
const { User } = require('../models/user');
|
||||
|
||||
/// ... rivedere il crea gruppo... notifiche...
|
||||
try {
|
||||
if (!recnotif.typesend) {
|
||||
@@ -248,9 +257,12 @@ module.exports = {
|
||||
usernameDest: recnotif.usernameDest ? recnotif.usernameDest : recnotif.dest,
|
||||
tag: recnotif.tag ? recnotif.tag : '',
|
||||
actions: recnotif.actions ? recnotif.actions : [],
|
||||
id: recnotif._id
|
||||
id: recnotif._id,
|
||||
textaddTelegram: recnotif.textaddTelegram ? recnotif.textaddTelegram : '',
|
||||
textcontent_Telegram: recnotif.textcontent_Telegram ? recnotif.textcontent_Telegram : '',
|
||||
linkaddTelegram: recnotif.linkaddTelegram ? recnotif.linkaddTelegram : '',
|
||||
};
|
||||
|
||||
|
||||
if (tools.isBitActive(recnotif.typesend, shared_consts.MessageOptions.Notify_ByPushNotification) && this.checkifSendPushNotification) {
|
||||
params.typesend = params.typesend + shared_consts.TypeSend.PUSH_NOTIFICATION;
|
||||
invia = true;
|
||||
@@ -285,7 +297,9 @@ module.exports = {
|
||||
SendMsgToParam: async function (idapp, params) {
|
||||
|
||||
try {
|
||||
console.log('SendMsgToParam', params.typesend);
|
||||
// console.log('SendMsgToParam', params.typesend, params.typemsg);
|
||||
|
||||
const { User } = require('../models/user');
|
||||
|
||||
let textsent = '';
|
||||
|
||||
@@ -365,6 +379,7 @@ module.exports = {
|
||||
{
|
||||
username: 1,
|
||||
'profile.teleg_id': 1,
|
||||
'profile.notifs': 1,
|
||||
},
|
||||
).lean();
|
||||
|
||||
@@ -372,49 +387,66 @@ module.exports = {
|
||||
for (const user of arrusers) {
|
||||
|
||||
const mytitle = await tools.convertSpecialTags(user, params.title);
|
||||
const mycontent = await tools.convertSpecialTags(user, params.content);
|
||||
const mycontent = await tools.convertSpecialTags(user, params.textcontent_Telegram ? params.textcontent_Telegram : params.content);
|
||||
|
||||
let usernotifprofile = null;
|
||||
if (user.profile.notifs)
|
||||
usernotifprofile = user.profile.notifs.find((notif) => notif.dir === params.typenotif);
|
||||
|
||||
let risult = null;
|
||||
|
||||
if (params.sendreally) {
|
||||
if (tools.isBitActive(params.typesend, shared_consts.TypeSend.PUSH_NOTIFICATION)) {
|
||||
const myparam = { ...params };
|
||||
risult = await tools.sendNotificationToUser(user._id, mytitle, mycontent, myparam.openUrl, myparam.openUrl2, myparam.tag,
|
||||
myparam.actions, myparam.id).
|
||||
then(ris => {
|
||||
|
||||
}).
|
||||
catch(e => {
|
||||
console.error(e.message);
|
||||
});
|
||||
let sendmsg = false;
|
||||
|
||||
if (params.typenotif === shared_consts.TypeNotifs.TYPEDIR_FAVORITE) {
|
||||
if (!usernotifprofile || (usernotifprofile && tools.isBitActive(usernotifprofile.value, shared_consts.TypeNotifs.ID_FAVORITE_ADDED))) {
|
||||
sendmsg = true;
|
||||
}
|
||||
if (tools.isBitActive(params.typesend, shared_consts.TypeSend.TELEGRAM)) {
|
||||
const telegid = user.profile.teleg_id;
|
||||
} else {
|
||||
sendmsg = true;
|
||||
}
|
||||
|
||||
text = tools.getContentNotifByParams(params, mycontent, shared_consts.TypeSend.TELEGRAM);
|
||||
if (telegid > 0) {
|
||||
risult = await telegrambot.local_sendMsgTelegramByIdTelegram(idapp, telegid, text);
|
||||
await tools.snooze(50);
|
||||
if (sendmsg) {
|
||||
if (params.sendreally) {
|
||||
if (tools.isBitActive(params.typesend, shared_consts.TypeSend.PUSH_NOTIFICATION)) {
|
||||
const myparam = { ...params };
|
||||
risult = await tools.sendNotificationToUser(user._id, mytitle, mycontent, myparam.openUrl, myparam.openUrl2, myparam.tag,
|
||||
myparam.actions, myparam.id).
|
||||
then(ris => {
|
||||
|
||||
textsent = risult.text;
|
||||
}).
|
||||
catch(e => {
|
||||
console.error(e.message);
|
||||
});
|
||||
|
||||
}
|
||||
if (tools.isBitActive(params.typesend, shared_consts.TypeSend.TELEGRAM)) {
|
||||
const telegid = user.profile.teleg_id;
|
||||
|
||||
text = tools.getContentNotifByParams(params, mycontent, shared_consts.TypeSend.TELEGRAM);
|
||||
if (telegid > 0) {
|
||||
risult = await telegrambot.local_sendMsgTelegramByIdTelegram(idapp, telegid, text);
|
||||
await tools.snooze(25);
|
||||
|
||||
textsent = risult.text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
numrec++;
|
||||
if (params.sendreally && risult) {
|
||||
nummsgsent++;
|
||||
}
|
||||
numrec++;
|
||||
if (params.sendreally && risult) {
|
||||
nummsgsent++;
|
||||
}
|
||||
|
||||
if (nummsgsent > 0 && (nummsgsent % 100) === 0) {
|
||||
console.log('Inviati ', nummsgsent, 'messaggi...');
|
||||
if (nummsgsent > 0 && (nummsgsent % 100) === 0) {
|
||||
console.log('Inviati ', nummsgsent, 'messaggi...');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nummsgsent > 0) {
|
||||
console.log('FINE Invio Messaggi ! Inviati Totali: ', nummsgsent, 'su', numrec);
|
||||
if (nummsgsent != numrec && (numrec !== 1))
|
||||
console.log('FINE Invio Messaggi ! Inviati Totali: ', nummsgsent, 'su', numrec);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -535,69 +567,167 @@ module.exports = {
|
||||
}
|
||||
|
||||
},
|
||||
ReplaceCircuitName: async function (idapp, search_circuitname, replace_circuitname) {
|
||||
|
||||
const { SendNotif } = require('../models/sendnotif');
|
||||
getNumFavoriteByIdObj: async function (idapp, numtab, id) {
|
||||
|
||||
if (!search_circuitname || !replace_circuitname) {
|
||||
return false;
|
||||
}
|
||||
const { Reaction } = require('../models/reaction');
|
||||
|
||||
let query = [
|
||||
{
|
||||
$match: {
|
||||
idapp,
|
||||
idrec: id,
|
||||
},
|
||||
},
|
||||
{
|
||||
$group:
|
||||
{
|
||||
_id: null,
|
||||
count: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$fav", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
{ $project: { _id: 0 } }
|
||||
];
|
||||
|
||||
try {
|
||||
let ris = null;
|
||||
console.log('ReplaceCircuitName = ', search_circuitname, replace_circuitname);
|
||||
const [result] = await Reaction.aggregate(query);
|
||||
|
||||
ris = await Circuit.findOneAndUpdate({ idapp, name: search_circuitname }, { $set: { name: replace_circuitname } });
|
||||
console.log('Circuit result = ', ris);
|
||||
|
||||
if (ris) {
|
||||
|
||||
ris = await User.updateMany({ idapp, 'profile.mycircuits.circuitname': search_circuitname },
|
||||
{
|
||||
$set:
|
||||
{ 'profile.mycircuits.$.circuitname': replace_circuitname }
|
||||
});
|
||||
|
||||
ris = await MyGroup.updateMany({ idapp, 'mycircuits.circuitname': search_circuitname },
|
||||
{
|
||||
$set:
|
||||
{ 'mycircuits.$.circuitname': replace_circuitname }
|
||||
});
|
||||
|
||||
|
||||
ris = await User.updateMany({ idapp, 'profile.last_circuitpath': search_circuitname },
|
||||
{
|
||||
$set:
|
||||
{ 'profile.last_circuitpath': replace_circuitname }
|
||||
});
|
||||
|
||||
ris = await SendNotif.updateMany({ idapp, 'extrarec.circuitname': search_circuitname },
|
||||
{
|
||||
$set:
|
||||
{ 'extrarec.circuitname': replace_circuitname }
|
||||
});
|
||||
|
||||
ris = await SendNotif.updateMany({ idapp, 'extrarec.name': search_circuitname },
|
||||
{
|
||||
$set:
|
||||
{ 'extrarec.name': replace_circuitname }
|
||||
});
|
||||
|
||||
ris = await SendNotif.updateMany({ idapp, 'extrafield': search_circuitname },
|
||||
{
|
||||
$set:
|
||||
{ 'extrafield': replace_circuitname }
|
||||
});
|
||||
|
||||
console.log(' ... done ' + replace_circuitname);
|
||||
return true;
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return false;
|
||||
return result ? result.count : 0;
|
||||
} catch (err) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
},
|
||||
|
||||
getNumBookByIdObj: async function (idapp, numtab, id) {
|
||||
|
||||
const { Reaction } = require('../models/reaction');
|
||||
|
||||
let query = [
|
||||
{
|
||||
$match: {
|
||||
idapp,
|
||||
idrec: id,
|
||||
},
|
||||
},
|
||||
{
|
||||
$group:
|
||||
{
|
||||
_id: null,
|
||||
count: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$book", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
{ $project: { _id: 0 } }
|
||||
];
|
||||
|
||||
try {
|
||||
const [result] = await Reaction.aggregate(query);
|
||||
|
||||
return result ? result.count : 0;
|
||||
} catch (err) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
},
|
||||
|
||||
getNumAttendByIdObj: async function (idapp, numtab, id) {
|
||||
|
||||
const { Reaction } = require('../models/reaction');
|
||||
|
||||
let query = [
|
||||
{
|
||||
$match: {
|
||||
idapp,
|
||||
idrec: id,
|
||||
},
|
||||
},
|
||||
{
|
||||
$group:
|
||||
{
|
||||
_id: null,
|
||||
count: {
|
||||
$sum: {
|
||||
$cond: {
|
||||
if: { $ifNull: ["$attent", false] }, // Check if the field exists and is not null
|
||||
then: 1, // Increment count by 1 if the field exists
|
||||
else: 0, // Otherwise, keep the count unchanged
|
||||
}
|
||||
},
|
||||
|
||||
/*$sum:
|
||||
{
|
||||
$reduce: {
|
||||
input: "$profile.attend",
|
||||
initialValue: 0,
|
||||
in: {
|
||||
$add: ["$$value", "$$this.num"]
|
||||
}
|
||||
}
|
||||
}*/
|
||||
},
|
||||
}
|
||||
},
|
||||
{ $project: { _id: 0 } }
|
||||
];
|
||||
|
||||
try {
|
||||
const [result] = await Reaction.aggregate(query);
|
||||
|
||||
return result ? result.count : 0;
|
||||
} catch (err) {
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
|
||||
getUserCreatorByNumTabAndId: async function (idapp, id, numtab) {
|
||||
try {
|
||||
const table = tools.getTableByNumTab(numtab);
|
||||
const mytable = this.getTableByTableName(table);
|
||||
|
||||
const { User } = require('../models/user');
|
||||
|
||||
if (mytable) {
|
||||
const rec = await mytable.findOne({ _id: id, idapp }, { username: 1, lang: 1, userId: 1, descr: 1 });
|
||||
if (rec) {
|
||||
const recuser = await User.getUserById(idapp, rec.userId);
|
||||
|
||||
let numattend = await this.getNumAttendByIdObj(idapp, numtab, id);
|
||||
let numfav = await this.getNumFavoriteByIdObj(idapp, numtab, id);
|
||||
let numbook = await this.getNumBookByIdObj(idapp, numtab, id);
|
||||
let exist = false;
|
||||
if (table === shared_consts.TABLES_MYBACHECAS)
|
||||
exist = numattend > 1;
|
||||
else
|
||||
exist = numfav > 1;
|
||||
if (recuser)
|
||||
return { userId: rec.userId, username: recuser.username, descr: rec.descr, id: rec._id, table, exist, numfav, numattend, numbook };
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Err:', e);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ module.exports = Object.freeze({
|
||||
RIS_CODE_EMAIL_ALREADY_VERIFIED: -5,
|
||||
RIS_CODE_EMAIL_VERIFIED: 1,
|
||||
|
||||
RIS_CODE_REC_DUPLICATED_DESCR_CITY_USER: -110,
|
||||
RIS_CODE_REC_ALREADY_EXIST_SYMBOL: -102,
|
||||
RIS_CODE_REC_ALREADY_EXIST_CODE: -101,
|
||||
RIS_CODE_REC_ALREADY_EXIST_NAME: -100,
|
||||
|
||||
@@ -3,6 +3,7 @@ module.exports = {
|
||||
CHECK_READ_GUIDELINES: 1,
|
||||
CHECK_SEE_VIDEO_PRINCIPI: 2,
|
||||
},
|
||||
LIMIT_NOTIF_FOR_USER: 200,
|
||||
|
||||
QUERYTYPE_MYGROUP: 1,
|
||||
QUERYTYPE_REFUSED_USER_GRP: 2,
|
||||
@@ -46,6 +47,7 @@ module.exports = {
|
||||
OPTIONS_SEARCH_ONLY_FULL_WORDS: 1,
|
||||
OPTIONS_SEARCH_USER_ONLY_FULL_WORDS: 2,
|
||||
OPTIONS_SEARCH_USER_ALL_WORDS: 4,
|
||||
OPTIONS_ADD_COUNT_FAVORITE: 8,
|
||||
|
||||
FRIENDSCMD: {
|
||||
SETTRUST: 121,
|
||||
@@ -80,6 +82,7 @@ module.exports = {
|
||||
CREATE: 1001,
|
||||
REQ: 2000,
|
||||
SET: 2001,
|
||||
SETFIDO: 2005,
|
||||
REMOVE_FROM_MYLIST: 2144,
|
||||
REFUSE_REQ: 2145,
|
||||
CANCEL_REQ: 2146,
|
||||
@@ -94,6 +97,10 @@ module.exports = {
|
||||
SENDCOINS_REFUSE_SENT: 2222,
|
||||
},
|
||||
|
||||
USERCMD: {
|
||||
FAVORITE: 3001,
|
||||
},
|
||||
|
||||
REPORT_FILT_RESP: 1,
|
||||
REPORT_FILT_ATTIVITA: 2,
|
||||
|
||||
@@ -133,8 +140,33 @@ module.exports = {
|
||||
TABLES_MYHOSPS: 'myhosps',
|
||||
TABLES_MYGOODS: 'mygoods',
|
||||
TABLES_MYEVENTS: 'myevents',
|
||||
TABLES_CIRCUITS: 'circuits',
|
||||
TABLES_MYGROUPS: 'mygroups',
|
||||
|
||||
MYTABS: [{ id: 0, table: 'none' },
|
||||
{ id: 1, table: 'myskills' },
|
||||
{ id: 2, table: 'mybachecas' },
|
||||
{ id: 3, table: 'myhosps' },
|
||||
{ id: 4, table: 'mygoods' },
|
||||
{ id: 5, table: 'myevents' }],
|
||||
|
||||
CMD_REACTION: {
|
||||
SET_FAVORITE: 1,
|
||||
SET_BOOKMARK: 2,
|
||||
SET_SEEN: 3,
|
||||
SET_ATTEND: 4,
|
||||
},
|
||||
|
||||
REACTIONS_FIELD:
|
||||
{
|
||||
numseen: 1,
|
||||
numbook: 1,
|
||||
numfav: 1,
|
||||
numattend: 1,
|
||||
},
|
||||
|
||||
TABLES_ENABLE_GETREC_BYID: ['mybachecas', 'myhosps', 'myskills', 'mygoods'],
|
||||
TABLES_REACTIONS: ['mybachecas', 'myhosps', 'myskills', 'mygoods'],
|
||||
|
||||
TABLES_USER_INCLUDE_MY: ['mygroups', 'circuits'],
|
||||
TABLES_GETCOMPLETEREC: ['myskills', 'mybachecas', 'myhosps', 'mygoods'],
|
||||
@@ -142,6 +174,7 @@ module.exports = {
|
||||
//++Todo: per abilitare gli utenti ad inserire un Circuito aggiungere 'circuits' alla lista TABLES_PERM_NEWREC
|
||||
TABLES_PERM_NEWREC: ['skills', 'goods', 'subskills', 'mygroups', 'myhosps'],
|
||||
TABLES_REC_ID: ['skills', 'goods', 'subskills'],
|
||||
TABLES_FAVORITE_BOOKMARK: ['myskills', 'mygoods', 'mybachecas', 'myhosps'],
|
||||
|
||||
TABLES_VISU_STAT_IN_HOME: ['myskills', 'mybachecas', 'myhosps', 'mygoods', 'mygroups', 'circuits'],
|
||||
|
||||
@@ -152,13 +185,13 @@ module.exports = {
|
||||
TABLES_GROUPS_NOTIFICATION: ['mygroups'],
|
||||
TABLES_CIRCUITS_NOTIFICATION: ['circuits'],
|
||||
|
||||
TABLES_NUM_AS_ID_NUMBER: [ ],
|
||||
TABLES_NUM_AS_ID_NUMBER: [],
|
||||
|
||||
TABLES_ID_STRING: [
|
||||
'circuits',
|
||||
'accounts',
|
||||
'movements',
|
||||
],
|
||||
'circuits',
|
||||
'accounts',
|
||||
'movements',
|
||||
],
|
||||
|
||||
TABLES_ID_NUMBER: [
|
||||
'permissions',
|
||||
@@ -173,16 +206,18 @@ module.exports = {
|
||||
'subskills',
|
||||
'cities',
|
||||
'provinces',
|
||||
'myskills',
|
||||
'mybachecas',
|
||||
'myhosps',
|
||||
'mygoods',
|
||||
'mygroups'
|
||||
// 'myskills',
|
||||
// 'mybachecas',
|
||||
// 'myhosps',
|
||||
// 'mygoods',
|
||||
// 'mygroups'
|
||||
],
|
||||
TABLES_USER_ID: ['mygroups', 'myskills', 'mybachecas', 'myhosps', 'mygoods'],
|
||||
TABLES_CREATEDBY: ['mygroups', 'circuits'],
|
||||
TABLES_UPDATE_LASTMODIFIED: ['myskills', 'mybachecas', 'myhosps', 'mygoods', 'bots', 'mygroups', 'circuits'],
|
||||
|
||||
TABLES_FIELDS_DESCR_AND_CITY_AND_USER: ['myskills', 'mybachecas', 'myhosps', 'mygoods'],
|
||||
|
||||
TABLES_PERM_CHANGE_FOR_USERS: ['myskills', 'mybachecas', 'myhosps', 'mygoods'],
|
||||
|
||||
TABLES_POPULATE_DATA: [
|
||||
@@ -193,19 +228,19 @@ module.exports = {
|
||||
table: 'adtypes',
|
||||
key: 'descr',
|
||||
},
|
||||
{table: 'catgrps', key: 'descr'},
|
||||
{ table: 'catgrps', key: 'descr' },
|
||||
{
|
||||
table: 'contribtypes',
|
||||
key: 'descr',
|
||||
},
|
||||
{table: 'goods', key: 'descr'},
|
||||
{table: 'levels', key: 'descr'},
|
||||
{table: 'cities', key: 'comune'},
|
||||
{table: 'provinces', key: 'descr'},
|
||||
{table: 'sectorgoods', key: 'descr'},
|
||||
{table: 'sectors', key: 'descr'},
|
||||
{table: 'skills', key: 'descr'},
|
||||
{table: 'statusSkills', key: 'descr'},
|
||||
{ table: 'goods', key: 'descr' },
|
||||
{ table: 'levels', key: 'descr' },
|
||||
{ table: 'cities', key: 'comune' },
|
||||
{ table: 'provinces', key: 'descr' },
|
||||
{ table: 'sectorgoods', key: 'descr' },
|
||||
{ table: 'sectors', key: 'descr' },
|
||||
{ table: 'skills', key: 'descr' },
|
||||
{ table: 'statusSkills', key: 'descr' },
|
||||
],
|
||||
|
||||
VISIB_ALL: 0,
|
||||
@@ -213,6 +248,12 @@ module.exports = {
|
||||
VISIB_ONLY_MANAGER: 2,
|
||||
VISIB_ONLY_ADMIN: 4,
|
||||
|
||||
CIRCUIT_CFG: {
|
||||
MULT_FIDO_USER: 2.0,
|
||||
MULT_FIDO_GROUP: 2.0,
|
||||
},
|
||||
|
||||
|
||||
Visibility_Group: {
|
||||
PRIVATE: 1,
|
||||
HIDDEN: 2,
|
||||
@@ -224,6 +265,8 @@ module.exports = {
|
||||
BOTTYPE_LINK: 2,
|
||||
BOTTYPE_TEXT: 3,
|
||||
BOTTYPE_MENU: 4,
|
||||
BOTTYPE_MARKDOWN: 5,
|
||||
BOTTYPE_BOTTONI_INLINE: 6,
|
||||
|
||||
RIS_OK: '👍🏻 OK',
|
||||
|
||||
@@ -296,6 +339,8 @@ module.exports = {
|
||||
RICHIESTA_AMICIZIA: 15,
|
||||
RICHIESTA_HANDSHAKE: 16,
|
||||
RICHIESTA_CIRCUIT: 20,
|
||||
RICHIESTA_FIDO: 25,
|
||||
ENTRA_RIS_ITALIA: 30,
|
||||
},
|
||||
|
||||
OrderStatus: {
|
||||
@@ -321,6 +366,9 @@ module.exports = {
|
||||
Notif_Reg_Bot_ToManagers: 1,
|
||||
Notif_Reg_Push_Admin: 2,
|
||||
Need_Aportador_On_DataReg_To_Verify_Reg: 4,
|
||||
AskInvitantesulBot: 8,
|
||||
AskUsernameSulBot: 16,
|
||||
registerUserWithBot: 32,
|
||||
},
|
||||
|
||||
MsgTeleg: {
|
||||
@@ -344,6 +392,7 @@ module.exports = {
|
||||
NEW_ADV_MY_GROUPS: 8,
|
||||
NEW_ADV_MY_RIS_CIRCUIT: 16,
|
||||
NEW_ADV_SECTOR: 32,
|
||||
NEW_ADV_YOUR_PROVINCE: 64,
|
||||
},
|
||||
|
||||
StatusNotifs: {
|
||||
@@ -386,10 +435,13 @@ module.exports = {
|
||||
TYPEDIR_BACHECA: 1,
|
||||
ID_BACHECA_NEW_GOOD: 1,
|
||||
ID_BACHECA_NEW_SERVICE: 2,
|
||||
ID_BACHECA_NEW_HOSP: 4,
|
||||
|
||||
TYPEDIR_EVENTS: 2,
|
||||
ID_EVENTS_NEW_REC: 1,
|
||||
ID_EVENTS_REMOVE_REC: 2,
|
||||
ID_EVENTS_ATTEND: 4,
|
||||
ID_EVENTS_SEND_MSG: 8,
|
||||
|
||||
TYPEDIR_FRIENDS: 3,
|
||||
ID_FRIENDS_NEW_REC: 1,
|
||||
@@ -426,6 +478,7 @@ module.exports = {
|
||||
ID_CIRCUIT_SENDCOINSREQ_SENT: 4096,
|
||||
ID_CIRCUIT_COINS_ACCEPTED_SENT: 8192,
|
||||
ID_CIRCUIT_COINS_REFUSED_SENT: 16384,
|
||||
ID_CIRCUIT_SETFIDO: 32768,
|
||||
|
||||
TYPEDIR_BOOKING: 6,
|
||||
|
||||
@@ -435,12 +488,15 @@ module.exports = {
|
||||
TYPEDIR_HANDSHAKE: 10,
|
||||
ID_HANDSHAKE_ACCEPTED: 2,
|
||||
|
||||
TYPEDIR_FAVORITE: 11,
|
||||
ID_FAVORITE_ADDED: 1,
|
||||
|
||||
TYPEDIR_TEST: 444,
|
||||
ID_TEST_NEW_REC: 1,
|
||||
},
|
||||
|
||||
|
||||
// Tipi di Notifiche:
|
||||
// Tipi di Notifiche:
|
||||
/*
|
||||
Notif: {
|
||||
UPDATE_APP: 1,
|
||||
@@ -492,11 +548,11 @@ module.exports = {
|
||||
DEFAULT_NOTIFS_USER: [
|
||||
{
|
||||
'dir': 1,
|
||||
'value': 24
|
||||
'value': 88
|
||||
},
|
||||
{
|
||||
'dir': 2,
|
||||
'value': 1
|
||||
'value': 4
|
||||
},
|
||||
{
|
||||
'dir': 3,
|
||||
@@ -509,7 +565,15 @@ module.exports = {
|
||||
{
|
||||
'dir': 5,
|
||||
'value': 1
|
||||
}
|
||||
},
|
||||
{
|
||||
'dir': 11,
|
||||
'value': 1
|
||||
},
|
||||
{
|
||||
'dir': 12,
|
||||
'value': 1
|
||||
},
|
||||
],
|
||||
|
||||
CIRCUIT_STATUS: {
|
||||
@@ -526,4 +590,224 @@ module.exports = {
|
||||
SCOPERTO_MAX_CONTO_COMUNITARIO: 1000,
|
||||
},
|
||||
|
||||
TABLETYPE: {
|
||||
DefaultCal: 0,
|
||||
MyBachecas: 1,
|
||||
},
|
||||
|
||||
getProjectByTable(table, proj_add) {
|
||||
let proj = {}
|
||||
|
||||
if (table === this.TABLES_MYGOODS) {
|
||||
proj = {
|
||||
'recGood': 1,
|
||||
'sectorGood': 1,
|
||||
'idSectorGood': 1,
|
||||
'idGood': 1,
|
||||
'idShipping': 1,
|
||||
'idStatusGood': 1,
|
||||
//**ADDFIELD_MYGOOD
|
||||
}
|
||||
|
||||
} else if (table === this.TABLES_MYGROUPS) {
|
||||
proj = {
|
||||
groupname: 1,
|
||||
title: 1,
|
||||
descr: 1,
|
||||
img: 1,
|
||||
visibility: 1,
|
||||
admins: 1,
|
||||
idCatGrp: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
photos: 1,
|
||||
idCity: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
link_telegram: 1,
|
||||
comune: 1,
|
||||
mycities: 1,
|
||||
sector: 1,
|
||||
recCatGrp: 1,
|
||||
}
|
||||
} else if (table === this.TABLES_CIRCUITS) {
|
||||
proj = {
|
||||
_id: 1,
|
||||
groupnameId: 1,
|
||||
path: 1,
|
||||
name: 1,
|
||||
strProv: 1,
|
||||
subname: 1,
|
||||
longdescr: 1,
|
||||
regulation: 1,
|
||||
numMembers: 1,
|
||||
totCircolante: 1,
|
||||
totTransato: 1,
|
||||
systemUserId: 1,
|
||||
createdBy: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
nome_valuta: 1,
|
||||
fido_scoperto_default: 1,
|
||||
deperimento: 1,
|
||||
showAlways: 1,
|
||||
status: 1,
|
||||
transactionsEnabled: 1,
|
||||
qta_max_default: 1,
|
||||
fido_scoperto_default_grp: 1,
|
||||
qta_max_default_grp: 1,
|
||||
valuta_per_euro: 1,
|
||||
symbol: 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
visibility: 1,
|
||||
color: 1,
|
||||
abbrev: 1,
|
||||
data_costituz: 1,
|
||||
photos: 1,
|
||||
admins: 1,
|
||||
req_users: 1,
|
||||
refused_users: 1,
|
||||
'mycities': 1,
|
||||
//**ADDFIELD_CIRCUITS
|
||||
}
|
||||
} else if (table === this.TABLES_MYSKILLS) {
|
||||
proj = {
|
||||
recSkill: 1,
|
||||
sector: 1,
|
||||
idSector: 1,
|
||||
idSkill: 1,
|
||||
myskill: 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
numLevel: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
//**ADDFIELD_MYSKILL
|
||||
}
|
||||
|
||||
} else if (table === this.TABLES_MYHOSPS) {
|
||||
proj = {
|
||||
visibile: 1,
|
||||
typeHosp: 1,
|
||||
numMaxPeopleHosp: 1,
|
||||
accomodation: 1,
|
||||
preferences: 1,
|
||||
idContribType: 1,
|
||||
photos: 1,
|
||||
idCity: 1,
|
||||
note: 1,
|
||||
website: 1,
|
||||
link_maplocation: 1,
|
||||
}
|
||||
|
||||
} else if (table === this.TABLES_MYBACHECAS) {
|
||||
proj = {
|
||||
recSkill: 1,
|
||||
sector: 1,
|
||||
idSector: 1,
|
||||
idSkill: 1,
|
||||
// 'idSubSkill': 1,
|
||||
idStatusSkill: 1,
|
||||
idContribType: 1,
|
||||
dateTimeStart: 1,
|
||||
dateTimeEnd: 1,
|
||||
website: 1,
|
||||
organisedBy: 1,
|
||||
contact_phone: 1,
|
||||
contact_telegram: 1,
|
||||
address: 1,
|
||||
min_partecip: 1,
|
||||
max_partecip: 1,
|
||||
contribstr: 1,
|
||||
link_maplocation: 1,
|
||||
'mygrp.groupname': 1,
|
||||
'mygrp.title': 1,
|
||||
'mygrp.photos': 1,
|
||||
//**ADDFIELD_MYBACHECAS
|
||||
}
|
||||
}
|
||||
|
||||
if (proj_add)
|
||||
proj = Object.assign({}, proj, proj_add);
|
||||
|
||||
return proj;
|
||||
},
|
||||
|
||||
getProjectForAll(proj_add, table) {
|
||||
let proj = {
|
||||
idContribType: 1,
|
||||
idCity: 1,
|
||||
pub_to_share: 1,
|
||||
adType: 1,
|
||||
photos: 1,
|
||||
note: 1,
|
||||
descr: 1,
|
||||
date_created: 1,
|
||||
date_updated: 1,
|
||||
userId: 1,
|
||||
username: 1,
|
||||
name: 1,
|
||||
surname: 1,
|
||||
groupname: 1,
|
||||
lasttimeonline: 1,
|
||||
comune: 1,
|
||||
myreact: 1,
|
||||
mycities: 1,
|
||||
lang: 1,
|
||||
'profile.img': 1,
|
||||
'profile.mygroups': 1,
|
||||
'profile.mycircuits': 1,
|
||||
'profile.qualifica': 1,
|
||||
'profile.resid_province': 1,
|
||||
'profile.resid_card': 1,
|
||||
'profile.username_telegram': 1,
|
||||
'profile.favorite': 1,
|
||||
'profile.bookmark': 1,
|
||||
'profile.attend': 1,
|
||||
'profile.seen': 1,
|
||||
reported: 1,
|
||||
date_report: 1,
|
||||
username_who_report: 1,
|
||||
namecomplete: 1,
|
||||
date_reg: 1,
|
||||
};
|
||||
|
||||
if (proj_add)
|
||||
proj = Object.assign({}, proj, proj_add);
|
||||
|
||||
proj = {...proj, ...this.REACTIONS_FIELD};
|
||||
|
||||
if (table) {
|
||||
let proj_add3 = this.getProjectByTable(table);
|
||||
proj = Object.assign({}, proj, proj_add3);
|
||||
}
|
||||
|
||||
return proj;
|
||||
},
|
||||
|
||||
getDirectoryByTable(table, barre = false) {
|
||||
let add = '';
|
||||
if (barre)
|
||||
add = '/';
|
||||
|
||||
if (table === 'myskills') {
|
||||
return add + 'myservice' + add
|
||||
} else if (table === 'mybachecas') {
|
||||
return add + 'mypage' + add
|
||||
} else if (table === 'myhosps') {
|
||||
return add + 'myhosps' + add
|
||||
} else if (table === 'mygoods') {
|
||||
return add + 'mygood' + add
|
||||
} else if (table === 'mygroups') {
|
||||
return add + 'grp' + add
|
||||
} else if (table === 'circuits') {
|
||||
return add + 'circuit' + add
|
||||
}
|
||||
|
||||
return ''
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user