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

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.
@@ -371,7 +371,8 @@ let UserService = class UserService {
371
371
  const fieldsToUpdate = Object.entries(fieldMapping)
372
372
  .filter(([tsField]) => {
373
373
  const value = user[tsField];
374
- return value !== undefined && value !== null && value !== '';
374
+ // Includiamo il campo se è definito (anche se è una stringa vuota)
375
+ return value !== undefined && value !== null;
375
376
  })
376
377
  .map(([tsField, config]) => {
377
378
  const value = user[tsField];
@@ -387,12 +388,21 @@ let UserService = class UserService {
387
388
  return;
388
389
  }
389
390
  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) {
391
+ // Prima verifichiamo se esiste il record
392
+ const checkQuery = `SELECT COUNT(*) as CNT FROM FILTRI WHERE CODUTE = ?`;
393
+ const existingRecord = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, checkQuery, [
394
+ codiceUtente,
395
+ ]);
396
+ const exists = existingRecord[0].CNT > 0;
397
+ if (exists) {
398
+ // Se esiste, facciamo l'UPDATE
399
+ const updates = fieldsToUpdate.map((f) => `${f.dbField} = ?`).join(', ');
400
+ const values = [...fieldsToUpdate.map((f) => f.value), codiceUtente];
401
+ const updateQuery = `UPDATE FILTRI SET ${updates} WHERE CODUTE = ?`;
402
+ yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, updateQuery, values);
403
+ }
404
+ else {
405
+ // Se non esiste, facciamo l'INSERT
396
406
  const dbFields = ['CODUTE', ...fieldsToUpdate.map((f) => f.dbField)];
397
407
  const placeholders = dbFields.map(() => '?');
398
408
  const insertValues = [codiceUtente, ...fieldsToUpdate.map((f) => f.value)];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emilsoftware-utilities",
3
- "version": "1.4.0-dev.15",
3
+ "version": "1.4.0-dev.17",
4
4
  "description": "Utilities for EmilSoftware",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",