1.0.7 • Published 9 years ago

@marcoleo/asset-manager v1.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
9 years ago

#asset-manager

A node.js module for NodeJS Avanscoperta Course. This module handles the insert and update of an Asset in a mongodb istance.

npm install marcoleo/asset-manager

Usage

var asset_manager = require('asset-manager')(dbname,collectionname)
asset_manager.put({name: 'prova', status: 'status'}, function (err, result) {
      console.log(result)
      });

Methods

put

A method to insert an Asset in a Mongo database.

function(obj, cb){
	if(obj._id){
		obj._id = "";
	}
	
	var result = Joi.validate(obj, schema)

	if(result.error != null)
		return cb(result.error,null);
		asset.findAndModify({
		    query: mongojs.ObjectId(obj._id) ,
		    update: { $set: obj },
		    new: true,
		    upsert:true
		}, function(err, doc, lastErrorObject) {
		    cb(err,doc);
		});
	}

get

A method to update an Asset in a Mongo database.

	function(query,cb){
		if(query == null || query === undefined)
			return cb({error:"Must Provide a query"},null);
		
		asset.findOne(query,cb);
	}

close

A method to close the connection to Mongo database.

	function(){
		db.close();
	}

Dependencies

Joi for validation mongojs for database connection mocha for testing

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago