@@ -14,60 +14,60 @@ export class CategoryService {
14
14
constructor ( private httpClient : HttpClient , private router : Router ) {
15
15
}
16
16
17
+ static handleError ( error : any ) : Observable < never > {
18
+ console . log ( 'ERROR:' ) ;
19
+ console . error ( error ) ;
20
+ return throwError ( 'Server error (' + error . status + '): ' + error . text ( ) ) ;
21
+ }
22
+
17
23
getCategories ( ) : Observable < Category [ ] > {
18
- return this . httpClient . get ( BASE_URL ) . pipe (
19
- catchError ( error => this . handleError ( error ) )
24
+ return this . httpClient . get ( BASE_URL + 'categories' ) . pipe (
25
+ catchError ( error => CategoryService . handleError ( error ) )
20
26
) as Observable < Category [ ] > ;
21
27
}
22
28
23
29
getCategory ( id : number | string ) : Observable < Category > {
24
- return this . httpClient . get ( BASE_URL + id ) . pipe (
25
- catchError ( error => this . handleError ( error ) )
30
+ return this . httpClient . get ( BASE_URL + 'categories/' + id ) . pipe (
31
+ catchError ( error => CategoryService . handleError ( error ) )
26
32
) as Observable < Category > ;
27
33
}
28
34
29
- addCategory ( title : string , description : string , icon : string ) {
35
+ addCategory ( title : string , description : string , icon : string ) : Observable < any > {
30
36
31
- this . httpClient . post ( BASE_URL + 'admin/categories' , { title, description, icon} , { withCredentials : true } )
37
+ /* this.httpClient.post(BASE_URL + 'admin/categories', {title, description, icon}, {withCredentials: true})
32
38
.subscribe(
33
39
(response) => this.router.navigate(['profile']),
34
40
(error) => alert('Usuario ya existe, inicie sesión')
35
- ) ;
36
- /*return this.httpClient.post(BASE_URL + 'admin/categories', {title, description, icon})
37
- .pipe(
38
- catchError(error => this.handleError(error))
39
41
);*/
42
+ return this . httpClient . post ( BASE_URL + 'admin/categories' , { title, description, icon} , { withCredentials : true } )
43
+ . pipe (
44
+ catchError ( error => CategoryService . handleError ( error ) )
45
+ ) ;
40
46
}
41
47
42
- setCategoryImage ( category : Category , formData : FormData ) {
43
- return this . httpClient . post ( BASE_URL + category . id_CATEGORY + '/image' , formData )
48
+ setCategoryImage ( category : Category , formData : FormData ) : Observable < any > {
49
+ return this . httpClient . post ( BASE_URL + 'admin/categories/' + category . id_CATEGORY + '/image' , formData )
44
50
. pipe (
45
- catchError ( error => this . handleError ( error ) )
51
+ catchError ( error => CategoryService . handleError ( error ) )
46
52
) ;
47
53
}
48
54
49
- deleteCategoryImage ( category : Category ) {
50
- return this . httpClient . delete ( BASE_URL + category . id_CATEGORY + '/image' )
55
+ deleteCategoryImage ( category : Category ) : Observable < any > {
56
+ return this . httpClient . delete ( BASE_URL + 'admin/categories/' + category . id_CATEGORY + '/image' )
51
57
. pipe (
52
- catchError ( error => this . handleError ( error ) )
58
+ catchError ( error => CategoryService . handleError ( error ) )
53
59
) ;
54
60
}
55
61
56
- deleteCategory ( category : Category ) {
57
- return this . httpClient . delete ( BASE_URL + category . id_CATEGORY ) . pipe (
58
- catchError ( error => this . handleError ( error ) )
62
+ deleteCategory ( category : Category ) : Observable < any > {
63
+ return this . httpClient . delete ( BASE_URL + 'admin/categories/' + category . id_CATEGORY ) . pipe (
64
+ catchError ( error => CategoryService . handleError ( error ) )
59
65
) ;
60
66
}
61
67
62
- updateCategory ( category : Category ) {
63
- return this . httpClient . put ( BASE_URL + category . id_CATEGORY , category ) . pipe (
64
- catchError ( error => this . handleError ( error ) )
68
+ updateCategory ( category : Category ) : Observable < any > {
69
+ return this . httpClient . put ( BASE_URL + 'admin/categories/' + category . id_CATEGORY , category ) . pipe (
70
+ catchError ( error => CategoryService . handleError ( error ) )
65
71
) ;
66
72
}
67
-
68
- private handleError ( error : any ) {
69
- console . log ( 'ERROR:' ) ;
70
- console . error ( error ) ;
71
- return throwError ( 'Server error (' + error . status + '): ' + error . text ( ) ) ;
72
- }
73
73
}
0 commit comments