import { Injectable } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';

@Injectable()
export class JobService {

  result: any;
  constructor(private http: HttpClient) { }

  addJob(topic, date, story) {
    const uri = 'http://localhost:4000/jobs/add';
    const obj = {

      topic: topic,
      date: date,
      story: story
    };
    this
      .http
      .post(uri, obj)
      .subscribe(res =>
        console.log('Done'));
  }

  getJob() {
    const uri = 'http://localhost:4000/jobs';
    return this
      .http
      .get(uri)
      .map(res => {
        return res;
      });
  }

  ediJob(id) {
    const uri = 'http://localhost:4000/jobs/edi' + id;
    return this
      .http
      .get(uri)
      .map(res => {
        return res;
      });
  }

  updateJob(topic, story, date, id2) {
    const uri = 'http://locahost:4000/jobs/update/' + id2;

    const obj = {
      topic: topic,
      date: date,
      story: story
    };
    this
      .http
      .post(uri, obj)
      .subscribe(res => console.log('Done'));
  }

  deleteJob(id) {
    const uri = 'http://localhost:4000/jobs/delete/' + id;

    return this
      .http
      .get(uri)
      .map(res => {
        return res;
      });
  }
}
