emilsoftware-utilities 1.4.0 → 1.5.0-dev.2
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 +34 -0
- 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/AccessiModule.js +7 -4
- package/dist/accessi-module/Controllers/AuthController.js +18 -0
- package/dist/accessi-module/Controllers/EmailController.d.ts +1 -0
- package/dist/accessi-module/Controllers/EmailController.js +33 -6
- package/dist/accessi-module/Controllers/FiltriController.d.ts +11 -0
- package/dist/accessi-module/Controllers/FiltriController.js +106 -0
- 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 +59 -7
- package/dist/accessi-module/Dtos/FiltriUtente.js +92 -33
- package/dist/accessi-module/Dtos/RegisterRequest.d.ts +6 -9
- package/dist/accessi-module/Dtos/RegisterRequest.js +52 -38
- 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/TipoFiltro.d.ts +13 -0
- package/dist/accessi-module/Dtos/TipoFiltro.js +90 -0
- package/dist/accessi-module/Dtos/UserDto.d.ts +4 -9
- package/dist/accessi-module/Dtos/UserDto.js +66 -53
- package/dist/accessi-module/Services/AuthService/AuthService.d.ts +3 -1
- package/dist/accessi-module/Services/AuthService/AuthService.js +24 -13
- package/dist/accessi-module/Services/EmailService/EmailService.d.ts +1 -1
- package/dist/accessi-module/Services/EmailService/EmailService.js +70 -32
- package/dist/accessi-module/Services/FiltriService/FiltriService.d.ts +11 -0
- package/dist/accessi-module/Services/FiltriService/FiltriService.js +126 -0
- package/dist/accessi-module/Services/UserService/UserService.d.ts +12 -9
- package/dist/accessi-module/Services/UserService/UserService.js +149 -57
- package/dist/emilsoftware-utilities-1.5.0-dev.2.tgz +0 -0
- package/package.json +1 -1
- package/dist/emilsoftware-utilities-1.4.0.tgz +0 -0
|
@@ -29,11 +29,13 @@ const Utilities_1 = require("../../../Utilities");
|
|
|
29
29
|
const StatoRegistrazione_1 = require("../../Dtos/StatoRegistrazione");
|
|
30
30
|
const EmailService_1 = require("../EmailService/EmailService");
|
|
31
31
|
const PermissionService_1 = require("../PermissionService/PermissionService");
|
|
32
|
+
const FiltriService_1 = require("../FiltriService/FiltriService");
|
|
32
33
|
let UserService = class UserService {
|
|
33
|
-
constructor(accessiOptions, emailService, permissionService) {
|
|
34
|
+
constructor(accessiOptions, emailService, permissionService, filtriService) {
|
|
34
35
|
this.accessiOptions = accessiOptions;
|
|
35
36
|
this.emailService = emailService;
|
|
36
37
|
this.permissionService = permissionService;
|
|
38
|
+
this.filtriService = filtriService;
|
|
37
39
|
}
|
|
38
40
|
getUsers(filters, options) {
|
|
39
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -63,8 +65,9 @@ let UserService = class UserService {
|
|
|
63
65
|
F.CODCLISUPER AS cod_cli_super,
|
|
64
66
|
F.CODAGE AS cod_age,
|
|
65
67
|
F.CODCLICOL AS cod_cli_col,
|
|
66
|
-
F.CODCLIENTI AS
|
|
67
|
-
F.TIPFIL AS tip_fil
|
|
68
|
+
F.CODCLIENTI AS cod_clienti,
|
|
69
|
+
F.TIPFIL AS tip_fil,
|
|
70
|
+
F.IDXPOS AS idx_postazione
|
|
68
71
|
FROM UTENTI U
|
|
69
72
|
INNER JOIN UTENTI_CONFIG G ON U.CODUTE = G.CODUTE
|
|
70
73
|
LEFT JOIN FILTRI F ON F.CODUTE = U.CODUTE
|
|
@@ -80,29 +83,30 @@ let UserService = class UserService {
|
|
|
80
83
|
queryParams.push(filters.codiceUtente);
|
|
81
84
|
}
|
|
82
85
|
query += ` ORDER BY U.CODUTE DESC `;
|
|
83
|
-
let users = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, queryParams);
|
|
86
|
+
let users = (yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, queryParams));
|
|
84
87
|
users = users.map(Utilities_1.RestUtilities.convertKeysToCamelCase);
|
|
85
88
|
let usersResponse = [];
|
|
86
|
-
console.log(
|
|
89
|
+
console.log('OPTIONS: ', options);
|
|
87
90
|
for (const user of users) {
|
|
88
91
|
let userGrants = null;
|
|
89
92
|
if (options.includeGrants)
|
|
90
93
|
userGrants = yield this.permissionService.getUserRolesAndGrants(user.codiceUtente);
|
|
91
94
|
let extensionFields = options.includeExtensionFields ? {} : null;
|
|
95
|
+
//todo: se non è prendente extensionFieldOptions va in errore. Risolvere il problema
|
|
92
96
|
if (options.includeExtensionFields) {
|
|
93
97
|
for (const ext of this.accessiOptions.extensionFieldsOptions) {
|
|
94
|
-
const values = (yield Orm_1.Orm.query(ext.databaseOptions, `SELECT ${ext.tableFields.join(
|
|
98
|
+
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
99
|
extensionFields[ext.objectKey] = values;
|
|
96
100
|
}
|
|
97
101
|
}
|
|
98
102
|
let userResult = {
|
|
99
103
|
utente: user,
|
|
100
104
|
userGrants: userGrants,
|
|
101
|
-
extensionFields: extensionFields
|
|
105
|
+
extensionFields: extensionFields,
|
|
102
106
|
};
|
|
103
107
|
usersResponse.push(userResult);
|
|
104
108
|
}
|
|
105
|
-
console.log(
|
|
109
|
+
console.log('OPTIONS: ', options);
|
|
106
110
|
return usersResponse;
|
|
107
111
|
}
|
|
108
112
|
catch (error) {
|
|
@@ -114,7 +118,9 @@ let UserService = class UserService {
|
|
|
114
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
119
|
try {
|
|
116
120
|
const query = `SELECT CODUTE as codice_utente FROM UTENTI WHERE LOWER(USRNAME) = ?`;
|
|
117
|
-
const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [
|
|
121
|
+
const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [
|
|
122
|
+
email.trim().toLowerCase(),
|
|
123
|
+
]);
|
|
118
124
|
return result.map(Utilities_1.RestUtilities.convertKeysToCamelCase)[0];
|
|
119
125
|
}
|
|
120
126
|
catch (error) {
|
|
@@ -144,30 +150,29 @@ let UserService = class UserService {
|
|
|
144
150
|
INNER JOIN UTENTI_CONFIG C ON C.CODUTE = U.CODUTE
|
|
145
151
|
WHERE LOWER(U.USRNAME) = ?
|
|
146
152
|
`;
|
|
147
|
-
const utenti = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [email])
|
|
148
|
-
.then(results => results.map(Utilities_1.RestUtilities.convertKeysToCamelCase));
|
|
153
|
+
const utenti = (yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [email]).then((results) => results.map(Utilities_1.RestUtilities.convertKeysToCamelCase)));
|
|
149
154
|
return utenti.length > 0 ? utenti[0] : null;
|
|
150
155
|
});
|
|
151
156
|
}
|
|
152
|
-
getUserFilters(codiceUtente) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
157
|
+
// async getUserFilters(codiceUtente: number): Promise<FiltriUtente[]> {
|
|
158
|
+
// const query = `
|
|
159
|
+
// SELECT
|
|
160
|
+
// F.PROG AS progressivo,
|
|
161
|
+
// F.NUMREP AS numero_report,
|
|
162
|
+
// F.IDXPERS AS indice_personale,
|
|
163
|
+
// F.CODCLISUPER AS codice_cliente_super,
|
|
164
|
+
// F.CODAGE AS cod_age,
|
|
165
|
+
// F.CODCLICOL AS codice_cliente_collegato,
|
|
166
|
+
// F.CODCLIENTI AS codice_clienti,
|
|
167
|
+
// F.TIPFIL AS tipo_filtro,
|
|
168
|
+
// F.IDXPOS AS idx_postazione
|
|
169
|
+
// FROM FILTRI F
|
|
170
|
+
// WHERE F.CODUTE = ?
|
|
171
|
+
// `;
|
|
172
|
+
// return (await Orm.query(this.accessiOptions.databaseOptions, query, [codiceUtente]).then(
|
|
173
|
+
// (results) => results.map(RestUtilities.convertKeysToCamelCase),
|
|
174
|
+
// )) as FiltriUtente[];
|
|
175
|
+
// }
|
|
171
176
|
insertUserFilters(codiceUtente, filterData) {
|
|
172
177
|
return __awaiter(this, void 0, void 0, function* () {
|
|
173
178
|
try {
|
|
@@ -177,11 +182,12 @@ let UserService = class UserService {
|
|
|
177
182
|
const fieldMapping = {
|
|
178
183
|
numeroReport: { dbField: 'NUMREP', type: 'number' },
|
|
179
184
|
indicePersonale: { dbField: 'IDXPERS', type: 'number' },
|
|
180
|
-
codiceClienteSuper: { dbField: 'CODCLISUPER', type: '
|
|
181
|
-
|
|
182
|
-
codiceClienteCollegato: { dbField: 'CODCLICOL', type: '
|
|
185
|
+
codiceClienteSuper: { dbField: 'CODCLISUPER', type: 'number' },
|
|
186
|
+
codAge: { dbField: 'CODAGE', type: 'number' },
|
|
187
|
+
codiceClienteCollegato: { dbField: 'CODCLICOL', type: 'number' },
|
|
183
188
|
codiceClienti: { dbField: 'CODCLIENTI', type: 'string' },
|
|
184
|
-
|
|
189
|
+
tipFil: { dbField: 'TIPFIL', type: 'number' },
|
|
190
|
+
idxPostazione: { dbField: 'IDXPOS', type: 'number' },
|
|
185
191
|
};
|
|
186
192
|
const fieldsToInsert = Object.entries(fieldMapping)
|
|
187
193
|
.filter(([tsField]) => {
|
|
@@ -203,9 +209,9 @@ let UserService = class UserService {
|
|
|
203
209
|
}
|
|
204
210
|
yield this.executeInTransaction(() => __awaiter(this, void 0, void 0, function* () {
|
|
205
211
|
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, 'DELETE FROM FILTRI WHERE CODUTE = ?', [codiceUtente]);
|
|
206
|
-
const dbFields = ['CODUTE', ...fieldsToInsert.map(f => f.dbField)];
|
|
212
|
+
const dbFields = ['CODUTE', ...fieldsToInsert.map((f) => f.dbField)];
|
|
207
213
|
const placeholders = dbFields.map(() => '?');
|
|
208
|
-
const values = [codiceUtente, ...fieldsToInsert.map(f => f.value)];
|
|
214
|
+
const values = [codiceUtente, ...fieldsToInsert.map((f) => f.value)];
|
|
209
215
|
const insertQuery = `INSERT INTO FILTRI (${dbFields.join(', ')}) VALUES (${placeholders.join(', ')})`;
|
|
210
216
|
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, insertQuery, values);
|
|
211
217
|
}));
|
|
@@ -223,9 +229,9 @@ let UserService = class UserService {
|
|
|
223
229
|
register(registrationData) {
|
|
224
230
|
return __awaiter(this, void 0, void 0, function* () {
|
|
225
231
|
try {
|
|
226
|
-
const existingUser = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions,
|
|
232
|
+
const existingUser = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, 'SELECT CODUTE FROM UTENTI WHERE USRNAME = ?', [registrationData.email]);
|
|
227
233
|
if (existingUser.length > 0) {
|
|
228
|
-
throw new Error(
|
|
234
|
+
throw new Error('Questa e-mail è già stata utilizzata!');
|
|
229
235
|
}
|
|
230
236
|
const queryUtenti = `INSERT INTO UTENTI (USRNAME, STAREG) VALUES (?,?) RETURNING CODUTE`;
|
|
231
237
|
const paramsUtenti = [registrationData.email, StatoRegistrazione_1.StatoRegistrazione.INVIO];
|
|
@@ -252,7 +258,8 @@ let UserService = class UserService {
|
|
|
252
258
|
}
|
|
253
259
|
const queryUtentiConfig = `INSERT INTO UTENTI_CONFIG (${utentiConfigFields.join(', ')}) VALUES (${utentiConfigPlaceholders.join(', ')})`;
|
|
254
260
|
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtentiConfig, utentiConfigParams);
|
|
255
|
-
|
|
261
|
+
//await this.insertUserFilters(codiceUtente, registrationData);
|
|
262
|
+
yield this.filtriService.upsertFiltriUtente(codiceUtente, registrationData);
|
|
256
263
|
if (!!registrationData.roles && registrationData.roles.length > 0) {
|
|
257
264
|
yield this.permissionService.assignRolesToUser(codiceUtente, registrationData.roles);
|
|
258
265
|
}
|
|
@@ -270,24 +277,24 @@ let UserService = class UserService {
|
|
|
270
277
|
return __awaiter(this, void 0, void 0, function* () {
|
|
271
278
|
try {
|
|
272
279
|
if (!codiceUtente)
|
|
273
|
-
throw new Error(
|
|
280
|
+
throw new Error('Impossibile aggiornare senza codice utente.');
|
|
274
281
|
// Costruzione dinamica della query per UTENTI
|
|
275
282
|
const utentiUpdates = [];
|
|
276
283
|
const utentiParams = [];
|
|
277
284
|
if (user.email !== undefined) {
|
|
278
|
-
utentiUpdates.push(
|
|
285
|
+
utentiUpdates.push('usrname = ?');
|
|
279
286
|
utentiParams.push(user.email);
|
|
280
287
|
}
|
|
281
288
|
if (user.flagGdpr !== undefined) {
|
|
282
|
-
utentiUpdates.push(
|
|
289
|
+
utentiUpdates.push('flggdpr = ?');
|
|
283
290
|
utentiParams.push(user.flagGdpr);
|
|
284
291
|
}
|
|
285
292
|
if (user.statoRegistrazione !== undefined) {
|
|
286
|
-
utentiUpdates.push(
|
|
293
|
+
utentiUpdates.push('stareg = ?');
|
|
287
294
|
utentiParams.push(user.statoRegistrazione);
|
|
288
295
|
}
|
|
289
296
|
if (utentiUpdates.length > 0) {
|
|
290
|
-
const queryUtenti = `UPDATE UTENTI SET ${utentiUpdates.join(
|
|
297
|
+
const queryUtenti = `UPDATE UTENTI SET ${utentiUpdates.join(', ')} WHERE CODUTE = ?`;
|
|
291
298
|
utentiParams.push(codiceUtente);
|
|
292
299
|
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtenti, utentiParams);
|
|
293
300
|
}
|
|
@@ -295,47 +302,47 @@ let UserService = class UserService {
|
|
|
295
302
|
const utentiConfigUpdates = [];
|
|
296
303
|
const utentiConfigParams = [];
|
|
297
304
|
if (user.cognome !== undefined) {
|
|
298
|
-
utentiConfigUpdates.push(
|
|
305
|
+
utentiConfigUpdates.push('cognome = ?');
|
|
299
306
|
utentiConfigParams.push(user.cognome);
|
|
300
307
|
}
|
|
301
308
|
if (user.nome !== undefined) {
|
|
302
|
-
utentiConfigUpdates.push(
|
|
309
|
+
utentiConfigUpdates.push('nome = ?');
|
|
303
310
|
utentiConfigParams.push(user.nome);
|
|
304
311
|
}
|
|
305
312
|
if (user.avatar !== undefined) {
|
|
306
|
-
utentiConfigUpdates.push(
|
|
313
|
+
utentiConfigUpdates.push('avatar = ?');
|
|
307
314
|
utentiConfigParams.push(user.avatar);
|
|
308
315
|
}
|
|
309
316
|
if (user.flagDueFattori !== undefined) {
|
|
310
|
-
utentiConfigUpdates.push(
|
|
317
|
+
utentiConfigUpdates.push('flg2fatt = ?');
|
|
311
318
|
utentiConfigParams.push(user.flagDueFattori);
|
|
312
319
|
}
|
|
313
320
|
if (user.codiceLingua !== undefined) {
|
|
314
|
-
utentiConfigUpdates.push(
|
|
321
|
+
utentiConfigUpdates.push('codlingua = ?');
|
|
315
322
|
utentiConfigParams.push(user.codiceLingua);
|
|
316
323
|
}
|
|
317
324
|
if (user.cellulare !== undefined) {
|
|
318
|
-
utentiConfigUpdates.push(
|
|
325
|
+
utentiConfigUpdates.push('cellulare = ?');
|
|
319
326
|
utentiConfigParams.push(user.cellulare);
|
|
320
327
|
}
|
|
321
328
|
if (user.flagSuper !== undefined) {
|
|
322
|
-
utentiConfigUpdates.push(
|
|
329
|
+
utentiConfigUpdates.push('flgsuper = ?');
|
|
323
330
|
utentiConfigParams.push(user.flagSuper);
|
|
324
331
|
}
|
|
325
332
|
if (user.paginaDefault !== undefined) {
|
|
326
|
-
utentiConfigUpdates.push(
|
|
333
|
+
utentiConfigUpdates.push('pagdef = ?');
|
|
327
334
|
utentiConfigParams.push(user.paginaDefault);
|
|
328
335
|
}
|
|
329
336
|
if (user.jsonMetadata !== undefined) {
|
|
330
|
-
utentiConfigUpdates.push(
|
|
337
|
+
utentiConfigUpdates.push('json_metadata = ?');
|
|
331
338
|
utentiConfigParams.push(user.jsonMetadata);
|
|
332
339
|
}
|
|
333
340
|
if (user.ragSocCli !== undefined) {
|
|
334
|
-
utentiConfigUpdates.push(
|
|
341
|
+
utentiConfigUpdates.push('ragsoccli = ?');
|
|
335
342
|
utentiConfigParams.push(user.ragSocCli);
|
|
336
343
|
}
|
|
337
344
|
if (utentiConfigUpdates.length > 0) {
|
|
338
|
-
const queryUtentiConfig = `UPDATE UTENTI_CONFIG SET ${utentiConfigUpdates.join(
|
|
345
|
+
const queryUtentiConfig = `UPDATE UTENTI_CONFIG SET ${utentiConfigUpdates.join(', ')} WHERE CODUTE = ?`;
|
|
339
346
|
utentiConfigParams.push(codiceUtente);
|
|
340
347
|
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtentiConfig, utentiConfigParams);
|
|
341
348
|
}
|
|
@@ -345,17 +352,100 @@ let UserService = class UserService {
|
|
|
345
352
|
if (!!user.permissions && user.permissions.length > 0) {
|
|
346
353
|
yield this.permissionService.assignPermissionsToUser(codiceUtente, user.permissions);
|
|
347
354
|
}
|
|
355
|
+
//await this.updateUserFilters(codiceUtente, user);
|
|
356
|
+
yield this.filtriService.upsertFiltriUtente(codiceUtente, user);
|
|
348
357
|
}
|
|
349
358
|
catch (error) {
|
|
350
359
|
throw error;
|
|
351
360
|
}
|
|
352
361
|
});
|
|
353
362
|
}
|
|
363
|
+
updateUserFilters(codiceUtente, user) {
|
|
364
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
365
|
+
try {
|
|
366
|
+
if (!codiceUtente || codiceUtente <= 0) {
|
|
367
|
+
throw new Error('Codice utente non valido');
|
|
368
|
+
}
|
|
369
|
+
const fieldMapping = {
|
|
370
|
+
numRep: { dbField: 'NUMREP', type: 'number' },
|
|
371
|
+
idxPers: { dbField: 'IDXPERS', type: 'number' },
|
|
372
|
+
codCliSuper: { dbField: 'CODCLISUPER', type: 'number' },
|
|
373
|
+
codAge: { dbField: 'CODAGE', type: 'number' },
|
|
374
|
+
codCliCol: { dbField: 'CODCLICOL', type: 'number' },
|
|
375
|
+
codiceClienti: { dbField: 'CODCLIENTI', type: 'string' },
|
|
376
|
+
tipFil: { dbField: 'TIPFIL', type: 'number' },
|
|
377
|
+
idxPostazione: { dbField: 'IDXPOS', type: 'number' },
|
|
378
|
+
};
|
|
379
|
+
const fieldsToUpdate = Object.entries(fieldMapping)
|
|
380
|
+
.filter(([tsField]) => {
|
|
381
|
+
const value = user[tsField];
|
|
382
|
+
// Includiamo il campo se è definito (anche se è una stringa vuota)
|
|
383
|
+
return value !== undefined && value !== null;
|
|
384
|
+
})
|
|
385
|
+
.map(([tsField, config]) => {
|
|
386
|
+
const value = user[tsField];
|
|
387
|
+
if (config.type === 'number' && typeof value !== 'number') {
|
|
388
|
+
throw new Error(`Il campo ${tsField} deve essere un numero`);
|
|
389
|
+
}
|
|
390
|
+
if (config.type === 'string' && typeof value !== 'string') {
|
|
391
|
+
throw new Error(`Il campo ${tsField} deve essere una stringa`);
|
|
392
|
+
}
|
|
393
|
+
return { tsField, dbField: config.dbField, value };
|
|
394
|
+
});
|
|
395
|
+
if (fieldsToUpdate.length === 0) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
yield this.executeInTransaction(() => __awaiter(this, void 0, void 0, function* () {
|
|
399
|
+
// Prima verifichiamo se esiste il record
|
|
400
|
+
const checkQuery = `SELECT COUNT(*) as CNT FROM FILTRI WHERE CODUTE = ?`;
|
|
401
|
+
const existingRecord = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, checkQuery, [
|
|
402
|
+
codiceUtente,
|
|
403
|
+
]);
|
|
404
|
+
const exists = existingRecord[0].CNT > 0;
|
|
405
|
+
if (exists) {
|
|
406
|
+
// Se esiste, facciamo l'UPDATE
|
|
407
|
+
const updates = fieldsToUpdate.map((f) => `${f.dbField} = ?`).join(', ');
|
|
408
|
+
const values = [...fieldsToUpdate.map((f) => f.value), codiceUtente];
|
|
409
|
+
const updateQuery = `UPDATE FILTRI SET ${updates} WHERE CODUTE = ?`;
|
|
410
|
+
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, updateQuery, values);
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
// Se non esiste, facciamo l'INSERT
|
|
414
|
+
const dbFields = ['CODUTE', ...fieldsToUpdate.map((f) => f.dbField)];
|
|
415
|
+
const placeholders = dbFields.map(() => '?');
|
|
416
|
+
const insertValues = [codiceUtente, ...fieldsToUpdate.map((f) => f.value)];
|
|
417
|
+
const insertQuery = `INSERT INTO FILTRI (${dbFields.join(', ')}) VALUES (${placeholders.join(', ')})`;
|
|
418
|
+
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, insertQuery, insertValues);
|
|
419
|
+
}
|
|
420
|
+
}));
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
throw new Error(`Errore durante l'aggiornamento dei filtri per utente ${codiceUtente}: ${error.message}`);
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
}
|
|
354
427
|
deleteUser(codiceCliente) {
|
|
355
428
|
return __awaiter(this, void 0, void 0, function* () {
|
|
356
429
|
try {
|
|
357
430
|
const query = `UPDATE UTENTI SET STAREG = ? WHERE CODUTE = ?`;
|
|
358
|
-
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [
|
|
431
|
+
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [
|
|
432
|
+
StatoRegistrazione_1.StatoRegistrazione.DELETE,
|
|
433
|
+
codiceCliente,
|
|
434
|
+
]);
|
|
435
|
+
}
|
|
436
|
+
catch (error) {
|
|
437
|
+
throw error;
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
setStato(codiceCliente, statoRegistrazione) {
|
|
442
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
443
|
+
try {
|
|
444
|
+
const query = `UPDATE UTENTI SET STAREG = ? WHERE CODUTE = ?`;
|
|
445
|
+
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [
|
|
446
|
+
statoRegistrazione,
|
|
447
|
+
codiceCliente,
|
|
448
|
+
]);
|
|
359
449
|
}
|
|
360
450
|
catch (error) {
|
|
361
451
|
throw error;
|
|
@@ -381,5 +471,7 @@ exports.UserService = UserService = __decorate([
|
|
|
381
471
|
autobind_1.autobind,
|
|
382
472
|
(0, common_1.Injectable)(),
|
|
383
473
|
__param(0, (0, common_1.Inject)('ACCESSI_OPTIONS')),
|
|
384
|
-
__metadata("design:paramtypes", [Object, EmailService_1.EmailService,
|
|
474
|
+
__metadata("design:paramtypes", [Object, EmailService_1.EmailService,
|
|
475
|
+
PermissionService_1.PermissionService,
|
|
476
|
+
FiltriService_1.FiltriService])
|
|
385
477
|
], UserService);
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|