diff --git a/app/src/components/AudioRow/AudioRow.tsx b/app/src/components/AudioRow/AudioRow.tsx index 653ddd4..39c2f9f 100644 --- a/app/src/components/AudioRow/AudioRow.tsx +++ b/app/src/components/AudioRow/AudioRow.tsx @@ -4,15 +4,15 @@ import { getCallRecord } from '../../utils/apiGetRecord'; interface AudioRowProps { length: string; isHovered: boolean; - recordId: number; - partnershipId: string; + record: string; + partnership_id: string; } const AudioRow: React.FC = ({ length, isHovered, - recordId, - partnershipId, + record, + partnership_id, }) => { if (!length) { return null; @@ -20,8 +20,10 @@ const AudioRow: React.FC = ({ const handlePlay = async () => { try { - const audioUrl = await getCallRecord({ recordId, partnershipId }); + const audioUrl = await getCallRecord({ record, partnership_id }); + console.log(audioUrl); const newAudio = new Audio(audioUrl); + newAudio.play(); } catch (error) { console.error('Ошибка при воспроизведении записи:', error); diff --git a/app/src/components/Table/Table.tsx b/app/src/components/Table/Table.tsx index 8111915..6845d24 100644 --- a/app/src/components/Table/Table.tsx +++ b/app/src/components/Table/Table.tsx @@ -9,8 +9,8 @@ interface TableRowData { source: string; score: string; length: string; - id: number; - partnershipId: string; + record: string; + partnership_id: string; } interface TableProps { diff --git a/app/src/components/TableRow/TableRow.tsx b/app/src/components/TableRow/TableRow.tsx index be5f6a6..eba9646 100644 --- a/app/src/components/TableRow/TableRow.tsx +++ b/app/src/components/TableRow/TableRow.tsx @@ -10,8 +10,8 @@ interface TableRowProps { source: string; score: string; length: string; - id: number; - partnershipId: string; + record: string; + partnership_id: string; } const TableRow: React.FC = ({ @@ -22,8 +22,8 @@ const TableRow: React.FC = ({ source, score, length, - id, - partnershipId, + record, + partnership_id, }) => { const [isHovered, setIsHovered] = useState(false); @@ -49,8 +49,8 @@ const TableRow: React.FC = ({ diff --git a/app/src/utils/api.ts b/app/src/utils/api.ts index 1a9f9da..bc3f26e 100644 --- a/app/src/utils/api.ts +++ b/app/src/utils/api.ts @@ -2,7 +2,8 @@ import axios, { AxiosError } from 'axios'; export interface Call { id: number; - partnershipId: string; + record: string; + partnership_id: string; date: string; time: number; from_number: string; diff --git a/app/src/utils/apiGetRecord.ts b/app/src/utils/apiGetRecord.ts index 79fa778..9cddc77 100644 --- a/app/src/utils/apiGetRecord.ts +++ b/app/src/utils/apiGetRecord.ts @@ -1,35 +1,43 @@ -import axios from 'axios'; +import axios, { AxiosError } from 'axios'; const BASE_URL = 'https://api.skilla.ru/mango/getRecord'; const token = 'testtoken'; interface GetCallRecordParams { - recordId: number; - partnershipId: string; + record: string; + partnership_id: string; +} + +interface ApiError { + description: string; } export const getCallRecord = async ({ - recordId, - partnershipId, + record, + partnership_id, }: GetCallRecordParams): Promise => { - const requestBody = { - record: recordId, - partnership_id: partnershipId, - }; - try { - const response = await axios.post(BASE_URL, requestBody, { - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json', - }, - responseType: 'blob', - }); + const url = `${BASE_URL}?record=${encodeURIComponent(record)}&partnership_id=${encodeURIComponent(partnership_id)}`; + + const response = await axios.post( + url, + {}, + { + headers: { + Authorization: `Bearer ${token}`, + }, + responseType: 'blob', + } + ); const audioUrl = URL.createObjectURL(response.data); return audioUrl; - } catch (error) { + } catch (err) { + const error = err as AxiosError; console.error('Ошибка при получении записи звонка:', error); - throw error; + const errorMessage = error.response?.data + ? error.response.data.description + : 'Ошибка сети'; + throw new Error(errorMessage); } }; diff --git a/app/src/utils/formatCalls.ts b/app/src/utils/formatCalls.ts index 081a4d5..2ea29a0 100644 --- a/app/src/utils/formatCalls.ts +++ b/app/src/utils/formatCalls.ts @@ -29,8 +29,8 @@ export const formatCalls = (calls: Call[]) => { source: call.source || '', score: 'Отлично', length: callLength, - id: call.id, - partnershipId: call.partnershipId, + record: call.record, + partnership_id: call.partnership_id, }; }); };