<commit_before>'use strict';
// =========================================================================
//
// Controller for publicComments
//
// =========================================================================
var path            = require ('path');
var mongoose        = require ('mongoose');
var CRUD            = require (path.resolve('./modules/core/server/controllers/core.crud.controller'));
var Model           = mongoose.model ('PublicComment');
var CommentDocument = mongoose.model ('CommentDocument');
var BucketComment   = mongoose.model ('BucketComment');
var helpers         = require (path.resolve('./modules/core/server/controllers/core.helpers.controller'));
var _               = require ('lodash');

var crud = new CRUD (Model);

// -------------------------------------------------------------------------
//
// look at all documents under the comment, if any are deferred then set
// overall status to deferred. if comment is deferred then overall is defe
//
// -------------------------------------------------------------------------
var overallStatus = function (currentStatus, documents) {
	switch (currentStatus) {
		case 'Unvetted':
		case 'Rejected':
		case 'Deferred':
		case 'Accepted':
			break;
		case 'Published':
			_.each (documents, function (doc) {
				if (doc.eaoStatus === 'Deferred') currentStatus = 'Deferred';
			});
	}
	return currentStatus;
};
exports.overallStatus = overallStatus;

var saveComment = function (comment, req) {
	return new Promise (function (resolve, reject) {
		comment.dateUpdated  = Date.now();
		comment.updatedBy    = (req.user) ? req.user._id : null;
		comment.save ().then (resolve, reject);
	});
};
var saveDocument = function (doc, req) {
	return new Promise (function (resolve, reject) {
		doc.dateUpdated  = Date.now();
		doc.updatedBy    = (req.user) ? req.user._id : null;
		doc.save ().then (resolve, reject);
	});
};
// -------------------------------------------------------------------------
//
// get all docs attached to a comment
//
// -------------------------------------------------------------------------
var getDocumentsForComment = function (commentId) {
	return new Promise (function (resolve, reject) {
		CommentDocument.find ({publicComment:commentId}).populate('bucket').exec(function (err, model) {
			if (err) return reject (err);
			else {
				console.log (model);
				var ret = [];
				_.each (model, function (m) {
					ret.push (m.bucket);
				});
				resolve (ret);
			}
		});
	});
};

// -------------------------------------------------------------------------
//
// get all topics for a comment
//
// -------------------------------------------------------------------------
var getTopicsForComment = function (commentId) {
	return new Promise (function (resolve, reject) {
		resolve ([]);
	});
};

// -------------------------------------------------------------------------
//
// get all buckets for a comment
//
// -------------------------------------------------------------------------
var getBucketsForComment = function (commentId) {
	return new Promise (function (resolve, reject) {
		BucketComment.find ({publicComment: commentId}).populate('bucket').exec(function (err, models) {
			if (err) return reject (err);
			else {
				console.log (models);
				var ret = [];
				_.each (models, function (m) {
					ret.push (m.bucket);
				});<commit_msg>fixed error in document retrieval<commit_after>'use strict';
// =========================================================================
//
// Controller for publicComments
//
// =========================================================================
var path            = require ('path');
var mongoose        = require ('mongoose');
var CRUD            = require (path.resolve('./modules/core/server/controllers/core.crud.controller'));
var Model           = mongoose.model ('PublicComment');
var CommentDocument = mongoose.model ('CommentDocument');
var BucketComment   = mongoose.model ('BucketComment');
var helpers         = require (path.resolve('./modules/core/server/controllers/core.helpers.controller'));
var _               = require ('lodash');

var crud = new CRUD (Model);

// -------------------------------------------------------------------------
//
// look at all documents under the comment, if any are deferred then set
// overall status to deferred. if comment is deferred then overall is defe
//
// -------------------------------------------------------------------------
var overallStatus = function (currentStatus, documents) {
	switch (currentStatus) {
		case 'Unvetted':
		case 'Rejected':
		case 'Deferred':
		case 'Accepted':
			break;
		case 'Published':
			_.each (documents, function (doc) {
				if (doc.eaoStatus === 'Deferred') currentStatus = 'Deferred';
			});
	}
	return currentStatus;
};
exports.overallStatus = overallStatus;

var saveComment = function (comment, req) {
	return new Promise (function (resolve, reject) {
		comment.dateUpdated  = Date.now();
		comment.updatedBy    = (req.user) ? req.user._id : null;
		comment.save ().then (resolve, reject);
	});
};
var saveDocument = function (doc, req) {
	return new Promise (function (resolve, reject) {
		doc.dateUpdated  = Date.now();
		doc.updatedBy    = (req.user) ? req.user._id : null;
		doc.save ().then (resolve, reject);
	});
};
// -------------------------------------------------------------------------
//
// get all docs attached to a comment
//
// -------------------------------------------------------------------------
var getDocumentsForComment = function (commentId) {
	return new Promise (function (resolve, reject) {
		CommentDocument.find ({publicComment:commentId}, function (err, model) {
			if (err) return reject (err);
			else {
				resolve (model);
			}
		});
	});
};

// -------------------------------------------------------------------------
//
// get all topics for a comment
//
// -------------------------------------------------------------------------
var getTopicsForComment = function (commentId) {
	return new Promise (function (resolve, reject) {
		resolve ([]);
	});
};

// -------------------------------------------------------------------------
//
// get all buckets for a comment
//
// -------------------------------------------------------------------------
var getBucketsForComment = function (commentId) {
	return new Promise (function (resolve, reject) {
		BucketComment.find ({publicComment: commentId}).populate('bucket').exec(function (err, models) {
			if (err) return reject (err);
			else {
				console.log (models);
				var ret = [];
				_.each (models, function (m) {
					ret.push (m.bucket);
				});
{'fraction_non_alphanumeric': 0.3383617438527681, 'fraction_numerical': 0.0, 'mean_word_length': 1.7659574468085106, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6817236', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1580, 'n_words': 459}