Created
December 4, 2015 06:09
-
-
Save Suave/5cfa68108a864110d5de to your computer and use it in GitHub Desktop.
mongoose validator error async issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.create = function*(){ | |
var body = this.request.body, | |
name = body.name, | |
type = body.shop_type, | |
context = body.context; | |
/* | |
this.checkBody("name").notEmpty("请输入商户名称"); | |
this.checkBody("shop_type").notEmpty("请输入原料名"); | |
this.checkBody("context").notEmpty("请输入口味描述"); | |
if(this.errors){ | |
return this.body = {retcode:1 , message:'请输入完整信息'}; | |
} | |
*/ | |
var checkShop = yield Shop.model.findOne({name:name}).exec(); | |
if(checkShop != null){ | |
return this.body = {retcode:1,message:'已存在相同的商户'} | |
} | |
var shopData = {}; | |
shopData.name = name; | |
shopData.type = type; | |
shopData.context = context; | |
try{ | |
var newShop = new Shop.model(shopData); | |
yield newShop.save(function(err){ | |
if(err) { | |
return this.body = {retcode: 1, message: err.errors}; | |
} else { | |
return this.body = {retcode: 0} | |
} | |
}); | |
} catch(ex) { | |
} | |
/* | |
var result = yield (function(newShop){ | |
return function(fn){newShop.save(fn)}; | |
})(newShop); | |
return this.body = {retcode:0} | |
*/ | |
return this.body = {retcode: 0} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment