-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanufacture-service.ts
More file actions
59 lines (51 loc) · 2.16 KB
/
Copy pathmanufacture-service.ts
File metadata and controls
59 lines (51 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { HttpClient } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import { PaginatedResponse } from '../models/pagination/pagination.model';
import { environment } from '../../../environments/environment';
import { buildHttpParams } from './build-http-params';
import { ManufacturerResponse } from '../models/manufactureres/manufacturer-response.model';
import { GeneralOptionQuery } from '../models/generals/general-option-query.model';
import { ManufacturerOption } from '../models/manufactureres/manufaturer-options.model';
import { getAllResponse } from '../models/generals/general-responses-list.model';
import { GeneralOption } from '../models/generals/general-options-response.model';
import { ManufacturerRequest } from '../models/manufactureres/manufacturer-request.model';
@Injectable({
providedIn: 'root',
})
export class ManufacturerService {
private http = inject(HttpClient);
private api = environment.apiUrl;
private flag = 'manufacturer';
getAll(filters: Partial<GeneralOptionQuery>) {
const params = buildHttpParams(filters);
return this.http.get<PaginatedResponse<ManufacturerResponse>>(`${this.api}/${this.flag}`, {
params,
});
}
getOptions(filters: GeneralOptionQuery) {
const params = buildHttpParams(filters);
return this.http.get<getAllResponse<GeneralOption[]>>(`${this.api}/${this.flag}/options`, {
params,
});
}
getById(id: string) {
return this.http.get<ManufacturerResponse>(`${this.api}/${this.flag}/${id}`);
}
getManufacturerByProduct(productId: string) {
return this.http.get<getAllResponse<ManufacturerOption[]>>(
`${this.api}/${this.flag}/product/${productId}`,
);
}
createManufacturer(data: ManufacturerRequest) {
return this.http.post<getAllResponse<ManufacturerResponse>>(`${this.api}/${this.flag}`, data);
}
updateManufacturer(id: string, data: ManufacturerRequest) {
return this.http.put<getAllResponse<ManufacturerResponse>>(
`${this.api}/${this.flag}/${id}`,
data,
);
}
deleteManufacturer(id: string) {
return this.http.delete<getAllResponse<ManufacturerResponse>>(`${this.api}/${this.flag}/${id}`);
}
}