emilsoftware-utilities 1.4.0 → 1.5.0-dev.1

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.
Files changed (27) hide show
  1. package/README.MD +34 -0
  2. package/dist/Utilities.d.ts +1 -0
  3. package/dist/Utilities.js +8 -0
  4. package/dist/accessi-module/AccessiModule.d.ts +11 -2
  5. package/dist/accessi-module/Controllers/AuthController.js +18 -0
  6. package/dist/accessi-module/Controllers/EmailController.d.ts +1 -0
  7. package/dist/accessi-module/Controllers/EmailController.js +33 -6
  8. package/dist/accessi-module/Controllers/UserController.d.ts +2 -0
  9. package/dist/accessi-module/Controllers/UserController.js +132 -30
  10. package/dist/accessi-module/Dtos/FiltriUtente.d.ts +3 -2
  11. package/dist/accessi-module/Dtos/FiltriUtente.js +10 -6
  12. package/dist/accessi-module/Dtos/RegisterRequest.d.ts +7 -5
  13. package/dist/accessi-module/Dtos/RegisterRequest.js +90 -21
  14. package/dist/accessi-module/Dtos/SetStatoRegistrazione.d.ts +5 -0
  15. package/dist/accessi-module/Dtos/SetStatoRegistrazione.js +32 -0
  16. package/dist/accessi-module/Dtos/StatoRegistrazione.d.ts +1 -0
  17. package/dist/accessi-module/Dtos/StatoRegistrazione.js +2 -1
  18. package/dist/accessi-module/Dtos/UserDto.d.ts +5 -4
  19. package/dist/accessi-module/Dtos/UserDto.js +85 -34
  20. package/dist/accessi-module/Services/AuthService/AuthService.js +17 -9
  21. package/dist/accessi-module/Services/EmailService/EmailService.d.ts +1 -1
  22. package/dist/accessi-module/Services/EmailService/EmailService.js +70 -32
  23. package/dist/accessi-module/Services/UserService/UserService.d.ts +10 -7
  24. package/dist/accessi-module/Services/UserService/UserService.js +126 -39
  25. package/dist/emilsoftware-utilities-1.5.0-dev.1.tgz +0 -0
  26. package/package.json +1 -1
  27. package/dist/emilsoftware-utilities-1.4.0.tgz +0 -0
@@ -38,21 +38,33 @@ 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.query(this.accessiOptions.databaseOptions, "UPDATE UTENTI SET KEYREG = ?, STAREG = ? WHERE USRNAME = ? RETURNING CODUTE", [resetToken, StatoRegistrazione_1.StatoRegistrazione.INVIO, email]);
48
- if (result.length === 0) {
49
- throw new Error("Email non trovata.");
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
56
+ let resetUrl = `${confirmationEmailUrl}/api/accessi/email/reset-password-page/${resetToken}${returnUrlQueryParams}`;
57
+ //solo se gli do la customResetPage
58
+ if (customResetPage) {
59
+ resetUrl = customResetPage + '?token=' + resetToken;
50
60
  }
51
- const returnUrlQueryParams = "?returnUrl=" + this.accessiOptions.confirmationEmailReturnUrl + "&prefix=" + ((_a = this.accessiOptions.confirmationEmailPrefix) !== null && _a !== void 0 ? _a : '');
52
- const { confirmationEmailUrl } = this.accessiOptions;
53
- const resetUrl = `${confirmationEmailUrl}/api/accessi/email/reset-password-page/${resetToken}${returnUrlQueryParams}`;
54
61
  let sPhrase;
55
- sPhrase = ` Gentile utente,<br>
62
+ if (htmlMail) {
63
+ sPhrase = htmlMail;
64
+ sPhrase.replace('#link_conferma_password_url', resetUrl);
65
+ }
66
+ else {
67
+ sPhrase = ` Gentile utente,<br>
56
68
  abbiamo ricevuto la tua richiesta.<br><br>
57
69
 
58
70
  Per completare l'operazione, clicca sul link qui sotto:<br>
@@ -64,11 +76,12 @@ let EmailService = class EmailService {
64
76
  Questa è una comunicazione automatica, ti preghiamo di non rispondere a questa email.<br><br>
65
77
 
66
78
  Grazie.<br>`;
79
+ }
67
80
  const html = this.GetHtmlMail(sPhrase);
68
81
  const mailOptions = {
69
82
  from: this.accessiOptions.emailOptions.from,
70
83
  to: email,
71
- subject: "Scelta nuova password",
84
+ subject: 'Scelta nuova password',
72
85
  text: sPhrase,
73
86
  html: html,
74
87
  };
@@ -192,7 +205,8 @@ let EmailService = class EmailService {
192
205
  sTxt += ' table.kmSplitContentRightContentContainer,';
193
206
  sTxt += ' table.kmColumnContainer,';
194
207
  sTxt += ' td.kmVerticalButtonBarContentOuter table.kmButtonBarContent,';
195
- sTxt += ' td.kmVerticalButtonCollectionContentOuter table.kmButtonCollectionContent,';
208
+ sTxt +=
209
+ ' td.kmVerticalButtonCollectionContentOuter table.kmButtonCollectionContent,';
196
210
  sTxt += ' table.kmVerticalButton,';
197
211
  sTxt += ' table.kmVerticalButtonContent {';
198
212
  sTxt += ' width: 100% !important';
@@ -272,44 +286,68 @@ let EmailService = class EmailService {
272
286
  sTxt += ' }';
273
287
  sTxt += ' </style>';
274
288
  sTxt += '</head>';
275
- sTxt += '<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">';
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">';
276
291
  sTxt += ' <center>';
277
- sTxt += ' <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%">';
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%">';
278
294
  sTxt += ' <tbody>';
279
295
  sTxt += ' <tr>';
280
- sTxt += ' <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%">';
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%">';
281
298
  sTxt += ' <!--[if !mso]>';
282
299
  sTxt += ' <!-->';
283
- sTxt += ' <div class="templateContainer" style="border:0 none #aaa;background-color:#F2F2F2;border-radius:0;display: table; width:90%">';
300
+ sTxt +=
301
+ ' <div class="templateContainer" style="border:0 none #aaa;background-color:#F2F2F2;border-radius:0;display: table; width:90%">';
284
302
  sTxt += ' <div class="templateContainerInner" style="padding:0">';
285
303
  sTxt += ' <!--';
286
304
  sTxt += ' <![endif]-->';
287
305
  sTxt += ' <!--[if mso]>';
288
- sTxt += ' <table border="0" cellpadding="0" cellspacing="0" class="templateContainer" width="90%" ';
289
- sTxt += ' style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;">';
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;">';
290
310
  sTxt += ' <tbody>';
291
311
  sTxt += ' <tr>';
292
- sTxt += ' <td class="templateContainerInner" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;">';
312
+ sTxt +=
313
+ ' <td class="templateContainerInner" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;">';
293
314
  sTxt += ' <![endif]-->';
294
- sTxt += ' <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
315
+ sTxt +=
316
+ ' <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
295
317
  sTxt += ' <tr>';
296
- sTxt += ' <td align="center" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
297
- sTxt += ' <table border="0" cellpadding="0" cellspacing="0" class="templateRow" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
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">';
298
322
  sTxt += ' <tbody>';
299
323
  sTxt += ' <tr>';
300
- sTxt += ' <td class="rowContainer kmFloatLeft" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
301
- sTxt += ' <table border="0" cellpadding="0" cellspacing="0" class="kmTextBlock" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
302
- sTxt += ' <tbody class="kmTextBlockOuter">';
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">';
303
330
  sTxt += ' <tr>';
304
- sTxt += ' <td class="kmTextBlockInner" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;background-color:#FFFFFF;">';
305
- sTxt += ' <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">';
306
- sTxt += ' <tbody>';
307
- sTxt += ' <tr>';
308
- sTxt += ' <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;">';
309
- sTxt += ' <p>' + sPhrase + '<p>';
310
- sTxt += ' </td>';
311
- sTxt += ' </tr>';
312
- sTxt += ' </tbody>';
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>';
313
351
  sTxt += ' </table>';
314
352
  sTxt += ' </td>';
315
353
  sTxt += ' </tr>';
@@ -1,10 +1,11 @@
1
- import { AccessiOptions } from "../../AccessiModule";
2
- import { EmailService } from "../EmailService/EmailService";
3
- import { FiltriUtente } from "../../Dtos/FiltriUtente";
4
- import { GetUsersResult } from "../../Dtos/GetUsersResponse";
5
- import { PermissionService } from "../PermissionService/PermissionService";
6
- import { UserDto } from "../../Dtos";
7
- import { RegisterRequest } from "../../Dtos/RegisterRequest";
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 tip_fil
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,29 +81,30 @@ 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("OPTIONS: ", options);
87
+ console.log('OPTIONS: ', options);
87
88
  for (const user of users) {
88
89
  let userGrants = null;
89
90
  if (options.includeGrants)
90
91
  userGrants = yield this.permissionService.getUserRolesAndGrants(user.codiceUtente);
91
92
  let extensionFields = options.includeExtensionFields ? {} : null;
93
+ //todo: se non è prendente extensionFieldOptions va in errore. Risolvere il problema
92
94
  if (options.includeExtensionFields) {
93
95
  for (const ext of this.accessiOptions.extensionFieldsOptions) {
94
- 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
+ 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);
95
97
  extensionFields[ext.objectKey] = values;
96
98
  }
97
99
  }
98
100
  let userResult = {
99
101
  utente: user,
100
102
  userGrants: userGrants,
101
- extensionFields: extensionFields
103
+ extensionFields: extensionFields,
102
104
  };
103
105
  usersResponse.push(userResult);
104
106
  }
105
- console.log("OPTIONS: ", options);
107
+ console.log('OPTIONS: ', options);
106
108
  return usersResponse;
107
109
  }
108
110
  catch (error) {
@@ -114,7 +116,9 @@ let UserService = class UserService {
114
116
  return __awaiter(this, void 0, void 0, function* () {
115
117
  try {
116
118
  const query = `SELECT CODUTE as codice_utente FROM UTENTI WHERE LOWER(USRNAME) = ?`;
117
- const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [email.trim().toLowerCase()]);
119
+ const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [
120
+ email.trim().toLowerCase(),
121
+ ]);
118
122
  return result.map(Utilities_1.RestUtilities.convertKeysToCamelCase)[0];
119
123
  }
120
124
  catch (error) {
@@ -144,8 +148,7 @@ let UserService = class UserService {
144
148
  INNER JOIN UTENTI_CONFIG C ON C.CODUTE = U.CODUTE
145
149
  WHERE LOWER(U.USRNAME) = ?
146
150
  `;
147
- const utenti = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [email])
148
- .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)));
149
152
  return utenti.length > 0 ? utenti[0] : null;
150
153
  });
151
154
  }
@@ -157,15 +160,15 @@ let UserService = class UserService {
157
160
  F.NUMREP AS numero_report,
158
161
  F.IDXPERS AS indice_personale,
159
162
  F.CODCLISUPER AS codice_cliente_super,
160
- F.CODAGE AS codice_agenzia,
163
+ F.CODAGE AS cod_age,
161
164
  F.CODCLICOL AS codice_cliente_collegato,
162
165
  F.CODCLIENTI AS codice_clienti,
163
- F.TIPFIL AS tipo_filtro
166
+ F.TIPFIL AS tipo_filtro,
167
+ F.IDXPOS AS idx_postazione
164
168
  FROM FILTRI F
165
169
  WHERE F.CODUTE = ?
166
170
  `;
167
- return yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [codiceUtente])
168
- .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)));
169
172
  });
170
173
  }
171
174
  insertUserFilters(codiceUtente, filterData) {
@@ -177,11 +180,12 @@ let UserService = class UserService {
177
180
  const fieldMapping = {
178
181
  numeroReport: { dbField: 'NUMREP', type: 'number' },
179
182
  indicePersonale: { dbField: 'IDXPERS', type: 'number' },
180
- codiceClienteSuper: { dbField: 'CODCLISUPER', type: 'string' },
181
- codiceAgenzia: { dbField: 'CODAGE', type: 'string' },
182
- codiceClienteCollegato: { dbField: 'CODCLICOL', type: 'string' },
183
+ codiceClienteSuper: { dbField: 'CODCLISUPER', type: 'number' },
184
+ codAge: { dbField: 'CODAGE', type: 'number' },
185
+ codiceClienteCollegato: { dbField: 'CODCLICOL', type: 'number' },
183
186
  codiceClienti: { dbField: 'CODCLIENTI', type: 'string' },
184
- tipoFiltro: { dbField: 'TIPFIL', type: 'string' }
187
+ tipoFiltro: { dbField: 'TIPFIL', type: 'number' },
188
+ idxPostazione: { dbField: 'IDXPOS', type: 'number' },
185
189
  };
186
190
  const fieldsToInsert = Object.entries(fieldMapping)
187
191
  .filter(([tsField]) => {
@@ -203,9 +207,9 @@ let UserService = class UserService {
203
207
  }
204
208
  yield this.executeInTransaction(() => __awaiter(this, void 0, void 0, function* () {
205
209
  yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, 'DELETE FROM FILTRI WHERE CODUTE = ?', [codiceUtente]);
206
- const dbFields = ['CODUTE', ...fieldsToInsert.map(f => f.dbField)];
210
+ const dbFields = ['CODUTE', ...fieldsToInsert.map((f) => f.dbField)];
207
211
  const placeholders = dbFields.map(() => '?');
208
- const values = [codiceUtente, ...fieldsToInsert.map(f => f.value)];
212
+ const values = [codiceUtente, ...fieldsToInsert.map((f) => f.value)];
209
213
  const insertQuery = `INSERT INTO FILTRI (${dbFields.join(', ')}) VALUES (${placeholders.join(', ')})`;
210
214
  yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, insertQuery, values);
211
215
  }));
@@ -223,9 +227,9 @@ let UserService = class UserService {
223
227
  register(registrationData) {
224
228
  return __awaiter(this, void 0, void 0, function* () {
225
229
  try {
226
- const existingUser = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, "SELECT CODUTE FROM UTENTI WHERE USRNAME = ?", [registrationData.email]);
230
+ const existingUser = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, 'SELECT CODUTE FROM UTENTI WHERE USRNAME = ?', [registrationData.email]);
227
231
  if (existingUser.length > 0) {
228
- throw new Error("Questa e-mail è già stata utilizzata!");
232
+ throw new Error('Questa e-mail è già stata utilizzata!');
229
233
  }
230
234
  const queryUtenti = `INSERT INTO UTENTI (USRNAME, STAREG) VALUES (?,?) RETURNING CODUTE`;
231
235
  const paramsUtenti = [registrationData.email, StatoRegistrazione_1.StatoRegistrazione.INVIO];
@@ -270,24 +274,24 @@ let UserService = class UserService {
270
274
  return __awaiter(this, void 0, void 0, function* () {
271
275
  try {
272
276
  if (!codiceUtente)
273
- throw new Error("Impossibile aggiornare senza codice utente.");
277
+ throw new Error('Impossibile aggiornare senza codice utente.');
274
278
  // Costruzione dinamica della query per UTENTI
275
279
  const utentiUpdates = [];
276
280
  const utentiParams = [];
277
281
  if (user.email !== undefined) {
278
- utentiUpdates.push("usrname = ?");
282
+ utentiUpdates.push('usrname = ?');
279
283
  utentiParams.push(user.email);
280
284
  }
281
285
  if (user.flagGdpr !== undefined) {
282
- utentiUpdates.push("flggdpr = ?");
286
+ utentiUpdates.push('flggdpr = ?');
283
287
  utentiParams.push(user.flagGdpr);
284
288
  }
285
289
  if (user.statoRegistrazione !== undefined) {
286
- utentiUpdates.push("stareg = ?");
290
+ utentiUpdates.push('stareg = ?');
287
291
  utentiParams.push(user.statoRegistrazione);
288
292
  }
289
293
  if (utentiUpdates.length > 0) {
290
- const queryUtenti = `UPDATE UTENTI SET ${utentiUpdates.join(", ")} WHERE CODUTE = ?`;
294
+ const queryUtenti = `UPDATE UTENTI SET ${utentiUpdates.join(', ')} WHERE CODUTE = ?`;
291
295
  utentiParams.push(codiceUtente);
292
296
  yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtenti, utentiParams);
293
297
  }
@@ -295,47 +299,47 @@ let UserService = class UserService {
295
299
  const utentiConfigUpdates = [];
296
300
  const utentiConfigParams = [];
297
301
  if (user.cognome !== undefined) {
298
- utentiConfigUpdates.push("cognome = ?");
302
+ utentiConfigUpdates.push('cognome = ?');
299
303
  utentiConfigParams.push(user.cognome);
300
304
  }
301
305
  if (user.nome !== undefined) {
302
- utentiConfigUpdates.push("nome = ?");
306
+ utentiConfigUpdates.push('nome = ?');
303
307
  utentiConfigParams.push(user.nome);
304
308
  }
305
309
  if (user.avatar !== undefined) {
306
- utentiConfigUpdates.push("avatar = ?");
310
+ utentiConfigUpdates.push('avatar = ?');
307
311
  utentiConfigParams.push(user.avatar);
308
312
  }
309
313
  if (user.flagDueFattori !== undefined) {
310
- utentiConfigUpdates.push("flg2fatt = ?");
314
+ utentiConfigUpdates.push('flg2fatt = ?');
311
315
  utentiConfigParams.push(user.flagDueFattori);
312
316
  }
313
317
  if (user.codiceLingua !== undefined) {
314
- utentiConfigUpdates.push("codlingua = ?");
318
+ utentiConfigUpdates.push('codlingua = ?');
315
319
  utentiConfigParams.push(user.codiceLingua);
316
320
  }
317
321
  if (user.cellulare !== undefined) {
318
- utentiConfigUpdates.push("cellulare = ?");
322
+ utentiConfigUpdates.push('cellulare = ?');
319
323
  utentiConfigParams.push(user.cellulare);
320
324
  }
321
325
  if (user.flagSuper !== undefined) {
322
- utentiConfigUpdates.push("flgsuper = ?");
326
+ utentiConfigUpdates.push('flgsuper = ?');
323
327
  utentiConfigParams.push(user.flagSuper);
324
328
  }
325
329
  if (user.paginaDefault !== undefined) {
326
- utentiConfigUpdates.push("pagdef = ?");
330
+ utentiConfigUpdates.push('pagdef = ?');
327
331
  utentiConfigParams.push(user.paginaDefault);
328
332
  }
329
333
  if (user.jsonMetadata !== undefined) {
330
- utentiConfigUpdates.push("json_metadata = ?");
334
+ utentiConfigUpdates.push('json_metadata = ?');
331
335
  utentiConfigParams.push(user.jsonMetadata);
332
336
  }
333
337
  if (user.ragSocCli !== undefined) {
334
- utentiConfigUpdates.push("ragsoccli = ?");
338
+ utentiConfigUpdates.push('ragsoccli = ?');
335
339
  utentiConfigParams.push(user.ragSocCli);
336
340
  }
337
341
  if (utentiConfigUpdates.length > 0) {
338
- const queryUtentiConfig = `UPDATE UTENTI_CONFIG SET ${utentiConfigUpdates.join(", ")} WHERE CODUTE = ?`;
342
+ const queryUtentiConfig = `UPDATE UTENTI_CONFIG SET ${utentiConfigUpdates.join(', ')} WHERE CODUTE = ?`;
339
343
  utentiConfigParams.push(codiceUtente);
340
344
  yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtentiConfig, utentiConfigParams);
341
345
  }
@@ -345,17 +349,99 @@ let UserService = class UserService {
345
349
  if (!!user.permissions && user.permissions.length > 0) {
346
350
  yield this.permissionService.assignPermissionsToUser(codiceUtente, user.permissions);
347
351
  }
352
+ yield this.updateUserFilters(codiceUtente, user);
348
353
  }
349
354
  catch (error) {
350
355
  throw error;
351
356
  }
352
357
  });
353
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
+ }
354
423
  deleteUser(codiceCliente) {
355
424
  return __awaiter(this, void 0, void 0, function* () {
356
425
  try {
357
426
  const query = `UPDATE UTENTI SET STAREG = ? WHERE CODUTE = ?`;
358
- yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [StatoRegistrazione_1.StatoRegistrazione.DELETE, codiceCliente]);
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
+ ]);
359
445
  }
360
446
  catch (error) {
361
447
  throw error;
@@ -381,5 +467,6 @@ exports.UserService = UserService = __decorate([
381
467
  autobind_1.autobind,
382
468
  (0, common_1.Injectable)(),
383
469
  __param(0, (0, common_1.Inject)('ACCESSI_OPTIONS')),
384
- __metadata("design:paramtypes", [Object, EmailService_1.EmailService, PermissionService_1.PermissionService])
470
+ __metadata("design:paramtypes", [Object, EmailService_1.EmailService,
471
+ PermissionService_1.PermissionService])
385
472
  ], UserService);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emilsoftware-utilities",
3
- "version": "1.4.0",
3
+ "version": "1.5.0-dev.1",
4
4
  "description": "Utilities for EmilSoftware",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",