equirment.service.ts 2.22 KB
Newer Older
1 2 3
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Equirment, SearchEquirmentModel } from '../models/equirment.model';
4
import { ItemDetail } from '../models/itemDetail.model';
Your Name committed
5
import { Observable } from 'rxjs';
6
import { Type } from '../models/type.model';
7 8 9 10

@Injectable({ providedIn: 'root' })
export class EquirmentService {

11
  constructor(private http: HttpClient) { }
Your Name committed
12
  url: string = "http://5fa9-110-169-221-194.ngrok.io";
Your Name committed
13
  listEquirment: Equirment[] = []
14

15
  addEquirment(model: Equirment) {
Your Name committed
16 17
    // this.listEquirment.push(model);
    console.log("model", model)
Your Name committed
18
    this.http.post(this.url + "/eqment/", model).subscribe(response => {
Your Name committed
19 20
      console.log(response);
    })
21 22
  }

23 24 25 26 27 28
  addType(model : Type) {
    this.http.post(this.url + "/type/", model).subscribe(response => {
      console.log(response);
    })
  }

Your Name committed
29 30
  getListEquirment(): Observable<Equirment[]> {
    return this.http.get<Equirment[]>(this.url + "/eqment/lists");
31 32 33
  }

  searchListEquirment(searchModel: SearchEquirmentModel) {
34
    this.http.get(this.url + '&startDate=' + searchModel.sDate.split("-")[2] + '-' + searchModel.sDate.split("-")[1] + '-' + searchModel.sDate.split("-")[0] + '&endDate=' + searchModel.eDate.split("-")[2] + '-' + searchModel.eDate.split("-")[1] + '-' + searchModel.eDate.split("-")[0] + '&startTime=' + searchModel.sTime + ':00' + '&endTime=' + searchModel.eTime + ':00').subscribe((response: any) => {
35 36 37 38 39 40 41 42
      console.log(response);
      this.listEquirment = response;
    }, error => {
      console.log(error)
      alert("ไม่สามารถค้นหาอุปกรณ์ที่ว่างได้ เนื่องจาก :\n" + error.message)
    })
  }

Your Name committed
43 44
  deleteEquirment(model: Equirment) {
    this.http.delete(this.url + "/eqment/" + model.eqId).subscribe(response => {
45
      console.log(response);
Your Name committed
46
      this.getListEquirment()
47 48 49 50
      alert("ลบข้อมูลอุปกรณ์สำเร็จ")
    })
  }

Your Name committed
51 52
  updateEquirment(model: Equirment) {
    this.http.put(this.url + "/eqment/" + model.eqId, model).subscribe(response => {
53 54 55 56
      console.log(response);
      alert("อัพเดทข้อมูลอุปกรณ์สำเร็จ")
    })
  }
57
}