PageSourceSearch

https://dgac.gob.gt/assets/vehicleService-XApui8X4.js

js dgac.gob.gt collected 2026-10-02 11:17:54 UTC 4,684 bytes, 1 lines download raw bytes

1import{f as s,g as d,n as p,c3 as E,$ as g}from"./index-DVu_w4ho.js";import{d as y}from"./duplicateGuardService-Bau-AUQB.js";const m=async(e,o)=>{try{return await e()}catch(t){if(!navigator.onLine||(t==null?void 0:t.code)==="ECONNABORTED"||(t==null?void 0:t.message)==="Network Error"||t instanceof TypeError||typeof(t==null?void 0:t.message)=="string"&&t.message.toLowerCase().includes("failed to fetch")){console.log("📴 Sin red — encolando:",o.description);try{await g.addOperation({url:o.url,method:o.method,body:o.body,headers:d(),entityType:o.entityType,entityId:o.entityId,action:o.action,description:o.description,maxRetries:3})}catch(c){console.error("❌ Error guardando offline:",c)}return{success:!0,offline:!0,data:o.optimisticData??o.body??{},message:`${o.description} — Se sincronizará cuando vuelva la conexión`}}throw t}},u=e=>({...e,"Cache-Control":"no-store",Pragma:"no-cache",Expires:"0"}),w=e=>{const o=e.includes("?")?"&":"?";return`${e}${o}_ts=${Date.now()}`},S=e=>e?Array.isArray(e)?e:Array.isArray(e.data)?e.data:e.data?[e.data]:[]:[],h=e=>e?e.attributes?{id:e.id,...e.attributes}:e:null,$=e=>e&&typeof e=="object"&&"data"in e?e:{data:e},v=async(e,o)=>{const t=String(o||"").trim();if(!t||!/^\d+$/.test(t)&&t.length>=16)return t;try{const r=w(s(`${e}?filters[id][$eq]=${t}&fields[0]=documentId`)),c=await fetch(r,{headers:u(d())});if(c.ok){const n=await c.json(),i=(n==null?void 0:n.data)||n,a=Array.isArray(i)?i[0]:i,l=a==null?void 0:a.documentId;if(l)return String(l)}}catch(r){console.warn(`[vehicleService] No se pudo resolver documentId para ${e}/${t}:`,r)}return t},T={async getAll(e){var f;const{page:o=1,pageSize:t=25,search:r}=e||{};let c=`populate[0]=planned_routes&populate[1]=licencia&sort=createdAt:desc&pagination[page]=${o}&pagination[pageSize]=${t}`;r&&(c+=`&filters[$or][0][nombre][$containsi]=${encodeURIComponent(r)}&filters[$or][1][placa][$containsi]=${encodeURIComponent(r)}`);const n=w(E(s(`vehiculos?${c}`))),i=await fetch(n,{headers:u(d()),cache:"no-store"});if(!i.ok)throw new Error("No se pudieron cargar los vehículos");const a=await i.json(),l=S(a).map(h),I=((f=a==null?void 0:a.meta)==null?void 0:f.pagination)||(a==null?void 0:a.pagination)||{page:o,pageSize:t,total:l.length,pageCount:1};return{data:l,pagination:I}},async getById(e){const o=await v("vehiculos",e),t=w(s(`vehiculos/${o}?populate[0]=planned_routes&populate[1]=licencia`)),r=await fetch(t,{headers:u(d()),cache:"no-store"});if(!r.ok)throw new Error("No se pudo cargar el vehículo");const c=await r.json();return h(c.data||c)},async create(e){if((await y.exists({endpoint:"vehiculos",field:"placa",value:e==null?void 0:e.placa,caseInsensitive:!1})).exists)throw new Error("Ya existe un vehículo con esa placa");const t=$(e),r=await m(async()=>{const c=await fetch(s("vehiculos"),{method:"POST",headers:u(d()),body:JSON.stringify(t)});if(!c.ok)throw new Error("No se pudo crear el vehículo");const n=await c.json();return h(n.data||n)},{url:s("vehiculos"),method:"POST",body:t,entityType:"vehiculo",action:"create",description:"Crear vehículo",optimisticData:e});return r&&typeof r=="object"&&"offline"in r?r.data:(p({moduleName:"Vehículo",action:"created",record:r,recordId:(r==null?void 0:r.documentId)||(r==null?void 0:r.id),route:`/vehicle/${(r==null?void 0:r.documentId)||(r==null?void 0:r.id)}`,payload:e}),r)},async update(e,o){const t=await v("vehiculos",e);if((await y.exists({endpoint:"vehiculos",field:"placa",value:o==null?void 0:o.placa,excludeDocumentId:t,caseInsensitive:!1})).exists)throw new Error("Ya existe un vehículo con esa placa");const c=$(o),n=await m(async()=>{const i=await fetch(s(`vehiculos/${t}`),{method:"PUT",headers:u(d()),body:JSON.stringify(c)});if(!i.ok)throw new Error("No se pudo actualizar el vehículo");const a=await i.json();return h(a.data||a)},{url:s(`vehiculos/${t}`),method:"PUT",body:c,entityType:"vehiculo",entityId:t,action:"update",description:"Actualizar vehículo",optimisticData:o});return n&&typeof n=="object"&&"offline"in n?n.data:(p({moduleName:"Vehículo",action:"updated",record:n,recordId:(n==null?void 0:n.documentId)||t,route:`/vehicle/${(n==null?void 0:n.documentId)||t}`,payload:o}),n)},async delete(e){const o=await v("vehiculos",e),t=await m(async()=>
1{if(!(await fetch(s(`vehiculos/${o}`),{method:"DELETE",headers:u(d())})).ok)throw new Error("No se pudo eliminar el vehículo");return!0},{url:s(`vehiculos/${o}`),method:"DELETE",entityType:"vehiculo",entityId:o,action:"delete",description:"Eliminar vehículo"});return t&&typeof t=="object"&&"offline"in t?!0:(p({moduleName:"Vehículo",action:"deleted",record:{documentId:o},recordId:o,payload:{eliminado:!0}}),t)}};export{T as v};

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.