emilsoftware-utilities 1.4.0-dev.14 → 1.4.0-dev.15

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.
@@ -9,11 +9,11 @@ export declare class RegisterRequest {
9
9
  permissions?: Permission[];
10
10
  numeroReport?: number;
11
11
  indicePersonale?: number;
12
- codiceClienteSuper?: string;
13
- codiceAgenzia?: string;
14
- codiceClienteCollegato?: string;
12
+ codiceClienteSuper?: number;
13
+ codiceAgenzia?: number;
14
+ codiceClienteCollegato?: number;
15
15
  codiceClienti?: string;
16
- tipoFiltro?: string;
16
+ tipoFiltro?: number;
17
17
  avatar?: string;
18
18
  flagDueFattori?: boolean;
19
19
  paginaDefault?: string;
@@ -83,23 +83,23 @@ __decorate([
83
83
  __decorate([
84
84
  (0, swagger_1.ApiPropertyOptional)({
85
85
  description: "Codice del cliente principale (super).",
86
- example: "CLT_SUP_1234",
86
+ example: 123,
87
87
  }),
88
- __metadata("design:type", String)
88
+ __metadata("design:type", Number)
89
89
  ], RegisterRequest.prototype, "codiceClienteSuper", void 0);
90
90
  __decorate([
91
91
  (0, swagger_1.ApiPropertyOptional)({
92
92
  description: "Codice dell'agenzia associata.",
93
- example: "AGZ_5678",
93
+ example: 123,
94
94
  }),
95
- __metadata("design:type", String)
95
+ __metadata("design:type", Number)
96
96
  ], RegisterRequest.prototype, "codiceAgenzia", void 0);
97
97
  __decorate([
98
98
  (0, swagger_1.ApiPropertyOptional)({
99
99
  description: "Codice del cliente collegato.",
100
- example: "CLT_COL_8765",
100
+ example: "123",
101
101
  }),
102
- __metadata("design:type", String)
102
+ __metadata("design:type", Number)
103
103
  ], RegisterRequest.prototype, "codiceClienteCollegato", void 0);
104
104
  __decorate([
105
105
  (0, swagger_1.ApiPropertyOptional)({
@@ -113,7 +113,7 @@ __decorate([
113
113
  description: "Tipo di filtro applicato.",
114
114
  example: "esclusivo",
115
115
  }),
116
- __metadata("design:type", String)
116
+ __metadata("design:type", Number)
117
117
  ], RegisterRequest.prototype, "tipoFiltro", void 0);
118
118
  __decorate([
119
119
  (0, swagger_1.ApiPropertyOptional)({
@@ -25,9 +25,9 @@ export declare class UserDto {
25
25
  prog?: number;
26
26
  numRep?: number;
27
27
  idxPers?: number;
28
- codiceClienteSuper?: string;
29
- codiceAge?: string;
30
- codiceClienteCol?: string;
28
+ codiceClienteSuper?: number;
29
+ codiceAge?: number;
30
+ codiceClienteCol?: number;
31
31
  codiceClienti?: string;
32
- tipoFil?: string;
32
+ tipoFil?: number;
33
33
  }
@@ -114,16 +114,16 @@ __decorate([
114
114
  __metadata("design:type", Number)
115
115
  ], UserDto.prototype, "idxPers", void 0);
116
116
  __decorate([
117
- (0, swagger_1.ApiPropertyOptional)({ description: "Codice cliente super.", example: "CLI001" }),
118
- __metadata("design:type", String)
117
+ (0, swagger_1.ApiPropertyOptional)({ description: "Codice cliente super.", example: 123 }),
118
+ __metadata("design:type", Number)
119
119
  ], UserDto.prototype, "codiceClienteSuper", void 0);
120
120
  __decorate([
121
- (0, swagger_1.ApiPropertyOptional)({ description: "Codice agente.", example: "AGT456" }),
122
- __metadata("design:type", String)
121
+ (0, swagger_1.ApiPropertyOptional)({ description: "Codice agente.", example: 123 }),
122
+ __metadata("design:type", Number)
123
123
  ], UserDto.prototype, "codiceAge", void 0);
124
124
  __decorate([
125
- (0, swagger_1.ApiPropertyOptional)({ description: "Codice cliente collettivo.", example: "CLCOL789" }),
126
- __metadata("design:type", String)
125
+ (0, swagger_1.ApiPropertyOptional)({ description: "Codice cliente collettivo.", example: 123 }),
126
+ __metadata("design:type", Number)
127
127
  ], UserDto.prototype, "codiceClienteCol", void 0);
128
128
  __decorate([
129
129
  (0, swagger_1.ApiPropertyOptional)({ description: "Codici multipli clienti.", example: "CLI001, CLI002" }),
@@ -131,5 +131,5 @@ __decorate([
131
131
  ], UserDto.prototype, "codiceClienti", void 0);
132
132
  __decorate([
133
133
  (0, swagger_1.ApiPropertyOptional)({ description: "Tipo di filiale.", example: "HQ" }),
134
- __metadata("design:type", String)
134
+ __metadata("design:type", Number)
135
135
  ], UserDto.prototype, "tipoFil", void 0);
@@ -27,6 +27,7 @@ export declare class UserService {
27
27
  private executeInTransaction;
28
28
  register(registrationData: RegisterRequest): Promise<string>;
29
29
  updateUser(codiceUtente: number, user: UserDto): Promise<void>;
30
+ updateUserFilters(codiceUtente: number, user: UserDto): Promise<void>;
30
31
  deleteUser(codiceCliente: number): Promise<void>;
31
32
  setStato(codiceCliente: number, statoRegistrazione: StatoRegistrazione): Promise<void>;
32
33
  setGdpr(codiceUtente: number): Promise<any>;
@@ -178,9 +178,9 @@ let UserService = class UserService {
178
178
  const fieldMapping = {
179
179
  numeroReport: { dbField: 'NUMREP', type: 'number' },
180
180
  indicePersonale: { dbField: 'IDXPERS', type: 'number' },
181
- codiceClienteSuper: { dbField: 'CODCLISUPER', type: 'string' },
182
- codiceAgenzia: { dbField: 'CODAGE', type: 'string' },
183
- codiceClienteCollegato: { dbField: 'CODCLICOL', type: 'string' },
181
+ codiceClienteSuper: { dbField: 'CODCLISUPER', type: 'number' },
182
+ codiceAgenzia: { dbField: 'CODAGE', type: 'number' },
183
+ codiceClienteCollegato: { dbField: 'CODCLICOL', type: 'number' },
184
184
  codiceClienti: { dbField: 'CODCLIENTI', type: 'string' },
185
185
  tipoFiltro: { dbField: 'TIPFIL', type: 'string' },
186
186
  };
@@ -346,13 +346,66 @@ let UserService = class UserService {
346
346
  if (!!user.permissions && user.permissions.length > 0) {
347
347
  yield this.permissionService.assignPermissionsToUser(codiceUtente, user.permissions);
348
348
  }
349
- yield this.insertUserFilters(codiceUtente, user);
349
+ yield this.updateUserFilters(codiceUtente, user);
350
350
  }
351
351
  catch (error) {
352
352
  throw error;
353
353
  }
354
354
  });
355
355
  }
356
+ updateUserFilters(codiceUtente, user) {
357
+ return __awaiter(this, void 0, void 0, function* () {
358
+ try {
359
+ if (!codiceUtente || codiceUtente <= 0) {
360
+ throw new Error('Codice utente non valido');
361
+ }
362
+ const fieldMapping = {
363
+ numRep: { dbField: 'NUMREP', type: 'number' },
364
+ idxPers: { dbField: 'IDXPERS', type: 'number' },
365
+ codCliSuper: { dbField: 'CODCLISUPER', type: 'number' },
366
+ codAge: { dbField: 'CODAGE', type: 'number' },
367
+ codCliCol: { dbField: 'CODCLICOL', type: 'number' },
368
+ codiceClienti: { dbField: 'CODCLIENTI', type: 'string' },
369
+ tipFil: { dbField: 'TIPFIL', type: 'string' },
370
+ };
371
+ const fieldsToUpdate = Object.entries(fieldMapping)
372
+ .filter(([tsField]) => {
373
+ const value = user[tsField];
374
+ return value !== undefined && value !== null && value !== '';
375
+ })
376
+ .map(([tsField, config]) => {
377
+ const value = user[tsField];
378
+ if (config.type === 'number' && typeof value !== 'number') {
379
+ throw new Error(`Il campo ${tsField} deve essere un numero`);
380
+ }
381
+ if (config.type === 'string' && typeof value !== 'string') {
382
+ throw new Error(`Il campo ${tsField} deve essere una stringa`);
383
+ }
384
+ return { tsField, dbField: config.dbField, value };
385
+ });
386
+ if (fieldsToUpdate.length === 0) {
387
+ return;
388
+ }
389
+ yield this.executeInTransaction(() => __awaiter(this, void 0, void 0, function* () {
390
+ const updates = fieldsToUpdate.map((f) => `${f.dbField} = ?`).join(', ');
391
+ const values = [...fieldsToUpdate.map((f) => f.value), codiceUtente];
392
+ const updateQuery = `UPDATE FILTRI SET ${updates} WHERE CODUTE = ?`;
393
+ const result = yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, updateQuery, values);
394
+ // If no record was updated, we need to insert a new one
395
+ if (!result) {
396
+ const dbFields = ['CODUTE', ...fieldsToUpdate.map((f) => f.dbField)];
397
+ const placeholders = dbFields.map(() => '?');
398
+ const insertValues = [codiceUtente, ...fieldsToUpdate.map((f) => f.value)];
399
+ const insertQuery = `INSERT INTO FILTRI (${dbFields.join(', ')}) VALUES (${placeholders.join(', ')})`;
400
+ yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, insertQuery, insertValues);
401
+ }
402
+ }));
403
+ }
404
+ catch (error) {
405
+ throw new Error(`Errore durante l'aggiornamento dei filtri per utente ${codiceUtente}: ${error.message}`);
406
+ }
407
+ });
408
+ }
356
409
  deleteUser(codiceCliente) {
357
410
  return __awaiter(this, void 0, void 0, function* () {
358
411
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emilsoftware-utilities",
3
- "version": "1.4.0-dev.14",
3
+ "version": "1.4.0-dev.15",
4
4
  "description": "Utilities for EmilSoftware",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",