<commit_before>import $ from 'jquery';
import async from 'async';

export default class UserModel {
  static login(body, doneCallback, failCallback) {

    $.post('/api/users/login', body)
    .done(function(result) {
      doneCallback(result.id);
    })
    .fail(function(e) {
      failCallback(e.status);
    });
  }

  static updateProvisionAvtivity(body, doneCallback, failCallback) {
    const token = sessionStorage.getItem('token');

    if (!token) {
      failCallback(401);
      return;
    }

    $.ajax({
      url: `/api/provisionActivities?access_token=${token}`,
      type: 'POST',
      data: JSON.stringify(body),
      contentType: 'application/json; charset=utf-8',
      dataType: 'json'
    })
    .done(function(result) {
      doneCallback(result);
    })
    .fail(function(e) {
      failCallback(e.status);
    });
  }

  static addStation(station, contact, cb) {
    const token = sessionStorage.getItem('token');

    if (!token) {
      return;
    }

    async.series([
      callback => {
        $.post(`/api/stations?access_token=${token}`, station)
        .done(data => {
          station = data;
          callback();
        })
        .fail(callback);
      },
      callback => {
        contact.id = station.id;
        $.ajax({
          url: `/api/stations/${station.id}/contacts?access_token=${token}`,
          type: 'POST',
          data: JSON.stringify(contact),
          contentType: 'application/json; charset=utf-8',
          dataType: 'json'
        })
        .done(data => {
          station._contacts.push(data);
          callback();
        })
        .fail(callback);
      }
    ], err => {
      cb(err, station);
    });
  }

  static getStationInfo(id, doneCallback, failCallback) {
    const token = sessionStorage.getItem('token');

    if (!token) {
      failCallback(401);
      return;
    }

    let filter = {
      'include': [
        {'provisionRequirements': 'provisionActivities'},
        {'batches': 'provisionActivities'}
      ]
    };
    filter = encodeURIComponent(JSON.stringify(filter));

    const path = `/api/stations/${id}?filter=${filter}&access_token=${token}`;

    $.get(path)
    .done(function(result) {
      doneCallback(result);
    })
    .fail(function(e) {
      failCallback(e.status);
    });
  }

  static getStationBatches(id, doneCallback, failCallback) {
    const token = sessionStorage.getItem('token');

    if (!token) {
      failCallback(401);
      return;
    }

    const path = `/api/stations/${id}/batches?access_token=${token}`;

    $.get(path)
    .done(function(result) {
      doneCallback(result);
    })
    .fail(function(e) {
      failCallback(e.status);
    });
  }
}<commit_msg>use fetch instead of jquery in UserModel.js<commit_after>import { fetchJSON, postJSON} from '../utils';

export default class UserModel {
  static login(body, doneCallback, failCallback) {

    postJSON('/api/users/login', body)
    .then(json => {
      if (json.error) {
        return failCallback(json.error.status);
      }
      else {
        return doneCallback(json.id);
      }
    })
    .catch(err => {
      failCallback(err);
    });
  }

  static updateProvisionAvtivity(body, doneCallback, failCallback) {
    const token = sessionStorage.getItem('token');

    if (!token) {
      failCallback(401);
      return;
    }

    postJSON(`/api/provisionActivities?access_token=${token}`, body)
    .then(doneCallback)
    .catch(failCallback);
  }

  static addStation(station, contact, cb) {
    const token = sessionStorage.getItem('token');

    if (!token) {
      return;
    }

    postJSON(`/api/stations?access_token=${token}`, station)
    .then(json => station = json)
    .then(() => {
      const url = `/api/stations/${station.id}/contacts?access_token=${token}`;
      contact.id = station.id;
      return postJSON(url, contact);
    })
    .then(json => station._contacts.push(json))
    .then(() => cb(null, station))
    .catch(err => cb(err));
  }

  static getStationInfo(id, doneCallback, failCallback) {
    const token = sessionStorage.getItem('token');

    if (!token) {
      failCallback(401);
      return;
    }

    let filter = {
      'include': [
        {'provisionRequirements': 'provisionActivities'},
        {'batches': 'provisionActivities'}
      ]
    };
    filter = encodeURIComponent(JSON.stringify(filter));

    const path = `/api/stations/${id}?filter=${filter}&access_token=${token}`;

    fetchJSON(path)
    .then(doneCallback)
    .catch(failCallback);
  }

  static getStationBatches(id, doneCallback, failCallback) {
    const token = sessionStorage.getItem('token');

    if (!token) {
      failCallback(401);
      return;
    }

    const path = `/api/stations/${id}/batches?access_token=${token}`;

    fetchJSON(path)
    .then(doneCallback)
    .catch(failCallback);
  }
}
{'fraction_non_alphanumeric': 0.1573750257148735, 'fraction_numerical': 0.004114379757251594, 'mean_word_length': 2.5855457227138645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '2250706', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1507, 'n_words': 256}