3

I am new to typescript. I have got an id generated after post function. Now by using that _id generated in post,using that i must call PUT function for play pause, when play pause button is called response must go to server. I am here by sharing my code of both ts and API service,

API code for PUT:

    edit(updateId) {
  console.log(updateId);
  let authToken = JSON.parse(localStorage.getItem('authToken'));
  var company_id = JSON.parse(localStorage.getItem('company_id'));
  var queries = "?authToken=" + authToken + "&&_id="+ company_id +"&&view_id=2";
 return this.http.put(urlBase + '/timerEntry/' + updateId ,options)
                  .map(this.extractData)
                  .catch(this.handleError);
}

TS code: This is for POST function

this.ApiService
 .addtimerEntries(new_task)
              .subscribe(
                entry  => {
                 console.log(entry)
                  this.todays.today.push(entry.data[0]);
                  this.updateId = entry.data[0]._id;
                 console.log(this.updateId);
              this.toasterService.pop('success', 'Entry added 
               successfully');
              this.newTask.hide();
            },
          error => {
          this.toasterService.pop('error', 'Something went wrong!');
        });

This is for PUT function:

 playTimer() {
     this.timerService.playTimer();
      this.playDiv = true;
      console.log(this.updateId);
      if (this.updateId){ 
    this.ApiService
           .edit( this.updateId)
           .subscribe(
             user => {
               console.log(user);
               this.ApiService
                          .getEntries(this.workEmail)
                          .subscribe(
                            entries  => {
                              console.log(entries);
                              this.entries = entries;
                      this.toasterService.pop('success', 'updated successfully');},
                    error => {
                      //console.log(error);
                    });
             },
             error => {
                this.toasterService.pop('error', 'Something went wrong!');
             });
    }
    }
    pauseTimer() {
     this.timerService.pauseTimer();
      this.playDiv = false;
    }

Consoled Output:

data:Array(1)
0:Object
category_id:1
client_id:15
company_id:4
department_id:26
entry_type:"checkin_entry"
project_id:7
subcategories:Array(1)
times:Array(1)
workEmail:"[email protected]"
_id:"59362522325a5a0786f661b3" 
6
  • from where you are calling edit function? Commented Jun 6, 2017 at 12:49
  • are you getting console.log(this.updateId); as undefined Commented Jun 7, 2017 at 8:00
  • no i have got that _id now, when i press play/pause button Commented Jun 7, 2017 at 8:02
  • ok, where are you getting the issue now? Commented Jun 7, 2017 at 8:03
  • it is showing 404 error Commented Jun 7, 2017 at 8:04

1 Answer 1

1

According to your code, you called different baseUrl for post and put. so it is giving 404 error

So, in PUT change

return this.http.put(urlBase + '/timerEntry/' + updateId ,options)

to

return this.http.put(timerUrlBase + '/timerEntry/' + updateId ,options)

So, your service code will be,

edit(updateId) { 
    console.log(updateId); 
    let authToken = JSON.parse(localStorage.getItem('authToken')); 
    var company_id = JSON.parse(localStorage.getItem('company_id')); 
    var queries = "?authToken=" + authToken + "&&_id="+ company_id +"&&view_id=2"; 
    return this.http.put(timerUrlBase + '/timerEntry/' + updateId ,options) 
    .map(this.extractData) 
    .catch(this.handleError); 
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.