<commit_before>'use strict';

const BaseRepository = require('@gfcc/mongo-tenant-repository/BaseRepository');

class ReleaseNotesRepository extends BaseRepository {
  getSchemaDefinition() {
    const MixedType = this.getSchemaTypes().Mixed;

    return {
      scope: { type: String, 'default': 'global', required: true },
      name: { type: String, required: true },
      ownerAccountId: { type: String, required: true },

      title: String,
      description: String,
      releases: [{
        version: String,
        date: Date,
        title: String,
        description: String,
        added: [MixedType],
        removed: [MixedType],
        changed: [MixedType],
        improved: [MixedType],
        deprecated: [MixedType],
        fixed: [MixedType],
        secured: [MixedType],
      }]
    };
  }

  applySchemaPlugins(schema) {
    super.applySchemaPlugins(schema);

    schema.index({ scope: 1, name: 1 }, { unique: true });

    return this;
  }

  findOneByScopeAndName(scope, name, callback) {
    this.findOne({
      scope: scope,
      name: name
    }, callback);

    return this;
  }

  findAllByScope(scope, callback) {
    this.find({
      scope: scope
    }, callback);

    return this;
  }

  /**
   * Retrieves the list of release notes owned by the given account.
   *
   * @param {string} ownerAccountId
   * @param callback
   * @return {BaseRepository}
   */
  findAllByOwnerAccountId(ownerAccountId, callback) {
    return this.find({
      ownerAccountId,
    }, callback);
  }

  /**
   * Retrieve a list of the nth newest release notes.
   *
   * @param {number} count
   * @param {function} callback
   */
  findNewest(count, callback) {
    this.findList({}, {
      limit: count,
      sort: {
        createdAt: -1
      }
    }, (err, releaseNotesList) => {
      if (err) {
        return void callback(err);
      }

      return void callback(null, releaseNotesList.items);
    });
  }
}

module.exports = ReleaseNotesRepository;
<commit_msg>Introduce latestVersion and latestReleaseDate fields on release notes db model.<commit_after>'use strict';

const BaseRepository = require('@gfcc/mongo-tenant-repository/BaseRepository');

class ReleaseNotesRepository extends BaseRepository {
  getSchemaDefinition() {
    const MixedType = this.getSchemaTypes().Mixed;

    return {
      scope: { type: String, 'default': 'global', required: true },
      name: { type: String, required: true },
      ownerAccountId: { type: String, required: true },

      latestVersion: String,
      latestReleaseDate: Date,

      title: String,
      description: String,
      releases: [{
        version: String,
        date: Date,
        title: String,
        description: String,
        added: [MixedType],
        removed: [MixedType],
        changed: [MixedType],
        improved: [MixedType],
        deprecated: [MixedType],
        fixed: [MixedType],
        secured: [MixedType],
      }]
    };
  }

  applySchemaPlugins(schema) {
    super.applySchemaPlugins(schema);

    schema.index({ scope: 1, name: 1 }, { unique: true });

    return this;
  }

  findOneByScopeAndName(scope, name, callback) {
    this.findOne({
      scope: scope,
      name: name
    }, callback);

    return this;
  }

  findAllByScope(scope, callback) {
    this.find({
      scope: scope
    }, callback);

    return this;
  }

  /**
   * Retrieves the list of release notes owned by the given account.
   *
   * @param {string} ownerAccountId
   * @param callback
   * @return {BaseRepository}
   */
  findAllByOwnerAccountId(ownerAccountId, callback) {
    return this.find({
      ownerAccountId,
    }, callback);
  }

  /**
   * Retrieve a list of the nth newest release notes.
   *
   * @param {number} count
   * @param {function} callback
   */
  findNewest(count, callback) {
    this.findList({}, {
      limit: count,
      sort: {
        createdAt: -1
      }
    }, (err, releaseNotesList) => {
      if (err) {
        return void callback(err);
      }

      return void callback(null, releaseNotesList.items);
    });
  }
}

module.exports = ReleaseNotesRepository;

{'fraction_non_alphanumeric': 0.12139568693966561, 'fraction_numerical': 0.001453840562151684, 'mean_word_length': 2.510204081632653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1352562', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1227, 'n_words': 309}