emilsoftware-utilities 1.4.0-dev.10 → 1.4.0-dev.11

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.
@@ -1,9 +1,9 @@
1
- import { Response, Request } from "express";
2
- import { AccessiOptions } from "../AccessiModule";
3
- import { UserService } from "../Services/UserService/UserService";
4
- import { EmailService } from "../Services/EmailService/EmailService";
5
- import { UserDto } from "../Dtos";
6
- import { RegisterRequest } from "../Dtos/RegisterRequest";
1
+ import { Response, Request } from 'express';
2
+ import { AccessiOptions } from '../AccessiModule';
3
+ import { UserService } from '../Services/UserService/UserService';
4
+ import { EmailService } from '../Services/EmailService/EmailService';
5
+ import { StatoRegistrazione, UserDto } from '../Dtos';
6
+ import { RegisterRequest } from '../Dtos/RegisterRequest';
7
7
  export declare class UserController {
8
8
  private readonly userService;
9
9
  private readonly emailService;
@@ -13,6 +13,7 @@ export declare class UserController {
13
13
  serveResetPasswordPage(res: Response, token: string): Promise<void>;
14
14
  getUsers(res: Response, email?: string, codiceUtente?: number, includeExtensionFields?: boolean, includeGrants?: boolean): Promise<Response<any, Record<string, any>>>;
15
15
  deleteUser(codiceUtente: number, res: Response): Promise<Response<any, Record<string, any>>>;
16
+ setStatoRegistrazione(codiceUtente: number, statoRegistrazione: StatoRegistrazione, res: Response): Promise<Response<any, Record<string, any>>>;
16
17
  register(request: Request, registrationData: RegisterRequest, res: Response): Promise<Response<any, Record<string, any>>>;
17
18
  updateUtente(codiceUtente: number, user: UserDto, res: Response): Promise<Response<any, Record<string, any>>>;
18
19
  setGdpr(codiceUtente: number, res: Response): Promise<Response<any, Record<string, any>>>;
@@ -43,7 +43,7 @@ let UserController = UserController_1 = class UserController {
43
43
  }
44
44
  serveResetPasswordPage(res, token) {
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
- return res.sendFile((0, path_1.join)(__dirname, "..", "Views", "reset-password.html"));
46
+ return res.sendFile((0, path_1.join)(__dirname, '..', 'Views', 'reset-password.html'));
47
47
  });
48
48
  }
49
49
  getUsers(res, email, codiceUtente, includeExtensionFields, includeGrants) {
@@ -58,7 +58,7 @@ let UserController = UserController_1 = class UserController {
58
58
  return Utilities_1.RestUtilities.sendBaseResponse(res, users);
59
59
  }
60
60
  catch (error) {
61
- this.logger.error("Errore durante il recupero degli utenti: ", error);
61
+ this.logger.error('Errore durante il recupero degli utenti: ', error);
62
62
  return Utilities_1.RestUtilities.sendErrorMessage(res, error, UserController_1.name);
63
63
  }
64
64
  });
@@ -76,6 +76,21 @@ let UserController = UserController_1 = class UserController {
76
76
  }
77
77
  });
78
78
  }
79
+ setStatoRegistrazione(codiceUtente, statoRegistrazione, res) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ try {
82
+ if (!codiceUtente)
83
+ throw new Error('Il codice utente è obbligatorio.');
84
+ if (statoRegistrazione === undefined)
85
+ throw new Error('Lo stato registrazione è obbligatorio.');
86
+ yield this.userService.setStato(codiceUtente, statoRegistrazione);
87
+ return Utilities_1.RestUtilities.sendOKMessage(res, `Lo stato dell'utente ${codiceUtente} è stato aggiornato a ${statoRegistrazione}.`);
88
+ }
89
+ catch (error) {
90
+ return Utilities_1.RestUtilities.sendErrorMessage(res, error, UserController_1.name);
91
+ }
92
+ });
93
+ }
79
94
  register(request, registrationData, res) {
80
95
  return __awaiter(this, void 0, void 0, function* () {
81
96
  try {
@@ -92,7 +107,7 @@ let UserController = UserController_1 = class UserController {
92
107
  return __awaiter(this, void 0, void 0, function* () {
93
108
  try {
94
109
  if (!codiceUtente)
95
- throw new Error("Il codice utente è obbligatorio.");
110
+ throw new Error('Il codice utente è obbligatorio.');
96
111
  yield this.userService.updateUser(codiceUtente, user);
97
112
  return Utilities_1.RestUtilities.sendOKMessage(res, `L'utente ${codiceUtente} è stato aggiornato con successo.`);
98
113
  }
@@ -105,7 +120,7 @@ let UserController = UserController_1 = class UserController {
105
120
  return __awaiter(this, void 0, void 0, function* () {
106
121
  try {
107
122
  if (!codiceUtente)
108
- throw new Error("Il codice utente è obbligatorio.");
123
+ throw new Error('Il codice utente è obbligatorio.');
109
124
  yield this.userService.setGdpr(codiceUtente);
110
125
  return Utilities_1.RestUtilities.sendOKMessage(res, `L'utente ${codiceUtente} ha accettato il GDPR.`);
111
126
  }
@@ -118,78 +133,83 @@ let UserController = UserController_1 = class UserController {
118
133
  exports.UserController = UserController;
119
134
  __decorate([
120
135
  (0, swagger_1.ApiOperation)({
121
- summary: "Servire la pagina di reset password",
122
- operationId: "serveResetPasswordPageUser",
136
+ summary: 'Servire la pagina di reset password',
137
+ operationId: 'serveResetPasswordPageUser',
123
138
  }),
124
139
  (0, swagger_1.ApiParam)({
125
- name: "token",
126
- description: "Token per il reset della password",
140
+ name: 'token',
141
+ description: 'Token per il reset della password',
127
142
  required: true,
128
143
  }),
129
- (0, common_1.Get)("reset-password/:token"),
144
+ (0, common_1.Get)('reset-password/:token'),
130
145
  __param(0, (0, common_1.Res)()),
131
- __param(1, (0, common_1.Param)("token")),
146
+ __param(1, (0, common_1.Param)('token')),
132
147
  __metadata("design:type", Function),
133
148
  __metadata("design:paramtypes", [Object, String]),
134
149
  __metadata("design:returntype", Promise)
135
150
  ], UserController.prototype, "serveResetPasswordPage", null);
136
151
  __decorate([
137
152
  (0, swagger_1.ApiOperation)({
138
- summary: "Recupera la lista degli utenti",
139
- operationId: "getUsers",
153
+ summary: 'Recupera la lista degli utenti',
154
+ operationId: 'getUsers',
140
155
  }),
141
156
  (0, swagger_1.ApiResponse)({
142
157
  status: 200,
143
- description: "Lista utenti recuperata con successo",
158
+ description: 'Lista utenti recuperata con successo',
144
159
  type: GetUsersResponse_1.GetUsersResponse,
145
160
  }),
146
- (0, swagger_1.ApiResponse)({ status: 401, description: "Credenziali non valide" }),
161
+ (0, swagger_1.ApiResponse)({ status: 401, description: 'Credenziali non valide' }),
147
162
  (0, swagger_1.ApiQuery)({
148
- name: "email",
163
+ name: 'email',
149
164
  required: false,
150
165
  description: "Email dell'utente da cercare",
151
166
  }),
152
167
  (0, swagger_1.ApiQuery)({
153
- name: "codiceUtente",
168
+ name: 'codiceUtente',
154
169
  required: false,
155
170
  description: "Codice dell'utente da cercare",
156
171
  }),
157
172
  (0, swagger_1.ApiQuery)({
158
- name: "includeExtensionFields",
173
+ name: 'includeExtensionFields',
159
174
  required: false,
160
- description: "Includi extension fields (chiamata più pesante)",
175
+ description: 'Includi extension fields (chiamata più pesante)',
161
176
  }),
162
177
  (0, swagger_1.ApiQuery)({
163
- name: "includeGrants",
178
+ name: 'includeGrants',
164
179
  required: false,
165
- description: "Includi Permessi (chiamata più pesante)",
180
+ description: 'Includi Permessi (chiamata più pesante)',
166
181
  }),
167
- (0, common_1.Get)("get-users"),
182
+ (0, common_1.Get)('get-users'),
168
183
  __param(0, (0, common_1.Res)()),
169
- __param(1, (0, common_1.Query)("email")),
170
- __param(2, (0, common_1.Query)("codiceUtente")),
171
- __param(3, (0, common_1.Query)("includeExtensionFields", new common_1.ParseBoolPipe({ optional: true }))),
172
- __param(4, (0, common_1.Query)("includeGrants", new common_1.ParseBoolPipe({ optional: true }))),
184
+ __param(1, (0, common_1.Query)('email')),
185
+ __param(2, (0, common_1.Query)('codiceUtente')),
186
+ __param(3, (0, common_1.Query)('includeExtensionFields', new common_1.ParseBoolPipe({ optional: true }))),
187
+ __param(4, (0, common_1.Query)('includeGrants', new common_1.ParseBoolPipe({ optional: true }))),
173
188
  __metadata("design:type", Function),
174
189
  __metadata("design:paramtypes", [Object, String, Number, Boolean, Boolean]),
175
190
  __metadata("design:returntype", Promise)
176
191
  ], UserController.prototype, "getUsers", null);
177
192
  __decorate([
178
- (0, swagger_1.ApiOperation)({ summary: "Elimina un utente", operationId: "deleteUser" }),
193
+ (0, swagger_1.ApiOperation)({
194
+ summary: 'Elimina un utente',
195
+ operationId: 'deleteUser',
196
+ description: `Imposta lo stato di un utente a 50(eliminato)
197
+ Non esegue una eliminazione dei record`,
198
+ }),
179
199
  (0, swagger_1.ApiParam)({
180
- name: "codiceUtente",
200
+ name: 'codiceUtente',
181
201
  description: "Codice identificativo dell'utente da eliminare",
182
202
  required: true,
183
- example: "USR123",
203
+ example: 'USR123',
184
204
  }),
185
- (0, swagger_1.ApiResponse)({ status: 200, description: "Utente eliminato con successo" }),
205
+ (0, swagger_1.ApiResponse)({ status: 200, description: 'Utente eliminato con successo' }),
186
206
  (0, swagger_1.ApiResponse)({
187
207
  status: 400,
188
- description: "Errore nei parametri della richiesta",
208
+ description: 'Errore nei parametri della richiesta',
189
209
  }),
190
- (0, swagger_1.ApiResponse)({ status: 500, description: "Errore interno del server" }),
191
- (0, common_1.Delete)("delete-user/:codiceUtente"),
192
- __param(0, (0, common_1.Param)("codiceUtente")),
210
+ (0, swagger_1.ApiResponse)({ status: 500, description: 'Errore interno del server' }),
211
+ (0, common_1.Delete)('delete-user/:codiceUtente'),
212
+ __param(0, (0, common_1.Param)('codiceUtente')),
193
213
  __param(1, (0, common_1.Res)()),
194
214
  __metadata("design:type", Function),
195
215
  __metadata("design:paramtypes", [Number, Object]),
@@ -197,26 +217,77 @@ __decorate([
197
217
  ], UserController.prototype, "deleteUser", null);
198
218
  __decorate([
199
219
  (0, swagger_1.ApiOperation)({
200
- summary: "Registra un nuovo utente",
201
- operationId: "register",
220
+ summary: 'Imposta lo stato di registrazione di un utente',
221
+ operationId: 'setStatoRegistrazione',
222
+ description: `Imposta lo stato di registrazione di un utente. Stati possibili:
223
+ - 0: NULL (non definito)
224
+ - 5: INSERT (inserito)
225
+ - 10: INVIO (inviato)
226
+ - 20: CONF (confermato)
227
+ - 50: DELETE (eliminato)
228
+ - 99: BLOCC (bloccato)`,
229
+ }),
230
+ (0, swagger_1.ApiBody)({
231
+ schema: {
232
+ type: 'object',
233
+ required: ['codiceUtente', 'statoRegistrazione'],
234
+ properties: {
235
+ codiceUtente: {
236
+ type: 'number',
237
+ description: "Codice identificativo dell'utente",
238
+ example: 123,
239
+ },
240
+ statoRegistrazione: {
241
+ type: 'number',
242
+ enum: [0, 5, 10, 20, 50, 99],
243
+ description: 'Nuovo stato di registrazione',
244
+ example: 20,
245
+ },
246
+ },
247
+ },
248
+ }),
249
+ (0, swagger_1.ApiResponse)({
250
+ status: 200,
251
+ description: 'Stato registrazione aggiornato con successo',
252
+ }),
253
+ (0, swagger_1.ApiResponse)({
254
+ status: 400,
255
+ description: 'Errore nei parametri della richiesta',
256
+ }),
257
+ (0, swagger_1.ApiResponse)({
258
+ status: 500,
259
+ description: 'Errore interno del server',
260
+ }),
261
+ (0, common_1.Post)('set-stato'),
262
+ __param(0, (0, common_1.Body)('codiceUtente')),
263
+ __param(1, (0, common_1.Body)('statoRegistrazione')),
264
+ __param(2, (0, common_1.Res)()),
265
+ __metadata("design:type", Function),
266
+ __metadata("design:paramtypes", [Number, Number, Object]),
267
+ __metadata("design:returntype", Promise)
268
+ ], UserController.prototype, "setStatoRegistrazione", null);
269
+ __decorate([
270
+ (0, swagger_1.ApiOperation)({
271
+ summary: 'Registra un nuovo utente',
272
+ operationId: 'register',
202
273
  }),
203
274
  (0, swagger_1.ApiBody)({
204
275
  type: RegisterRequest_1.RegisterRequest,
205
276
  description: "Dati necessari per la registrazione dell'utente",
206
277
  }),
207
278
  (0, swagger_1.ApiCreatedResponse)({
208
- description: "Utente registrato con successo. Restituisce il codice utente e invia una mail di conferma/reset password.",
279
+ description: 'Utente registrato con successo. Restituisce il codice utente e invia una mail di conferma/reset password.',
209
280
  type: RegisterResponse_1.RegisterResponse,
210
281
  }),
211
282
  (0, swagger_1.ApiResponse)({
212
283
  status: common_1.HttpStatus.BAD_REQUEST,
213
- description: "Errore nella registrazione. Potrebbe essere dovuto a dati mancanti, email già esistente o configurazione non valida.",
284
+ description: 'Errore nella registrazione. Potrebbe essere dovuto a dati mancanti, email già esistente o configurazione non valida.',
214
285
  }),
215
286
  (0, swagger_1.ApiResponse)({
216
287
  status: common_1.HttpStatus.INTERNAL_SERVER_ERROR,
217
- description: "Errore interno del server durante la registrazione o l’invio dell’email.",
288
+ description: 'Errore interno del server durante la registrazione o l’invio dell’email.',
218
289
  }),
219
- (0, common_1.Post)("register"),
290
+ (0, common_1.Post)('register'),
220
291
  __param(0, (0, common_1.Req)()),
221
292
  __param(1, (0, common_1.Body)()),
222
293
  __param(2, (0, common_1.Res)()),
@@ -226,14 +297,14 @@ __decorate([
226
297
  ], UserController.prototype, "register", null);
227
298
  __decorate([
228
299
  (0, swagger_1.ApiOperation)({
229
- summary: "Aggiorna un utente esistente",
230
- operationId: "updateUtente",
300
+ summary: 'Aggiorna un utente esistente',
301
+ operationId: 'updateUtente',
231
302
  }),
232
303
  (0, swagger_1.ApiParam)({
233
- name: "codiceUtente",
304
+ name: 'codiceUtente',
234
305
  description: "Codice identificativo dell'utente da aggiornare",
235
306
  required: true,
236
- example: "USR123",
307
+ example: 'USR123',
237
308
  }),
238
309
  (0, swagger_1.ApiBody)({
239
310
  type: Dtos_1.UserDto,
@@ -241,11 +312,11 @@ __decorate([
241
312
  }),
242
313
  (0, swagger_1.ApiResponse)({
243
314
  status: common_1.HttpStatus.OK,
244
- description: "Utente aggiornato con successo",
315
+ description: 'Utente aggiornato con successo',
245
316
  }),
246
317
  (0, swagger_1.ApiResponse)({ status: 400, description: "Errore nell'aggiornamento" }),
247
- (0, common_1.Put)("update-user/:codiceUtente"),
248
- __param(0, (0, common_1.Param)("codiceUtente")),
318
+ (0, common_1.Put)('update-user/:codiceUtente'),
319
+ __param(0, (0, common_1.Param)('codiceUtente')),
249
320
  __param(1, (0, common_1.Body)()),
250
321
  __param(2, (0, common_1.Res)()),
251
322
  __metadata("design:type", Function),
@@ -254,31 +325,31 @@ __decorate([
254
325
  ], UserController.prototype, "updateUtente", null);
255
326
  __decorate([
256
327
  (0, swagger_1.ApiOperation)({
257
- summary: "Imposta il consenso GDPR per un utente",
258
- operationId: "setGdpr",
328
+ summary: 'Imposta il consenso GDPR per un utente',
329
+ operationId: 'setGdpr',
259
330
  }),
260
331
  (0, swagger_1.ApiParam)({
261
- name: "codiceUtente",
332
+ name: 'codiceUtente',
262
333
  description: "Codice identificativo dell'utente che accetta il GDPR",
263
334
  required: true,
264
- example: "USR123",
335
+ example: 'USR123',
265
336
  }),
266
337
  (0, swagger_1.ApiResponse)({
267
338
  status: 200,
268
- description: "Consenso GDPR impostato con successo",
339
+ description: 'Consenso GDPR impostato con successo',
269
340
  }),
270
- (0, swagger_1.ApiResponse)({ status: 400, description: "Errore nella richiesta" }),
271
- (0, common_1.Patch)("set-gdpr/:codiceUtente"),
272
- __param(0, (0, common_1.Param)("codiceUtente")),
341
+ (0, swagger_1.ApiResponse)({ status: 400, description: 'Errore nella richiesta' }),
342
+ (0, common_1.Patch)('set-gdpr/:codiceUtente'),
343
+ __param(0, (0, common_1.Param)('codiceUtente')),
273
344
  __param(1, (0, common_1.Res)()),
274
345
  __metadata("design:type", Function),
275
346
  __metadata("design:paramtypes", [Number, Object]),
276
347
  __metadata("design:returntype", Promise)
277
348
  ], UserController.prototype, "setGdpr", null);
278
349
  exports.UserController = UserController = UserController_1 = __decorate([
279
- (0, swagger_1.ApiTags)("User"),
280
- (0, common_1.Controller)("accessi/user"),
281
- __param(2, (0, common_1.Inject)("ACCESSI_OPTIONS")),
350
+ (0, swagger_1.ApiTags)('User'),
351
+ (0, common_1.Controller)('accessi/user'),
352
+ __param(2, (0, common_1.Inject)('ACCESSI_OPTIONS')),
282
353
  __metadata("design:paramtypes", [UserService_1.UserService,
283
354
  EmailService_1.EmailService, Object])
284
355
  ], UserController);
@@ -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;
@@ -27,5 +28,6 @@ export declare class UserService {
27
28
  register(registrationData: RegisterRequest): Promise<string>;
28
29
  updateUser(codiceUtente: number, user: UserDto): Promise<void>;
29
30
  deleteUser(codiceCliente: number): Promise<void>;
31
+ setStato(codiceCliente: number, statoRegistrazione: StatoRegistrazione): Promise<void>;
30
32
  setGdpr(codiceUtente: number): Promise<any>;
31
33
  }
@@ -80,10 +80,10 @@ let UserService = class UserService {
80
80
  queryParams.push(filters.codiceUtente);
81
81
  }
82
82
  query += ` ORDER BY U.CODUTE DESC `;
83
- let users = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, queryParams);
83
+ let users = (yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, queryParams));
84
84
  users = users.map(Utilities_1.RestUtilities.convertKeysToCamelCase);
85
85
  let usersResponse = [];
86
- console.log("OPTIONS: ", options);
86
+ console.log('OPTIONS: ', options);
87
87
  for (const user of users) {
88
88
  let userGrants = null;
89
89
  if (options.includeGrants)
@@ -92,18 +92,18 @@ let UserService = class UserService {
92
92
  //todo: se non è prendente extensionFieldOptions va in errore. Risolvere il problema
93
93
  if (options.includeExtensionFields) {
94
94
  for (const ext of this.accessiOptions.extensionFieldsOptions) {
95
- 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
+ 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
96
  extensionFields[ext.objectKey] = values;
97
97
  }
98
98
  }
99
99
  let userResult = {
100
100
  utente: user,
101
101
  userGrants: userGrants,
102
- extensionFields: extensionFields
102
+ extensionFields: extensionFields,
103
103
  };
104
104
  usersResponse.push(userResult);
105
105
  }
106
- console.log("OPTIONS: ", options);
106
+ console.log('OPTIONS: ', options);
107
107
  return usersResponse;
108
108
  }
109
109
  catch (error) {
@@ -115,7 +115,9 @@ let UserService = class UserService {
115
115
  return __awaiter(this, void 0, void 0, function* () {
116
116
  try {
117
117
  const query = `SELECT CODUTE as codice_utente FROM UTENTI WHERE LOWER(USRNAME) = ?`;
118
- const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [email.trim().toLowerCase()]);
118
+ const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [
119
+ email.trim().toLowerCase(),
120
+ ]);
119
121
  return result.map(Utilities_1.RestUtilities.convertKeysToCamelCase)[0];
120
122
  }
121
123
  catch (error) {
@@ -145,8 +147,7 @@ let UserService = class UserService {
145
147
  INNER JOIN UTENTI_CONFIG C ON C.CODUTE = U.CODUTE
146
148
  WHERE LOWER(U.USRNAME) = ?
147
149
  `;
148
- const utenti = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [email])
149
- .then(results => results.map(Utilities_1.RestUtilities.convertKeysToCamelCase));
150
+ const utenti = (yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [email]).then((results) => results.map(Utilities_1.RestUtilities.convertKeysToCamelCase)));
150
151
  return utenti.length > 0 ? utenti[0] : null;
151
152
  });
152
153
  }
@@ -165,8 +166,7 @@ let UserService = class UserService {
165
166
  FROM FILTRI F
166
167
  WHERE F.CODUTE = ?
167
168
  `;
168
- return yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [codiceUtente])
169
- .then(results => results.map(Utilities_1.RestUtilities.convertKeysToCamelCase));
169
+ return (yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [codiceUtente]).then((results) => results.map(Utilities_1.RestUtilities.convertKeysToCamelCase)));
170
170
  });
171
171
  }
172
172
  insertUserFilters(codiceUtente, filterData) {
@@ -182,7 +182,7 @@ let UserService = class UserService {
182
182
  codiceAgenzia: { dbField: 'CODAGE', type: 'string' },
183
183
  codiceClienteCollegato: { dbField: 'CODCLICOL', type: 'string' },
184
184
  codiceClienti: { dbField: 'CODCLIENTI', type: 'string' },
185
- tipoFiltro: { dbField: 'TIPFIL', type: 'string' }
185
+ tipoFiltro: { dbField: 'TIPFIL', type: 'string' },
186
186
  };
187
187
  const fieldsToInsert = Object.entries(fieldMapping)
188
188
  .filter(([tsField]) => {
@@ -204,9 +204,9 @@ let UserService = class UserService {
204
204
  }
205
205
  yield this.executeInTransaction(() => __awaiter(this, void 0, void 0, function* () {
206
206
  yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, 'DELETE FROM FILTRI WHERE CODUTE = ?', [codiceUtente]);
207
- const dbFields = ['CODUTE', ...fieldsToInsert.map(f => f.dbField)];
207
+ const dbFields = ['CODUTE', ...fieldsToInsert.map((f) => f.dbField)];
208
208
  const placeholders = dbFields.map(() => '?');
209
- const values = [codiceUtente, ...fieldsToInsert.map(f => f.value)];
209
+ const values = [codiceUtente, ...fieldsToInsert.map((f) => f.value)];
210
210
  const insertQuery = `INSERT INTO FILTRI (${dbFields.join(', ')}) VALUES (${placeholders.join(', ')})`;
211
211
  yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, insertQuery, values);
212
212
  }));
@@ -224,9 +224,9 @@ let UserService = class UserService {
224
224
  register(registrationData) {
225
225
  return __awaiter(this, void 0, void 0, function* () {
226
226
  try {
227
- const existingUser = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, "SELECT CODUTE FROM UTENTI WHERE USRNAME = ?", [registrationData.email]);
227
+ const existingUser = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, 'SELECT CODUTE FROM UTENTI WHERE USRNAME = ?', [registrationData.email]);
228
228
  if (existingUser.length > 0) {
229
- throw new Error("Questa e-mail è già stata utilizzata!");
229
+ throw new Error('Questa e-mail è già stata utilizzata!');
230
230
  }
231
231
  const queryUtenti = `INSERT INTO UTENTI (USRNAME, STAREG) VALUES (?,?) RETURNING CODUTE`;
232
232
  const paramsUtenti = [registrationData.email, StatoRegistrazione_1.StatoRegistrazione.INVIO];
@@ -271,24 +271,24 @@ let UserService = class UserService {
271
271
  return __awaiter(this, void 0, void 0, function* () {
272
272
  try {
273
273
  if (!codiceUtente)
274
- throw new Error("Impossibile aggiornare senza codice utente.");
274
+ throw new Error('Impossibile aggiornare senza codice utente.');
275
275
  // Costruzione dinamica della query per UTENTI
276
276
  const utentiUpdates = [];
277
277
  const utentiParams = [];
278
278
  if (user.email !== undefined) {
279
- utentiUpdates.push("usrname = ?");
279
+ utentiUpdates.push('usrname = ?');
280
280
  utentiParams.push(user.email);
281
281
  }
282
282
  if (user.flagGdpr !== undefined) {
283
- utentiUpdates.push("flggdpr = ?");
283
+ utentiUpdates.push('flggdpr = ?');
284
284
  utentiParams.push(user.flagGdpr);
285
285
  }
286
286
  if (user.statoRegistrazione !== undefined) {
287
- utentiUpdates.push("stareg = ?");
287
+ utentiUpdates.push('stareg = ?');
288
288
  utentiParams.push(user.statoRegistrazione);
289
289
  }
290
290
  if (utentiUpdates.length > 0) {
291
- const queryUtenti = `UPDATE UTENTI SET ${utentiUpdates.join(", ")} WHERE CODUTE = ?`;
291
+ const queryUtenti = `UPDATE UTENTI SET ${utentiUpdates.join(', ')} WHERE CODUTE = ?`;
292
292
  utentiParams.push(codiceUtente);
293
293
  yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtenti, utentiParams);
294
294
  }
@@ -296,47 +296,47 @@ let UserService = class UserService {
296
296
  const utentiConfigUpdates = [];
297
297
  const utentiConfigParams = [];
298
298
  if (user.cognome !== undefined) {
299
- utentiConfigUpdates.push("cognome = ?");
299
+ utentiConfigUpdates.push('cognome = ?');
300
300
  utentiConfigParams.push(user.cognome);
301
301
  }
302
302
  if (user.nome !== undefined) {
303
- utentiConfigUpdates.push("nome = ?");
303
+ utentiConfigUpdates.push('nome = ?');
304
304
  utentiConfigParams.push(user.nome);
305
305
  }
306
306
  if (user.avatar !== undefined) {
307
- utentiConfigUpdates.push("avatar = ?");
307
+ utentiConfigUpdates.push('avatar = ?');
308
308
  utentiConfigParams.push(user.avatar);
309
309
  }
310
310
  if (user.flagDueFattori !== undefined) {
311
- utentiConfigUpdates.push("flg2fatt = ?");
311
+ utentiConfigUpdates.push('flg2fatt = ?');
312
312
  utentiConfigParams.push(user.flagDueFattori);
313
313
  }
314
314
  if (user.codiceLingua !== undefined) {
315
- utentiConfigUpdates.push("codlingua = ?");
315
+ utentiConfigUpdates.push('codlingua = ?');
316
316
  utentiConfigParams.push(user.codiceLingua);
317
317
  }
318
318
  if (user.cellulare !== undefined) {
319
- utentiConfigUpdates.push("cellulare = ?");
319
+ utentiConfigUpdates.push('cellulare = ?');
320
320
  utentiConfigParams.push(user.cellulare);
321
321
  }
322
322
  if (user.flagSuper !== undefined) {
323
- utentiConfigUpdates.push("flgsuper = ?");
323
+ utentiConfigUpdates.push('flgsuper = ?');
324
324
  utentiConfigParams.push(user.flagSuper);
325
325
  }
326
326
  if (user.paginaDefault !== undefined) {
327
- utentiConfigUpdates.push("pagdef = ?");
327
+ utentiConfigUpdates.push('pagdef = ?');
328
328
  utentiConfigParams.push(user.paginaDefault);
329
329
  }
330
330
  if (user.jsonMetadata !== undefined) {
331
- utentiConfigUpdates.push("json_metadata = ?");
331
+ utentiConfigUpdates.push('json_metadata = ?');
332
332
  utentiConfigParams.push(user.jsonMetadata);
333
333
  }
334
334
  if (user.ragSocCli !== undefined) {
335
- utentiConfigUpdates.push("ragsoccli = ?");
335
+ utentiConfigUpdates.push('ragsoccli = ?');
336
336
  utentiConfigParams.push(user.ragSocCli);
337
337
  }
338
338
  if (utentiConfigUpdates.length > 0) {
339
- const queryUtentiConfig = `UPDATE UTENTI_CONFIG SET ${utentiConfigUpdates.join(", ")} WHERE CODUTE = ?`;
339
+ const queryUtentiConfig = `UPDATE UTENTI_CONFIG SET ${utentiConfigUpdates.join(', ')} WHERE CODUTE = ?`;
340
340
  utentiConfigParams.push(codiceUtente);
341
341
  yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtentiConfig, utentiConfigParams);
342
342
  }
@@ -356,7 +356,24 @@ let UserService = class UserService {
356
356
  return __awaiter(this, void 0, void 0, function* () {
357
357
  try {
358
358
  const query = `UPDATE UTENTI SET STAREG = ? WHERE CODUTE = ?`;
359
- yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [StatoRegistrazione_1.StatoRegistrazione.DELETE, codiceCliente]);
359
+ yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [
360
+ StatoRegistrazione_1.StatoRegistrazione.DELETE,
361
+ codiceCliente,
362
+ ]);
363
+ }
364
+ catch (error) {
365
+ throw error;
366
+ }
367
+ });
368
+ }
369
+ setStato(codiceCliente, statoRegistrazione) {
370
+ return __awaiter(this, void 0, void 0, function* () {
371
+ try {
372
+ const query = `UPDATE UTENTI SET STAREG = ? WHERE CODUTE = ?`;
373
+ yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [
374
+ statoRegistrazione,
375
+ codiceCliente,
376
+ ]);
360
377
  }
361
378
  catch (error) {
362
379
  throw error;
@@ -382,5 +399,6 @@ exports.UserService = UserService = __decorate([
382
399
  autobind_1.autobind,
383
400
  (0, common_1.Injectable)(),
384
401
  __param(0, (0, common_1.Inject)('ACCESSI_OPTIONS')),
385
- __metadata("design:paramtypes", [Object, EmailService_1.EmailService, PermissionService_1.PermissionService])
402
+ __metadata("design:paramtypes", [Object, EmailService_1.EmailService,
403
+ PermissionService_1.PermissionService])
386
404
  ], UserService);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emilsoftware-utilities",
3
- "version": "1.4.0-dev.10",
3
+ "version": "1.4.0-dev.11",
4
4
  "description": "Utilities for EmilSoftware",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",