Skip to content

Commit e4985eb

Browse files
committed
catalogs tested
1 parent 9692ece commit e4985eb

3 files changed

Lines changed: 86 additions & 13 deletions

File tree

examples/main.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async function main() : Promise<void> {
1010
apiUrl: 'https://localhost:7173',
1111
apiKey: 'sk_development_833a58f9_8212_43ce_b544_f2fa93b1e895',
1212
tenant: 'e839651d-1765-4cd0-ba7f-547a4c20580f',
13-
debug:false
13+
debug:true
1414
};
1515

1616
// Sellos SAT CSD del emisor para emisión de CFDI
@@ -204,6 +204,21 @@ async function main() : Promise<void> {
204204
// console.log('apiResponse:', apiResponse);
205205

206206

207+
// Listar catálogos
208+
// const apiResponse = await client.catalogs.getList(1, 100);
209+
// console.log('apiResponse:', apiResponse);
210+
211+
// Obtener registro de catálogo por ID (Obtiene el registro '03' (Transferencia electrónica de fondos) en el catalogo de formas de pago (SatPaymentForms))
212+
// const apiResponse = await client.catalogs.getRecordById("SatPaymentForms", "03");
213+
// console.log('apiResponse:', apiResponse);
214+
215+
// Busca en un catálogo. (Busca en el catalogo de formas de pago (SatPaymentForms) los registros que contengan la palabra 'Tarjeta')
216+
// const apiResponse = await client.catalogs.searchCatalog("SatPaymentForms", "Tarjeta", 1, 100);
217+
// console.log('apiResponse:', apiResponse);
218+
219+
220+
221+
207222
console.log('End Fiscalapi node...');
208223
} catch (error: unknown) {
209224
console.error('Error inesperado:', error);

src/abstractions/catalog-service.interface.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,38 @@
22
import { IFiscalapiService } from './fiscalapi-service.interface';
33
import { CatalogDto } from '../common/catalog-dto';
44
import { ApiResponse } from '../common/api-response';
5+
import { PagedList } from '../common/paged-list';
56

67
/**
78
* Interfaz del servicio de catálogos
89
*/
910
export interface ICatalogService extends IFiscalapiService<CatalogDto> {
11+
12+
13+
/**
14+
* /api/v4/catalogs/<catalogName>/key/<id>
15+
* Recupera un registro específico por catalogName e id
16+
*
17+
* @param catalogName - Nombre del catálogo
18+
* @param id - Identificador del registro
19+
*/
20+
getRecordById(catalogName: string, id: string): Promise<ApiResponse<CatalogDto>>;
21+
1022
/**
11-
* Obtiene un catálogo por su código
12-
* @param {string} catalogType - Tipo de catálogo
13-
* @returns {Promise<ApiResponse<CatalogDto[]>>} Lista de elementos del catálogo
23+
* GET /api/v4/catalogs/{catalogName}/{searchText}
24+
* Busca registros en un catálogo específico
25+
*
26+
* @param catalogName - Nombre del catálogo
27+
* @param searchText - Texto de búsqueda
28+
* @param pageNumber - Número de página (opcional, default: 1)
29+
* @param pageSize - Tamaño de página (opcional, default: 50)
1430
*/
15-
getCatalog(catalogType: string): Promise<ApiResponse<CatalogDto[]>>;
31+
searchCatalog(
32+
catalogName: string,
33+
searchText: string,
34+
pageNumber?: number,
35+
pageSize?: number
36+
): Promise<ApiResponse<PagedList<CatalogDto>>>;
37+
38+
1639
}

src/services/catalog-service.ts

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
21
import { CatalogDto } from '../common/catalog-dto';
32
import { IFiscalapiHttpClient } from '../http/fiscalapi-http-client.interface';
43
import { ApiResponse } from '../common/api-response';
54
import { 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

Comments
 (0)