217 lines
6.4 KiB
TypeScript
217 lines
6.4 KiB
TypeScript
import { PagedResultDto } from '@/proxy'
|
|
import apiService from './api.service'
|
|
import {
|
|
CrudEndpoint,
|
|
CreateUpdateCrudEndpointDto,
|
|
CreateUpdateCustomComponentDto,
|
|
CreateUpdateSqlTableDto,
|
|
CustomComponent,
|
|
CustomComponentDto,
|
|
SqlTable,
|
|
} from '@/proxy/developerKit/models'
|
|
|
|
class DeveloperKitService {
|
|
async getSqlTables(): Promise<PagedResultDto<SqlTable>> {
|
|
const response = await apiService.fetchData<PagedResultDto<SqlTable>>({
|
|
url: '/api/app/sql-table',
|
|
method: 'GET',
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async getActiveSqlTables(): Promise<PagedResultDto<SqlTable>> {
|
|
const response = await apiService.fetchData<PagedResultDto<SqlTable>>({
|
|
url: '/api/app/sql-table/active-tables',
|
|
method: 'GET',
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async getSqlTable(id: string): Promise<SqlTable> {
|
|
const response = await apiService.fetchData<SqlTable>({
|
|
url: `/api/app/sql-table/${id}`,
|
|
method: 'GET',
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async createSqlTable(data: CreateUpdateSqlTableDto): Promise<SqlTable> {
|
|
const response = await apiService.fetchData<SqlTable>({
|
|
url: '/api/app/sql-table',
|
|
method: 'POST',
|
|
data: data as any,
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async updateSqlTable(id: string, entity: CreateUpdateSqlTableDto): Promise<SqlTable> {
|
|
const response = await apiService.fetchData<SqlTable>({
|
|
url: `/api/app/sql-table/${id}`,
|
|
method: 'PUT',
|
|
data: entity as any,
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async deleteSqlTable(id: string): Promise<void> {
|
|
await apiService.fetchData<void>({
|
|
url: `/api/app/sql-table/${id}`,
|
|
method: 'DELETE',
|
|
})
|
|
}
|
|
|
|
async toggleSqlTableActiveStatus(id: string): Promise<void> {
|
|
await apiService.fetchData<void>({
|
|
url: `/api/app/sql-table/${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',
|
|
})
|
|
}
|
|
|
|
// 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()
|