285 lines
8.5 KiB
TypeScript
285 lines
8.5 KiB
TypeScript
import { PagedResultDto } from '@/proxy'
|
|
import apiService from './api.service'
|
|
import {
|
|
CrudEndpoint,
|
|
ApiMigration,
|
|
CreateUpdateCrudEndpointDto,
|
|
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/crud-migration',
|
|
method: 'GET',
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async getMigration(id: string): Promise<ApiMigration> {
|
|
const response = await apiService.fetchData<ApiMigration>({
|
|
url: `/api/app/crud-migration/${id}`,
|
|
method: 'GET',
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async createMigration(data: CreateUpdateApiMigrationDto): Promise<ApiMigration> {
|
|
const response = await apiService.fetchData<ApiMigration>({
|
|
url: '/api/app/crud-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/crud-migration/${id}`,
|
|
method: 'PUT',
|
|
data: data as any,
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async deleteMigration(id: string): Promise<void> {
|
|
await apiService.fetchData<void>({
|
|
url: `/api/app/crud-migration/${id}`,
|
|
method: 'DELETE',
|
|
})
|
|
}
|
|
|
|
async applyMigration(id: string): Promise<ApiMigration> {
|
|
const response = await apiService.fetchData<ApiMigration>({
|
|
url: `/api/app/crud-migration/${id}/apply-migration`,
|
|
method: 'POST',
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async getPendingMigrations(): Promise<PagedResultDto<ApiMigration>> {
|
|
const response = await apiService.fetchData<PagedResultDto<ApiMigration>>({
|
|
url: '/api/app/crud-migration/pending-migrations',
|
|
method: 'GET',
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async generateMigration(entityId: string): Promise<ApiMigration> {
|
|
const response = await apiService.fetchData<ApiMigration>({
|
|
url: `/api/app/crud-migration/generate-migration/${entityId}`,
|
|
method: 'POST',
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
// Generated Endpoint endpoints
|
|
async getGeneratedEndpoints(): Promise<PagedResultDto<CrudEndpoint>> {
|
|
const response = await apiService.fetchData<PagedResultDto<CrudEndpoint>>({
|
|
url: '/api/app/crud-endpoint-generate',
|
|
method: 'GET',
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async getActiveGeneratedEndpoints(): Promise<PagedResultDto<CrudEndpoint>> {
|
|
const response = await apiService.fetchData<PagedResultDto<CrudEndpoint>>({
|
|
url: '/api/app/crud-endpoint-generate/active-endpoints',
|
|
method: 'GET',
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async getEndpointsByEntity(entityId: string): Promise<PagedResultDto<CrudEndpoint>> {
|
|
const response = await apiService.fetchData<PagedResultDto<CrudEndpoint>>({
|
|
url: `/api/app/crud-endpoint-generate/endpoints-by-entity/${entityId}`,
|
|
method: 'GET',
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async getGeneratedEndpoint(id: string): Promise<CrudEndpoint> {
|
|
const response = await apiService.fetchData<CrudEndpoint>({
|
|
url: `/api/app/crud-endpoint-generate/${id}`,
|
|
method: 'GET',
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async createGeneratedEndpoint(data: CreateUpdateCrudEndpointDto): Promise<CrudEndpoint> {
|
|
const response = await apiService.fetchData<CrudEndpoint>({
|
|
url: '/api/app/crud-endpoint-generate',
|
|
method: 'POST',
|
|
data: data as any,
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async updateGeneratedEndpoint(
|
|
id: string,
|
|
endpoint: CreateUpdateCrudEndpointDto,
|
|
): Promise<CrudEndpoint> {
|
|
const response = await apiService.fetchData<CrudEndpoint>({
|
|
url: `/api/app/crud-endpoint-generate/${id}`,
|
|
method: 'PUT',
|
|
data: endpoint as any,
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async deleteGeneratedEndpoint(id: string): Promise<void> {
|
|
await apiService.fetchData<void>({
|
|
url: `/api/app/crud-endpoint-generate/${id}`,
|
|
method: 'DELETE',
|
|
})
|
|
}
|
|
|
|
async toggleGeneratedEndpoint(id: string): Promise<CrudEndpoint> {
|
|
const response = await apiService.fetchData<CrudEndpoint>({
|
|
url: `/api/app/crud-endpoint-generate/${id}/toggle`,
|
|
method: 'POST',
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async generateCrudEndpoints(entityId: string): Promise<PagedResultDto<CrudEndpoint>> {
|
|
const response = await apiService.fetchData<PagedResultDto<CrudEndpoint>>({
|
|
url: `/api/app/crud-endpoint-generate/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()
|