comanda.service.ts 1.53 KB
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { APP_SETTINGS } from 'src/etc/AppSettings';
import { IComanda } from 'src/app/interfaces/IComanda';

@Injectable({
  providedIn: 'root'
})
export class ComandaService {
  urlDeboSuite = APP_SETTINGS.apiDeboSuite;

  constructor(
    private http: HttpClient,
  ) { }

  getPendientesEntrega() {
    return this.http.get(`${this.urlDeboSuite}/comandas/pendientes-entrega`);
  }

  update(data: object) {
    return this.http.post(`${this.urlDeboSuite}/comandas/update`, { data: data });
  }

  getAll() {
    return this.http.get(`${this.urlDeboSuite}/comandas`);
  }

  imprimirComandaCocina(idComanda: number) {
    return this.http.get(`${this.urlDeboSuite}/comandas/imprimir/${idComanda}`);
  }

  startTimerComanda(comanda: IComanda, tipo: string) {
    let hours = 0;
    let minutes = 0;
    let seconds = 0;
    comanda[`hours${tipo}`] = '0';
    comanda[`seconds${tipo}`] = comanda[`minutes${tipo}`] = '00';
    comanda[`timer${tipo}`] = setInterval(() => {
      seconds++;
      comanda[`seconds${tipo}`] = seconds < 10 ? `0${seconds}` : seconds.toString();
      if (seconds === 60) {
        minutes++;
        comanda[`minutes${tipo}`] = minutes < 10 ? `0${minutes}` : minutes.toString();
        seconds = 0;
        comanda[`seconds${tipo}`] = '00';
      }
      if (minutes === 60) {
        hours++;
        minutes = 0;
        comanda[`hours${tipo}`] = hours.toString();
        comanda[`minutes${tipo}`] = '00';
      }
    }, 1000);
  }

}