// dependencies
var CRUD = require ("./crud")
  , ObjectId = require ("mongodb").ObjectID
  , templates = [
        {
            name: "map"
          , id: "534ffc85f607d65614ad00e4"
        }
      , {
            name: "marker"
          , id:   "534ffe16f607d65614ad00e5"
        }
      , {
            name: "infowin"
          , id: "534ffe16f607d65614ad00e6"
        }
      , {
            name: "icon"
          , id: "534fffd7f607d65614ad00f7"
        }
    ]
  ;

/*
 *  Function generator for APIS
 *
 * */
function generateApiSet (templateId) {
    return {
        create: function (options, callback) {
            CRUD.create ({
                _tp: [ ObjectId (templateId) ]
              , templateId: templateId
              , data: options.data
              , options: options.options
              , callback: callback
            });
        }
      , read: function (options, callback) {
            CRUD.read ({
                templateId: templateId
              , query: options.query
              , options: options.options
              , callback: callback
            });
        }
      , update: function (options, callback) {
            CRUD.update ({
                templateId: templateId
              , query: options.query
              , data: data
              , options: options.options
              , callback: callback
            });
        }
      , delete: function (options, callback) {
            CRUD.delete ({
                templateId: templateId
              , query: options.query
              , options: options.options
              , callback: callback
            });
        }
    };
};

// this object will be exported
var Api = {};

// each template
for (var i = 0; i < templates.length; ++i) {

    // get the current template
    var cTemplate = templates[i];

    // generate methods for this template
    Api[cTemplate.name] = generateApiSet (cTemplate.id);
}

// exports the module
module.exports = Api;

@@ -605,32 +605,33 @@
 ns, callback) %7B%0A
+%0A
             CRUD
@@ -630,43 +630,139 @@
     
-CRUD.create (%7B%0A                _tp:
+// force data to be an object and attach _tp field%0A            options.data = Object (options.data);%0A            options.data._tp =
  %5B O
@@ -783,16 +783,18 @@
 ateId) %5D
+;%0A
 %0A       
@@ -798,19 +798,46 @@
         
+CRUD.create (%7B%0A             
   
-,
  templat

Attach _tp field correctly