126 lines
3.9 KiB
TypeScript
126 lines
3.9 KiB
TypeScript
import { PagedResultDto } from '@/proxy'
|
|
import apiService from './api.service'
|
|
import {
|
|
CrudEndpoint,
|
|
CreateUpdateCustomComponentDto,
|
|
CustomComponent,
|
|
CustomComponentDto,
|
|
} from '@/proxy/developerKit/models'
|
|
|
|
class DeveloperKitService {
|
|
// Custom Component endpoints
|
|
async getCustomComponents(): Promise<PagedResultDto<CustomComponentDto>> {
|
|
const response = await apiService.fetchData<PagedResultDto<CustomComponentDto>>({
|
|
url: '/api/app/custom-component',
|
|
method: 'GET',
|
|
params: { maxResultCount: 1000 },
|
|
})
|
|
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 payload =
|
|
component.props === undefined
|
|
? { ...component, props: (await this.getCustomComponent(id)).props }
|
|
: component
|
|
const response = await apiService.fetchData<CustomComponent>({
|
|
url: `/api/app/custom-component/${id}`,
|
|
method: 'PUT',
|
|
data: payload 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 toggleGeneratedEndpoint(id: string): Promise<CrudEndpoint> {
|
|
const response = await apiService.fetchData<CrudEndpoint>({
|
|
url: `/api/app/crud-endpoint-generate/${id}/toggle`,
|
|
method: 'POST',
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
/**
|
|
* @param operationTypes Aktif baslatilacak operasyonlar; verilmezse hepsi aktif uretilir.
|
|
* Listede olmayanlar pasif olarak kaydedilir.
|
|
*/
|
|
async generateCrudEndpoints(
|
|
entityName: string,
|
|
operationTypes?: string[],
|
|
): Promise<PagedResultDto<CrudEndpoint>> {
|
|
const response = await apiService.fetchData<PagedResultDto<CrudEndpoint>>({
|
|
url: `/api/app/crud-endpoint-generate/generate-crud-endpoints/${entityName}`,
|
|
method: 'POST',
|
|
params: operationTypes?.length ? { operationTypes: operationTypes.join(',') } : undefined,
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async getEndpointsByEntity(entityName: string): Promise<CrudEndpoint[]> {
|
|
const response = await apiService.fetchData<CrudEndpoint[]>({
|
|
url: `/api/app/crud-endpoint-generate/endpoints-by-entity/${entityName}`,
|
|
method: 'GET',
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async deleteGeneratedEndpointsByEntity(entityName: string): Promise<void> {
|
|
await apiService.fetchData<void>({
|
|
url: `/api/app/crud-endpoint-generate/by-entity/${entityName}`,
|
|
method: 'DELETE',
|
|
})
|
|
}
|
|
|
|
async getGeneratedListEndpoints(): Promise<PagedResultDto<CrudEndpoint>> {
|
|
const response = await apiService.fetchData<PagedResultDto<CrudEndpoint>>({
|
|
url: '/api/app/crud-endpoint-generate',
|
|
method: 'GET',
|
|
params: { maxResultCount: 1000 },
|
|
})
|
|
return response.data
|
|
}
|
|
|
|
async deleteGeneratedEndpoint(id: string): Promise<void> {
|
|
await apiService.fetchData<void>({
|
|
url: `/api/app/crud-endpoint-generate/${id}`,
|
|
method: 'DELETE',
|
|
})
|
|
}
|
|
}
|
|
|
|
export const developerKitService = new DeveloperKitService()
|