<commit_before>"use strict";
const mongoose = require('mongoose')
const Topic = require('./topic')
const logger = require('../logger')
const websockets = require('../websockets')()

/*
 * The purpose of this setter is to end all playing episodes
 * because there can be only one to rule them all
 */
function stopPlayingEpisodes (time_value) {
  this.constructor // get the Model to execute queries
    .find({ ended : null })
    .where('_id').ne(this._id)
    .where('started').ne(null)
    .then(function(results) { // we end all other episodes that are playing
      results.forEach(function (episode) {
        episode.ended = Date.now()
        episode.save()
      })
    })
    .catch(function(error) {
      logger.error(error)
    })

  this.ended = null

  return time_value // hmm, we can also return Date.now() instead ?
}

let episodeSchema = new mongoose.Schema({
    number: { type: Number, required: true, index: true },
    name: { type: String },
    date: { type: Date, default: Date.now },
    started: { type: Date, set: stopPlayingEpisodes },
    ended: { type: Date },
    created: { type: Date, required: true },
    modified: { type: Date, required: true },
    program: { type: mongoose.Schema.Types.ObjectId, ref:'Program', required: true, index: true },<commit_msg>[-] Date isn't needed anymore<commit_after>"use strict";
const mongoose = require('mongoose')
const Topic = require('./topic')
const logger = require('../logger')
const websockets = require('../websockets')()

/*
 * The purpose of this setter is to end all playing episodes
 * because there can be only one to rule them all
 */
function stopPlayingEpisodes (time_value) {
  this.constructor // get the Model to execute queries
    .find({ ended : null })
    .where('_id').ne(this._id)
    .where('started').ne(null)
    .then(function(results) { // we end all other episodes that are playing
      results.forEach(function (episode) {
        episode.ended = Date.now()
        episode.save()
      })
    })
    .catch(function(error) {
      logger.error(error)
    })

  this.ended = null

  return time_value // hmm, we can also return Date.now() instead ?
}

let episodeSchema = new mongoose.Schema({
    number: { type: Number, required: true, index: true },
    name: { type: String },
    started: { type: Date, set: stopPlayingEpisodes },
    ended: { type: Date },
    created: { type: Date, required: true },
    modified: { type: Date, required: true },
    program: { type: mongoose.Schema.Types.ObjectId, ref:'Program', required: true, index: true },
{'fraction_non_alphanumeric': 0.14146150840171942, 'fraction_numerical': 0.0, 'mean_word_length': 3.2244224422442245, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2334419', 'n_tokens_mistral': 763, 'n_tokens_neox': 757, 'n_words': 243}