<commit_before>import db from 'baqend'

/**
Das Modell dient als Schnittstelle zur Datenbank
*/
class Modul {
  constructor () {
    this.swopCards = []
  }

  /**
  Loggt den User ein
  @param username: der username (Emailadresse) des Users
  @param pw: password des Users
  @return Promise
  */
  login (username, pw) {
    username = username.toLowerCase()
    return db.User.login(username, pw)
  }

  /**
  Loggt den User aus
  @return Promise
  */
  logout () {
    return db.User.logout()
  }

  register (displayName, username, password) {
    username = username.toLowerCase()
    return db.User.register(username, password)
      // return db.modules.post('updateRestrictedUserInfo', {id: userObject.id, displayName: displayName})
  }

  // /**
  //  * Registriert einen neuen User
  //  * @param displayName
  //  * @param username
  //  * @param password
  //  * @returns {*|Promise.<model.User>}
  //  */
  // register (displayName, username, password) {
  //   return db.User.register(username, password).then(() => {
  //     return db.modules.post('createRestrictedUserInfo', {
  //       displayName: displayName,
  //       email: username
  //     })
  //   })
  // }

  /**
   * getDisplayName from the current user
   * @returns {Promise.<TResult>}
   */
  getDisplayName () {
    return db.User.load(db.User.me.id, {depth: 1}).then((user) => {
      return user.restrictedUserInfo.displayName
    })
  }

  getEmail () {
    return db.User.load(db.User.me.id, {depth: 1}).then((user) => {
      return user.restrictedUserInfo.email
    })
  }

  /**
   * updates the displayName of the user
   * @param displayName
   * @returns {Promise.<*>}
   */
  updateUsername (displayName) {
    return db.modules.post('updateDisplayName', {displayName: displayName})
  }

  /**
   * updates the email of the user, but it is not the login email
   * @param email
   * @returns {Promise.<*>}
   */
  updateEmail (email) {
    return db.modules.post('updateEmail', {email: email})
  }

  /**
   * Deletes the user for EVER
   * @returns {*|{value}}
   */
  delete () {
    return db.modules.post('deleteUser')
  }

  /**
   * change the password
   * @param {String} oldPassword
   * @param {String} newPassword
   * @returns {*|{value}}
   */
  changePassword (oldPassword, newPassword) {
    return db.User.newPassword(db.User.me.username, oldPassword, newPassword)
  }

  /**
   * Create a new course
   * @param name String
   * @param courseId String
   * @returns {Promise.<*>}
   */
  createCourse (name, courseId) {
    return db.modules.post('createCourse', {id: courseId, name: name})
  }

  /**
   * Get all courses from the database
   * @return Promise
   */
  getAllCourses () {
    return db.Course.find()
      .ascending('name')
      .resultList().then((result) => {
        return result
      })
  }

  /**
  * Erstellt eine Swopcard und speichert Sie in der Datenbank ab
  @param courseId: String, die Id des Kurses
  @param group: String, optional, die Gruppe in der sich der User befindet
  @param searchedCourses: [String], Ids der Kurse die gesucht werden
  @param searchedGroups: [String], Gruppennamen der Gruppen die gesucht werden
  @throws Error sofern ein Kurs nicht existiert
  @return Promise
  */
  createSwopCard (searchedCourses, searchedGroups, courseId, group) {
    db.modules.post('createSwopCard', {
      searchedCourses,
      searchedGroups,
      courseId,
      group
    })
  }

  /**
   * load a swopcard object by its id
   * @param swopCardId
   */
  loadSwopCardById (swopCardId) {
    return db.SwopCard.load(swopCardId)
  }

  /**
   * get all swopCards from the current User
   * @returns Set
   */
  getMySwopCards () {
    // var currentUser = db.User.me
    return db.User.load(db.User.me.id, {depth: 3}).then((currentUser) => {
      return Array.from(currentUser.swopCards)
    })
  }

  /**
   * Deletes a swopcard by its given id
   * @param id of the swopCard<commit_msg>decrease depth from 3 to 2<commit_after>import db from 'baqend'

/**
Das Modell dient als Schnittstelle zur Datenbank
*/
class Modul {
  constructor () {
    this.swopCards = []
  }

  /**
  Loggt den User ein
  @param username: der username (Emailadresse) des Users
  @param pw: password des Users
  @return Promise
  */
  login (username, pw) {
    username = username.toLowerCase()
    return db.User.login(username, pw)
  }

  /**
  Loggt den User aus
  @return Promise
  */
  logout () {
    return db.User.logout()
  }

  register (displayName, username, password) {
    username = username.toLowerCase()
    return db.User.register(username, password)
      // return db.modules.post('updateRestrictedUserInfo', {id: userObject.id, displayName: displayName})
  }

  // /**
  //  * Registriert einen neuen User
  //  * @param displayName
  //  * @param username
  //  * @param password
  //  * @returns {*|Promise.<model.User>}
  //  */
  // register (displayName, username, password) {
  //   return db.User.register(username, password).then(() => {
  //     return db.modules.post('createRestrictedUserInfo', {
  //       displayName: displayName,
  //       email: username
  //     })
  //   })
  // }

  /**
   * getDisplayName from the current user
   * @returns {Promise.<TResult>}
   */
  getDisplayName () {
    return db.User.load(db.User.me.id, {depth: 1}).then((user) => {
      return user.restrictedUserInfo.displayName
    })
  }

  getEmail () {
    return db.User.load(db.User.me.id, {depth: 1}).then((user) => {
      return user.restrictedUserInfo.email
    })
  }

  /**
   * updates the displayName of the user
   * @param displayName
   * @returns {Promise.<*>}
   */
  updateUsername (displayName) {
    return db.modules.post('updateDisplayName', {displayName: displayName})
  }

  /**
   * updates the email of the user, but it is not the login email
   * @param email
   * @returns {Promise.<*>}
   */
  updateEmail (email) {
    return db.modules.post('updateEmail', {email: email})
  }

  /**
   * Deletes the user for EVER
   * @returns {*|{value}}
   */
  delete () {
    return db.modules.post('deleteUser')
  }

  /**
   * change the password
   * @param {String} oldPassword
   * @param {String} newPassword
   * @returns {*|{value}}
   */
  changePassword (oldPassword, newPassword) {
    return db.User.newPassword(db.User.me.username, oldPassword, newPassword)
  }

  /**
   * Create a new course
   * @param name String
   * @param courseId String
   * @returns {Promise.<*>}
   */
  createCourse (name, courseId) {
    return db.modules.post('createCourse', {id: courseId, name: name})
  }

  /**
   * Get all courses from the database
   * @return Promise
   */
  getAllCourses () {
    return db.Course.find()
      .ascending('name')
      .resultList().then((result) => {
        return result
      })
  }

  /**
  * Erstellt eine Swopcard und speichert Sie in der Datenbank ab
  @param courseId: String, die Id des Kurses
  @param group: String, optional, die Gruppe in der sich der User befindet
  @param searchedCourses: [String], Ids der Kurse die gesucht werden
  @param searchedGroups: [String], Gruppennamen der Gruppen die gesucht werden
  @throws Error sofern ein Kurs nicht existiert
  @return Promise
  */
  createSwopCard (searchedCourses, searchedGroups, courseId, group) {
    db.modules.post('createSwopCard', {
      searchedCourses,
      searchedGroups,
      courseId,
      group
    })
  }

  /**
   * load a swopcard object by its id
   * @param swopCardId
   */
  loadSwopCardById (swopCardId) {
    return db.SwopCard.load(swopCardId)
  }

  /**
   * get all swopCards from the current User
   * @returns Set
   */
  getMySwopCards () {
    // var currentUser = db.User.me
    return db.User.load(db.User.me.id, {depth: 2}).then((currentUser) => {
      return Array.from(currentUser.swopCards)
    })
  }

  /**
   * Deletes a swopcard by its given id
   * @param id of the swopCard
{'fraction_non_alphanumeric': 0.13520698822635777, 'fraction_numerical': 0.001012786428661856, 'mean_word_length': 2.712406015037594, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, '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': '1025002', 'n_tokens_mistral': 2638, 'n_tokens_neox': 2598, 'n_words': 652}