createMarkedItem.js

/**
 * Created by WORKER on 05-09-2015.
 */
var async = require('async')
var getMarkedItems = require('./getMarkedItems')

/**
 * Build list of habits.
 * @param  {Object} options Input parameters
 */
function createMarkedItem(options) {
  var newItemName = options.data.templates[0].fields[0].name
  var createdAt = Date.now()
  var data = {
    list: []
  }
  var items = []
  console.log('Creating marked item: ' + newItemName)

  if (newItemName) {
    options.DB.MarkClln.insert(
      { name: newItemName, createdAt: createdAt },
      function (err, docs) {
        console.log('Inserted to MarkClln')
        options.data.templates[0].fields[0].name = docs.insertedIds[0]
        options.DB.TemplateClln.insert(
          options.data.templates,
          function (err, snippets) {
            if (err) {
              console.log(err)
            } else {
              console.log(snippets)
            }

            getMarkedItems(options)
          }
        )
      }
    )
  }
}

module.exports = createMarkedItem