'use strict'

/**
 * Sample API controller. Can safely be removed.
 */

const Sample = require('../models').sample.Sample
const co = require('co')

module.exports = {
  getData: co.wrap(getData),
  postData: co.wrap(postData)
}

function * getData (req, res, next) {
  try {
    const doc = yield Sample.findById(req.params.id)

    if (!doc) {
      return next()
    }

    res.json({ id: doc._id, name: doc.name })
  } catch (err) {
    next(err)
  }
}

function * postData (req, res, next) {
  try {
    let doc = yield Sample.findById(req.params.id)

    if (!doc) {
      doc = new Sample({
        _id: req.params.id,
        name: req.body.name
      })
    } else {
      doc.name = req.body.name
    }

    yield doc.save()
    res.json({ id: doc._id, name: doc.name })
  } catch (err) {
    next(err)
  }
}

@@ -272,21 +272,125 @@
 y %7B%0A    
-const
+let doc = %7B%7D%0A    if (process.env.NODE_MOCK) %7B%0A      doc = yield %7B_id: 0, name: 'mockdata'%7D%0A    %7D else %7B%0A     
  doc = y
@@ -416,32 +416,38 @@
 d(req.params.id)
+%0A    %7D
 %0A%0A    if (!doc) 

Support for startMock mode in getData