tailjng 0.0.57 → 0.0.59

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.
@@ -27,7 +27,7 @@ Authors:
27
27
  License:
28
28
  This project is licensed under the BSD 3-Clause - see the LICENSE file for more details.
29
29
 
30
- Version: 0.0.57
30
+ Version: 0.0.59
31
31
  Creation Date: 2025-01-04
32
32
  ===============================================`
33
33
 
@@ -938,6 +938,17 @@ class JGenericCrudService {
938
938
  this.paramsHttpService = paramsHttpService;
939
939
  this.converterCrudService = converterCrudService;
940
940
  }
941
+ /**
942
+ * Method to build the URL for the request.
943
+ * @param urlBase Base URL for the request.
944
+ * @param endpoint Distinctive of the endpoint ('role', 'status', etc.)
945
+ * @param id Identifier of the record (optional).
946
+ * @returns
947
+ */
948
+ buildUrl(urlBase, endpoint, id) {
949
+ const baseUrl = urlBase ? `${urlBase}/${endpoint}` : `${this.config.urlBase}/${endpoint}`;
950
+ return id !== undefined && id !== null ? `${baseUrl}/${id}` : baseUrl;
951
+ }
941
952
  /**
942
953
  * Method to get all records from an endpoint.
943
954
  * @param urlBase Base URL for the request.
@@ -946,7 +957,7 @@ class JGenericCrudService {
946
957
  * @returns Observable with the API response.
947
958
  */
948
959
  findAll({ urlBase, endpoint, params }) {
949
- const url = urlBase ? `${urlBase}/${endpoint}` : `${this.config.urlBase}/${endpoint}`;
960
+ const url = this.buildUrl(urlBase, endpoint);
950
961
  let httpParams;
951
962
  if (params)
952
963
  httpParams = this.paramsHttpService.resParams(params);
@@ -960,8 +971,22 @@ class JGenericCrudService {
960
971
  * @returns Observable with the API response.
961
972
  */
962
973
  findOne({ urlBase, endpoint, id }) {
963
- const url = urlBase ? `${urlBase}/${endpoint}` : `${this.config.urlBase}/${endpoint}`;
964
- return this.http.get(`${url}/${id}`).pipe(map(response => response.data[endpoint]));
974
+ const url = this.buildUrl(urlBase, endpoint, id);
975
+ return this.http.get(url).pipe(map(response => response.data[endpoint]));
976
+ }
977
+ /**
978
+ * Method to count the records of an endpoint.
979
+ * @param urlBase Base URL for the request.
980
+ * @param endpoint Distinctive of the endpoint ('role', 'status', etc.)
981
+ * @param params Parameters of the request.
982
+ * @returns Observable with the API response.
983
+ */
984
+ count({ urlBase, endpoint, params }) {
985
+ const url = this.buildUrl(urlBase, endpoint);
986
+ let httpParams;
987
+ if (params)
988
+ httpParams = this.paramsHttpService.resParams(params);
989
+ return this.http.get(`${url}/count`, { params: httpParams });
965
990
  }
966
991
  /**
967
992
  * Method to create a record in an endpoint.
@@ -971,7 +996,7 @@ class JGenericCrudService {
971
996
  * @returns Observable with the API response.
972
997
  */
973
998
  create({ urlBase, endpoint, data }) {
974
- const url = urlBase ? `${urlBase}/${endpoint}` : `${this.config.urlBase}/${endpoint}`;
999
+ const url = this.buildUrl(urlBase, endpoint);
975
1000
  return this.http.post(url, data);
976
1001
  }
977
1002
  /**
@@ -983,8 +1008,20 @@ class JGenericCrudService {
983
1008
  * @returns Observable with the API response.
984
1009
  */
985
1010
  update({ urlBase, endpoint, id, data }) {
986
- const url = urlBase ? `${urlBase}/${endpoint}` : `${this.config.urlBase}/${endpoint}`;
987
- return this.http.put(`${url}/${id}`, data);
1011
+ const url = this.buildUrl(urlBase, endpoint, id);
1012
+ return this.http.put(url, data);
1013
+ }
1014
+ /**
1015
+ * Method to partially update a record in an endpoint.
1016
+ * @param urlBase Base URL for the request.
1017
+ * @param endpoint Distinctive of the endpoint ('role', 'status', etc.)
1018
+ * @param id Identifier of the record.
1019
+ * @param data Data of the record to update.
1020
+ * @returns Observable with the API response.
1021
+ */
1022
+ patch({ urlBase, endpoint, id, data }) {
1023
+ const url = this.buildUrl(urlBase, endpoint, id);
1024
+ return this.http.patch(url, data);
988
1025
  }
989
1026
  /**
990
1027
  * Method to delete a record from an endpoint.
@@ -993,21 +1030,21 @@ class JGenericCrudService {
993
1030
  * @param id Identifier of the record.
994
1031
  * @returns Observable with the API response.
995
1032
  */
996
- delete({ urlBase, endpoint, id }) {
997
- const url = urlBase ? `${urlBase}/${endpoint}` : `${this.config.urlBase}/${endpoint}`;
998
- return this.http.delete(`${url}/${id}`);
1033
+ delete({ urlBase, endpoint, id, data }) {
1034
+ const url = this.buildUrl(urlBase, endpoint, id);
1035
+ return this.http.delete(url, { body: data });
999
1036
  }
1000
1037
  /**
1001
1038
  * Method to update the status of a record in an endpoint.
1002
- * @param urlBase Base URL for the request.
1039
+ * @param urlBase Base URL for the request.
1003
1040
  * @param endpoint Distinctive of the endpoint ('role', 'status', etc.)
1004
1041
  * @param id Identifier of the record.
1005
1042
  * @param data Data of a boolean record to update.
1006
1043
  * @returns Observable with the API response.
1007
1044
  */
1008
1045
  toggle({ urlBase, endpoint, id, data }) {
1009
- const url = urlBase ? `${urlBase}/${endpoint}` : `${this.config.urlBase}/${endpoint}`;
1010
- return this.http.patch(`${url}/toggle/${id}`, data);
1046
+ const url = this.buildUrl(urlBase, `${endpoint}/toggle`, id);
1047
+ return this.http.patch(url, data);
1011
1048
  }
1012
1049
  /**
1013
1050
  * Method to create multiple records in an endpoint.
@@ -1017,7 +1054,7 @@ class JGenericCrudService {
1017
1054
  * @returns Observable with the API response.
1018
1055
  */
1019
1056
  createMany({ urlBase, endpoint, data }) {
1020
- const url = urlBase ? `${urlBase}/${endpoint}/bulk` : `${this.config.urlBase}/${endpoint}/bulk`;
1057
+ const url = this.buildUrl(urlBase, `${endpoint}/bulk`);
1021
1058
  return this.http.post(url, data);
1022
1059
  }
1023
1060
  /**