emilsoftware-utilities 1.6.1-dev.1 → 1.6.1-dev.2

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.
@@ -51,11 +51,16 @@ let PermissionService = class PermissionService {
51
51
  }
52
52
  updateOrInsertRole(role_1) {
53
53
  return __awaiter(this, arguments, void 0, function* (role, codiceRuolo = null) {
54
+ var _a, _b, _c, _d, _e;
54
55
  // creazione nuovo ruolo
55
56
  if (!codiceRuolo) {
56
- let createRoleQuery = `INSERT INTO RUOLI (DESRUO) VALUES (?) RETURNING CODRUO`;
57
- let result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, createRoleQuery, [role.descrizioneRuolo]);
58
- codiceRuolo = result[0].CODRUO;
57
+ const createRoleQuery = `INSERT INTO RUOLI (DESRUO) VALUES (?)`;
58
+ yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, createRoleQuery, [role.descrizioneRuolo]);
59
+ const createdRoleResult = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, 'SELECT FIRST 1 CODRUO FROM RUOLI WHERE DESRUO = ? ORDER BY CODRUO DESC', [role.descrizioneRuolo]);
60
+ codiceRuolo = (_c = (_b = (_a = createdRoleResult === null || createdRoleResult === void 0 ? void 0 : createdRoleResult[0]) === null || _a === void 0 ? void 0 : _a.CODRUO) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : (_e = (_d = createdRoleResult === null || createdRoleResult === void 0 ? void 0 : createdRoleResult[0]) === null || _d === void 0 ? void 0 : _d.codruo) === null || _e === void 0 ? void 0 : _e.toString();
61
+ if (!codiceRuolo) {
62
+ throw new Error('Creazione ruolo non riuscita: impossibile recuperare CODRUO.');
63
+ }
59
64
  }
60
65
  else
61
66
  // aggiornamento ruolo esistente
@@ -25,7 +25,7 @@ export declare class UserService {
25
25
  getUserByEmail(email: string): Promise<UserDto | null>;
26
26
  insertUserFilters(codiceUtente: number, filterData: RegisterRequest): Promise<void>;
27
27
  private executeInTransaction;
28
- register(registrationData: RegisterRequest): Promise<string>;
28
+ register(registrationData: RegisterRequest): Promise<number>;
29
29
  updateUser(codiceUtente: number, user: UserDto): Promise<void>;
30
30
  updateUserFilters(codiceUtente: number, user: UserDto): Promise<void>;
31
31
  deleteUser(codiceCliente: number): Promise<void>;
@@ -172,14 +172,14 @@ let UserService = class UserService {
172
172
  }
173
173
  // async getUserFilters(codiceUtente: number): Promise<FiltriUtente[]> {
174
174
  // const query = `
175
- // SELECT
176
- // F.PROG AS progressivo,
177
- // F.NUMREP AS numero_report,
175
+ // SELECT
176
+ // F.PROG AS progressivo,
177
+ // F.NUMREP AS numero_report,
178
178
  // F.IDXPERS AS indice_personale,
179
- // F.CODCLISUPER AS codice_cliente_super,
180
- // F.CODAGE AS cod_age,
179
+ // F.CODCLISUPER AS codice_cliente_super,
180
+ // F.CODAGE AS cod_age,
181
181
  // F.CODCLICOL AS codice_cliente_collegato,
182
- // F.CODCLIENTI AS codice_clienti,
182
+ // F.CODCLIENTI AS codice_clienti,
183
183
  // F.TIPFIL AS tipo_filtro,
184
184
  // F.IDXPOS AS idx_postazione
185
185
  // FROM FILTRI F
@@ -244,14 +244,20 @@ let UserService = class UserService {
244
244
  }
245
245
  register(registrationData) {
246
246
  return __awaiter(this, void 0, void 0, function* () {
247
+ var _a, _b, _c;
247
248
  try {
248
249
  const existingUser = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, 'SELECT CODUTE FROM UTENTI WHERE USRNAME = ?', [registrationData.email]);
249
250
  if (existingUser.length > 0) {
250
251
  throw new Error('Questa e-mail è già stata utilizzata!');
251
252
  }
252
- const queryUtenti = `INSERT INTO UTENTI (USRNAME, STAREG) VALUES (?,?) RETURNING CODUTE`;
253
+ const queryUtenti = `INSERT INTO UTENTI (USRNAME, STAREG) VALUES (?,?)`;
253
254
  const paramsUtenti = [registrationData.email, StatoRegistrazione_1.StatoRegistrazione.INVIO];
254
- const codiceUtente = (yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, queryUtenti, paramsUtenti)).CODUTE;
255
+ yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtenti, paramsUtenti);
256
+ const codiceUtenteResult = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, 'SELECT FIRST 1 CODUTE FROM UTENTI WHERE USRNAME = ? ORDER BY CODUTE DESC', [registrationData.email]);
257
+ const codiceUtente = Number((_b = (_a = codiceUtenteResult === null || codiceUtenteResult === void 0 ? void 0 : codiceUtenteResult[0]) === null || _a === void 0 ? void 0 : _a.CODUTE) !== null && _b !== void 0 ? _b : (_c = codiceUtenteResult === null || codiceUtenteResult === void 0 ? void 0 : codiceUtenteResult[0]) === null || _c === void 0 ? void 0 : _c.codute);
258
+ if (!codiceUtente) {
259
+ throw new Error('Creazione utente non riuscita: impossibile recuperare CODUTE.');
260
+ }
255
261
  const utentiConfigFields = ['CODUTE', 'COGNOME', 'NOME'];
256
262
  const utentiConfigPlaceholders = ['?', '?', '?'];
257
263
  const utentiConfigParams = [codiceUtente, registrationData.cognome, registrationData.nome];
@@ -269,7 +275,7 @@ let UserService = class UserService {
269
275
  if (value !== undefined && value !== null) {
270
276
  utentiConfigFields.push(dbField);
271
277
  utentiConfigPlaceholders.push('?');
272
- utentiConfigParams.push(value);
278
+ utentiConfigParams.push(Number(value));
273
279
  }
274
280
  }
275
281
  const queryUtentiConfig = `INSERT INTO UTENTI_CONFIG (${utentiConfigFields.join(', ')}) VALUES (${utentiConfigPlaceholders.join(', ')})`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emilsoftware-utilities",
3
- "version": "1.6.1-dev.1",
3
+ "version": "1.6.1-dev.2",
4
4
  "description": "Utilities for EmilSoftware",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",