1// END TRIP 2async function endTrip(tripId) { 3 const res = await fetch(`${clientJsonUrl}`, { 4 headers: {'Content-Type': 'application/json', 'Authorization': `Bearer ${token}`}, 5 method: 'POST', 6 body: JSON.stringify({ 7 appType: 'endTrip', 8 // createdBy: userId, 9 // userId: userId, 10 // parentId: parentId, 11 tripId: tripId 12 }) 13 }) 14 15 const data = await res.json() 16 17 return data 18} 19 20// GET APPLICATIONS 21async function getApplications(parentId) { 22 const res = await fetch(`${clientJsonUrl}?appType=getApplication&parentId=${parentId}`, { 23 // headers: {'Authorization': `Bearer ${token}`} 24 credentials: "include" 25 }) 26 27 const data = await res.json() 28 29 return data 30} 31 32// GET CARGOS 33async function getCargo(status=null, cargo_id=null) { 34 console.log(cargo_id) 35 const res = await fetch(`${clientJsonUrl}?appType=getCargo${status ? `&status=${status}` : '' }${ cargo_id ? `&cargoId=${cargo_id}` : '' }`, { 36 // headers: {'Authorization': `Bearer ${token}`} 37 credentials: "include" 38 }) 39 const data = await res.json() 40 41 return data 42} 43 44// GET INVOICES 45async function getInvoices(parentId, invoiceId=null) { 46 const res = await fetch(`${clientJsonUrl}?appType=getInvoices&parentId=${parentId}${ invoiceId ? `&invoiceId=${invoiceId}` : '' }`, { 47 // headers: {'Authorization': `Bearer ${token}`} 48 credentials: "include" 49 }) 50 const data = await res.json() 51 52 return data 53} 54 55// CLIENT REGISTER 56async function register(form_data) { 57 const res = await fetch(`${clientFormDataUrl}`, { 58 method: "POST", 59 body: form_data, 60 }) 61 62 const data = await res.json() 63 64 return data 65} 66 67// GET USERS 68async function getUsers(parentId) { 69 const res = await fetch(`${clientJsonUrl}?appType=getUsers&parentId=${parentId}`, { 70 // headers: {'Authorization': `Bearer ${token}`} 71 credentials: "include" 72 }) 73 const data = await res.json() 74 75 return data 76} 77 78// REGISTER USER 79async function addUser(user) { 80 const res = await fetch(`${clientJsonUrl}`, { 81 headers: {'Content-Type': 'application/json', 'Authorization': `Bearer ${token}`}, 82 method: "POST", 83 body: JSON.stringify(user) 84 }) 85 86 const data = await res.json() 87 88 return data 89} 90 91// GET ROLES 92async function getRoles() { 93 const res = await fetch(`${clientJsonUrl}?appType=getRole`, { 94 // headers: {'Authorization': `Bearer ${token}`} 95 credentials: "include" 96 }) 97 const data = await res.json() 98 99 return data 100} 101 102// TOGGLE USER 103async function toggleUser(toggledUserId, parentId, userId, status) { 104 const res = await fetch(`${clientJsonUrl}`, { 105 headers: {'Content-Type': 'application/json', 'Authorization': `Bearer ${token}`}, 106 method: 'POST', 107 body: JSON.stringify({ 108 'appType': 'toggleUser', 109 'userId': parseInt(toggledUserId), 110 'parentId': parentId, 111 'createdBy': userId, 112 'status': status 113 }) 114 }) 115 const data = await res.json() 116 117 return data 118} 119 120// ADD CARGO 121// async function addCargo(cargo_data) { 122// const res = await fetch(`${clientJsonUrl}`, { 123// headers: {'Content-Type': 'application/json'}, 124// method: 'POST', 125// body: JSON.stringify(cargo_data) 126// }) 127 128// const data = await res.json() 129 130// return data 131// } 132 133async function addCargo(cargo_data) { 134 const res = await fetch(`${clientFormDataUrl}`, { 135 method: 'POST', 136 body: cargo_data, 137 // headers: {'Authorization': `Bearer ${token}`} 138 credentials: "include" 139 }) 140 141 const data = await res.json() 142 143 return data 144} 145 146// GET DELIVERY NOTES 147async function getDeliveryNotes(parentId, noteId=null) { 148 const res = await fetch(`${clientJsonUrl}?appType=getDelivery&parentId=${parentId}${ noteId ? `&cargoId=${noteId}` : '' }`, { 149 // headers: {'Authorization': `Bearer ${token}`} 150 credentials: "include" 151 }) 152 const data = await res.json() 153 154 return data 155} 156 157// LOGIN 158async function login(login_data) { 159 const res = await fetch(`${clientJsonUrl}`, { 160 headers: {'Content-Type': 'application/json'}, 161 method: 'POST', 162 body: JSON.stringify(login_data) 163 }) 164 165 const data = await res.json() 166 167 if (data.status == 'failed') { 168 let messages = data.message 169 let messageString = "" 170 if (typeof messages == 'object') {
171 messages.forEach(message => { 172 messageString += `${message}\n` 173 }) 174 swal("Failed to log in", messageString, "warning") 175 return false 176 } 177 178 else if (typeof messages == 'string') { 179 swal("Failed to log in", messages, "warning") 180 return false 181 } 182 } 183 184 console.debug("Passed") 185 186 return data 187} 188 189async function editCargo(cargo_data) { 190 const res = await fetch(`${clientFormDataUrl}`, { 191 method: 'POST', 192 body: cargo_data, 193 // headers: {'Authorization': `Bearer ${token}`} 194 credentials: "include" 195 }) 196 197 const data = await res.json() 198 199 return data 200} 201 202async function getContainerSizes() { 203 const res = await fetch(`${clientJsonUrl}?appType=getContainerSize`, { 204 // headers: {'Authorization': `Bearer ${token}`} 205 credentials: "include" 206 }) 207 const data = await res.json() 208 209 return data 210} 211 212async function getLocations() { 213 const res = await fetch(`${clientJsonUrl}?appType=getLocation`, { 214 // headers: {'Authorization': `Bearer ${token}`} 215 credentials: "include" 216 }) 217 const data = await res.json() 218 219 return data 220} 221 222async function checkRoute(cityOrigin, cityDest, size) { 223 const res = await fetch(`${clientJsonUrl}?appType=checkRoute&cityOrigin=${cityOrigin}&cityDest=${cityDest}&size=${size}`, { 224 // headers: {'Authorization': `Bearer ${token}`} 225 credentials: "include" 226 }) 227 const data = await res.json() 228 229 return data 230} 231 232async function getAuditLogs() { 233 const res = await fetch(`${clientJsonUrl}?appType=getAudit`, { 234 // headers: {'Authorization': `Bearer ${token}`} 235 credentials: "include" 236 }) 237 const data = await res.json() 238 239 return data 240} 241 242async function getPermissions() { 243 const res = await fetch(`${clientJsonUrl}?appType=getPermission&userType=2`, { 244 // headers: {'Authorization': `Bearer ${token}`} 245 credentials: "include" 246 }) 247 248 const data = await res.json() 249 250 return data 251} 252 253async function addRole(roleData) { 254 const res = await fetch(`${clientJsonUrl}`, { 255 headers: {'Content-Type': 'application/json' ,'Authorization': `Bearer ${token}`}, 256 method: 'POST', 257 body: JSON.stringify(roleData) 258 }) 259 260 const data = await res.json() 261 262 return data 263} 264 265async function getRoles() { 266 const res = await fetch(`${clientJsonUrl}?appType=getRole`, { 267 // headers: {'Authorization': `Bearer ${token}`} 268 credentials: "include", 269 }) 270 271 const data = await res.json() 272 273 return data 274} 275 276async function toggleRole(roleData) { 277 const res = await fetch(`${clientJsonUrl}`, { 278 headers: {'Content-Type': "application/json",'Authorization': `Bearer ${token}`}, 279 method: 'POST', 280 body: JSON.stringify(roleData) 281 }) 282 283 const data = await res.json() 284 285 return data 286} 287 288async function getSecurityQuestions() { 289 const res = await fetch(`${clientJsonUrl}?appType=getUserSecurity`, { 290 // headers: {'Authorization': `Bearer ${token}`} 291 credentials: "include", 292 }) 293 294 const data = await res.json() 295 296 return data 297} 298 299async function confirmSecurityQuestion(questionData) { 300 const res = await fetch(`${clientJsonUrl}`, { 301 headers: {'Content-Type': "application/json",'Authorization': `Bearer ${token}`}, 302 method: 'POST', 303 body: JSON.stringify(questionData) 304 }) 305 306 const data = await res.json() 307 308 return data 309} 310 311async function changePw(pwData) { 312 const res = await fetch(`${clientJsonUrl}`, { 313 headers: {'Content-Type': "application/json",'Authorization': `Bearer ${token}`}, 314 method: 'POST', 315 body: JSON.stringify(pwData) 316 }) 317 318 const data = await res.json() 319 320 return data 321} 322 323async function editUser(userData) { 324 const res = await fetch(`${clientJsonUrl}`, { 325 headers: {'Content-Type': "application/json",'Authorization': `Bearer ${token}`}, 326 method: 'POST', 327 body: JSON.stringify(userData) 328 }) 329 330 const data = await res.json() 331 332 return data 333} 334 335async function exportToPdf(url) { 336 const headers = { 337 'Content-Type': 'application/json', 338 'Authorization': `Bearer ${token}` 339 } 340 341 const res = await fetch(url, headers) 342 const data = await res.json() // post this data to template 343 344 if (data.status != 'failed') { 345 const res2 = await fetch('template_url', headers) 346 const data2 = await res2.json() 347 348 return data2 // or redirect to data 2? 349 } 350} 351 352async function getTrip(tripId) { 353 const res = await fetch(`${clientJsonUrl}
353?appType=getTrip&tripId=${tripId}`, { 354 // headers: {'Authorization': `Bearer ${token}`} 355 credentials: "include" 356 }) 357 const data = await res.json() 358 359 return data 360} 361 362async function getCurrency() { 363 const res = await fetch(`${clientJsonUrl}?appType=getCurrency`, { 364 // headers: {'Authorization': `Bearer ${token}`} 365 credentials: "include" 366 }) 367 const data = await res.json() 368 369 return data 370} 371 372async function getDocuments() { 373 const res = await fetch(`${clientJsonUrl}?appType=getDocuments`, { 374 // headers: {'Authorization': `Bearer ${token}`} 375 credentials: "include" 376 }) 377 const data = await res.json() 378 379 return data 380} 381 382async function addDocument(documentFormData) { 383 const res = await fetch(`${clientFormDataUrl}`, { 384 // headers: {'Authorization': `Bearer ${token}`} 385 credentials: "include", 386 method: 'POST', 387 body: documentFormData 388 }) 389 const data = await res.json() 390 391 return data 392} 393 394async function init_session(payload) { 395 try { 396 let formData = new FormData(); 397 for (key in payload) { 398 formData.append(key, payload[key]) 399 } 400 401 const res = await fetch(`${clientUrl}/sessions.php`, { 402 method: "POST", 403 body: formData 404 }) 405 406 const data = await res.json(); 407 408 return data; 409 } 410 411 catch(error) { 412 return {"status": "failed", "message": error.message} 413 } 414} 415 416async function getData(filterParams) { 417 try { 418 419 if (!filterParams["appType"]) { 420 throw new Error("appType is a required parameter"); 421 } 422 423 let queryParams = new URLSearchParams(filterParams).toString() 424 425 const res = await fetch(`${clientJsonUrl}?${queryParams}`, { 426 // headers: { 'Authorization': `Bearer ${token}` } 427 credentials: "include" 428 }) 429 const data = await res.json() 430 431 return data; 432 } 433 434 catch(error) { 435 return {"status": "failed", "message": error.message} 436 } 437} 438 439async function postData(payload, json=true) { 440 try { 441 if (!payload['appType']) { 442 throw new Error("appType is a required parameter"); 443 } 444 let fetchParams = { 445 headers: {'Content-Type': 'application/json'}, 446 method: 'POST', 447 body: JSON.stringify(payload) 448 }; 449 450 if (!json) { 451 let formdata = new FormData(); 452 for (key in payload) { 453 formdata.append(key, payload[key]); 454 } 455 456 fetchParams = { 457 method: 'POST', 458 body: formdata 459 } 460 } 461 462 const res = await fetch(`${json ? clientJsonUrl : clientFormDataUrl}`, fetchParams) 463 464 const data = await res.json(); 465 466 return data; 467 } 468 469 catch(error) { 470 return {"status": "failed", "message": error.message} 471 } 472} 473 474async function exportAsPdf(fileName, params) { 475 try { 476 let exportFormData = new FormData() 477 let time = new Date().toISOString(); 478 for (field in params) { 479 exportFormData.append(field, params[field]) 480 } 481 482 const res = await fetch(`${clientPdfExportUrl}`, { 483 // headers: {'Authorization': `Bearer ${token}`}, 484 method: 'POST', 485 credentials: "include", 486 body: exportFormData 487 }) 488 489 // const jsonRes = await res.json(); 490 // console.log("Json: ", jsonRes); 491 // const data = await jsonRes; 492 // console.log("Data: ", data) 493 494 const blob = await res.blob(); 495 496 const file = new File([blob], `${fileName}_${time}.pdf`, { type: 'application/pdf' }); 497 let fileUrl = URL.createObjectURL(file); 498 const popup = window.open(fileUrl, '_blank') 499 500 if (!popup) { 501 return {"status": "failed", "message": "Please disable your pop-up blocker and export again"} 502 } 503 504 return {"status": "success"} 505 506 } 507 508 catch(error) { 509 return {"status": "failed", "message": error.message} 510 } 511}
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.