Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/richardzcode/contacts
Experimenting node.js Main purpose on finding best practice.
https://github.com/richardzcode/contacts
Last synced: about 1 month ago
JSON representation
Experimenting node.js Main purpose on finding best practice.
- Host: GitHub
- URL: https://github.com/richardzcode/contacts
- Owner: richardzcode
- Created: 2011-12-09T01:09:40.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2012-01-15T10:49:05.000Z (almost 13 years ago)
- Last Synced: 2024-04-13T22:12:22.024Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 211 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Contacts
Experimenting node.js.
## JavaScript Object
Extended Object and Array a bit.
#### Object.extend(from, replace)
Add properties of _from_ object to current object.
If same property exists, then replace if _replace_ is true. Default true.#### Object.subset(names)
Return a new object with subset of properties of current object.#### Array.merge(ary)
Merge _ary_ into current array.## Context
A context object is added to each request. It is used for template rendering.
### Flash message
Context object handles flash messages. Flash message is a kind of message that generated on business logic layer, supposed to be displayed to user once, and only once. It needs to handle case of redirect. Here we use session object to persist messages util they are renderred once.
Currently two type: error, info.
#### context.error(msg)
Add error message[s]. _msg_ can be string or array of strings.
If no _msg_ supplied then return all errors.#### context.info(msg)
Add info message[s]. _msg_ can be string or array of strings.
If no _msg_ supplied then return all info messages.#### conext.clearFlash()
Clear flash messages from session.## Model
The first goal is to implemente Active Record pattern talk to MongoDB.
Models are defined unser models/ directory. To use:
var Contact = require('../models').Contact;
var contact = new Contact();
...
contact.bind(data);
contact.save(caller, callback);
...Each model only need to define FIELD_MAP to have basic methods
* validate
* bind
* find
* save
* deleteExample:
module.exports.name = 'Contact';module.exports.klass = function(data) {
this.collection_name = 'contact';this.FIELDMAP = {
name: {default: '', type: 'string', required: true},
owner_id: {default: '', type: 'ObjectId', required: true},
primary_contact_type: {default: '', type: 'string', required: true}, // email|phone|skype
primary_contact: {default: '', type: 'string', required: true},
created_on: {default: new Date(), type: 'datetime'},
modified_on: {default: new Date(), type: 'datetime'}
}if (this.init) {
this.init(data);
}
}Not finished yet...