Skip to content

Calculate the differences between two customer objects and build the update actions

License

Notifications You must be signed in to change notification settings

lpinca/build-actions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

build-actions

Version npm Build Status Coverage Status

Calculate the differences between two customer objects and build the update actions as defined in http://dev.sphere.io/http-api-projects-customers.html.

Install

npm install --save build-actions

API

This module exports a single function that takes two arguments:

  1. An object representing a customer.
  2. An object representing the updated version of the same customer.

The function returns an array of update actions.

var buildActions = require('build-actions');

var before = {
  email: 'foo.bar@domain.com',
  firstName: 'foo',
  lastName: 'bar',
  addresses: []
};

var after = {
  customerNumber: '123456',
  email: 'foobar@domain.com',
  firstName: 'foo',
  lastName: 'bar',
  middleName: 'baz',
  addresses: [{
    id: 'FjAJrc2C',
    country: 'NL'
  }],
  defaultShippingAddressId: 'FjAJrc2C'
};

var actions = buildActions(before, after);

console.log(actions);

/*
[{
  action: 'changeEmail',
  email: 'foobar@domain.com'
}, {
  action: 'addAddress',
  address: {
    id: 'FjAJrc2C',
    country: 'NL'
  }
}, {
  action: 'setCustomerNumber',
  customerNumber: '123456'
}, {
  action: 'changeName',
  firstName: 'foo',
  lastName: 'bar',
  middleName: 'baz'
}, {
  action: 'setDefaultShippingAddress',
  addressId: 'FjAJrc2C'
}]
*/

License

MIT

About

Calculate the differences between two customer objects and build the update actions

Resources

License

Stars

Watchers

Forks

Packages

No packages published