@@ -2,11 +2,16 @@ import { HttpClient } from '@angular/common/http';
22import { inject , Injectable } from '@angular/core' ;
33import { PaginatedResponse } from '../models/pagination/pagination.model' ;
44import { environment } from '../../../environments/environment' ;
5- import { CategoryResponse } from '../models/catetories/categories.model' ;
5+ import {
6+ CategoryResponse ,
7+ CreateCategoryPayload ,
8+ UpdateCategoryPayload ,
9+ } from '../models/catetories/categories.model' ;
610import { buildHttpParams } from './build-http-params' ;
711import { CategoryOption } from '../models/catetories/category-options.model' ;
812import { GeneralOptionQuery } from '../models/generals/general-option-query.model' ;
913import { getAllResponse } from '../models/generals/general-responses-list.model' ;
14+ import { CategoryDefaultQuery } from '../models/catetories/categories-default-query' ;
1015
1116@Injectable ( {
1217 providedIn : 'root' ,
@@ -16,8 +21,11 @@ export class CategoryService {
1621 private api = environment . apiUrl ;
1722 private flag = 'category' ;
1823
19- getAll ( ) {
20- return this . http . get < PaginatedResponse < CategoryResponse > > ( `${ this . api } /${ this . flag } ` ) ;
24+ getAll ( filters : CategoryDefaultQuery ) {
25+ const params = buildHttpParams ( filters ) ;
26+ return this . http . get < PaginatedResponse < CategoryResponse > > ( `${ this . api } /${ this . flag } ` , {
27+ params,
28+ } ) ;
2129 }
2230
2331 getOptions ( filters : GeneralOptionQuery ) {
@@ -31,15 +39,15 @@ export class CategoryService {
3139 return this . http . get < CategoryResponse > ( `${ this . api } /${ this . flag } /${ id } ` ) ;
3240 }
3341
34- create ( data : FormData ) {
35- return this . http . post < CategoryResponse > ( `${ this . api } /${ this . flag } ` , data ) ;
42+ create ( data : CreateCategoryPayload ) {
43+ return this . http . post < getAllResponse < CategoryResponse > > ( `${ this . api } /${ this . flag } ` , data ) ;
3644 }
3745
38- update ( id : string , data : FormData ) {
39- return this . http . post < CategoryResponse > ( `${ this . api } /${ this . flag } /${ id } ` , data ) ;
46+ update ( id : string , data : UpdateCategoryPayload ) {
47+ return this . http . put < getAllResponse < CategoryResponse > > ( `${ this . api } /${ this . flag } /${ id } ` , data ) ;
4048 }
4149
4250 delete ( id : string ) {
43- return this . http . delete < void > ( `${ this . api } /${ this . flag } /${ id } ` ) ;
51+ return this . http . delete < getAllResponse < CategoryResponse > > ( `${ this . api } /${ this . flag } /${ id } ` ) ;
4452 }
4553}
0 commit comments