PageSourceSearch

https://girardota.gov.co/SiteAssets/V3/assets/Componentes/maintramites/js/main/services.js

js girardota.gov.co collected 2026-10-01 13:02:22 UTC 3,386 bytes, 113 lines download raw bytes

1// Ingrese en el objeto los parametros que va a consultar de la lista
2const nombreSitio = "atencion-y-servicio-a-la-ciudadania";
3const nombreBiblioteca = "TramitesyServicios";
4
5const parametros = {
6  id: "ID",
7  titleTramite: "Title",
8  Dependencia: "Dependencia",
9  Recaudo: "Recaudo",
10  urlTramite: "Tr_x00e1_mite_x0020_Online",
11  suit: "Categor_x00ed_a_x0020_SUIT",
12  descripcion: "Descripcion",
13  activo: "activo",
14  duracionTramite: "duracionTramite",
15  type: "TipoTramite"
16};
17
18const URL_API = `${location.protocol}//${location.host}/${nombreSitio}/_api/web/lists/getbytitle('${nombreBiblioteca}')/items?$select=${parametros.id},${parametros.titleTramite},${parametros.Dependencia},${parametros.Recaudo},${parametros.urlTramite},${parametros.suit},${parametros.descripcion},${parametros.activo},${parametros.duracionTramite},${parametros.type}`;
19
20export const getData = async () => {
21  try {
22    const response = await fetch(URL_API, {
23      method: "GET",
24      headers: {
25        Accept: "application/json; odata=verbose",
26      },
27    });
28    const data = await response.json();
29
30    let tramites = [];
31    let filters = [];
32    if (data?.d?.results?.length != 0) {
33      tramites = formarterData(data.d.results);
34      filters = fillFilters(data.d.results);
35    }
36
37    return [tramites, filters];
38  } catch (error) {
39    console.log(error);
40    return [[], []];
41  }
42};
43
44function formarterData(array) {
45  let tram = [];
46
47  array.forEach((item) => {
48    const newTra = {
49      id: Number(item.ID),
50      title: item?.Title ? item.Title.trim() : "Sin título",
51      description: formatDescription(item["Descripcion"]),
52      type: obtaintype(item["TipoTramite"]),
53      duration: item.duracionTramite,
54      active: item.activo,
55      url: item["Tr_x00e1_mite_x0020_Online"]?.Url ? item["Tr_x00e1_mite_x0020_Online"].Url : "",
56      cost: obtainCost(item["Recaudo"]),
57      dependencia: item.Dependencia,
58      suit: item["Categor_x00ed_a_x0020_SUIT"]?.Description ? item["Categor_x00ed_a_x0020_SUIT"].Description : "",
59    };
60    tram.push(newTra);
61  });
62
63  return tram;
64}
65
66function formatDescription(rawDescripcion) {
67  if (!rawDescripcion) return "Sin descripción";
68  let tempDiv = document.createElement("div");
69  tempDiv.innerHTML = rawDescripcion;
70  return tempDiv.textContent || tempDiv.innerText || "";
71}
72
73function obtaintype(type) {
74  if (!type) return -1;
75  
76  const tramiteType = [
77    "Trámite Online",
78    "Trámite parcialmente en línea",
79    "Trámite presencial",
80  ];
81  
82  let indexR = -1;
83  tramiteType.forEach((item, index) => {
84    if (item.toLowerCase() === type.toString().trim().toLowerCase()) {
85      indexR = index;
86    }
87  });
88
89  return indexR;
90}
91
92function obtainCost(cost) {
93  if (!cost) return 2; // No definido si viene null o vacío
94
95  const normalizedCost = cost.toString().trim().toLowerCase();
96
97  if (normalizedCost === "si") return 0; // Mapea a index 0
98  if (normalizedCost === "no") return 1; // Mapea a index 1
99  
100  return 2; // "No definido" por defecto para cualquier otro valor
101}
102
103function fillFilters(array) {
104  let filt = [];
105  if (array.length != 0) {
106    array.forEach((item) => {
107      if (item.Dependencia && !filt.includes(item.Dependencia)) {
108        filt.push(item.Dependencia);
109      }
110    });
111  }
112  return filt;
113}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.