var express = require('express'),
    router = express.Router(),
    user = require('../models/user');

//get all user
router.get('/', function (req, res) {

});

//get user by id
router.get('/:id', function (req, res) {

    user.findOne({ _id: req.params.id }, function (err, user) {
        if (err) throw err;

        res.json(user);
    });
});

//put user to db
router.put('/', function (req, res) {

    var user_info = new user({
        user_name: 'leixu2txtek',
        display_name: 'Lei Xu',
        password: '111111',
        date_created: new Date(),
        sex: '男',
        age: 25,
        school: '中国科技大学',
        company: {
            name: '安徽讯飞皆成软件技术有限公司',
            title: '软件开发工程师',
            location: '安徽合肥'
        }
    });

    user_info.save(function (err, doc) {

        console.log('saved!');
        res.send('添加成功');
    });
});

//modify user
router.post('/', function (req, res) {

});

//delete user by id
router.delete('/:id', function (req, res) {

});

module.exports = router;
@@ -271,20 +271,20 @@
 n (err, 
-user
+data
 ) %7B%0A    
@@ -409,25 +409,20 @@
     var 
-user_info
+data
  = new u
@@ -757,17 +757,12 @@
     
-user_info
+data
 .sav
@@ -779,18 +779,19 @@
  (err, d
-oc
+ata
 ) %7B%0A%0A   
@@ -881,24 +881,27 @@
 uter.post('/
+:id
 ', function 
@@ -918,77 +918,1186 @@
  %7B%0A%0A
-%7D);%0A%0A//delete user by id%0Arouter.delete('/:id', function (req, res) %7B%0A
+    user.findOne(%7B _id: req.params.id %7D, function (err, data) %7B%0A        if (err) throw err;%0A%0A        //TODO validate params%0A%0A        if (req.params.display_name) data.display_name = req.params.display_name.trim();%0A        if (req.params.sex) data.sex = req.params.sex;%0A        if (req.params.age) data.age = req.params.age;%0A        if (req.params.school) data.school = req.params.school.trim();%0A%0A        if (req.params.company) %7B%0A%0A            if (req.params.company.name) data.company.name = req.params.company.name.trim();%0A            if (req.params.company.title) data.company.title = req.params.company.title.trim();%0A            if (req.params.company.location) data.company.location = req.params.company.location.trim();%0A        %7D%0A%0A        data.save(function (err, data) %7B%0A            if (err) throw err;%0A%0A            res.json(%7B code: 1, msg: '%E4%BF%AE%E6%94%B9%E6%88%90%E5%8A%9F' %7D);%0A        %7D);%0A    %7D);%0A%7D);%0A%0A//delete user by id%0Arouter.delete('/:id', function (req, res) %7B%0A%0A    user.findOne(%7B _id: req.params.id %7D, function (err, data) %7B%0A        if (err) throw err;%0A%0A        data.remove(function (err) %7B%0A            if (err) throw err;%0A%0A            res.json(%7B code: 1, msg: '%E5%88%A0%E9%99%A4%E6%88%90%E5%8A%9F' %7D);%0A        %7D);%0A    %7D);
 %0A%7D);

add modify user action