fix(core): fixed all res.send(message) of not found from db by id

This commit is contained in:
OldHawk
2018-01-21 16:27:17 +08:00
parent 6c07a86693
commit 2a995dcf18
11 changed files with 37 additions and 50 deletions

View File

@@ -330,9 +330,7 @@ exports.makerByID = function (req, res, next, id) {
if (err) {
return next(err);
} else if (!maker) {
return res.status(404).send({
message: 'No maker with that identifier has been found'
});
return res.status(404).send();
}
req.maker = maker;
next();

View File

@@ -326,9 +326,7 @@ exports.collectionByID = function (req, res, next, id) {
if (err) {
return next(err);
} else if (!coll) {
return res.status(404).send({
message: 'No collection with that identifier has been found'
});
return res.status(404).send();
}
req.collection = coll;
next();

View File

@@ -187,9 +187,7 @@ exports.forumByID = function (req, res, next, id) {
if (err) {
return next(err);
} else if (!forum) {
return res.status(404).send({
message: 'No forum with that identifier has been found'
});
return res.status(404).send();
}
req.forum = forum;
next();

View File

@@ -1065,9 +1065,7 @@ exports.topicById = function (req, res, next, id) {
if (err) {
return next(err);
} else if (!topic) {
return res.status(404).send({
message: 'No topic with that identifier has been found'
});
return res.status(404).send();
}
req.topic = topic;
next();

View File

@@ -462,9 +462,7 @@ exports.invitationByID = function (req, res, next, id) {
if (err) {
return next(err);
} else if (!invitation) {
return res.status(404).send({
message: 'No invitation with that identifier has been found'
});
return res.status(404).send();
}
req.invitation = invitation;
next();

View File

@@ -107,9 +107,7 @@ exports.adminMessageByID = function (req, res, next, id) {
if (err) {
return next(err);
} else if (!message) {
return res.status(404).send({
message: 'No message with that identifier has been found'
});
return res.status(404).send();
}
req.adminMessage = message;
next();

View File

@@ -357,9 +357,7 @@ exports.messageByID = function (req, res, next, id) {
if (err) {
return next(err);
} else if (!message) {
return res.status(404).send({
message: 'No message with that identifier has been found'
});
return res.status(404).send();
}
req.message = message;
next();

View File

@@ -327,9 +327,7 @@ exports.requestByID = function (req, res, next, id) {
if (err) {
return next(err);
} else if (!request) {
return res.status(404).send({
message: 'No request with that identifier has been found'
});
return res.status(404).send();
}
req.request = request;
next();

View File

@@ -115,9 +115,7 @@ exports.completeByID = function (req, res, next, id) {
if (err) {
return next(err);
} else if (!complete) {
return res.status(404).send({
message: 'No complete with that identifier has been found'
});
return res.status(404).send();
}
req.complate = complete;
next();

View File

@@ -2103,7 +2103,7 @@ exports.torrentByID = function (req, res, next, id) {
};
var findOtherTorrents = function (torrent, callback) {
if (torrent.resource_detail_info.id) {
if (torrent && torrent.resource_detail_info.id) {
var condition = {
torrent_status: 'reviewed',
'resource_detail_info.id': torrent.resource_detail_info.id
@@ -2136,33 +2136,40 @@ exports.torrentByID = function (req, res, next, id) {
};
var writeAllFiles = function (torrent, callback) {
var filePath = config.uploads.torrent.file.dest + torrent.torrent_filename;
nt.read(filePath, function (err, torrent_data) {
if (err) {
callback(err);
} else {
var mdata = torrent_data.metadata;
torrent._all_files = [];
if (mdata.info.files) {
mdata.info.files.forEach(function (f) {
torrent._all_files.push(f.path.join('/') + ', ' + common.fileSizeFormat(f.length, 2));
});
if (torrent) {
var filePath = config.uploads.torrent.file.dest + torrent.torrent_filename;
nt.read(filePath, function (err, torrent_data) {
if (err) {
callback(err);
} else {
torrent._all_files.push(mdata.info.name + ', ' + common.fileSizeFormat(mdata.info.length, 2));
var mdata = torrent_data.metadata;
torrent._all_files = [];
if (mdata.info.files) {
mdata.info.files.forEach(function (f) {
torrent._all_files.push(f.path.join('/') + ', ' + common.fileSizeFormat(f.length, 2));
});
} else {
torrent._all_files.push(mdata.info.name + ', ' + common.fileSizeFormat(mdata.info.length, 2));
}
callback(null, torrent);
}
callback(null, torrent);
}
});
});
} else {
callback(null, torrent);
}
};
async.waterfall([findTorrents, findOtherTorrents, writeAllFiles], function (err, torrent) {
if (err) {
next(err);
} else {
req.torrent = torrent;
if (torrent) {
req.torrent = torrent;
} else {
return res.status(404).send();
}
next();
}
});

View File

@@ -134,9 +134,7 @@ exports.traceByID = function (req, res, next, id) {
if (err) {
return next(err);
} else if (!trace) {
return res.status(404).send({
message: 'No trace with that identifier has been found'
});
return res.status(404).send();
}
req.trace = trace;
next();