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

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.
@@ -387,12 +387,21 @@ let UserService = class UserService {
387
387
  return;
388
388
  }
389
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) {
390
+ // Prima verifichiamo se esiste il record
391
+ const checkQuery = `SELECT COUNT(*) as CNT FROM FILTRI WHERE CODUTE = ?`;
392
+ const existingRecord = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, checkQuery, [
393
+ codiceUtente,
394
+ ]);
395
+ const exists = existingRecord[0].CNT > 0;
396
+ if (exists) {
397
+ // Se esiste, facciamo l'UPDATE
398
+ const updates = fieldsToUpdate.map((f) => `${f.dbField} = ?`).join(', ');
399
+ const values = [...fieldsToUpdate.map((f) => f.value), codiceUtente];
400
+ const updateQuery = `UPDATE FILTRI SET ${updates} WHERE CODUTE = ?`;
401
+ yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, updateQuery, values);
402
+ }
403
+ else {
404
+ // Se non esiste, facciamo l'INSERT
396
405
  const dbFields = ['CODUTE', ...fieldsToUpdate.map((f) => f.dbField)];
397
406
  const placeholders = dbFields.map(() => '?');
398
407
  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.16",
4
4
  "description": "Utilities for EmilSoftware",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",