Sistemato magazzino
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
export type StatoCategoria = 'confermata' | 'da_approvare';
|
||||
|
||||
export interface Categoria {
|
||||
id: string;
|
||||
nome: string;
|
||||
stato: StatoCategoria;
|
||||
creatoDaOrgId: string | null;
|
||||
creatoIl: string;
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CategorieApiService {
|
||||
private readonly http = inject(HttpClient);
|
||||
|
||||
getCategorie(): Observable<Categoria[]> {
|
||||
return this.http.get<Categoria[]>(`${environment.magazzinoApiBaseUrl}/categorie`);
|
||||
}
|
||||
|
||||
getCategoriePubbliche(nome?: string): Observable<Categoria[]> {
|
||||
const params = nome ? new HttpParams().set('nome', nome) : undefined;
|
||||
return this.http.get<Categoria[]>(`${environment.magazzinoApiBaseUrl}/categorie/pubbliche`, { params });
|
||||
}
|
||||
|
||||
creaCategoria(nome: string): Observable<Categoria> {
|
||||
return this.http.post<Categoria>(`${environment.magazzinoApiBaseUrl}/categorie`, { nome });
|
||||
}
|
||||
|
||||
aggiornaCategoria(id: string, nome: string): Observable<Categoria> {
|
||||
return this.http.put<Categoria>(`${environment.magazzinoApiBaseUrl}/categorie/${id}`, { nome });
|
||||
}
|
||||
|
||||
eliminaCategoria(id: string): Observable<void> {
|
||||
return this.http.delete<void>(`${environment.magazzinoApiBaseUrl}/categorie/${id}`);
|
||||
}
|
||||
|
||||
proponiCategoria(nome: string): Observable<Categoria> {
|
||||
return this.http.post<Categoria>(`${environment.magazzinoApiBaseUrl}/categorie/proposte`, { nome });
|
||||
}
|
||||
|
||||
approvaCategoria(id: string): Observable<Categoria> {
|
||||
return this.http.post<Categoria>(`${environment.magazzinoApiBaseUrl}/categorie/${id}/approva`, {});
|
||||
}
|
||||
|
||||
rifiutaCategoria(id: string): Observable<void> {
|
||||
return this.http.post<void>(`${environment.magazzinoApiBaseUrl}/categorie/${id}/rifiuta`, {});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user