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

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,10 @@
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 { UserDto } from '../Dtos';
6
+ import { RegisterRequest } from '../Dtos/RegisterRequest';
7
+ import { SetStatoRegistrazioneDto } from '../Dtos/SetStatoRegistrazione';
7
8
  export declare class UserController {
8
9
  private readonly userService;
9
10
  private readonly emailService;
@@ -13,6 +14,7 @@ export declare class UserController {
13
14
  serveResetPasswordPage(res: Response, token: string): Promise<void>;
14
15
  getUsers(res: Response, email?: string, codiceUtente?: number, includeExtensionFields?: boolean, includeGrants?: boolean): Promise<Response<any, Record<string, any>>>;
15
16
  deleteUser(codiceUtente: number, res: Response): Promise<Response<any, Record<string, any>>>;
17
+ setStatoRegistrazione(body: SetStatoRegistrazioneDto, res: Response): Promise<Response<any, Record<string, any>>>;
16
18
  register(request: Request, registrationData: RegisterRequest, res: Response): Promise<Response<any, Record<string, any>>>;
17
19
  updateUtente(codiceUtente: number, user: UserDto, res: Response): Promise<Response<any, Record<string, any>>>;
18
20
  setGdpr(codiceUtente: number, res: Response): Promise<Response<any, Record<string, any>>>;
@@ -34,6 +34,7 @@ const Dtos_1 = require("../Dtos");
34
34
  const RegisterResponse_1 = require("../Dtos/RegisterResponse");
35
35
  const RegisterRequest_1 = require("../Dtos/RegisterRequest");
36
36
  const Logger_1 = require("../../Logger");
37
+ const SetStatoRegistrazione_1 = require("../Dtos/SetStatoRegistrazione");
37
38
  let UserController = UserController_1 = class UserController {
38
39
  constructor(userService, emailService, options) {
39
40
  this.userService = userService;
@@ -43,7 +44,7 @@ let UserController = UserController_1 = class UserController {
43
44
  }
44
45
  serveResetPasswordPage(res, token) {
45
46
  return __awaiter(this, void 0, void 0, function* () {
46
- return res.sendFile((0, path_1.join)(__dirname, "..", "Views", "reset-password.html"));
47
+ return res.sendFile((0, path_1.join)(__dirname, '..', 'Views', 'reset-password.html'));
47
48
  });
48
49
  }
49
50
  getUsers(res, email, codiceUtente, includeExtensionFields, includeGrants) {
@@ -58,7 +59,7 @@ let UserController = UserController_1 = class UserController {
58
59
  return Utilities_1.RestUtilities.sendBaseResponse(res, users);
59
60
  }
60
61
  catch (error) {
61
- this.logger.error("Errore durante il recupero degli utenti: ", error);
62
+ this.logger.error('Errore durante il recupero degli utenti: ', error);
62
63
  return Utilities_1.RestUtilities.sendErrorMessage(res, error, UserController_1.name);
63
64
  }
64
65
  });
@@ -76,6 +77,22 @@ let UserController = UserController_1 = class UserController {
76
77
  }
77
78
  });
78
79
  }
80
+ setStatoRegistrazione(body, res) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ try {
83
+ let { codiceUtente, statoRegistrazione } = body;
84
+ if (!codiceUtente)
85
+ throw new Error('Il codice utente è obbligatorio.');
86
+ if (statoRegistrazione === undefined)
87
+ throw new Error('Lo stato registrazione è obbligatorio.');
88
+ yield this.userService.setStato(codiceUtente, statoRegistrazione);
89
+ return Utilities_1.RestUtilities.sendOKMessage(res, `Lo stato dell'utente ${codiceUtente} è stato aggiornato a ${statoRegistrazione}.`);
90
+ }
91
+ catch (error) {
92
+ return Utilities_1.RestUtilities.sendErrorMessage(res, error, UserController_1.name);
93
+ }
94
+ });
95
+ }
79
96
  register(request, registrationData, res) {
80
97
  return __awaiter(this, void 0, void 0, function* () {
81
98
  try {
@@ -92,7 +109,7 @@ let UserController = UserController_1 = class UserController {
92
109
  return __awaiter(this, void 0, void 0, function* () {
93
110
  try {
94
111
  if (!codiceUtente)
95
- throw new Error("Il codice utente è obbligatorio.");
112
+ throw new Error('Il codice utente è obbligatorio.');
96
113
  yield this.userService.updateUser(codiceUtente, user);
97
114
  return Utilities_1.RestUtilities.sendOKMessage(res, `L'utente ${codiceUtente} è stato aggiornato con successo.`);
98
115
  }
@@ -105,7 +122,7 @@ let UserController = UserController_1 = class UserController {
105
122
  return __awaiter(this, void 0, void 0, function* () {
106
123
  try {
107
124
  if (!codiceUtente)
108
- throw new Error("Il codice utente è obbligatorio.");
125
+ throw new Error('Il codice utente è obbligatorio.');
109
126
  yield this.userService.setGdpr(codiceUtente);
110
127
  return Utilities_1.RestUtilities.sendOKMessage(res, `L'utente ${codiceUtente} ha accettato il GDPR.`);
111
128
  }
@@ -118,78 +135,83 @@ let UserController = UserController_1 = class UserController {
118
135
  exports.UserController = UserController;
119
136
  __decorate([
120
137
  (0, swagger_1.ApiOperation)({
121
- summary: "Servire la pagina di reset password",
122
- operationId: "serveResetPasswordPageUser",
138
+ summary: 'Servire la pagina di reset password',
139
+ operationId: 'serveResetPasswordPageUser',
123
140
  }),
124
141
  (0, swagger_1.ApiParam)({
125
- name: "token",
126
- description: "Token per il reset della password",
142
+ name: 'token',
143
+ description: 'Token per il reset della password',
127
144
  required: true,
128
145
  }),
129
- (0, common_1.Get)("reset-password/:token"),
146
+ (0, common_1.Get)('reset-password/:token'),
130
147
  __param(0, (0, common_1.Res)()),
131
- __param(1, (0, common_1.Param)("token")),
148
+ __param(1, (0, common_1.Param)('token')),
132
149
  __metadata("design:type", Function),
133
150
  __metadata("design:paramtypes", [Object, String]),
134
151
  __metadata("design:returntype", Promise)
135
152
  ], UserController.prototype, "serveResetPasswordPage", null);
136
153
  __decorate([
137
154
  (0, swagger_1.ApiOperation)({
138
- summary: "Recupera la lista degli utenti",
139
- operationId: "getUsers",
155
+ summary: 'Recupera la lista degli utenti',
156
+ operationId: 'getUsers',
140
157
  }),
141
158
  (0, swagger_1.ApiResponse)({
142
159
  status: 200,
143
- description: "Lista utenti recuperata con successo",
160
+ description: 'Lista utenti recuperata con successo',
144
161
  type: GetUsersResponse_1.GetUsersResponse,
145
162
  }),
146
- (0, swagger_1.ApiResponse)({ status: 401, description: "Credenziali non valide" }),
163
+ (0, swagger_1.ApiResponse)({ status: 401, description: 'Credenziali non valide' }),
147
164
  (0, swagger_1.ApiQuery)({
148
- name: "email",
165
+ name: 'email',
149
166
  required: false,
150
167
  description: "Email dell'utente da cercare",
151
168
  }),
152
169
  (0, swagger_1.ApiQuery)({
153
- name: "codiceUtente",
170
+ name: 'codiceUtente',
154
171
  required: false,
155
172
  description: "Codice dell'utente da cercare",
156
173
  }),
157
174
  (0, swagger_1.ApiQuery)({
158
- name: "includeExtensionFields",
175
+ name: 'includeExtensionFields',
159
176
  required: false,
160
- description: "Includi extension fields (chiamata più pesante)",
177
+ description: 'Includi extension fields (chiamata più pesante)',
161
178
  }),
162
179
  (0, swagger_1.ApiQuery)({
163
- name: "includeGrants",
180
+ name: 'includeGrants',
164
181
  required: false,
165
- description: "Includi Permessi (chiamata più pesante)",
182
+ description: 'Includi Permessi (chiamata più pesante)',
166
183
  }),
167
- (0, common_1.Get)("get-users"),
184
+ (0, common_1.Get)('get-users'),
168
185
  __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 }))),
186
+ __param(1, (0, common_1.Query)('email')),
187
+ __param(2, (0, common_1.Query)('codiceUtente')),
188
+ __param(3, (0, common_1.Query)('includeExtensionFields', new common_1.ParseBoolPipe({ optional: true }))),
189
+ __param(4, (0, common_1.Query)('includeGrants', new common_1.ParseBoolPipe({ optional: true }))),
173
190
  __metadata("design:type", Function),
174
191
  __metadata("design:paramtypes", [Object, String, Number, Boolean, Boolean]),
175
192
  __metadata("design:returntype", Promise)
176
193
  ], UserController.prototype, "getUsers", null);
177
194
  __decorate([
178
- (0, swagger_1.ApiOperation)({ summary: "Elimina un utente", operationId: "deleteUser" }),
195
+ (0, swagger_1.ApiOperation)({
196
+ summary: 'Elimina un utente',
197
+ operationId: 'deleteUser',
198
+ description: `Imposta lo stato di un utente a 50(eliminato)
199
+ Non esegue una eliminazione dei record`,
200
+ }),
179
201
  (0, swagger_1.ApiParam)({
180
- name: "codiceUtente",
202
+ name: 'codiceUtente',
181
203
  description: "Codice identificativo dell'utente da eliminare",
182
204
  required: true,
183
- example: "USR123",
205
+ example: 'USR123',
184
206
  }),
185
- (0, swagger_1.ApiResponse)({ status: 200, description: "Utente eliminato con successo" }),
207
+ (0, swagger_1.ApiResponse)({ status: 200, description: 'Utente eliminato con successo' }),
186
208
  (0, swagger_1.ApiResponse)({
187
209
  status: 400,
188
- description: "Errore nei parametri della richiesta",
210
+ description: 'Errore nei parametri della richiesta',
189
211
  }),
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")),
212
+ (0, swagger_1.ApiResponse)({ status: 500, description: 'Errore interno del server' }),
213
+ (0, common_1.Delete)('delete-user/:codiceUtente'),
214
+ __param(0, (0, common_1.Param)('codiceUtente')),
193
215
  __param(1, (0, common_1.Res)()),
194
216
  __metadata("design:type", Function),
195
217
  __metadata("design:paramtypes", [Number, Object]),
@@ -197,26 +219,58 @@ __decorate([
197
219
  ], UserController.prototype, "deleteUser", null);
198
220
  __decorate([
199
221
  (0, swagger_1.ApiOperation)({
200
- summary: "Registra un nuovo utente",
201
- operationId: "register",
222
+ summary: 'Imposta lo stato di registrazione di un utente',
223
+ operationId: 'setStatoRegistrazione',
224
+ description: `Imposta lo stato di registrazione di un utente. Stati possibili:
225
+ - 0: NULL (non definito)
226
+ - 5: INSERT (inserito)
227
+ - 10: INVIO (inviato)
228
+ - 20: CONF (confermato)
229
+ - 50: DELETE (eliminato)
230
+ - 99: BLOCC (bloccato)`,
231
+ }),
232
+ (0, swagger_1.ApiResponse)({
233
+ status: 200,
234
+ description: 'Stato registrazione aggiornato con successo',
235
+ }),
236
+ (0, swagger_1.ApiResponse)({
237
+ status: 400,
238
+ description: 'Errore nei parametri della richiesta',
239
+ }),
240
+ (0, swagger_1.ApiResponse)({
241
+ status: 500,
242
+ description: 'Errore interno del server',
243
+ }),
244
+ (0, swagger_1.ApiBody)({ type: SetStatoRegistrazione_1.SetStatoRegistrazioneDto }),
245
+ (0, common_1.Post)('set-stato'),
246
+ __param(0, (0, common_1.Body)()),
247
+ __param(1, (0, common_1.Res)()),
248
+ __metadata("design:type", Function),
249
+ __metadata("design:paramtypes", [SetStatoRegistrazione_1.SetStatoRegistrazioneDto, Object]),
250
+ __metadata("design:returntype", Promise)
251
+ ], UserController.prototype, "setStatoRegistrazione", null);
252
+ __decorate([
253
+ (0, swagger_1.ApiOperation)({
254
+ summary: 'Registra un nuovo utente',
255
+ operationId: 'register',
202
256
  }),
203
257
  (0, swagger_1.ApiBody)({
204
258
  type: RegisterRequest_1.RegisterRequest,
205
259
  description: "Dati necessari per la registrazione dell'utente",
206
260
  }),
207
261
  (0, swagger_1.ApiCreatedResponse)({
208
- description: "Utente registrato con successo. Restituisce il codice utente e invia una mail di conferma/reset password.",
262
+ description: 'Utente registrato con successo. Restituisce il codice utente e invia una mail di conferma/reset password.',
209
263
  type: RegisterResponse_1.RegisterResponse,
210
264
  }),
211
265
  (0, swagger_1.ApiResponse)({
212
266
  status: common_1.HttpStatus.BAD_REQUEST,
213
- description: "Errore nella registrazione. Potrebbe essere dovuto a dati mancanti, email già esistente o configurazione non valida.",
267
+ description: 'Errore nella registrazione. Potrebbe essere dovuto a dati mancanti, email già esistente o configurazione non valida.',
214
268
  }),
215
269
  (0, swagger_1.ApiResponse)({
216
270
  status: common_1.HttpStatus.INTERNAL_SERVER_ERROR,
217
- description: "Errore interno del server durante la registrazione o l’invio dell’email.",
271
+ description: 'Errore interno del server durante la registrazione o l’invio dell’email.',
218
272
  }),
219
- (0, common_1.Post)("register"),
273
+ (0, common_1.Post)('register'),
220
274
  __param(0, (0, common_1.Req)()),
221
275
  __param(1, (0, common_1.Body)()),
222
276
  __param(2, (0, common_1.Res)()),
@@ -226,14 +280,14 @@ __decorate([
226
280
  ], UserController.prototype, "register", null);
227
281
  __decorate([
228
282
  (0, swagger_1.ApiOperation)({
229
- summary: "Aggiorna un utente esistente",
230
- operationId: "updateUtente",
283
+ summary: 'Aggiorna un utente esistente',
284
+ operationId: 'updateUtente',
231
285
  }),
232
286
  (0, swagger_1.ApiParam)({
233
- name: "codiceUtente",
287
+ name: 'codiceUtente',
234
288
  description: "Codice identificativo dell'utente da aggiornare",
235
289
  required: true,
236
- example: "USR123",
290
+ example: 'USR123',
237
291
  }),
238
292
  (0, swagger_1.ApiBody)({
239
293
  type: Dtos_1.UserDto,
@@ -241,11 +295,11 @@ __decorate([
241
295
  }),
242
296
  (0, swagger_1.ApiResponse)({
243
297
  status: common_1.HttpStatus.OK,
244
- description: "Utente aggiornato con successo",
298
+ description: 'Utente aggiornato con successo',
245
299
  }),
246
300
  (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")),
301
+ (0, common_1.Put)('update-user/:codiceUtente'),
302
+ __param(0, (0, common_1.Param)('codiceUtente')),
249
303
  __param(1, (0, common_1.Body)()),
250
304
  __param(2, (0, common_1.Res)()),
251
305
  __metadata("design:type", Function),
@@ -254,31 +308,31 @@ __decorate([
254
308
  ], UserController.prototype, "updateUtente", null);
255
309
  __decorate([
256
310
  (0, swagger_1.ApiOperation)({
257
- summary: "Imposta il consenso GDPR per un utente",
258
- operationId: "setGdpr",
311
+ summary: 'Imposta il consenso GDPR per un utente',
312
+ operationId: 'setGdpr',
259
313
  }),
260
314
  (0, swagger_1.ApiParam)({
261
- name: "codiceUtente",
315
+ name: 'codiceUtente',
262
316
  description: "Codice identificativo dell'utente che accetta il GDPR",
263
317
  required: true,
264
- example: "USR123",
318
+ example: 'USR123',
265
319
  }),
266
320
  (0, swagger_1.ApiResponse)({
267
321
  status: 200,
268
- description: "Consenso GDPR impostato con successo",
322
+ description: 'Consenso GDPR impostato con successo',
269
323
  }),
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")),
324
+ (0, swagger_1.ApiResponse)({ status: 400, description: 'Errore nella richiesta' }),
325
+ (0, common_1.Patch)('set-gdpr/:codiceUtente'),
326
+ __param(0, (0, common_1.Param)('codiceUtente')),
273
327
  __param(1, (0, common_1.Res)()),
274
328
  __metadata("design:type", Function),
275
329
  __metadata("design:paramtypes", [Number, Object]),
276
330
  __metadata("design:returntype", Promise)
277
331
  ], UserController.prototype, "setGdpr", null);
278
332
  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")),
333
+ (0, swagger_1.ApiTags)('User'),
334
+ (0, common_1.Controller)('accessi/user'),
335
+ __param(2, (0, common_1.Inject)('ACCESSI_OPTIONS')),
282
336
  __metadata("design:paramtypes", [UserService_1.UserService,
283
337
  EmailService_1.EmailService, Object])
284
338
  ], UserController);
@@ -0,0 +1,5 @@
1
+ import { StatoRegistrazione } from './StatoRegistrazione';
2
+ export declare class SetStatoRegistrazioneDto {
3
+ codiceUtente: number;
4
+ statoRegistrazione: StatoRegistrazione;
5
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SetStatoRegistrazioneDto = void 0;
13
+ const swagger_1 = require("@nestjs/swagger");
14
+ const StatoRegistrazione_1 = require("./StatoRegistrazione");
15
+ class SetStatoRegistrazioneDto {
16
+ }
17
+ exports.SetStatoRegistrazioneDto = SetStatoRegistrazioneDto;
18
+ __decorate([
19
+ (0, swagger_1.ApiProperty)({
20
+ description: "Codice identificativo dell'utente",
21
+ example: 123,
22
+ }),
23
+ __metadata("design:type", Number)
24
+ ], SetStatoRegistrazioneDto.prototype, "codiceUtente", void 0);
25
+ __decorate([
26
+ (0, swagger_1.ApiProperty)({
27
+ description: 'Nuovo stato di registrazione',
28
+ enum: [0, 5, 10, 20, 50, 99],
29
+ example: 20,
30
+ }),
31
+ __metadata("design:type", Number)
32
+ ], SetStatoRegistrazioneDto.prototype, "statoRegistrazione", void 0);
@@ -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.12",
4
4
  "description": "Utilities for EmilSoftware",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",