How to use the parcel.id function in parcel

To help you get started, we’ve selected a few parcel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github commercetools / nodejs / packages / csv-parser-orders / src / parsers / deliveries.js View on Github external
static _parseParcelInfo(data) {
    const transitionMap = {
      'parcel.height': 'measurements.heightInMillimeter',
      'parcel.length': 'measurements.lengthInMillimeter',
      'parcel.width': 'measurements.widthInMillimeter',
      'parcel.weight': 'measurements.weightInGram',
      'parcel.trackingId': 'trackingData.trackingId',
      'parcel.providerTransaction': 'trackingData.providerTransaction',
      'parcel.provider': 'trackingData.provider',
      'parcel.carrier': 'trackingData.carrier',
      'parcel.isReturn': 'trackingData.isReturn',
      'parcel.items': 'items',
    }

    const parcel = {
      id: data['parcel.id'],
    }

    // Build parcel object
    Object.keys(data).forEach(fieldName => {
      if (!transitionMap[fieldName]) return

      // All values are loaded as a string
      let fieldValue = data[fieldName]

      // do not set empty values
      if (fieldValue === '') return

      // Cast measurements to Number
      if (/^measurements/.test(transitionMap[fieldName]))
        fieldValue = Number(fieldValue)
github commercetools / nodejs / packages / csv-parser-orders / src / parsers / deliveries.js View on Github external
// Basic delivery object with delivery item
    const delivery = {
      id: data['delivery.id'],
      items: [
        {
          // there can be multiple delivery items with same item.id and
          // item.quantity therefore we use unique identifier _itemGroupId
          _groupId: data._itemGroupId,
          id: data['item.id'],
          quantity: parseInt(data['item.quantity'], 10),
        },
      ],
    }

    // Add parcel info if it is present
    if (data['parcel.id']) {
      const parcel = DeliveriesParser._parseParcelInfo(data)

      if (parcel.measurements && Object.keys(parcel.measurements).length !== 4)
        return Promise.reject(new Error('All measurement fields are mandatory'))

      delivery.parcels = [parcel]
    }

    const order = {
      orderNumber: data.orderNumber,
      shippingInfo: {
        deliveries: [delivery],
      },
    }
    return Promise.resolve(order)
  }

parcel

Blazing fast, zero configuration web application bundler

MIT
Latest version published 8 months ago

Package Health Score

87 / 100
Full package analysis