frontPanel/src/api/ticket.ts

47 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-05-13 13:24:41 +00:00
import { makeRequest } from "@api/makeRequest";
2024-02-06 14:39:02 +00:00
import { parseAxiosError } from "../utils/parse-error";
import { SendTicketMessageRequest } from "@frontend/kitui";
2024-05-13 13:24:41 +00:00
const API_URL = process.env.REACT_APP_DOMAIN + "/heruvym";
2024-02-06 14:39:02 +00:00
2024-05-13 13:24:41 +00:00
export const sendTicketMessage = async (
2024-02-06 14:39:02 +00:00
ticketId: string,
message: string,
2024-05-13 13:24:41 +00:00
): Promise<[null, string?]> => {
2024-02-06 14:39:02 +00:00
try {
const sendTicketMessageResponse = await makeRequest<
SendTicketMessageRequest,
null
>({
2024-05-13 13:24:41 +00:00
url: `${API_URL}/send`,
2024-02-06 14:39:02 +00:00
method: "POST",
useToken: true,
body: { ticket: ticketId, message: message, lang: "ru", files: [] },
});
return [sendTicketMessageResponse];
} catch (nativeError) {
const [error] = parseAxiosError(nativeError);
return [null, `Не удалось отправить сообщение. ${error}`];
}
2024-05-13 13:24:41 +00:00
};
2024-02-06 14:39:02 +00:00
2024-05-13 13:24:41 +00:00
export const shownMessage = async (id: string): Promise<[null, string?]> => {
2024-02-06 14:39:02 +00:00
try {
const shownMessageResponse = await makeRequest<{ id: string }, null>({
2024-05-13 13:24:41 +00:00
url: `${API_URL}/shown`,
2024-02-06 14:39:02 +00:00
method: "POST",
useToken: true,
body: { id },
});
return [shownMessageResponse];
} catch (nativeError) {
const [error] = parseAxiosError(nativeError);
return [null, `Не удалось прочесть сообщение. ${error}`];
}
2024-05-13 13:24:41 +00:00
};