contact-service
Version:
A simple array based service layer for address book apps
82 lines (60 loc) • 1.7 kB
Markdown
A simple array based service layer for address book apps
--------------------------------------------------------
### Installing:
<pre>
npm install --save contact-service
</pre>
### Using:
<pre>
var service = require("contact-service");
var c = service.getById(13);
console.log(c);
</pre>
### Currently avaiable member functions:
* getAll() --> returns all existing contacts
* getById(id) --> returns the corresponding contact or null if not found
* addNew(contact) --> adds the contact to the existing list of contcts with a new id
* update(contact) --> searches with the given contact's id and replaces the existing contact
* delete(id) --> searches with the given contact's id and deletes the same
### Get all contacts:
<pre>
var contacts = service.getAll();
contacts.forEach(c=>{
console.log(c);
});
</pre>
### Adding a new contact:
#### (Mandatory fields - first_name, last_name, email, phone, dob and city)
<pre>
var contact = {
first_name: 'Vinod',
last_name: 'Kumar',
email: 'vinod@vinod.co',
phone: '9731424784',
dob: '1974-01-20',
city: 'Bangalore'
};
contact = service.addNew(contact);
console.log(contact);
</pre>
### Deleting a contact with id:
<pre>
var id = 3;
var contact = service.delete(id);
console.log(`deleted: ${JSON.stringify(contact)}`);
</pre>
### Updating an existing contact (based on id):
#### (Mandatory fields - id, first_name, last_name, email, phone, dob and city)
<pre>
var contact = {
id: 3,
first_name: 'Vinod',
last_name: 'Kumar',
email: 'kumar@vinod.co',
phone: '9731424784',
dob: '1974-01-20',
city: 'Bangalore'
};
contact = service.update(contact);
console.log(`updated contact: ${JSON.stringify(contact)}`);
</pre>