'use strict';

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

class SubscriptionRepository extends BaseRepository {
  getSchemaDefinition() {
    return {
      subscriberId: {
        type: String,
        required: true,
        index: true,
      },
      releaseNotesId: {
        type: String,
        required: true,
        index: true,
      },
      releaseNotesScope: {
        type: String,
        required: true,
        index: true,
      },
      releaseNotesName: {
        type: String,
        required: true,
      },
      email: {
        type: String,
      },
    };
  }

  /**
   * Lookup all subscriptions of the given subscriber.
   *
   * @param {string} subscriberId
   * @param {function} callback
   * @return {SubscriptionRepository}
   */
  findBySubscriberId(subscriberId, callback) {
    return this.find({
      subscriberId,
    }, callback);
  }

  /**
   * Lookup all subscriptions of a subscriber on a specific release notes.
   *
   * @param subscriberId
   * @param releaseNotesScope
   * @param releaseNotesName
   * @param callback
   * @return {BaseRepository}
   */
  findBySubscriberAndReleaseNotes({ subscriberId, releaseNotesScope, releaseNotesName }, callback) {
    return this.find({
      subscriberId,
      releaseNotesScope,
      releaseNotesName,
    }, callback);
  }
}

module.exports = SubscriptionRepository;

@@ -1352,16 +1352,288 @@
 ck);%0A  %7D
+%0A%0A  /**%0A   * Lookup all subscriptions on the given release notes.%0A   *%0A   * @param releaseNotesId%0A   * @param callback%0A   * @return %7BBaseRepository%7D%0A   */%0A  findByReleaseNotesId(releaseNotesId, callback) %7B%0A    return this.find(%7B%0A      releaseNotesId,%0A    %7D, callback);%0A  %7D
 %0A%7D%0A%0Amodu

Add support for looking up all subscriptions on a specific release note.