PageSourceSearch

https://www.harmoniainc.jp/asset/js/api.js?1743423492

js harmoniainc.jp collected 2026-10-04 02:58:25 UTC 19,410 bytes, 593 lines download raw bytes

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.