HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/shop.komma.nl/resources/js/services/shipmentService.js
import { axios } from '../../../vendor/komma/kms/resources/js/global/axiosBootstrapper';

/**
 * The shipment service knows how to do api calls and handle the responses from the api.
 * All related to the shipment process. It does not do anything with the DOM.
 */
class ShipmentService {
    constructor() {
        this._baseRoute = '/api/v1/kms/shipments/';
    }

    /**
     * @return {Promise<AxiosResponse<any>>}
     */
    shipments() {
        return axios.get(
            this._baseRoute
        );
    }

    /**
     * @param id
     * @return {Promise<AxiosResponse<any>>}
     */
    shipment(id) {
        return axios.get(
            this._baseRoute + id
        );
    }

    /**
     * @param shipment
     * @return {Promise<AxiosResponse<any>>}
     */
    update(shipment) {
        return axios.patch(
            this._baseRoute + shipment.id,
            shipment
        );
    }

    /**
     * @param {int} shipmentId
     * @return {Promise<AxiosResponse<any>>}
     */
    clearOrderedProductsFromShipment(shipmentId) {
        return axios.patch(
            this._baseRoute + 'clear_ordered_products_from_shipment',
            { shipment_id: shipmentId }
        );
    }

    /**
     * @param {int} shipmentId
     * @param {int[]} orderedProductIds
     * @return {Promise<AxiosResponse<any>>}
     */
    removeOrderedProductsFromShipment(shipmentId, orderedProductIds = []) {
        return axios.patch(
            this._baseRoute + 'remove_ordered_products_from_shipment',
            {
                shipment_id: shipmentId,
                ordered_product_ids: orderedProductIds
            }
        );
    }

    /**
     * @param {int} shipmentId
     * @param {int[]} orderedProductIds
     * @return {Promise<AxiosResponse<any>>}
     */
    addOrderedProductsFromShipment(shipmentId, orderedProductIds) {
        return axios.patch(
            this._baseRoute + 'add_ordered_products_from_shipment',
            {
                shipment_id: shipmentId,
                ordered_product_ids: orderedProductIds
            }
        );
    }

    /**
     * @param {int[]} shipmentIds
     */
    notifyCarrier(shipmentIds) {
        return axios.patch(
            this._baseRoute + 'notifyCarrier',
            { shipment_ids: shipmentIds }
        );
    }

    /**
     * @param {int[]} shipmentIds
     */
    cancel(shipmentIds) {
        return axios.post(
            this._baseRoute + 'cancel',
            { shipment_ids: shipmentIds }
        );
    }

    /**
     * @param {Number} shipmentId
     * @return {string}
     */
    downloadLabelForShipmentUrl(shipmentId) {
        return this._baseRoute + 'label/' + shipmentId
    }
}

export { ShipmentService }