1
|
import { environment } from 'src/environments/environment';
|
2
|
import { Category } from './../../models/category.interface';
|
3
|
import { GenericRestService } from './../generic-rest.service';
|
4
|
import { Injectable } from '@angular/core';
|
5
|
import { HttpClient } from '@angular/common/http';
|
6
|
import { Observable } from 'rxjs';
|
7
|
|
8
|
@Injectable({
|
9
|
providedIn: 'root'
|
10
|
})
|
11
|
export class CategoriesService extends GenericRestService<Category> {
|
12
|
|
13
|
constructor(private http: HttpClient) {
|
14
|
super(`${environment.baseApiUrl}${environment.apiUrl.verificationRulesWs}/categories`, http); // TODO: Change this when GenericRestService<> changes.
|
15
|
}
|
16
|
|
17
|
public autosuggestCategoryName(name: string, classificationId: number = null): Observable<Category[]> {
|
18
|
return this.http.get<Category[]>(this.baseUrl + '/autocomplete/categoryByNameAndDocClassification', {
|
19
|
params: {
|
20
|
name: name,
|
21
|
classificationId: (classificationId ? classificationId.toString() : '')
|
22
|
}
|
23
|
});
|
24
|
}
|
25
|
|
26
|
public autosuggestCategoryCode(code: string, classificationId: number = null): Observable<Category[]> {
|
27
|
return this.http.get<Category[]>(this.baseUrl + '/autocomplete/categoryByCodeAndDocClassification', {
|
28
|
params: {
|
29
|
code: code,
|
30
|
classificationId: (classificationId ? classificationId.toString() : '')
|
31
|
}
|
32
|
});
|
33
|
}
|
34
|
|
35
|
public createNewCategory(category: Category) {
|
36
|
|
37
|
// Create the model required by the backend ('CreateCategoryRequestModel') before using the generic create method.
|
38
|
let createCategoryRequestModel = {
|
39
|
id: null,
|
40
|
docClassificationId: category.documentClassification.classificationId,
|
41
|
categoryName: category.categoryName,
|
42
|
categoryCode: category.categoryCode
|
43
|
}
|
44
|
|
45
|
return super.create(createCategoryRequestModel);
|
46
|
}
|
47
|
|
48
|
public updateCategory(category: Category) {
|
49
|
|
50
|
// Create the model required by the backend ('CreateCategoryRequestModel') before using the generic create method.
|
51
|
let updateCategoryRequestModel = {
|
52
|
id: category.id,
|
53
|
docClassificationId: category.documentClassification.classificationId,
|
54
|
categoryName: category.categoryName,
|
55
|
categoryCode: category.categoryCode
|
56
|
}
|
57
|
|
58
|
return super.update(updateCategoryRequestModel);
|
59
|
}
|
60
|
}
|