title: trying 2 requests in order(frontend, javascript, promise)
body: <p>I'm trying to make http requests one to upload file func"uploadFile(file)" and the other is to link my upload id to my user using this func "linkAvatar(id)" the problem is i need the uploadFile(file) finished first because that func gives me the id so i can use the linkAvatar(id) func.</p>
  
  <p>My http-service:</p>
  
  <pre><code>import {CustomHttpClient} from '../../../customHttpClient';
  import {inject} from 'aurelia-framework';
  
  @inject(CustomHttpClient)
  export class FilesHttpService {
  
    constructor(http) {
      this.http = http;
    }
  
    //upload file request
    uploadFile(file) {
      let data = new FormData();
      data.append('file', file);
      data.append('filename', file.name);
  
      return this.http.post('v1/files', data);
    }
  
    // linkAvatar request
    linkAvatar(id) {
      return this.http.patch('v1/users/me/video/'+id);
    }
  }
  </code></pre>
  
  <p>My component:</p>
  
  <pre><code>import {bindable, customElement} from 'aurelia-framework';
  import {inject} from 'aurelia-framework';
  import {AuthService} from 'wanderlima/aurelia-auth';
  import {CustomHttpClient} from '../../../../customHttpClient';
  import {FilesHttpService} from '../../services/files-http-service';
  import {UserHttpService} from '../../services/user-http-service';
  
  @inject(AuthService, CustomHttpClient, FilesHttpService, UserHttpService)
  
  @customElement('zm-zoome-yourself')
  export class ZmZoomeYourself {
  
    constructor(auth, http, fileUpload) {
      this.auth = auth.auth.getToken();
      this.http = http;
      this.fileUpload = fileUpload;
      //this.avatarUpload = userfile;
    }
  
    endRecord(file) {
      let msg = '';
      this.zoomeYourself = file;
      this.stopCount();
      //Is making this request but is not handling the response with .then() it goes to the other func linkAvatar(id) without entering .then
      this.fileUpload.uploadFile(file).then(function(res) {
        //Is entering this block of code only after linkAvatar(id)
        if (res.statusCode === 201) {
          var id = res.content.id;
          msg = 'upload realizado com sucesso!';
        } else {
          msg = 'ocorreu um erro ao enviar o arquivo';
        }
      });
      return this.fileUpload.linkAvatar(id);
    }
  }
  </code></pre>