emilsoftware-utilities 1.4.0-dev.2 → 1.4.0-dev.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +24 -22
- package/dist/Utilities.d.ts +1 -0
- package/dist/Utilities.js +8 -0
- package/dist/accessi-module/AccessiModule.d.ts +11 -2
- package/dist/accessi-module/Controllers/AuthController.js +18 -0
- package/dist/accessi-module/Controllers/EmailController.d.ts +0 -1
- package/dist/accessi-module/Controllers/EmailController.js +27 -15
- package/dist/accessi-module/Controllers/UserController.d.ts +2 -0
- package/dist/accessi-module/Controllers/UserController.js +132 -30
- package/dist/accessi-module/Dtos/FiltriUtente.d.ts +3 -2
- package/dist/accessi-module/Dtos/FiltriUtente.js +10 -6
- package/dist/accessi-module/Dtos/RegisterRequest.d.ts +7 -5
- package/dist/accessi-module/Dtos/RegisterRequest.js +90 -21
- package/dist/accessi-module/Dtos/SetStatoRegistrazione.d.ts +5 -0
- package/dist/accessi-module/Dtos/SetStatoRegistrazione.js +32 -0
- package/dist/accessi-module/Dtos/StatoRegistrazione.d.ts +1 -0
- package/dist/accessi-module/Dtos/StatoRegistrazione.js +2 -1
- package/dist/accessi-module/Dtos/UserDto.d.ts +5 -4
- package/dist/accessi-module/Dtos/UserDto.js +85 -34
- package/dist/accessi-module/Services/AuthService/AuthService.js +17 -9
- package/dist/accessi-module/Services/EmailService/EmailService.d.ts +1 -1
- package/dist/accessi-module/Services/EmailService/EmailService.js +62 -33
- package/dist/accessi-module/Services/UserService/UserService.d.ts +10 -7
- package/dist/accessi-module/Services/UserService/UserService.js +125 -39
- package/dist/emilsoftware-utilities-1.4.0-dev.21.tgz +0 -0
- package/package.json +1 -1
- package/dist/emilsoftware-utilities-1.4.0-dev.2.tgz +0 -0
|
@@ -38,21 +38,25 @@ let EmailService = class EmailService {
|
|
|
38
38
|
sendAccountUpdateEmail(email, message) {
|
|
39
39
|
throw new Error('Method not implemented.');
|
|
40
40
|
}
|
|
41
|
-
sendPasswordResetEmail(email,
|
|
41
|
+
sendPasswordResetEmail(email, htmlMail) {
|
|
42
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
43
|
var _a;
|
|
44
44
|
try {
|
|
45
45
|
const resetToken = (0, uuid_1.v4)(); // Generiamo un nuovo token unico
|
|
46
|
+
console.log('Generated reset token:', resetToken);
|
|
46
47
|
// Aggiorna il campo keyReg nel database
|
|
47
|
-
const result = yield Orm_1.Orm.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
const result = yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, 'UPDATE UTENTI SET KEYREG = ?, STAREG = ? WHERE USRNAME = ? ', [resetToken, StatoRegistrazione_1.StatoRegistrazione.INVIO, email]);
|
|
49
|
+
//costruizione dei queryparams
|
|
50
|
+
const returnUrlQueryParams = '?returnUrl=' +
|
|
51
|
+
this.accessiOptions.confirmationEmailReturnUrl +
|
|
52
|
+
'&prefix=' +
|
|
53
|
+
((_a = this.accessiOptions.confirmationEmailPrefix) !== null && _a !== void 0 ? _a : '');
|
|
54
|
+
const { confirmationEmailUrl, customResetPage } = this.accessiOptions;
|
|
55
|
+
// costruisco l'url di base
|
|
53
56
|
let resetUrl = `${confirmationEmailUrl}/api/accessi/email/reset-password-page/${resetToken}${returnUrlQueryParams}`;
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
//solo se gli do la customResetPage
|
|
58
|
+
if (customResetPage) {
|
|
59
|
+
resetUrl = customResetPage + '?token=' + resetToken;
|
|
56
60
|
}
|
|
57
61
|
let sPhrase;
|
|
58
62
|
if (htmlMail) {
|
|
@@ -77,7 +81,7 @@ let EmailService = class EmailService {
|
|
|
77
81
|
const mailOptions = {
|
|
78
82
|
from: this.accessiOptions.emailOptions.from,
|
|
79
83
|
to: email,
|
|
80
|
-
subject:
|
|
84
|
+
subject: 'Scelta nuova password',
|
|
81
85
|
text: sPhrase,
|
|
82
86
|
html: html,
|
|
83
87
|
};
|
|
@@ -201,7 +205,8 @@ let EmailService = class EmailService {
|
|
|
201
205
|
sTxt += ' table.kmSplitContentRightContentContainer,';
|
|
202
206
|
sTxt += ' table.kmColumnContainer,';
|
|
203
207
|
sTxt += ' td.kmVerticalButtonBarContentOuter table.kmButtonBarContent,';
|
|
204
|
-
sTxt +=
|
|
208
|
+
sTxt +=
|
|
209
|
+
' td.kmVerticalButtonCollectionContentOuter table.kmButtonCollectionContent,';
|
|
205
210
|
sTxt += ' table.kmVerticalButton,';
|
|
206
211
|
sTxt += ' table.kmVerticalButtonContent {';
|
|
207
212
|
sTxt += ' width: 100% !important';
|
|
@@ -281,44 +286,68 @@ let EmailService = class EmailService {
|
|
|
281
286
|
sTxt += ' }';
|
|
282
287
|
sTxt += ' </style>';
|
|
283
288
|
sTxt += '</head>';
|
|
284
|
-
sTxt +=
|
|
289
|
+
sTxt +=
|
|
290
|
+
'<body style="margin:0;padding:0;font-family:"Raleway", Helvetica, sans-serif;font-weight:400;letter-spacing:0.75px;line-height:180%;background-color:#F2F2F2">';
|
|
285
291
|
sTxt += ' <center>';
|
|
286
|
-
sTxt +=
|
|
292
|
+
sTxt +=
|
|
293
|
+
' <table align="center" border="0" cellpadding="0" cellspacing="0" id="bodyTable" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;padding:0;background-color:#F2F2F2;height:100%;margin:0;width:100%">';
|
|
287
294
|
sTxt += ' <tbody>';
|
|
288
295
|
sTxt += ' <tr>';
|
|
289
|
-
sTxt +=
|
|
296
|
+
sTxt +=
|
|
297
|
+
' <td align="center" id="bodyCell" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;padding-top:10px;padding-left:10px;padding-bottom:20px;padding-right:10px;border-top:0;height:100%;margin:0;width:100%">';
|
|
290
298
|
sTxt += ' <!--[if !mso]>';
|
|
291
299
|
sTxt += ' <!-->';
|
|
292
|
-
sTxt +=
|
|
300
|
+
sTxt +=
|
|
301
|
+
' <div class="templateContainer" style="border:0 none #aaa;background-color:#F2F2F2;border-radius:0;display: table; width:90%">';
|
|
293
302
|
sTxt += ' <div class="templateContainerInner" style="padding:0">';
|
|
294
303
|
sTxt += ' <!--';
|
|
295
304
|
sTxt += ' <![endif]-->';
|
|
296
305
|
sTxt += ' <!--[if mso]>';
|
|
297
|
-
sTxt +=
|
|
298
|
-
|
|
306
|
+
sTxt +=
|
|
307
|
+
' <table border="0" cellpadding="0" cellspacing="0" class="templateContainer" width="90%" ';
|
|
308
|
+
sTxt +=
|
|
309
|
+
' style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;">';
|
|
299
310
|
sTxt += ' <tbody>';
|
|
300
311
|
sTxt += ' <tr>';
|
|
301
|
-
sTxt +=
|
|
312
|
+
sTxt +=
|
|
313
|
+
' <td class="templateContainerInner" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;">';
|
|
302
314
|
sTxt += ' <![endif]-->';
|
|
303
|
-
sTxt +=
|
|
315
|
+
sTxt +=
|
|
316
|
+
' <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
|
|
304
317
|
sTxt += ' <tr>';
|
|
305
|
-
sTxt +=
|
|
306
|
-
|
|
318
|
+
sTxt +=
|
|
319
|
+
' <td align="center" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
|
|
320
|
+
sTxt +=
|
|
321
|
+
' <table border="0" cellpadding="0" cellspacing="0" class="templateRow" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
|
|
307
322
|
sTxt += ' <tbody>';
|
|
308
323
|
sTxt += ' <tr>';
|
|
309
|
-
sTxt +=
|
|
310
|
-
|
|
311
|
-
sTxt +=
|
|
324
|
+
sTxt +=
|
|
325
|
+
' <td class="rowContainer kmFloatLeft" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
|
|
326
|
+
sTxt +=
|
|
327
|
+
' <table border="0" cellpadding="0" cellspacing="0" class="kmTextBlock" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
|
|
328
|
+
sTxt +=
|
|
329
|
+
' <tbody class="kmTextBlockOuter">';
|
|
312
330
|
sTxt += ' <tr>';
|
|
313
|
-
sTxt +=
|
|
314
|
-
|
|
315
|
-
sTxt +=
|
|
316
|
-
|
|
317
|
-
sTxt +=
|
|
318
|
-
|
|
319
|
-
sTxt +=
|
|
320
|
-
|
|
321
|
-
sTxt +=
|
|
331
|
+
sTxt +=
|
|
332
|
+
' <td class="kmTextBlockInner" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;background-color:#FFFFFF;">';
|
|
333
|
+
sTxt +=
|
|
334
|
+
' <table align="left" border="0" cellpadding="0" cellspacing="0" class="kmTextContentContainer" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
|
|
335
|
+
sTxt +=
|
|
336
|
+
' <tbody>';
|
|
337
|
+
sTxt +=
|
|
338
|
+
' <tr>';
|
|
339
|
+
sTxt +=
|
|
340
|
+
' <td class="kmTextContent" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;color:#272727;font-family:Helvetica, Arial;font-size:13px;line-height:200%;letter-spacing:normal;text-align:left;padding-top:40px;padding-bottom:40px;padding-left:40px;padding-right:40px;">';
|
|
341
|
+
sTxt +=
|
|
342
|
+
' <p>' +
|
|
343
|
+
sPhrase +
|
|
344
|
+
'<p>';
|
|
345
|
+
sTxt +=
|
|
346
|
+
' </td>';
|
|
347
|
+
sTxt +=
|
|
348
|
+
' </tr>';
|
|
349
|
+
sTxt +=
|
|
350
|
+
' </tbody>';
|
|
322
351
|
sTxt += ' </table>';
|
|
323
352
|
sTxt += ' </td>';
|
|
324
353
|
sTxt += ' </tr>';
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { AccessiOptions } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { AccessiOptions } from '../../AccessiModule';
|
|
2
|
+
import { StatoRegistrazione } from '../../Dtos/StatoRegistrazione';
|
|
3
|
+
import { EmailService } from '../EmailService/EmailService';
|
|
4
|
+
import { FiltriUtente } from '../../Dtos/FiltriUtente';
|
|
5
|
+
import { GetUsersResult } from '../../Dtos/GetUsersResponse';
|
|
6
|
+
import { PermissionService } from '../PermissionService/PermissionService';
|
|
7
|
+
import { UserDto } from '../../Dtos';
|
|
8
|
+
import { RegisterRequest } from '../../Dtos/RegisterRequest';
|
|
8
9
|
export declare class UserService {
|
|
9
10
|
private readonly accessiOptions;
|
|
10
11
|
private readonly emailService;
|
|
@@ -26,6 +27,8 @@ export declare class UserService {
|
|
|
26
27
|
private executeInTransaction;
|
|
27
28
|
register(registrationData: RegisterRequest): Promise<string>;
|
|
28
29
|
updateUser(codiceUtente: number, user: UserDto): Promise<void>;
|
|
30
|
+
updateUserFilters(codiceUtente: number, user: UserDto): Promise<void>;
|
|
29
31
|
deleteUser(codiceCliente: number): Promise<void>;
|
|
32
|
+
setStato(codiceCliente: number, statoRegistrazione: StatoRegistrazione): Promise<void>;
|
|
30
33
|
setGdpr(codiceUtente: number): Promise<any>;
|
|
31
34
|
}
|
|
@@ -64,7 +64,8 @@ let UserService = class UserService {
|
|
|
64
64
|
F.CODAGE AS cod_age,
|
|
65
65
|
F.CODCLICOL AS cod_cli_col,
|
|
66
66
|
F.CODCLIENTI AS codice_clienti,
|
|
67
|
-
F.TIPFIL AS
|
|
67
|
+
F.TIPFIL AS tipo_filtro,
|
|
68
|
+
F.IDXPOS AS idx_postazione
|
|
68
69
|
FROM UTENTI U
|
|
69
70
|
INNER JOIN UTENTI_CONFIG G ON U.CODUTE = G.CODUTE
|
|
70
71
|
LEFT JOIN FILTRI F ON F.CODUTE = U.CODUTE
|
|
@@ -80,10 +81,10 @@ let UserService = class UserService {
|
|
|
80
81
|
queryParams.push(filters.codiceUtente);
|
|
81
82
|
}
|
|
82
83
|
query += ` ORDER BY U.CODUTE DESC `;
|
|
83
|
-
let users = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, queryParams);
|
|
84
|
+
let users = (yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, queryParams));
|
|
84
85
|
users = users.map(Utilities_1.RestUtilities.convertKeysToCamelCase);
|
|
85
86
|
let usersResponse = [];
|
|
86
|
-
console.log(
|
|
87
|
+
console.log('OPTIONS: ', options);
|
|
87
88
|
for (const user of users) {
|
|
88
89
|
let userGrants = null;
|
|
89
90
|
if (options.includeGrants)
|
|
@@ -92,18 +93,18 @@ let UserService = class UserService {
|
|
|
92
93
|
//todo: se non è prendente extensionFieldOptions va in errore. Risolvere il problema
|
|
93
94
|
if (options.includeExtensionFields) {
|
|
94
95
|
for (const ext of this.accessiOptions.extensionFieldsOptions) {
|
|
95
|
-
const values = (yield Orm_1.Orm.query(ext.databaseOptions, `SELECT ${ext.tableFields.join(
|
|
96
|
+
const values = (yield Orm_1.Orm.query(ext.databaseOptions, `SELECT ${ext.tableFields.join(',')} FROM ${ext.tableName} WHERE ${ext.tableJoinFieldName} = ?`, [user.codiceUtente])).map(Utilities_1.RestUtilities.convertKeysToCamelCase);
|
|
96
97
|
extensionFields[ext.objectKey] = values;
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
let userResult = {
|
|
100
101
|
utente: user,
|
|
101
102
|
userGrants: userGrants,
|
|
102
|
-
extensionFields: extensionFields
|
|
103
|
+
extensionFields: extensionFields,
|
|
103
104
|
};
|
|
104
105
|
usersResponse.push(userResult);
|
|
105
106
|
}
|
|
106
|
-
console.log(
|
|
107
|
+
console.log('OPTIONS: ', options);
|
|
107
108
|
return usersResponse;
|
|
108
109
|
}
|
|
109
110
|
catch (error) {
|
|
@@ -115,7 +116,9 @@ let UserService = class UserService {
|
|
|
115
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
116
117
|
try {
|
|
117
118
|
const query = `SELECT CODUTE as codice_utente FROM UTENTI WHERE LOWER(USRNAME) = ?`;
|
|
118
|
-
const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [
|
|
119
|
+
const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [
|
|
120
|
+
email.trim().toLowerCase(),
|
|
121
|
+
]);
|
|
119
122
|
return result.map(Utilities_1.RestUtilities.convertKeysToCamelCase)[0];
|
|
120
123
|
}
|
|
121
124
|
catch (error) {
|
|
@@ -145,8 +148,7 @@ let UserService = class UserService {
|
|
|
145
148
|
INNER JOIN UTENTI_CONFIG C ON C.CODUTE = U.CODUTE
|
|
146
149
|
WHERE LOWER(U.USRNAME) = ?
|
|
147
150
|
`;
|
|
148
|
-
const utenti = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [email])
|
|
149
|
-
.then(results => results.map(Utilities_1.RestUtilities.convertKeysToCamelCase));
|
|
151
|
+
const utenti = (yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [email]).then((results) => results.map(Utilities_1.RestUtilities.convertKeysToCamelCase)));
|
|
150
152
|
return utenti.length > 0 ? utenti[0] : null;
|
|
151
153
|
});
|
|
152
154
|
}
|
|
@@ -158,15 +160,15 @@ let UserService = class UserService {
|
|
|
158
160
|
F.NUMREP AS numero_report,
|
|
159
161
|
F.IDXPERS AS indice_personale,
|
|
160
162
|
F.CODCLISUPER AS codice_cliente_super,
|
|
161
|
-
F.CODAGE AS
|
|
163
|
+
F.CODAGE AS cod_age,
|
|
162
164
|
F.CODCLICOL AS codice_cliente_collegato,
|
|
163
165
|
F.CODCLIENTI AS codice_clienti,
|
|
164
|
-
F.TIPFIL AS tipo_filtro
|
|
166
|
+
F.TIPFIL AS tipo_filtro,
|
|
167
|
+
F.IDXPOS AS idx_postazione
|
|
165
168
|
FROM FILTRI F
|
|
166
169
|
WHERE F.CODUTE = ?
|
|
167
170
|
`;
|
|
168
|
-
return yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [codiceUtente])
|
|
169
|
-
.then(results => results.map(Utilities_1.RestUtilities.convertKeysToCamelCase));
|
|
171
|
+
return (yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [codiceUtente]).then((results) => results.map(Utilities_1.RestUtilities.convertKeysToCamelCase)));
|
|
170
172
|
});
|
|
171
173
|
}
|
|
172
174
|
insertUserFilters(codiceUtente, filterData) {
|
|
@@ -178,11 +180,12 @@ let UserService = class UserService {
|
|
|
178
180
|
const fieldMapping = {
|
|
179
181
|
numeroReport: { dbField: 'NUMREP', type: 'number' },
|
|
180
182
|
indicePersonale: { dbField: 'IDXPERS', type: 'number' },
|
|
181
|
-
codiceClienteSuper: { dbField: 'CODCLISUPER', type: '
|
|
182
|
-
|
|
183
|
-
codiceClienteCollegato: { dbField: 'CODCLICOL', type: '
|
|
183
|
+
codiceClienteSuper: { dbField: 'CODCLISUPER', type: 'number' },
|
|
184
|
+
codAge: { dbField: 'CODAGE', type: 'number' },
|
|
185
|
+
codiceClienteCollegato: { dbField: 'CODCLICOL', type: 'number' },
|
|
184
186
|
codiceClienti: { dbField: 'CODCLIENTI', type: 'string' },
|
|
185
|
-
tipoFiltro: { dbField: 'TIPFIL', type: '
|
|
187
|
+
tipoFiltro: { dbField: 'TIPFIL', type: 'number' },
|
|
188
|
+
idxPostazione: { dbField: 'IDXPOS', type: 'number' },
|
|
186
189
|
};
|
|
187
190
|
const fieldsToInsert = Object.entries(fieldMapping)
|
|
188
191
|
.filter(([tsField]) => {
|
|
@@ -204,9 +207,9 @@ let UserService = class UserService {
|
|
|
204
207
|
}
|
|
205
208
|
yield this.executeInTransaction(() => __awaiter(this, void 0, void 0, function* () {
|
|
206
209
|
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, 'DELETE FROM FILTRI WHERE CODUTE = ?', [codiceUtente]);
|
|
207
|
-
const dbFields = ['CODUTE', ...fieldsToInsert.map(f => f.dbField)];
|
|
210
|
+
const dbFields = ['CODUTE', ...fieldsToInsert.map((f) => f.dbField)];
|
|
208
211
|
const placeholders = dbFields.map(() => '?');
|
|
209
|
-
const values = [codiceUtente, ...fieldsToInsert.map(f => f.value)];
|
|
212
|
+
const values = [codiceUtente, ...fieldsToInsert.map((f) => f.value)];
|
|
210
213
|
const insertQuery = `INSERT INTO FILTRI (${dbFields.join(', ')}) VALUES (${placeholders.join(', ')})`;
|
|
211
214
|
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, insertQuery, values);
|
|
212
215
|
}));
|
|
@@ -224,9 +227,9 @@ let UserService = class UserService {
|
|
|
224
227
|
register(registrationData) {
|
|
225
228
|
return __awaiter(this, void 0, void 0, function* () {
|
|
226
229
|
try {
|
|
227
|
-
const existingUser = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions,
|
|
230
|
+
const existingUser = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, 'SELECT CODUTE FROM UTENTI WHERE USRNAME = ?', [registrationData.email]);
|
|
228
231
|
if (existingUser.length > 0) {
|
|
229
|
-
throw new Error(
|
|
232
|
+
throw new Error('Questa e-mail è già stata utilizzata!');
|
|
230
233
|
}
|
|
231
234
|
const queryUtenti = `INSERT INTO UTENTI (USRNAME, STAREG) VALUES (?,?) RETURNING CODUTE`;
|
|
232
235
|
const paramsUtenti = [registrationData.email, StatoRegistrazione_1.StatoRegistrazione.INVIO];
|
|
@@ -271,24 +274,24 @@ let UserService = class UserService {
|
|
|
271
274
|
return __awaiter(this, void 0, void 0, function* () {
|
|
272
275
|
try {
|
|
273
276
|
if (!codiceUtente)
|
|
274
|
-
throw new Error(
|
|
277
|
+
throw new Error('Impossibile aggiornare senza codice utente.');
|
|
275
278
|
// Costruzione dinamica della query per UTENTI
|
|
276
279
|
const utentiUpdates = [];
|
|
277
280
|
const utentiParams = [];
|
|
278
281
|
if (user.email !== undefined) {
|
|
279
|
-
utentiUpdates.push(
|
|
282
|
+
utentiUpdates.push('usrname = ?');
|
|
280
283
|
utentiParams.push(user.email);
|
|
281
284
|
}
|
|
282
285
|
if (user.flagGdpr !== undefined) {
|
|
283
|
-
utentiUpdates.push(
|
|
286
|
+
utentiUpdates.push('flggdpr = ?');
|
|
284
287
|
utentiParams.push(user.flagGdpr);
|
|
285
288
|
}
|
|
286
289
|
if (user.statoRegistrazione !== undefined) {
|
|
287
|
-
utentiUpdates.push(
|
|
290
|
+
utentiUpdates.push('stareg = ?');
|
|
288
291
|
utentiParams.push(user.statoRegistrazione);
|
|
289
292
|
}
|
|
290
293
|
if (utentiUpdates.length > 0) {
|
|
291
|
-
const queryUtenti = `UPDATE UTENTI SET ${utentiUpdates.join(
|
|
294
|
+
const queryUtenti = `UPDATE UTENTI SET ${utentiUpdates.join(', ')} WHERE CODUTE = ?`;
|
|
292
295
|
utentiParams.push(codiceUtente);
|
|
293
296
|
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtenti, utentiParams);
|
|
294
297
|
}
|
|
@@ -296,47 +299,47 @@ let UserService = class UserService {
|
|
|
296
299
|
const utentiConfigUpdates = [];
|
|
297
300
|
const utentiConfigParams = [];
|
|
298
301
|
if (user.cognome !== undefined) {
|
|
299
|
-
utentiConfigUpdates.push(
|
|
302
|
+
utentiConfigUpdates.push('cognome = ?');
|
|
300
303
|
utentiConfigParams.push(user.cognome);
|
|
301
304
|
}
|
|
302
305
|
if (user.nome !== undefined) {
|
|
303
|
-
utentiConfigUpdates.push(
|
|
306
|
+
utentiConfigUpdates.push('nome = ?');
|
|
304
307
|
utentiConfigParams.push(user.nome);
|
|
305
308
|
}
|
|
306
309
|
if (user.avatar !== undefined) {
|
|
307
|
-
utentiConfigUpdates.push(
|
|
310
|
+
utentiConfigUpdates.push('avatar = ?');
|
|
308
311
|
utentiConfigParams.push(user.avatar);
|
|
309
312
|
}
|
|
310
313
|
if (user.flagDueFattori !== undefined) {
|
|
311
|
-
utentiConfigUpdates.push(
|
|
314
|
+
utentiConfigUpdates.push('flg2fatt = ?');
|
|
312
315
|
utentiConfigParams.push(user.flagDueFattori);
|
|
313
316
|
}
|
|
314
317
|
if (user.codiceLingua !== undefined) {
|
|
315
|
-
utentiConfigUpdates.push(
|
|
318
|
+
utentiConfigUpdates.push('codlingua = ?');
|
|
316
319
|
utentiConfigParams.push(user.codiceLingua);
|
|
317
320
|
}
|
|
318
321
|
if (user.cellulare !== undefined) {
|
|
319
|
-
utentiConfigUpdates.push(
|
|
322
|
+
utentiConfigUpdates.push('cellulare = ?');
|
|
320
323
|
utentiConfigParams.push(user.cellulare);
|
|
321
324
|
}
|
|
322
325
|
if (user.flagSuper !== undefined) {
|
|
323
|
-
utentiConfigUpdates.push(
|
|
326
|
+
utentiConfigUpdates.push('flgsuper = ?');
|
|
324
327
|
utentiConfigParams.push(user.flagSuper);
|
|
325
328
|
}
|
|
326
329
|
if (user.paginaDefault !== undefined) {
|
|
327
|
-
utentiConfigUpdates.push(
|
|
330
|
+
utentiConfigUpdates.push('pagdef = ?');
|
|
328
331
|
utentiConfigParams.push(user.paginaDefault);
|
|
329
332
|
}
|
|
330
333
|
if (user.jsonMetadata !== undefined) {
|
|
331
|
-
utentiConfigUpdates.push(
|
|
334
|
+
utentiConfigUpdates.push('json_metadata = ?');
|
|
332
335
|
utentiConfigParams.push(user.jsonMetadata);
|
|
333
336
|
}
|
|
334
337
|
if (user.ragSocCli !== undefined) {
|
|
335
|
-
utentiConfigUpdates.push(
|
|
338
|
+
utentiConfigUpdates.push('ragsoccli = ?');
|
|
336
339
|
utentiConfigParams.push(user.ragSocCli);
|
|
337
340
|
}
|
|
338
341
|
if (utentiConfigUpdates.length > 0) {
|
|
339
|
-
const queryUtentiConfig = `UPDATE UTENTI_CONFIG SET ${utentiConfigUpdates.join(
|
|
342
|
+
const queryUtentiConfig = `UPDATE UTENTI_CONFIG SET ${utentiConfigUpdates.join(', ')} WHERE CODUTE = ?`;
|
|
340
343
|
utentiConfigParams.push(codiceUtente);
|
|
341
344
|
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtentiConfig, utentiConfigParams);
|
|
342
345
|
}
|
|
@@ -346,17 +349,99 @@ let UserService = class UserService {
|
|
|
346
349
|
if (!!user.permissions && user.permissions.length > 0) {
|
|
347
350
|
yield this.permissionService.assignPermissionsToUser(codiceUtente, user.permissions);
|
|
348
351
|
}
|
|
352
|
+
yield this.updateUserFilters(codiceUtente, user);
|
|
349
353
|
}
|
|
350
354
|
catch (error) {
|
|
351
355
|
throw error;
|
|
352
356
|
}
|
|
353
357
|
});
|
|
354
358
|
}
|
|
359
|
+
updateUserFilters(codiceUtente, user) {
|
|
360
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
361
|
+
try {
|
|
362
|
+
if (!codiceUtente || codiceUtente <= 0) {
|
|
363
|
+
throw new Error('Codice utente non valido');
|
|
364
|
+
}
|
|
365
|
+
const fieldMapping = {
|
|
366
|
+
numRep: { dbField: 'NUMREP', type: 'number' },
|
|
367
|
+
idxPers: { dbField: 'IDXPERS', type: 'number' },
|
|
368
|
+
codCliSuper: { dbField: 'CODCLISUPER', type: 'number' },
|
|
369
|
+
codAge: { dbField: 'CODAGE', type: 'number' },
|
|
370
|
+
codCliCol: { dbField: 'CODCLICOL', type: 'number' },
|
|
371
|
+
codiceClienti: { dbField: 'CODCLIENTI', type: 'string' },
|
|
372
|
+
tipoFiltro: { dbField: 'TIPFIL', type: 'number' },
|
|
373
|
+
idxPostazione: { dbField: 'IDXPOS', type: 'number' },
|
|
374
|
+
};
|
|
375
|
+
const fieldsToUpdate = Object.entries(fieldMapping)
|
|
376
|
+
.filter(([tsField]) => {
|
|
377
|
+
const value = user[tsField];
|
|
378
|
+
// Includiamo il campo se è definito (anche se è una stringa vuota)
|
|
379
|
+
return value !== undefined && value !== null;
|
|
380
|
+
})
|
|
381
|
+
.map(([tsField, config]) => {
|
|
382
|
+
const value = user[tsField];
|
|
383
|
+
if (config.type === 'number' && typeof value !== 'number') {
|
|
384
|
+
throw new Error(`Il campo ${tsField} deve essere un numero`);
|
|
385
|
+
}
|
|
386
|
+
if (config.type === 'string' && typeof value !== 'string') {
|
|
387
|
+
throw new Error(`Il campo ${tsField} deve essere una stringa`);
|
|
388
|
+
}
|
|
389
|
+
return { tsField, dbField: config.dbField, value };
|
|
390
|
+
});
|
|
391
|
+
if (fieldsToUpdate.length === 0) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
yield this.executeInTransaction(() => __awaiter(this, void 0, void 0, function* () {
|
|
395
|
+
// Prima verifichiamo se esiste il record
|
|
396
|
+
const checkQuery = `SELECT COUNT(*) as CNT FROM FILTRI WHERE CODUTE = ?`;
|
|
397
|
+
const existingRecord = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, checkQuery, [
|
|
398
|
+
codiceUtente,
|
|
399
|
+
]);
|
|
400
|
+
const exists = existingRecord[0].CNT > 0;
|
|
401
|
+
if (exists) {
|
|
402
|
+
// Se esiste, facciamo l'UPDATE
|
|
403
|
+
const updates = fieldsToUpdate.map((f) => `${f.dbField} = ?`).join(', ');
|
|
404
|
+
const values = [...fieldsToUpdate.map((f) => f.value), codiceUtente];
|
|
405
|
+
const updateQuery = `UPDATE FILTRI SET ${updates} WHERE CODUTE = ?`;
|
|
406
|
+
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, updateQuery, values);
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
// Se non esiste, facciamo l'INSERT
|
|
410
|
+
const dbFields = ['CODUTE', ...fieldsToUpdate.map((f) => f.dbField)];
|
|
411
|
+
const placeholders = dbFields.map(() => '?');
|
|
412
|
+
const insertValues = [codiceUtente, ...fieldsToUpdate.map((f) => f.value)];
|
|
413
|
+
const insertQuery = `INSERT INTO FILTRI (${dbFields.join(', ')}) VALUES (${placeholders.join(', ')})`;
|
|
414
|
+
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, insertQuery, insertValues);
|
|
415
|
+
}
|
|
416
|
+
}));
|
|
417
|
+
}
|
|
418
|
+
catch (error) {
|
|
419
|
+
throw new Error(`Errore durante l'aggiornamento dei filtri per utente ${codiceUtente}: ${error.message}`);
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
}
|
|
355
423
|
deleteUser(codiceCliente) {
|
|
356
424
|
return __awaiter(this, void 0, void 0, function* () {
|
|
357
425
|
try {
|
|
358
426
|
const query = `UPDATE UTENTI SET STAREG = ? WHERE CODUTE = ?`;
|
|
359
|
-
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [
|
|
427
|
+
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [
|
|
428
|
+
StatoRegistrazione_1.StatoRegistrazione.DELETE,
|
|
429
|
+
codiceCliente,
|
|
430
|
+
]);
|
|
431
|
+
}
|
|
432
|
+
catch (error) {
|
|
433
|
+
throw error;
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
setStato(codiceCliente, statoRegistrazione) {
|
|
438
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
439
|
+
try {
|
|
440
|
+
const query = `UPDATE UTENTI SET STAREG = ? WHERE CODUTE = ?`;
|
|
441
|
+
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [
|
|
442
|
+
statoRegistrazione,
|
|
443
|
+
codiceCliente,
|
|
444
|
+
]);
|
|
360
445
|
}
|
|
361
446
|
catch (error) {
|
|
362
447
|
throw error;
|
|
@@ -382,5 +467,6 @@ exports.UserService = UserService = __decorate([
|
|
|
382
467
|
autobind_1.autobind,
|
|
383
468
|
(0, common_1.Injectable)(),
|
|
384
469
|
__param(0, (0, common_1.Inject)('ACCESSI_OPTIONS')),
|
|
385
|
-
__metadata("design:paramtypes", [Object, EmailService_1.EmailService,
|
|
470
|
+
__metadata("design:paramtypes", [Object, EmailService_1.EmailService,
|
|
471
|
+
PermissionService_1.PermissionService])
|
|
386
472
|
], UserService);
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|