1// 2// WebAPIã¦ã¼ãã£ãªã㣠3// IE11ã§ä½¿ç¨ããå ´åã¯Promiseã使ç¨ã§ããããPolyfillãå°å ¥ãã¦ãã ããã 4// 5const Api = new function () { 6 const apiBaseUrl = location.origin + '/api'; 7 this.MSG_ERR_NETWORK = 'éä¿¡ã«å¤±æãã¾ããã'; 8 9 const fetchWrapper = function (baseUrl, method, paramsKeyValue) { 10 let params; 11 let url; 12 if (method === 'GET') { 13 params = { 14 method: 'GET', 15 mode: 'cors', 16 cache: 'no-cache', 17 headers: { 18 'Content-Type': 'application/json; charset=utf-8', 19 }, 20 }; 21 22 if (paramsKeyValue) { 23 const urlParam = new URLSearchParams(); 24 Object.keys(paramsKeyValue).map(function (key) { 25 urlParam.append(key, paramsKeyValue[key]); 26 }); 27 url = baseUrl + '/?' + urlParam.toString(); 28 } else { 29 url = baseUrl; 30 } 31 } 32 33 if (method === 'POST') { 34 params = { 35 method: 'POST', 36 mode: 'cors', 37 cache: 'no-cache', 38 headers: { 39 'Accept': 'application/json', 40 'Content-Type': 'application/json' 41 }, 42 }; 43 if (paramsKeyValue) { 44 params['body'] = JSON.stringify(paramsKeyValue); 45 } 46 url = baseUrl; 47 } 48 49 if (method === 'DELETE') { 50 params = { 51 method: 'DELETE', 52 mode: 'cors', 53 cache: 'no-cache', 54 headers: { 55 'Content-Type': 'application/json; charset=utf-8', 56 }, 57 }; 58 59 if (paramsKeyValue) { 60 const urlParam = new URLSearchParams(); 61 Object.keys(paramsKeyValue).map(function (key) { 62 urlParam.append(key, paramsKeyValue[key]); 63 }); 64 url = baseUrl + '/?' + urlParam.toString(); 65 } else { 66 url = baseUrl; 67 } 68 } 69 70 return fetch(url, params) 71 .then(function (response) { 72 if (!response.ok) { 73 throw new Error([response.status, response.statusText].join(' ')); 74 } 75 return response.json(); 76 })['catch'](function (ex) { 77 throw ex; 78 }); 79 }; 80 81 /** 82 * Ajaxéä¿¡ãå®è¡ãã 83 * 84 * @private 85 * @param {Object} params jQuery ajaxãã©ã¡ã¼ã¿ 86 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 87 */ 88 const requestAjax = function (params, success, failure) { 89 return new Promise(function (resolve, reject) { 90 $.ajax(params) 91 .done(function (data, textStatus, jqXHR) { 92 resolve({ 93 data: data, 94 textStatus: textStatus, 95 jqXHR: jqXHR, 96 }); 97 }) 98 .fail(function (jqXHR, textStatus, errorThrown) { 99 reject({ 100 jqXHR: jqXHR, 101 textStatus: textStatus, 102 errorThrown: errorThrown, 103 }); 104 }); 105 }); 106 }; 107 108 /** 109 * åºèæ å ±ãæ´æ°ãã 110 * @param {åºèID} shop_id 111 * @param {Object} params åºèæ´æ°ãã©ã¡ã¼ã¿ 112 */ 113 const postShopDetail = function (shopId, params) { 114 const baseUrl = apiBaseUrl + '/shop/index/' + shopId; 115 const keyValues = !params ? {} : params; 116 117 return fetchWrapper(baseUrl, 'POST', keyValues); 118 }; 119 this.postShopDetail = postShopDetail; 120 121 /** 122 * ãªã¤ã«äº¤æä¾¡æ ¼ãåå¾ãã 123 * 124 * @param {Number} displacementId ææ°éID 125 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 126 */ 127 const fetchOilPriceInfo = function (displacementId) { 128 const baseUrl = apiBaseUrl + '/shop/price/oil/' + displacementId; 129 130 return fetchWrapper(baseUrl, 'GET'); 131 }; 132 this.fetchOilPriceInfo = fetchOilPriceInfo; 133 134 /** 135 * ãªã¤ã«äº¤æä¾¡æ ¼ãæ´æ°ãã 136 * 137 * @param {Number} displacementId ææ°éID 138 * @param {Object} postData æ´æ°ãã¼ã¿ 139 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 140 */ 141 const updateOilPriceInfo = function (displacementId, params) { 142 const baseUrl = apiBaseUrl + '/shop/price/oil/' + displacementId;
143 const keyValues = !params ? {} : params; 144 145 return fetchWrapper(baseUrl, 'POST', keyValues); 146 }; 147 this.updateOilPriceInfo = updateOilPriceInfo; 148 149 /** 150 * ãªã¤ã«äº¤æä¾¡æ ¼ãåé¤ãã 151 * 152 * @param {Number} displacementId ææ°éID 153 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 154 */ 155 const deleteOilPriceInfo = function (displacementId) { 156 const baseUrl = apiBaseUrl + '/shop/price/oil/' + displacementId; 157 158 return fetchWrapper(baseUrl, 'DELETE'); 159 }; 160 this.deleteOilPriceInfo = deleteOilPriceInfo; 161 162 /** 163 * ã¿ã¤ã¤äº¤æä¾¡æ ¼ãåå¾ãã 164 * 165 * @param {Number} displacementId ææ°éID 166 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 167 */ 168 const fetchTirePriceInfo = function (displacementId) { 169 const baseUrl = apiBaseUrl + '/shop/price/tire/' + displacementId; 170 171 return fetchWrapper(baseUrl, 'GET'); 172 }; 173 this.fetchTirePriceInfo = fetchTirePriceInfo; 174 175 /** 176 * ã¿ã¤ã¤äº¤æä¾¡æ ¼ãæ´æ°ãã 177 * 178 * @param {Number} displacementId ææ°éID 179 * @param {Object} postData æ´æ°ãã¼ã¿ 180 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 181 */ 182 const updateTirePriceInfo = function (displacementId, params) { 183 const baseUrl = apiBaseUrl + '/shop/price/tire/' + displacementId; 184 const keyValues = !params ? {} : params; 185 186 return fetchWrapper(baseUrl, 'POST', keyValues); 187 }; 188 this.updateTirePriceInfo = updateTirePriceInfo; 189 190 /** 191 * ã¿ã¤ã¤äº¤æä¾¡æ ¼ãåé¤ãã 192 * 193 * @param {Number} displacementId ææ°éID 194 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 195 */ 196 const deleteTirePriceInfo = function (displacementId) { 197 const baseUrl = apiBaseUrl + '/shop/price/tire/' + displacementId; 198 199 return fetchWrapper(baseUrl, 'DELETE'); 200 }; 201 this.deleteTirePriceInfo = deleteTirePriceInfo; 202 203 /** 204 * ç¹æ¤ä¾¡æ ¼ãåå¾ãã 205 * 206 * @param {Number} displacementId ææ°éID 207 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 208 */ 209 const fetchInspectionPriceInfo = function (displacementId) { 210 const baseUrl = apiBaseUrl + '/shop/price/inspection/' + displacementId; 211 212 return fetchWrapper(baseUrl, 'GET'); 213 }; 214 this.fetchInspectionPriceInfo = fetchInspectionPriceInfo; 215 216 /** 217 * ç¹æ¤ä¾¡æ ¼ãæ´æ°ãã 218 * 219 * @param {Number} displacementId ææ°éID 220 * @param {Object} postData æ´æ°ãã¼ã¿ 221 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 222 */ 223 const updateInspectionPriceInfo = function (displacementId, params) { 224 const baseUrl = apiBaseUrl + '/shop/price/inspection/' + displacementId; 225 const keyValues = !params ? {} : params; 226 227 return fetchWrapper(baseUrl, 'POST', keyValues); 228 }; 229 this.updateInspectionPriceInfo = updateInspectionPriceInfo; 230 231 /** 232 * ç¹æ¤ä¾¡æ ¼ãåé¤ãã 233 * 234 * @param {Number} displacementId ææ°éID 235 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 236 */ 237 const deleteInspectionPriceInfo = function (displacementId) { 238 const baseUrl = apiBaseUrl + '/shop/price/inspection/' + displacementId; 239 240 return fetchWrapper(baseUrl, 'DELETE'); 241 }; 242 this.deleteInspectionPriceInfo = deleteInspectionPriceInfo; 243 244 /** 245 * ä¿®çä¾¡æ ¼ãåå¾ãã 246 * 247 * @param {Number} displacementId ææ°éID 248 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 249 */ 250 const fetchRepairPriceInfo = function (displacementId) { 251 const baseUrl = apiBaseUrl + '/shop/price/repair/' + displacementId; 252 253 return fetchWrapper(baseUrl, 'GET'); 254 }; 255 this.fetchRepairPriceInfo = fetchRepairPriceInfo; 256 257 /** 258 * ä¿®çä¾¡æ ¼ãæ´æ°ãã 259 * 260 * @param {Number} displacementId ææ°éID 261 * @param {Object} postData æ´æ°ãã¼ã¿ 262 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 263 */ 264 const updateRepairPriceInfo = function (displacementId, params) { 265 const baseUrl = apiBaseUrl + '/shop/price/repair/' + displacementId;
266 const keyValues = !params ? {} : params; 267 268 return fetchWrapper(baseUrl, 'POST', keyValues); 269 }; 270 this.updateRepairPriceInfo = updateRepairPriceInfo; 271 272 /** 273 * ä¿®çä¾¡æ ¼ãåé¤ãã 274 * 275 * @param {Number} displacementId ææ°éID 276 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 277 */ 278 const deleteRepairPriceInfo = function (displacementId) { 279 const baseUrl = apiBaseUrl + '/shop/price/repair/' + displacementId; 280 281 return fetchWrapper(baseUrl, 'DELETE'); 282 }; 283 this.deleteRepairPriceInfo = deleteRepairPriceInfo; 284 285 /** 286 * è»ç¨®æ å ±ä¸è¦§ãåå¾ãã 287 * 288 * @param {Number} makerId æ´æ°ãã¼ã¿ 289 * @param {Number} displacementId ææ°éID 290 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 291 */ 292 const fetchVehicleInfo = function (makerId, displacementId) { 293 const baseUrl = apiBaseUrl + '/vehicleType/list/' + makerId + '/' + displacementId; 294 295 return fetchWrapper(baseUrl, 'GET'); 296 }; 297 this.fetchVehicleInfo = fetchVehicleInfo; 298 299 /** 300 * 使¥å®ç¸¾ã®è¡¨ç¤ºé表示æ å ±ãã¾ã¨ãã¦æ´æ°ãã 301 * 302 * @param {Object[]} postData æ´æ°ãã¼ã¿é å 303 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 304 */ 305 const updateWorksList = function (postData) { 306 const params = { 307 type: 'POST', 308 url: apiBaseUrl + '/works/list', 309 data: JSON.stringify(postData), 310 contentType: 'application/json', 311 dataType: 'json' 312 }; 313 return requestAjax(params); 314 }; 315 this.updateWorksList = updateWorksList; 316 317 /** 318 * 使¥å®ç¸¾ãã¾ã¨ãã¦åé¤ãã 319 * 320 * @param {Number[]} deleteData åé¤ãã¼ã¿IDé å 321 * @returns 322 */ 323 const deleteWorksList = function (deleteData) { 324 const params = { 325 type: 'DELETE', 326 url: apiBaseUrl + '/works', 327 data: JSON.stringify(deleteData), 328 contentType: 'application/json', 329 dataType: 'json' 330 }; 331 return requestAjax(params); 332 }; 333 this.deleteWorksList = deleteWorksList; 334 335 /** 336 * 使¥å®ç¸¾ãç»é²ãã 337 * 338 * @param {Object} postData ç»é²ãã¼ã¿ 339 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 340 */ 341 const createWorkResult = function (params) { 342 const baseUrl = apiBaseUrl + '/works/index'; 343 const keyValues = !params ? {} : params; 344 345 return fetchWrapper(baseUrl, 'POST', keyValues); 346 }; 347 this.createWorkResult = createWorkResult; 348 349 /** 350 * 使¥å®ç¸¾ãæ´æ°ãã 351 * 352 * @param {Number} workResultId 使¥å®ç¸¾ID 353 * @param {Object} postData æ´æ°ãã¼ã¿ 354 * @returns {Promise} Promiseãªãã¸ã§ã¯ã 355 */ 356 const updateWorkResult = function (workResultId, params) { 357 const baseUrl = apiBaseUrl + '/works/index/' + workResultId; 358 const keyValues = !params ? {} : params; 359 360 return fetchWrapper(baseUrl, 'POST', keyValues); 361 }; 362 this.updateWorkResult = updateWorkResult; 363 364 /** 365 * ã·ã§ããã¬ãã¥ã¼æ å ±ãåå¾ãã 366 * 367 * @param {Number} shopReviewId ã·ã§ããã¬ãã¥ã¼ID 368 * @returns {Promise} éä¿¡çµæã®Promiseãªãã¸ã§ã¯ã 369 */ 370 const fetchShopReview = function (shopReviewId) { 371 const params = { 372 type: 'GET', 373 url: apiBaseUrl + '/review/index/' + shopReviewId, 374 contentType: 'application/json', 375 dataType: 'json' 376 }; 377 return requestAjax(params); 378 } 379 this.fetchShopReview = fetchShopReview; 380 381 /**
382 * ã·ã§ããã¬ãã¥ã¼æ å ±ã®åçãæ´æ°ãã 383 * 384 * @param {Number} shopReviewId ã·ã§ããã¬ãã¥ã¼ID 385 * @param {string} reply åçå 容 386 * @returns {Promise} éä¿¡çµæã®Promiseãªãã¸ã§ã¯ã 387 */ 388 const updateShopReviewReply = function (shopReviewId, params) { 389 const baseUrl = apiBaseUrl + '/review/index/' + shopReviewId; 390 const keyValues = !params ? {} : params; 391 392 return fetchWrapper(baseUrl, 'POST', keyValues); 393 }; 394 this.updateShopReviewReply = updateShopReviewReply; 395 396 /** 397 * @typedef {Object} ShopReviewPublishState 398 * @property {number} id ã·ã§ããã¬ãã¥ã¼ID 399 * @property {boolean} display_flag å ¬éãã©ã°(å ¬é: true, éå ¬é: false) 400 */ 401 /** 402 * ã·ã§ããã¬ãã¥ã¼æ å ±ã®å ¬éã»éå ¬éãã¾ã¨ãã¦æ´æ°ãã 403 * 404 * @param {Array<ShopReviewPublishState>} updates æ´æ°å¯¾è±¡ã®ã¹ãã¼ã¿ã¹ä¸è¦§ 405 * @returns {Promise} éä¿¡çµæã®Promiseãªãã¸ã§ã¯ã 406 */ 407 const updateShopReviewPublishState = function (updates) { 408 const params = { 409 type: 'POST', 410 url: apiBaseUrl + '/review/list', 411 data: JSON.stringify(updates), 412 contentType: 'application/json', 413 dataType: 'json' 414 }; 415 return requestAjax(params); 416 } 417 this.updateShopReviewPublishState = updateShopReviewPublishState; 418 419 420 /** 421 * ã·ã§ãããªã¹ããåå¾ãã 422 * 423 * @param {Array<ShopReviewPublishState>} updates æ´æ°å¯¾è±¡ã®ã¹ãã¼ã¿ã¹ä¸è¦§ 424 * @returns {Promise} éä¿¡çµæã®Promiseãªãã¸ã§ã¯ã 425 */ 426 const fetchShops = function () { 427 const params = { 428 type: 'GET', 429 url: apiBaseUrl + '/shop/list', 430 contentType: 'application/json', 431 dataType: 'json' 432 }; 433 return requestAjax(params); 434 } 435 this.fetchShops = fetchShops; 436 437 /** 438 * IDã§æå®ããé½éåºçå ã®å¸åºçºæãªã¹ããåå¾ãã 439 * @param {number} prefecture_id 440 * @return {Promise} Promiseãªãã¸ã§ã¯ã 441 */ 442 const fetchMunicipalities = function (prefecture_id) { 443 return fetch(apiBaseUrl + '/prefecture/municipality_list/' + prefecture_id, { 444 method: 'GET', 445 mode: 'cors', 446 cache: 'no-cache', 447 headers: { 448 'Content-Type': 'application/json; charset=utf-8', 449 }, 450 })['catch'](function (e) { 451 throw Error(e); 452 }).then(function (response) { 453 return response.json(); 454 }); 455 }; 456 this.fetchMunicipalities = fetchMunicipalities; 457 458 /** 459 * @typedef {Object} ContactPostParameter 460 * @property {number} shopId ã·ã§ããID 461 * @property {string} subject ååãä»¶å 462 * @property {string} telephone ååãå ã®é»è©±çªå· 463 * @property {string} contact ååãå 容 464 */ 465 /** 466 * ã·ã§ããã¸ã®ãååããæç¨¿ãã 467 * @param {number} shopId ã·ã§ããID 468 * @param {ContactPostParameter} params ãååããã©ã¡ã¼ã¿ãªãã¸ã§ã¯ã 469 * @return {Promise}
469 çµæã®Promiseãªãã¸ã§ã¯ã 470 */ 471 const sendInquiryMessage = function (shopId, params) { 472 473 const url = [apiBaseUrl, 'shop/inquiry', shopId].join('/'); 474 const messageParams = { 475 subject: '', 476 telephone: '', 477 residence: '', 478 content: '', 479 }; 480 481 Object.keys(messageParams).map(function (key) { 482 if (params[key]) { 483 messageParams[key] = params[key]; 484 } 485 }); 486 487 return axios.post(url, messageParams); 488 }; 489 this.sendInquiryMessage = sendInquiryMessage; 490 491 /** 492 * 使¥å®ç¸¾ä¸è¦§ãåå¾ãã 493 * @param {Object} params 494 */ 495 const fetchWorks = function (params) { 496 const baseUrl = apiBaseUrl + '/works/list'; 497 const keyValues = !params ? {} : params; 498 499 return fetchWrapper(baseUrl, 'GET', keyValues); 500 } 501 this.fetchWorks = fetchWorks; 502 503 /** 504 * æå®IDã®ä½æ¥å®ç¸¾æ å ±ãåå¾ãã 505 * @param {number} workId 使¥å®ç¸¾ID 506 * @param {number} shopId ã·ã§ããID 507 */ 508 const fetchWork = function (workId, shopId) { 509 const baseUrl = [apiBaseUrl, 'works', 'index', workId].join('/'); 510 const params = shopId ? { shop_id: shopId } : undefined; 511 512 return fetchWrapper(baseUrl, 'GET', params); 513 }; 514 this.fetchWork = fetchWork; 515 516 /** 517 * ã¬ãã¥ã¼ä¸è¦§ãåå¾ãã 518 * @param {Object} params 519 */ 520 const fetchReviews = function (params) { 521 const urlParams = new URLSearchParams(); 522 if (params) { 523 const obj = { 524 shop_id: !params.shopId ? undefined : params.shopId, 525 limit: !params.limit ? undefined : params.limit, 526 offset: !params.offset ? undefined : params.offset, 527 sort_column: params.sortColumn ? undefined : params.sortColumn, 528 sort_order: params.sortOrder ? undefined : params.sortOrder, 529 }; 530 531 Object.keys(obj).map(function (key) { 532 if (obj[key] !== undefined) { 533 urlParams.append(key, obj[key]); 534 } 535 }); 536 } 537 538 const queryString = Array.from(urlParams.entries()).length > 0 ? '?' + urlParams.toString() : ''; 539 const url = apiBaseUrl + '/review/list/' + queryString; 540 541 return fetchWrapper(url, 'GET'); 542 } 543 this.fetchReviews = fetchReviews; 544 545 const fetchPriceInfo = function (shopId, params) { 546 if (!shopId) { 547 throw new Error('ShopID is required.'); 548 } 549 const keyValues = !params ? {} : params; 550 return fetchWrapper([apiBaseUrl, 'shop/prices', shopId].join('/'), 'GET', keyValues); 551 }; 552 this.fetchPriceInfo = fetchPriceInfo; 553 554 const createMaintenanceOrder = function (params) { 555 const url = [apiBaseUrl, 'maintenance_orders'].join('/'); 556 const messageParams = { 557 maker_id: '', 558 displacement_id: '', 559 vehicle_id: '', 560 images: [], 561 content: '', 562 }; 563 564 Object.keys(messageParams).map(function (key){ 565 if (params[key]) { 566 messageParams[key] = params[key]; 567 } 568 }); 569 570 return fetchWrapper(url, 'POST', messageParams); 571 }; 572 this.createMaintenanceOrder = createMaintenanceOrder; 573 574 const updateMaintenanceOrder = function (orderId, params) { 575 const url = [apiBaseUrl, 'maintenance_orders', 'index', orderId].join('/'); 576 const messageParams = { 577 maker_id: '', 578 displacement_id: '', 579 vehicle_id: '', 580 images: [], 581 content: '', 582 }; 583 584 Object.keys(messageParams).map(function (key){ 585 if (params[key]) { 586 messageParams[key] = params[key]; 587 } 588 }); 589 590 return fetchWrapper(url, 'POST', messageParams); 591 }; 592 this.updateMaintenanceOrder = updateMaintenanceOrder; 593};
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.