All files / src/Batch ShopifyGetFulfillmentOrders.ts

100% Statements 11/11
100% Branches 0/0
100% Functions 3/3
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 11416x   16x   16x   16x   16x   16x     16x       1x 1x             1x       1x                                                                                                                                                                        
import ABatchNode from '@orchesty/nodejs-sdk/dist/lib/Batch/ABatchNode';
import ResponseDto from '@orchesty/nodejs-sdk/dist/lib/Transport/Curl/ResponseDto';
import { HttpMethods } from '@orchesty/nodejs-sdk/dist/lib/Transport/HttpMethods';
import BatchProcessDto from '@orchesty/nodejs-sdk/dist/lib/Utils/BatchProcessDto';
import ABaseShopify, { API_VERSION } from '../ABaseShopify';
 
export const NAME = 'shopify-get-fulfillment-orders';
 
const GET_FULFILLMENT_ORDERS = `admin/api/${API_VERSION}/fulfillment_orders/{id}/fulfillments.json`;
 
export default class ShopifyGetFulfillmentOrders extends ABatchNode {
 
    public getName(): string {
        return NAME;
    }
 
    public async processAction(dto: BatchProcessDto<IInput>): Promise<BatchProcessDto> {
        const { id } = dto.getJsonData();
        const requestDto = this.getApplication<ABaseShopify>().getRequestDto(
            dto,
            await this.getApplicationInstallFromProcess(dto),
            HttpMethods.GET,
            GET_FULFILLMENT_ORDERS.replace('{id}', id),
        );
 
        return this.setItemList(dto, await this.getSender().send<IResponse>(requestDto));
    }
 
    protected setItemList(dto: BatchProcessDto, response: ResponseDto<IResponse>): BatchProcessDto {
        return dto.setItemList(response.getJsonBody().fulfillments);
    }
 
}
 
export interface IInput {
    id: string;
}
 
/* eslint-disable @typescript-eslint/naming-convention */
export interface IOutput {
    id: number;
    order_id: number;
    admin_graphql_api_id: string;
    status: string;
    created_at: string;
    service: string;
    updated_at: string;
    tracking_company: string;
    shipment_status: string;
    location_id: number;
    origin_address: string;
    line_items: {
        id: number;
        admin_graphql_api_id: string;
        variant_id: number;
        title: string;
        quantity: number;
        sku: string;
        variant_title: string;
        vendor: string;
        fulfillment_service: string;
        product_id: number;
        requires_shipping: boolean;
        taxable: boolean;
        gift_card: boolean;
        name: string;
        variant_inventory_management: string;
        properties: unknown[];
        product_exists: boolean;
        fulfillable_quantity: number;
        grams: number;
        price: string;
        total_discount: string;
        fulfillment_status: string;
        price_set: {
            shop_money: {
                amount: string;
                currency_code: string;
            };
            presentment_money: {
                amount: string;
                currency_code: string;
            };
        };
        total_discount_set: {
            shop_money: {
                amount: string;
                currency_code: string;
            };
            presentment_money: {
                amount: string;
                currency_code: string;
            };
        };
        discount_allocations: unknown[];
        duties: unknown[];
        tax_lines: unknown[];
    }[];
    tracking_number: string;
    tracking_numbers: string[];
    tracking_url: string;
    tracking_urls: string[];
    receipt: {
        authorization: string;
        testcase: boolean;
    };
    name: string;
}
 
interface IResponse {
    fulfillments: IOutput[];
}
/* eslint-enable @typescript-eslint/naming-convention */