1-
21import { CatalogDto } from '../common/catalog-dto' ;
32import { IFiscalapiHttpClient } from '../http/fiscalapi-http-client.interface' ;
43import { ApiResponse } from '../common/api-response' ;
54import { BaseFiscalapiService } from './base-fiscalapi-service' ;
6- import { ICatalogService } from '..' ;
5+ import { ICatalogService , PagedList } from '..' ;
76
87/**
98 * Implementación del servicio de catálogos
@@ -18,10 +17,46 @@ export class CatalogService extends BaseFiscalapiService<CatalogDto> implements
1817 super ( httpClient , 'catalogs' , apiVersion ) ;
1918 }
2019
21- /**
22- * @inheritdoc
23- */
24- async getCatalog ( catalogType : string ) : Promise < ApiResponse < CatalogDto [ ] > > {
25- return this . httpClient . getAsync < CatalogDto [ ] > ( this . buildEndpoint ( catalogType ) ) ;
26- }
20+
21+
22+ /**
23+ * Recupera un registro de un catálogo por catalogName y id.
24+ *
25+ * @param catalogName - Nombre del catálogo
26+ * @param id - Id del registro en el catalogName
27+ * @returns Promise que resuelve en una respuesta API con CatalogDto
28+ */
29+ public async getRecordById ( catalogName : string , id : string ) : Promise < ApiResponse < CatalogDto > > {
30+ const path = `${ catalogName } /key/${ id } ` ;
31+ const endpoint = this . buildEndpoint ( path ) ;
32+ // api/v4/catalogs/<catalogName>/key/<id>
33+ return this . httpClient . getAsync < CatalogDto > ( endpoint ) ;
34+ }
35+
36+ /**
37+ * Busca en un catálogo.
38+ *
39+ * @param catalogName - Catalog name. Must be a catalog retrieved from getList()
40+ * @param searchText - Criterio de búsqueda. Debe tener 4 caracteres de longitud como mínimo.
41+ * @param pageNumber - Numero de pagina a recuperar (default: 1)
42+ * @param pageSize - Tamaño de la página entre 1 y 100 registros por página (default: 50)
43+ * @returns Promise que resuelve en una respuesta API con lista paginada de CatalogDto
44+ */
45+ public async searchCatalog (
46+ catalogName : string ,
47+ searchText : string ,
48+ pageNumber : number = 1 ,
49+ pageSize : number = 50
50+ ) : Promise < ApiResponse < PagedList < CatalogDto > > > {
51+ const path = `${ catalogName } /${ searchText } ` ;
52+ const queryParams = {
53+ pageNumber : pageNumber . toString ( ) ,
54+ pageSize : pageSize . toString ( )
55+ } ;
56+ const endpoint = this . buildEndpoint ( path , queryParams ) ;
57+ const response = await this . httpClient . getAsync < PagedList < CatalogDto > > ( endpoint ) ;
58+ return response ;
59+ }
60+
61+
2762}
0 commit comments