diff --git a/src/services/api/production.ts b/src/services/api/production.ts index d481081d..1f2a0373 100644 --- a/src/services/api/production.ts +++ b/src/services/api/production.ts @@ -12,6 +12,8 @@ import { NextDayRecording, } from '@/types/api/production/recording'; import { ProjectFlockKandang } from '@/types/api/production/project-flock-kandang'; +import { httpClient } from '@/services/http/client'; +import { formatDate } from '@/lib/helper'; export const ProjectFlockKandangApi = new BaseApiService< ProjectFlockKandang, @@ -88,6 +90,30 @@ export class RecordingService extends BaseApiService< } ); } + + async exportToExcel(initialQueryString: string) { + const params = new URLSearchParams(initialQueryString); + + params.set('export', 'excel'); + + const queryString = `?${params.toString()}`; + + const res = await httpClient(`${this.basePath}${queryString}`, { + method: 'GET', + responseType: 'blob', + }); + + const url = window.URL.createObjectURL(new Blob([res])); + const link = document.createElement('a'); + link.href = url; + + const fileName = `recording-${formatDate(Date.now(), 'DD-MM-YYYY')}.xlsx`; + link.setAttribute('download', fileName); + + document.body.appendChild(link); + link.click(); + link.remove(); + } } export const RecordingApi = new RecordingService('/production/recordings');