ngx-dsxlibrary 1.21.40 → 1.21.41

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.
@@ -2867,6 +2867,58 @@ class UtilityAddService {
2867
2867
  this._serviceAlerta.toastrAlerts(4, 'Error', error instanceof Error ? error.message : String(error), 2);
2868
2868
  }
2869
2869
  }
2870
+ /**
2871
+ * Maneja la respuesta estándar de una operación HTTP que devuelve un ServiceResult<T>,
2872
+ * mostrando alertas y realizando acciones comunes en formularios.
2873
+ *
2874
+ * @typeParam T - Tipo de dato contenido en la propiedad data de ServiceResult.
2875
+ * @param response - Respuesta del servicio (debe tener isSuccess, title, message, etc.).
2876
+ * @param urlHome - Ruta a la que se navega si la operación es exitosa y el id es mayor a 0.
2877
+ * @param form - Formulario reactivo a resetear si la operación es exitosa.
2878
+ * @param getForm - Función para recargar el formulario (por ejemplo, para obtener datos actualizados).
2879
+ * @param id - Identificador usado para decidir si se navega a urlHome tras éxito.
2880
+ *
2881
+ * @example
2882
+ * // Uso típico en un componente con ServiceResult
2883
+ * this.utilityAddService.handleResponseService<MiModelo>(
2884
+ * response,
2885
+ * '/home',
2886
+ * this.form,
2887
+ * () => this.getForm(),
2888
+ * this.id
2889
+ * );
2890
+ *
2891
+ * @description
2892
+ * - Si response.isSuccess es true:
2893
+ * - Muestra alerta tipo toastr.
2894
+ * - Si id > 0, navega a urlHome.
2895
+ * - Resetea el formulario y ejecuta getForm().
2896
+ * - Si response.isSuccess es false:
2897
+ * - Muestra alerta visual personalizada con icono de error.
2898
+ */
2899
+ handleResponseService(response, urlHome, form, getForm, id) {
2900
+ try {
2901
+ this.logIfNotProduction('handleResponse - response:', response);
2902
+ if (response.isSuccess) {
2903
+ this._serviceAlerta.toastrAlerts(1, response.title, response.message, 2);
2904
+ if (id > 0) {
2905
+ this._router.navigate([urlHome]);
2906
+ }
2907
+ getForm();
2908
+ form?.reset();
2909
+ }
2910
+ else {
2911
+ this._serviceAlerta.alertaHtmlSuccess(response.title, response.message, {
2912
+ icono: 'icon2/hard_drive_error.png',
2913
+ showConfirmButton: true,
2914
+ });
2915
+ }
2916
+ }
2917
+ catch (error) {
2918
+ this.logIfNotProduction('Error en handleResponseService:', error);
2919
+ this._serviceAlerta.toastrAlerts(4, 'Error', error instanceof Error ? error.message : String(error), 2);
2920
+ }
2921
+ }
2870
2922
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: UtilityAddService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
2871
2923
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: UtilityAddService, providedIn: 'root' });
2872
2924
  }