fix(admin): fix error when chat_id is string

This commit is contained in:
2025-12-04 11:23:00 +03:00
parent 418a2fc5bb
commit 8f6af04e73
2 changed files with 22 additions and 5 deletions

View File

@@ -81,6 +81,13 @@ const settings = useSettingsStore();
const statusMessage = ref(null); const statusMessage = ref(null);
const isLoading = ref(false); const isLoading = ref(false);
const collapseId = useId(); const collapseId = useId();
const parseChatId = (value) => {
if (value === '' || value === null || value === undefined) return null;
const normalized = String(value).trim();
if (!/^-?\d+$/.test(normalized)) return null;
const parsed = Number.parseInt(normalized, 10);
return Number.isFinite(parsed) ? parsed : null;
};
const props = defineProps({ const props = defineProps({
label: { label: {
@@ -93,6 +100,10 @@ const props = defineProps({
}, },
}); });
if (typeof model.value === 'string') {
model.value = parseChatId(model.value);
}
const statusMessageClass = computed(() => { const statusMessageClass = computed(() => {
if (!statusMessage.value) return ''; if (!statusMessage.value) return '';
@@ -108,7 +119,7 @@ const statusMessageClass = computed(() => {
}); });
function handleInput(event) { function handleInput(event) {
model.value = event.target.value; model.value = parseChatId(event.target.value);
// Сбрасываем статус сообщения при изменении значения // Сбрасываем статус сообщения при изменении значения
if (statusMessage.value) { if (statusMessage.value) {
statusMessage.value = null; statusMessage.value = null;
@@ -148,9 +159,15 @@ async function getChatId() {
return; return;
} }
// Успешное получение Chat ID const parsedChatId = parseChatId(response.data.chat_id);
const chatId = response.data.chat_id;
model.value = chatId; if (parsedChatId === null) {
statusMessage.value = '❌ Ошибка: Chat ID вернулся в некорректном формате.';
console.error('Некорректный Chat ID в ответе:', response);
return;
}
model.value = parsedChatId;
statusMessage.value = '✅ ChatID успешно получен и подставлен в поле. Не забудьте сохранить настройки!'; statusMessage.value = '✅ ChatID успешно получен и подставлен в поле. Не забудьте сохранить настройки!';
} catch (error) { } catch (error) {
console.error('Ошибка при получении Chat ID:', error); console.error('Ошибка при получении Chat ID:', error);

View File

@@ -227,7 +227,7 @@ class SettingsSerializerService
throw new InvalidArgumentException('telegram.bot_token must be a string or null'); throw new InvalidArgumentException('telegram.bot_token must be a string or null');
} }
if (isset($data['chat_id']) && ! is_int($data['chat_id'])) { if (isset($data['chat_id']) && ! is_numeric($data['chat_id'])) {
throw new InvalidArgumentException('telegram.chat_id must be an integer or null'); throw new InvalidArgumentException('telegram.chat_id must be an integer or null');
} }