erp-platform/ui/src/services/developerKit.service.ts
Sedat ÖZTÜRK 8cc8ed07f9 Düzenleme
2025-08-11 09:34:44 +03:00

285 lines
8.4 KiB
TypeScript

import { PagedResultDto } from '@/proxy'
import apiService from './api.service'
import {
ApiEndpoint,
ApiMigration,
CreateUpdateApiEndpointDto,
CreateUpdateApiMigrationDto,
CreateUpdateCustomComponentDto,
CreateUpdateCustomEntityDto,
CustomComponent,
CustomComponentDto,
CustomEntity,
} from '@/proxy/developerKit/models'
class DeveloperKitService {
async getCustomEntities(): Promise<PagedResultDto<CustomEntity>> {
const response = await apiService.fetchData<PagedResultDto<CustomEntity>>({
url: '/api/app/custom-entity',
method: 'GET',
})
return response.data
}
async getActiveCustomEntities(): Promise<PagedResultDto<CustomEntity>> {
const response = await apiService.fetchData<PagedResultDto<CustomEntity>>({
url: '/api/app/custom-entity/active-entities',
method: 'GET',
})
return response.data
}
async getCustomEntity(id: string): Promise<CustomEntity> {
const response = await apiService.fetchData<CustomEntity>({
url: `/api/app/custom-entity/${id}`,
method: 'GET',
})
return response.data
}
async createCustomEntity(data: CreateUpdateCustomEntityDto): Promise<CustomEntity> {
const response = await apiService.fetchData<CustomEntity>({
url: '/api/app/custom-entity',
method: 'POST',
data: data as any,
})
return response.data
}
async updateCustomEntity(id: string, entity: CreateUpdateCustomEntityDto): Promise<CustomEntity> {
const response = await apiService.fetchData<CustomEntity>({
url: `/api/app/custom-entity/${id}`,
method: 'PUT',
data: entity as any,
})
return response.data
}
async deleteCustomEntity(id: string): Promise<void> {
await apiService.fetchData<void>({
url: `/api/app/custom-entity/${id}`,
method: 'DELETE',
})
}
async toggleCustomEntityActiveStatus(id: string): Promise<void> {
await apiService.fetchData<void>({
url: `/api/app/custom-entity/${id}/toggle-active-status`,
method: 'POST',
})
}
// Custom Component endpoints
async getCustomComponents(): Promise<PagedResultDto<CustomComponentDto>> {
const response = await apiService.fetchData<PagedResultDto<CustomComponentDto>>({
url: '/api/app/custom-component',
method: 'GET',
})
return response.data
}
async getActiveCustomComponents(): Promise<PagedResultDto<CustomComponentDto>> {
const response = await apiService.fetchData<PagedResultDto<CustomComponentDto>>({
url: '/api/app/custom-component/active-components',
method: 'GET',
})
return response.data
}
async getCustomComponent(id: string): Promise<CustomComponent> {
const response = await apiService.fetchData<CustomComponent>({
url: `/api/app/custom-component/${id}`,
method: 'GET',
})
return response.data
}
async createCustomComponent(component: CreateUpdateCustomComponentDto): Promise<CustomComponent> {
const response = await apiService.fetchData<CustomComponent>({
url: '/api/app/custom-component',
method: 'POST',
data: component as any,
})
return response.data
}
async updateCustomComponent(
id: string,
component: CreateUpdateCustomComponentDto,
): Promise<CustomComponent> {
const response = await apiService.fetchData<CustomComponent>({
url: `/api/app/custom-component/${id}`,
method: 'PUT',
data: component as any,
})
return response.data
}
async deleteCustomComponent(id: string): Promise<void> {
await apiService.fetchData<void>({
url: `/api/app/custom-component/${id}`,
method: 'DELETE',
})
}
// Migration endpoints
async getMigrations(): Promise<PagedResultDto<ApiMigration>> {
const response = await apiService.fetchData<PagedResultDto<ApiMigration>>({
url: '/api/app/api-migration',
method: 'GET',
})
return response.data
}
async getMigration(id: string): Promise<ApiMigration> {
const response = await apiService.fetchData<ApiMigration>({
url: `/api/app/api-migration/${id}`,
method: 'GET',
})
return response.data
}
async createMigration(data: CreateUpdateApiMigrationDto): Promise<ApiMigration> {
const response = await apiService.fetchData<ApiMigration>({
url: '/api/app/api-migration',
method: 'POST',
data: data as any,
})
return response.data
}
async updateMigration(id: string, data: CreateUpdateApiMigrationDto): Promise<ApiMigration> {
const response = await apiService.fetchData<ApiMigration>({
url: `/api/app/api-migration/${id}`,
method: 'PUT',
data: data as any,
})
return response.data
}
async deleteMigration(id: string): Promise<void> {
await apiService.fetchData<void>({
url: `/api/app/api-migration/${id}`,
method: 'DELETE',
})
}
async applyMigration(id: string): Promise<ApiMigration> {
const response = await apiService.fetchData<ApiMigration>({
url: `/api/app/api-migration/${id}/apply-migration`,
method: 'POST',
})
return response.data
}
async getPendingMigrations(): Promise<PagedResultDto<ApiMigration>> {
const response = await apiService.fetchData<PagedResultDto<ApiMigration>>({
url: '/api/app/api-migration/pending-migrations',
method: 'GET',
})
return response.data
}
async generateMigration(entityId: string): Promise<ApiMigration> {
const response = await apiService.fetchData<ApiMigration>({
url: `/api/app/api-migration/generate-migration/${entityId}`,
method: 'POST',
})
return response.data
}
// Generated Endpoint endpoints
async getGeneratedEndpoints(): Promise<PagedResultDto<ApiEndpoint>> {
const response = await apiService.fetchData<PagedResultDto<ApiEndpoint>>({
url: '/api/app/api-endpoint',
method: 'GET',
})
return response.data
}
async getActiveGeneratedEndpoints(): Promise<PagedResultDto<ApiEndpoint>> {
const response = await apiService.fetchData<PagedResultDto<ApiEndpoint>>({
url: '/api/app/api-endpoint/active-endpoints',
method: 'GET',
})
return response.data
}
async getEndpointsByEntity(entityId: string): Promise<PagedResultDto<ApiEndpoint>> {
const response = await apiService.fetchData<PagedResultDto<ApiEndpoint>>({
url: `/api/app/api-endpoint/endpoints-by-entity/${entityId}`,
method: 'GET',
})
return response.data
}
async getGeneratedEndpoint(id: string): Promise<ApiEndpoint> {
const response = await apiService.fetchData<ApiEndpoint>({
url: `/api/app/api-endpoint/${id}`,
method: 'GET',
})
return response.data
}
async createGeneratedEndpoint(data: CreateUpdateApiEndpointDto): Promise<ApiEndpoint> {
const response = await apiService.fetchData<ApiEndpoint>({
url: '/api/app/api-endpoint',
method: 'POST',
data: data as any,
})
return response.data
}
async updateGeneratedEndpoint(
id: string,
endpoint: CreateUpdateApiEndpointDto,
): Promise<ApiEndpoint> {
const response = await apiService.fetchData<ApiEndpoint>({
url: `/api/app/api-endpoint/${id}`,
method: 'PUT',
data: endpoint as any,
})
return response.data
}
async deleteGeneratedEndpoint(id: string): Promise<void> {
await apiService.fetchData<void>({
url: `/api/app/api-endpoint/${id}`,
method: 'DELETE',
})
}
async toggleGeneratedEndpoint(id: string): Promise<ApiEndpoint> {
const response = await apiService.fetchData<ApiEndpoint>({
url: `/api/app/api-endpoint/${id}/toggle`,
method: 'POST',
})
return response.data
}
async generateCrudEndpoints(entityId: string): Promise<PagedResultDto<ApiEndpoint>> {
const response = await apiService.fetchData<PagedResultDto<ApiEndpoint>>({
url: `/api/app/api-endpoint/generate-crud-endpoints/${entityId}`,
method: 'POST',
})
return response.data
}
// Health Check
async healthCheck(): Promise<{ status: string; timestamp: string }> {
try {
const response = await apiService.fetchData({
url: '/api/app/health',
method: 'GET',
})
if (response.status === 200) {
return { status: 'healthy', timestamp: new Date().toISOString() }
}
return { status: 'unhealthy', timestamp: new Date().toISOString() }
} catch {
return { status: 'offline', timestamp: new Date().toISOString() }
}
}
}
export const developerKitService = new DeveloperKitService()