|
@@ -3,20 +3,8 @@
|
|
|
*/
|
|
|
var rationRepository = require("../models/repositoryMap");
|
|
|
|
|
|
-var callback = function(req,res,err,data){
|
|
|
- if(data){
|
|
|
- res.status(200)
|
|
|
- res.json({success:true,data:data});
|
|
|
- }
|
|
|
- else
|
|
|
- if(err){
|
|
|
- res.status(500)
|
|
|
- res.json({success:false,error:err});
|
|
|
- }
|
|
|
- else{
|
|
|
- res.status(204);
|
|
|
- res.json({success:true});
|
|
|
- }
|
|
|
+var callback = function(req, res, err, message, data){
|
|
|
+ res.json({error: err, message: message, data: data});
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
@@ -24,18 +12,18 @@ module.exports = {
|
|
|
var rationObj = JSON.parse(req.body.rationRepObj);
|
|
|
rationRepository.addRationRepository(rationObj,function(err,data){
|
|
|
if (data) {
|
|
|
- callback(req, res, err, data);
|
|
|
+ callback(req, res, err, "has data", data);
|
|
|
} else {
|
|
|
- callback(req, res, err, null);
|
|
|
+ callback(req, res, err, "no data", null);
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
getDisPlayRationLibs: function(req, res){
|
|
|
rationRepository.getDisplayRationLibs(function(err, data){
|
|
|
if (data) {
|
|
|
- callback(req, res, err, data);
|
|
|
+ callback(req, res, err, "has data",data);
|
|
|
} else {
|
|
|
- callback(req, res, err, null);
|
|
|
+ callback(req, res, err, "no data", null);
|
|
|
}
|
|
|
});
|
|
|
},
|
|
@@ -43,9 +31,9 @@ module.exports = {
|
|
|
var libName = req.body.rationName;
|
|
|
rationRepository.getRealLibName(libName,function(err,data){
|
|
|
if (data) {
|
|
|
- callback(req, res, err, data);
|
|
|
+ callback(req, res, err, "has data", data);
|
|
|
} else {
|
|
|
- callback(req, res, err, null);
|
|
|
+ callback(req, res, err, "no data", null);
|
|
|
}
|
|
|
})
|
|
|
},
|
|
@@ -53,9 +41,9 @@ module.exports = {
|
|
|
var rationName = req.body.rationName;
|
|
|
rationRepository.deleteRationLib(rationName,function(err,data){
|
|
|
if (data) {
|
|
|
- callback(req, res, err, data);
|
|
|
+ callback(req, res, err, "has data", data);
|
|
|
} else {
|
|
|
- callback(req, res, err, null);
|
|
|
+ callback(req, res, err, "no data", null);
|
|
|
}
|
|
|
})
|
|
|
},
|
|
@@ -64,9 +52,9 @@ module.exports = {
|
|
|
var newName = req.body.newName;
|
|
|
rationRepository.updateName(orgName, newName, function(err, data){
|
|
|
if (data) {
|
|
|
- callback(req, res, err, data);
|
|
|
+ callback(req, res, err, "has data", data);
|
|
|
} else {
|
|
|
- callback(req, res, err, null);
|
|
|
+ callback(req, res, err, "no data", null);
|
|
|
}
|
|
|
});
|
|
|
}
|