53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { HttpClient } from '@angular/common/http';
|
|
import { Injectable, inject } from '@angular/core';
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { environment } from '../../environments/environment';
|
|
|
|
export type StatoMagazzinoVoce = 'buono' | 'da_riparare' | 'mancante';
|
|
|
|
export interface MagazzinoVoce {
|
|
id: string;
|
|
orgId: string;
|
|
materialeId: string;
|
|
materialeNome: string;
|
|
materialeCategoria: string;
|
|
quantitaPosseduta: number;
|
|
stato: StatoMagazzinoVoce;
|
|
posizione: string | null;
|
|
note: string | null;
|
|
}
|
|
|
|
export interface AggiungiMagazzinoVoceInput {
|
|
materialeId: string;
|
|
quantitaPosseduta: number;
|
|
stato: StatoMagazzinoVoce;
|
|
posizione?: string;
|
|
note?: string;
|
|
}
|
|
|
|
export interface AggiornaMagazzinoVoceInput {
|
|
materialeId?: string;
|
|
quantitaPosseduta?: number;
|
|
stato?: StatoMagazzinoVoce;
|
|
posizione?: string | null;
|
|
note?: string | null;
|
|
}
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class MagazzinoApiService {
|
|
private readonly http = inject(HttpClient);
|
|
|
|
getMagazzino(): Observable<MagazzinoVoce[]> {
|
|
return this.http.get<MagazzinoVoce[]>(`${environment.magazzinoApiBaseUrl}/magazzino`);
|
|
}
|
|
|
|
aggiungiVoce(input: AggiungiMagazzinoVoceInput): Observable<MagazzinoVoce> {
|
|
return this.http.post<MagazzinoVoce>(`${environment.magazzinoApiBaseUrl}/magazzino`, input);
|
|
}
|
|
|
|
aggiornaVoce(id: string, input: AggiornaMagazzinoVoceInput): Observable<MagazzinoVoce> {
|
|
return this.http.put<MagazzinoVoce>(`${environment.magazzinoApiBaseUrl}/magazzino/${id}`, input);
|
|
}
|
|
}
|