larvitproduct

0.13.9 • Public • Published

Build Status Dependencies

larvitproduct

Generic product module for nodejs.

Product data structure:

{
    "uuid": "string",
    "created": date,
    "attributes": {
        "name": ["Conductor"],
        "price": [200],
        "available color": ["blue", "green"]
    }
}

Installation

npm i --save larvitproduct

Usage

Create new instance of the lib

const {ProductLib} = require('larvitproduct');
 
const libOptions = {};
 
libOptions.log = log; // logging instance (see Log in larvitutils library)
libOptions.esIndexName  = 'anEsIndexName';
libOptions.mode = 'noSync'; // see larvitamsync library
libOptions.intercom = new Intercom('loopback interface');
libOptions.amsync = {};
libOptions.amsync.host  = null;
libOptions.amsync.minPort = null;
libOptions.amsync.maxPort = null;
libOptions.elasticsearch = es; // instance of elasticsearch.Client
 
const productLib = new ProductLib(libOptions, function (err) {
    if (err) throw err;
    // ProductLib instance created!
});

Add a new product

const {ProductLib, Product} = require('larvitproduct');
 
// Create productLib instance of ProductLib
 
const product = new Product({'productLib': productLib, 'log': optionalLoggingInstance});
// Or, use the factory function in ProductLib:
const otherProduct = productLib.createProduct(); // will initiate with log instance from productLib
 
product.attributes = {
    'name': 'Test product #69',
    'price': 99,
    'weight': 14,
    'color': ['blue', 'green']
};
 
product.save(function (err) {
    if (err) throw err;
    // Product saved!
});

Readme

Keywords

Package Sidebar

Install

npm i larvitproduct

Weekly Downloads

3

Version

0.13.9

License

ISC

Unpacked Size

151 kB

Total Files

26

Last publish

Collaborators

  • gagge
  • jaggu-snorr
  • klabbekluck
  • lilleman
  • vktr