<commit_before>let crypto = require('crypto'),
	mongoose = require('../../db/mongoose'),
	Schema = mongoose.Schema,
    ObjectId = require('mongodb').ObjectID,
    userModel = require('../userModel');


let schema = new Schema({  

						   author : {
											type: Schema.Types.ObjectId,
											ref: 'users',
											required: [true,  "*author news is required"]
									},

							title: {
										type:String,
										required: [true, "*news title is required"]
									},

							excerpt: {
										type:String,
										required: [true, "*excerpt news is required"],
										minlength : [20, "*text content news is required"]
									},
							textHtml : {
										type:String,
										required: [true, "*text content news is required"],
										minlength : [20, "*text content news is required"]
							}
					
	}, {timestamps: true});


let newsModel =  mongoose.model('news', schema);


module.exports = (function(){

	return {

		newsModel: newsModel,


		setNews(data, req){
				let excerptLimit = data.textHtml.length > 250 ? 100 : Math.round((data.textHtml.length/100)*20);
				let news = new newsModel({
					author: req.user._id,
					title: data.title,
					excerpt : data.textHtml.replace(/<\/?[^>]+>/g,'').replace(/&nbsp;/gi,' ').replace(/&ndash;/gi,' ').substr(0, excerptLimit) + "..",
					textHtml : data.textHtml
				});

				return news.save() 
			
		},

		getNews(_id){
			return newsModel.findOne({_id}).populate('author');
		},

		getAllNews(pagination){	 

			return new Promise((res, rej)=>{
				newsModel.count({}, (err, count)=>{
					console.log(count);

					if(!err){

						let responce = {};
						if(pagination){
							newsModel.find({}, 'title excerpt author createdAt').sort({'createdAt': -1}).populate('author').skip((pagination-1)*10).limit(10).then(posts=>{
								responce.posts = posts;
								responce.count = count;
								res(responce);
							}).catch(err=>{
								rej(err);
							})
							}

						if(!pagination){
							newsModel.find({}, 'title excerpt author createdAt').sort({'createdAt': -1}).populate('author').limit(10).then(posts=>{
								responce.posts = posts;
								responce.count = count;
								res(responce);
								
							}).catch(err=>{
								rej(err);
							})
							}

						}

					else{
						rej(err);
					}


				})
			})
			
		
		},

		updateNews(data, req){

			return newsModel.find({_id:data._id})
					.update({title: data.title, author: req.user._id, excerpt: data.excerpt});
		},

		deleteNews(_id){
			
			return newsModel.find({_id}).remove();
		},
		addPublisher(_id){
		return	userModel.getUser(_id).then(user=>{
				let publisher = {_id: user._id, 
									login:user.login,
									first_name: user.first_name,
									last_name: user.last_name,
								};

			newsModel.find().update({$set: {publishers: publisher}})
			.then(res=>{
				console.log(res)
			}).catch(err=>{
				console.log(err)
			})


			})
			
		}

			}



	}());








<commit_msg>news article edit<commit_after>let crypto = require('crypto'),
	mongoose = require('../../db/mongoose'),
	Schema = mongoose.Schema,
    ObjectId = require('mongodb').ObjectID,
    userModel = require('../userModel');


let schema = new Schema({  

						   author : {
											type: Schema.Types.ObjectId,
											ref: 'users',
											required: [true,  "*author news is required"]
									},

							title: {
										type:String,
										required: [true, "*news title is required"]
									},

							excerpt: {
										type:String,
										required: [true, "*excerpt news is required"],
										minlength : [20, "*text content news is required"]
									},
							textHtml : {
										type:String,
										required: [true, "*text content news is required"],
										minlength : [20, "*text content news is required"]
							}
					
	}, {timestamps: true});


let newsModel =  mongoose.model('news', schema);


module.exports = (function(){

	return {

		newsModel: newsModel,


		setNews(data, req){
				let excerptLimit = data.textHtml.length > 250 ? 100 : Math.round((data.textHtml.length/100)*20);
				let news = new newsModel({
					author: req.user._id,
					title: data.title,
					excerpt : data.textHtml.replace(/<\/?[^>]+>/g,'').replace(/&nbsp;/gi,' ').replace(/&ndash;/gi,' ').split('').slice(10) + " ..",
					textHtml : data.textHtml
				});

				return news.save() 
			
		},

		getNews(_id){
			return newsModel.findOne({_id}).populate('author');
		},

		getAllNews(pagination){	 

			return new Promise((res, rej)=>{
				newsModel.count({}, (err, count)=>{
					console.log(count);

					if(!err){

						let responce = {};
						if(pagination){
							newsModel.find({}, 'title excerpt author createdAt').sort({'createdAt': -1}).populate('author').skip((pagination-1)*10).limit(10).then(posts=>{
								responce.posts = posts;
								responce.count = count;
								res(responce);
							}).catch(err=>{
								rej(err);
							})
							}

						if(!pagination){
							newsModel.find({}, 'title excerpt author createdAt').sort({'createdAt': -1}).populate('author').limit(10).then(posts=>{
								responce.posts = posts;
								responce.count = count;
								res(responce);
								
							}).catch(err=>{
								rej(err);
							})
							}

						}

					else{
						rej(err);
					}


				})
			})
			
		
		},

		updateNews(data, req){

			return newsModel.find({_id:data._id})
					.update({title: data.title, author: req.user._id, excerpt: data.excerpt});
		},

		deleteNews(_id){
			
			return newsModel.find({_id}).remove();
		},
		addPublisher(_id){
		return	userModel.getUser(_id).then(user=>{
				let publisher = {_id: user._id, 
									login:user.login,
									first_name: user.first_name,
									last_name: user.last_name,
								};

			newsModel.find().update({$set: {publishers: publisher}})
			.then(res=>{
				console.log(res)
			}).catch(err=>{
				console.log(err)
			})


			})
			
		}

			}



	}());









{'fraction_non_alphanumeric': 0.17506276150627614, 'fraction_numerical': 0.008535564853556485, 'mean_word_length': 2.226781857451404, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '1972026', 'n_tokens_mistral': 2912, 'n_tokens_neox': 1913, 'n_words': 357}