Ecommerce Cart service using micro-base framework (beta).
Micro-base is a small framework to define and call services, and gives some basic utilities like config, logging, jobs and MongoDB access. More info abot the framework here.
cd src
npm install
npm start
The code is documented with docco and can be accessed here
The API is documented with aglio and can be accessed here
Shamefully, no tests yet.
The configuration properties are handled via the framework and nconf. Out of the box the framework reads the files:
config/development.json
config/default.json
node_modules/micro-base/modules/config/defaults.json
Each file in the list provides sensitive defaults for the previous one.
The file config/development.json is built with the NODE_ENV environment variable therefore, if you want to customize the configuration values for a different environment just start node with a different one.
If NODE_ENV is prod, the config file used will be config/prod.json
The service uses the framework provided db utilities, based in Mongoose.
You can customize the models used modifying the properties under thr models key.
The module must follow the following convention:
function hook(base) {
return (data) => {
return new Promise((resolve, reject) => {
return resolve(data);
});
};
}
module.exports = hook; "cartModel": "./models/cartModel"There is a "hook" system to allow customization of the different parts of the system.
You can provide your own implementation configuring the module to be used in a properties file.
Called before adding the entry to the Cart, used for validations.
"preAddToCart": {
"handler": "./modules/cart/hooks/preAddToCart",
"maxQuantityPerProduct": 10000,
"maxNumberOfEntries": 15
}Called to verify the stock and reserve it. Uses an external Stock Service.
"stockAvailability": {
"handler": "./modules/cart/hooks/stockAvailability",
"reserveStockForMinutes": 1440
}Add the entry to the Cart
"addToCart": {
"handler": "./modules/cart/hooks/addToCart"
}Called after the item was added to the Cart
"postAddToCart": {
"handler": "./modules/cart/hooks/postAddToCart",
}Saves the Cart using the framework provided db utilities
"saveCart": {
"handler": "./modules/cart/hooks/saveCart"
}Called after the Cart was succesfully saved
"postSaveCart": {
"handler": "./modules/cart/hooks/postSaveCart"
}