<commit_before>import {autobind} from 'core-decorators';

const firebaseArray = new WeakMap();
const firebaseObject = new WeakMap();
const REF = new WeakMap();
const AUTH = new WeakMap();

class Places {
  constructor($firebaseArray, $firebaseObject, Auth, FURL) {
    let baseref = new Firebase(FURL);
    firebaseArray.set(this, $firebaseArray);
    firebaseObject.set(this, $firebaseObject);
    REF.set(this, baseref.child('places'));
    AUTH.set(this, Auth);

    this.places = $firebaseArray(REF.get(this));
  }

  @autobind
  all() {
    let activePlaces = firebaseArray.get(this)(REF.get(this)
      .orderByChild('status').equalTo('active'));
    return activePlaces.$loaded();
  }

  @autobind
  get(placeId) {
    return firebaseObject.get(this)(REF.get(this).child(placeId)).$loaded();
  }

  @autobind
  create(placeInfo) {
    let {name, lastname} = AUTH.get(this).user.profile;
    placeInfo.TIMESTAMP = Firebase.ServerValue.TIMESTAMP;
    placeInfo.status = 'active';
    placeInfo.creator = AUTH.get(this).user.profile.username;
    placeInfo.creatorEmail = AUTH.get(this).user.profile.email;
    placeInfo.creatorFullName = `${name} ${lastname}`;
    return this.places.$add(placeInfo);
  }

  @autobind
  edit(placeId, newInfo) {
    let place = REF.get(this).child(placeId);
    let {name, capacity, location} = newInfo;
    // Set Exacts Values for our place
    let toSave = {
      name: name,
      capacity: capacity,
      location: location
    };

    return place.update(toSave);
  }

  // Removes don't really removes only set place.status to 'disabled'
  @autobind
  remove(placeId) {
    let place = REF.get(this).child(placeId);
    return place.update({status: 'disabled'});
  }
}

Places.$inject = ['$firebaseArray', '$firebaseObject', 'Auth', 'FURL'];

export default Places;<commit_msg>Add checkPlace(cheackAvailability before)<commit_after>import {
  autobind
}
from 'core-decorators';

const firebaseArray = new WeakMap();
const firebaseObject = new WeakMap();
const REF = new WeakMap();
const AUTH = new WeakMap();
const SEARCH = new WeakMap();

class Places {
  constructor($firebaseArray, $firebaseObject, Utilities, Auth, Search, FURL) {
    let baseref = new Firebase(FURL);
    firebaseArray.set(this, $firebaseArray);
    firebaseObject.set(this, $firebaseObject);
    REF.set(this, baseref.child('places'));
    AUTH.set(this, Auth);
    SEARCH.set(this, Search);

    this.Utilities = Utilities;
    this.places = $firebaseArray(REF.get(this));
  }

  @autobind
  all() {
    let activePlaces = firebaseArray.get(this)(REF.get(this)
      .orderByChild('status').equalTo('active'));
    return activePlaces.$loaded();
  }

  @autobind
  checkPlace(placeId, date, start, end) {
    let errMessage = {
      name: '',
      message: ''
    };
    start = this.Utilities.fixTime(date, start);
    end = this.Utilities.fixTime(date, end);

    let response = new Promise((resolve, reject) => {
      SEARCH.get(this).searchReservacionByDate(date)
        .then(reservas => {
          let reservasInPlace = reservas.filter(res => res.place === placeId);
          let filteredReservas = reservasInPlace.filter(res => {
            let answer;
            if (start.isSame(res.starts) || start.isBetween(res.starts, res.ends)) {
              errMessage.name = 'START_AT_SAME_TIME';
              errMessage.message = 'Both reservations has same or closer time';
              answer = true;
            } else if (start.isBefore(res.starts) && end.isAfter(res.starts)) {
              errMessage.name = 'ENDS_TOO_LATE';
              errMessage.message = 'Your reservation colides with other';
              answer = true;
            } else {
              answer = false;
            }

            return answer;
          });
          if (filteredReservas.length) {
            reject({
              data: filteredReservas,
              message: errMessage
            });
          } else {
            resolve({
              data: [],
              message: 'No colitions found'
            });
          }
        });
    });

    return response;
  }

  @autobind
  get(placeId) {
    return firebaseObject.get(this)(REF.get(this).child(placeId)).$loaded();
  }

  @autobind
  create(placeInfo) {
    let {
      name, lastname
    } = AUTH.get(this).user.profile;
    placeInfo.TIMESTAMP = Firebase.ServerValue.TIMESTAMP;
    placeInfo.status = 'active';
    placeInfo.creator = AUTH.get(this).user.profile.username;
    placeInfo.creatorEmail = AUTH.get(this).user.profile.email;
    placeInfo.creatorFullName = `${name} ${lastname}`;
    return this.places.$add(placeInfo);
  }

  @autobind
  edit(placeId, newInfo) {
    let place = REF.get(this).child(placeId);
    let {
      name, capacity, location
    } = newInfo;
    // Set Exacts Values for our place
    let toSave = {
      name: name,
      capacity: capacity,
      location: location
    };

    return place.update(toSave);
  }

  // Removes don't really removes only set place.status to 'disabled'
  @autobind
  remove(placeId) {
    let place = REF.get(this).child(placeId);
    return place.update({
      status: 'disabled'
    });
  }
}

Places.$inject = ['$firebaseArray', '$firebaseObject',
  'Utilities', 'Auth', 'Search', 'FURL'];

export default Places;
{'fraction_non_alphanumeric': 0.13764416713934582, 'fraction_numerical': 0.0, 'mean_word_length': 2.847272727272727, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5380315', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1673, 'n_words': 343}