ngx-dsxlibrary 1.21.40 → 1.21.42
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.
|
@@ -2308,21 +2308,63 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
|
|
|
2308
2308
|
}]
|
|
2309
2309
|
}] });
|
|
2310
2310
|
|
|
2311
|
+
/**
|
|
2312
|
+
* Servicio genérico para consumir endpoints REST de la API.
|
|
2313
|
+
*
|
|
2314
|
+
* @typeParam T Tipo de dato que representa el recurso manejado por el endpoint.
|
|
2315
|
+
*/
|
|
2311
2316
|
class EndpointService {
|
|
2317
|
+
/** Cliente HTTP de Angular utilizado para realizar las peticiones. */
|
|
2312
2318
|
http = inject(HttpClient);
|
|
2319
|
+
/** Configuración de entorno que contiene la URL base de la API. */
|
|
2313
2320
|
environment = inject(ENVIRONMENT);
|
|
2321
|
+
/**
|
|
2322
|
+
* Construye la URL completa del endpoint a partir de la configuración de entorno.
|
|
2323
|
+
*
|
|
2324
|
+
* @param endpoint Segmento del endpoint (por ejemplo: 'usuarios', 'facturas').
|
|
2325
|
+
* @returns URL absoluta del endpoint.
|
|
2326
|
+
*/
|
|
2314
2327
|
getUrl(endpoint) {
|
|
2315
2328
|
return `${this.environment.myAppUrl}api/${endpoint}`;
|
|
2316
2329
|
}
|
|
2330
|
+
/**
|
|
2331
|
+
* Obtiene un listado de recursos del endpoint especificado.
|
|
2332
|
+
*
|
|
2333
|
+
* @param endpoint Segmento del endpoint (sin la parte de `api/`).
|
|
2334
|
+
* @param invalidateCache Indica si se invalida la caché del lado del servidor.
|
|
2335
|
+
* @returns Observable con un arreglo de elementos del tipo `T`.
|
|
2336
|
+
*/
|
|
2317
2337
|
list(endpoint, invalidateCache = false) {
|
|
2318
2338
|
return this.http.get(`${this.getUrl(endpoint)}/listar/${invalidateCache}`);
|
|
2319
2339
|
}
|
|
2340
|
+
/**
|
|
2341
|
+
* Obtiene un recurso por su identificador.
|
|
2342
|
+
*
|
|
2343
|
+
* @param endpoint Segmento del endpoint (sin la parte de `api/`).
|
|
2344
|
+
* @param id Identificador del recurso a recuperar.
|
|
2345
|
+
* @returns Observable con el elemento del tipo `T`.
|
|
2346
|
+
*/
|
|
2320
2347
|
edit(endpoint, id) {
|
|
2321
2348
|
return this.http.get(`${this.getUrl(endpoint)}/get-id/${id}`);
|
|
2322
2349
|
}
|
|
2350
|
+
/**
|
|
2351
|
+
* Crea o actualiza un recurso en el endpoint especificado.
|
|
2352
|
+
*
|
|
2353
|
+
* @param endpoint Segmento del endpoint (sin la parte de `api/`).
|
|
2354
|
+
* @param values Objeto con los datos del recurso a guardar.
|
|
2355
|
+
* @returns Observable con el resultado del servicio que envuelve al tipo `T`.
|
|
2356
|
+
*/
|
|
2323
2357
|
save(endpoint, values) {
|
|
2324
2358
|
return this.http.put(`${this.getUrl(endpoint)}/save`, values);
|
|
2325
2359
|
}
|
|
2360
|
+
/**
|
|
2361
|
+
* Elimina un recurso del endpoint especificado.
|
|
2362
|
+
*
|
|
2363
|
+
* @param endpoint Segmento del endpoint (sin la parte de `api/`).
|
|
2364
|
+
* @param id Identificador del recurso a eliminar.
|
|
2365
|
+
* @param softDelete Indica si la eliminación es lógica (por defecto) o física.
|
|
2366
|
+
* @returns Observable con el modelo de respuesta HTTP genérico.
|
|
2367
|
+
*/
|
|
2326
2368
|
delete(endpoint, id, softDelete = true) {
|
|
2327
2369
|
return this.http.delete(`${this.getUrl(endpoint)}/delete/${id}/${softDelete}`);
|
|
2328
2370
|
}
|
|
@@ -2867,6 +2909,58 @@ class UtilityAddService {
|
|
|
2867
2909
|
this._serviceAlerta.toastrAlerts(4, 'Error', error instanceof Error ? error.message : String(error), 2);
|
|
2868
2910
|
}
|
|
2869
2911
|
}
|
|
2912
|
+
/**
|
|
2913
|
+
* Maneja la respuesta estándar de una operación HTTP que devuelve un ServiceResult<T>,
|
|
2914
|
+
* mostrando alertas y realizando acciones comunes en formularios.
|
|
2915
|
+
*
|
|
2916
|
+
* @typeParam T - Tipo de dato contenido en la propiedad data de ServiceResult.
|
|
2917
|
+
* @param response - Respuesta del servicio (debe tener isSuccess, title, message, etc.).
|
|
2918
|
+
* @param urlHome - Ruta a la que se navega si la operación es exitosa y el id es mayor a 0.
|
|
2919
|
+
* @param form - Formulario reactivo a resetear si la operación es exitosa.
|
|
2920
|
+
* @param getForm - Función para recargar el formulario (por ejemplo, para obtener datos actualizados).
|
|
2921
|
+
* @param id - Identificador usado para decidir si se navega a urlHome tras éxito.
|
|
2922
|
+
*
|
|
2923
|
+
* @example
|
|
2924
|
+
* // Uso típico en un componente con ServiceResult
|
|
2925
|
+
* this.utilityAddService.handleResponseService<MiModelo>(
|
|
2926
|
+
* response,
|
|
2927
|
+
* '/home',
|
|
2928
|
+
* this.form,
|
|
2929
|
+
* () => this.getForm(),
|
|
2930
|
+
* this.id
|
|
2931
|
+
* );
|
|
2932
|
+
*
|
|
2933
|
+
* @description
|
|
2934
|
+
* - Si response.isSuccess es true:
|
|
2935
|
+
* - Muestra alerta tipo toastr.
|
|
2936
|
+
* - Si id > 0, navega a urlHome.
|
|
2937
|
+
* - Resetea el formulario y ejecuta getForm().
|
|
2938
|
+
* - Si response.isSuccess es false:
|
|
2939
|
+
* - Muestra alerta visual personalizada con icono de error.
|
|
2940
|
+
*/
|
|
2941
|
+
handleResponseService(response, urlHome, form, getForm, id) {
|
|
2942
|
+
try {
|
|
2943
|
+
this.logIfNotProduction('handleResponse - response:', response);
|
|
2944
|
+
if (response.isSuccess) {
|
|
2945
|
+
this._serviceAlerta.toastrAlerts(1, response.title, response.message, 2);
|
|
2946
|
+
if (id > 0) {
|
|
2947
|
+
this._router.navigate([urlHome]);
|
|
2948
|
+
}
|
|
2949
|
+
getForm();
|
|
2950
|
+
form?.reset();
|
|
2951
|
+
}
|
|
2952
|
+
else {
|
|
2953
|
+
this._serviceAlerta.alertaHtmlSuccess(response.title, response.message, {
|
|
2954
|
+
icono: 'icon2/hard_drive_error.png',
|
|
2955
|
+
showConfirmButton: true,
|
|
2956
|
+
});
|
|
2957
|
+
}
|
|
2958
|
+
}
|
|
2959
|
+
catch (error) {
|
|
2960
|
+
this.logIfNotProduction('Error en handleResponseService:', error);
|
|
2961
|
+
this._serviceAlerta.toastrAlerts(4, 'Error', error instanceof Error ? error.message : String(error), 2);
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2870
2964
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: UtilityAddService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2871
2965
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: UtilityAddService, providedIn: 'root' });
|
|
2872
2966
|
}
|