UNPKG

bnk-components

Version:

Reusable React components for Issaglam UI - Modern, responsive UI components with TypeScript support

119 lines (118 loc) 4.65 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import api from './BaseApi'; export class BaseApiService { constructor(baseUrl = '/') { this.baseUrl = baseUrl; } // Basic HTTP methods get(url, config) { return __awaiter(this, void 0, void 0, function* () { const response = yield api.get(url, config); return response.data; }); } post(url, data, config) { return __awaiter(this, void 0, void 0, function* () { const response = yield api.post(url, data, config); return response.data; }); } put(url, data, config) { return __awaiter(this, void 0, void 0, function* () { const response = yield api.put(url, data, config); return response.data; }); } delete(url, config) { return __awaiter(this, void 0, void 0, function* () { const response = yield api.delete(url, config); return response.data; }); } } // Generic CRUD service implementation matching EndpointMapper.cs export class BaseCrudApiService extends BaseApiService { constructor(baseUrl) { super(baseUrl); } // Get single entity by ID - matches MapGet("/{id}") getAsync(id) { return __awaiter(this, void 0, void 0, function* () { return this.get(`${this.baseUrl}/${id}`); }); } // Get paged list of entities - matches MapGet("/") getListAsync(input) { return __awaiter(this, void 0, void 0, function* () { const params = new URLSearchParams(); if (input.maxResultCount !== undefined) params.append('maxResultCount', input.maxResultCount.toString()); if (input.skipCount !== undefined) params.append('skipCount', input.skipCount.toString()); if (input.sorting) params.append('sorting', input.sorting); // Add searchText if it exists if (input.searchText) params.append('searchText', input.searchText); const queryString = params.toString(); const url = queryString ? `${this.baseUrl}?${queryString}` : this.baseUrl; return this.get(url); }); } // Lookup method - matches MapPost("/lookup") getLookupAsync(request) { return __awaiter(this, void 0, void 0, function* () { return this.post(`${this.baseUrl}/lookup`, request); }); } // Create new entity - matches MapPost("/") createAsync(input) { return __awaiter(this, void 0, void 0, function* () { return this.post(this.baseUrl, input); }); } // Update existing entity - matches MapPut("/{id}") updateAsync(id, input) { return __awaiter(this, void 0, void 0, function* () { return this.put(`${this.baseUrl}/${id}`, input); }); } // Delete entity by ID - matches MapDelete("/{id}") deleteAsync(id) { return __awaiter(this, void 0, void 0, function* () { yield this.delete(`${this.baseUrl}/${id}`); }); } // Get total count getCountAsync() { return __awaiter(this, void 0, void 0, function* () { return this.get(`${this.baseUrl}/count`); }); } // Create multiple entities - matches MapPost("/range") createRangeAsync(input) { return __awaiter(this, void 0, void 0, function* () { yield this.post(`${this.baseUrl}/range`, input); }); } // Update multiple entities - matches MapPut("/range") updateRangeAsync(input) { return __awaiter(this, void 0, void 0, function* () { yield this.put(`${this.baseUrl}/range`, input); }); } // Delete multiple entities - matches MapDelete("/range") deleteRangeAsync(ids) { return __awaiter(this, void 0, void 0, function* () { yield this.delete(`${this.baseUrl}/range`, { data: ids }); }); } }