126 lines
3.1 KiB
TypeScript
126 lines
3.1 KiB
TypeScript
|
|
import { GeneratedReportDto, ReportTemplateDto } from '@/proxy/reports/models'
|
||
|
|
import apiService, { Config } from './api.service'
|
||
|
|
import { PagedAndSortedResultRequestDto, PagedResultDto } from '@/proxy'
|
||
|
|
|
||
|
|
export interface ReportsData {
|
||
|
|
templates: ReportTemplateDto[]
|
||
|
|
generatedReports: GeneratedReportDto[]
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface GenerateReportRequestDto {
|
||
|
|
templateId: string
|
||
|
|
parameters: Record<string, string>
|
||
|
|
}
|
||
|
|
|
||
|
|
export class ReportsService {
|
||
|
|
apiName = 'Default'
|
||
|
|
|
||
|
|
// Template operations
|
||
|
|
getTemplates = (input: PagedAndSortedResultRequestDto) =>
|
||
|
|
apiService.fetchData<PagedResultDto<ReportTemplateDto>, PagedAndSortedResultRequestDto>(
|
||
|
|
{
|
||
|
|
method: 'GET',
|
||
|
|
url: '/api/app/reports/templates',
|
||
|
|
params: {
|
||
|
|
sorting: input.sorting,
|
||
|
|
skipCount: input.skipCount,
|
||
|
|
maxResultCount: input.maxResultCount,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
{ apiName: this.apiName },
|
||
|
|
)
|
||
|
|
|
||
|
|
getTemplateById = (id: string) =>
|
||
|
|
apiService.fetchData<ReportTemplateDto>(
|
||
|
|
{
|
||
|
|
method: 'GET',
|
||
|
|
url: `/api/app/reports/templates/${id}`,
|
||
|
|
},
|
||
|
|
{ apiName: this.apiName },
|
||
|
|
)
|
||
|
|
|
||
|
|
createTemplate = (input: ReportTemplateDto) =>
|
||
|
|
apiService.fetchData(
|
||
|
|
{
|
||
|
|
method: 'POST',
|
||
|
|
url: '/api/app/reports/templates',
|
||
|
|
data: input,
|
||
|
|
},
|
||
|
|
{ apiName: this.apiName },
|
||
|
|
)
|
||
|
|
|
||
|
|
updateTemplate = (id: string, input: ReportTemplateDto) =>
|
||
|
|
apiService.fetchData<ReportTemplateDto, ReportTemplateDto>(
|
||
|
|
{
|
||
|
|
method: 'PUT',
|
||
|
|
url: `/api/app/reports/templates/${id}`,
|
||
|
|
data: input as any,
|
||
|
|
},
|
||
|
|
{ apiName: this.apiName },
|
||
|
|
)
|
||
|
|
|
||
|
|
deleteTemplate = (id: string) =>
|
||
|
|
apiService.fetchData(
|
||
|
|
{
|
||
|
|
method: 'DELETE',
|
||
|
|
url: `/api/app/reports/templates/${id}`,
|
||
|
|
},
|
||
|
|
{ apiName: this.apiName },
|
||
|
|
)
|
||
|
|
|
||
|
|
// Generated Reports operations
|
||
|
|
getGeneratedReports = (input: PagedAndSortedResultRequestDto) =>
|
||
|
|
apiService.fetchData<PagedResultDto<GeneratedReportDto>, PagedAndSortedResultRequestDto>(
|
||
|
|
{
|
||
|
|
method: 'GET',
|
||
|
|
url: '/api/app/reports/generated',
|
||
|
|
params: {
|
||
|
|
sorting: input.sorting,
|
||
|
|
skipCount: input.skipCount,
|
||
|
|
maxResultCount: input.maxResultCount,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
{ apiName: this.apiName },
|
||
|
|
)
|
||
|
|
|
||
|
|
getGeneratedReportById = (id: string) =>
|
||
|
|
apiService.fetchData<GeneratedReportDto>(
|
||
|
|
{
|
||
|
|
method: 'GET',
|
||
|
|
url: `/api/app/reports/generated/${id}`,
|
||
|
|
},
|
||
|
|
{ apiName: this.apiName },
|
||
|
|
)
|
||
|
|
|
||
|
|
generateReport = (input: GeneratedReportDto) =>
|
||
|
|
apiService.fetchData<GeneratedReportDto>(
|
||
|
|
{
|
||
|
|
method: 'POST',
|
||
|
|
url: '/api/app/reports/generate',
|
||
|
|
data: input as any,
|
||
|
|
},
|
||
|
|
{ apiName: this.apiName },
|
||
|
|
)
|
||
|
|
|
||
|
|
deleteGeneratedReport = (id: string) =>
|
||
|
|
apiService.fetchData(
|
||
|
|
{
|
||
|
|
method: 'DELETE',
|
||
|
|
url: `/api/app/reports/generated/${id}`,
|
||
|
|
},
|
||
|
|
{ apiName: this.apiName },
|
||
|
|
)
|
||
|
|
|
||
|
|
// Bulk operations
|
||
|
|
getAllData = () =>
|
||
|
|
apiService.fetchData<ReportsData>(
|
||
|
|
{
|
||
|
|
method: 'GET',
|
||
|
|
url: '/api/app/reports/all',
|
||
|
|
},
|
||
|
|
{ apiName: this.apiName },
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
export default ReportsService
|