function _updateEntity(resolve, reject, MongooseModel, req, entity) {
  // TODO: 这样会导致 put 效果与 patch 相同.
  MongooseModel.update({ id: entity.id }, req.body, (err) => {
    if (err) {
      return reject(err);
    }
    return resolve({ entity: req.body, originEntity: entity });
  });
}

function _createEntity(resolve, reject, MongooseModel, req, entity) {
  const uuidReg = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
  if (!uuidReg.test(req.params.id)) {
    return reject({ status: 400 }, { text: 'Id is not valid.' });
  }
  const newEntity = new MongooseModel(req.body);
  newEntity._id = req.params.id;
  newEntity.save((err) => {
    if (err) {
      return reject(err);
    }
    return resolve({ status: 201, entity: newEntity, originEntity: entity });
  });
}

export default (req, MongooseModel) => new Promise((resolve, reject) => {
  MongooseModel.findOne({ _id: req.params.id }, (err, entity) => {
    if (err) {
      return reject(err);
    }
    return entity
      ? _updateEntity(resolve, reject, MongooseModel, req, entity)
      : _createEntity(resolve, reject, MongooseModel, req, entity);
  });
});

@@ -68,44 +68,8 @@
  %7B%0D%0A
-  // TODO: %E8%BF%99%E6%A0%B7%E4%BC%9A%E5%AF%BC%E8%87%B4 put %E6%95%88%E6%9E%9C%E4%B8%8E patch %E7%9B%B8%E5%90%8C.%0D%0A
   Mo
@@ -516,12 +516,10 @@
  is 
+i
 n
-ot 
 vali

remove commit and edit msg.