Skip to content

Commit

Permalink
validators
Browse files Browse the repository at this point in the history
  • Loading branch information
gillohner committed Oct 8, 2024
1 parent 7f82ca1 commit e182ae4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions handlers/meetupHandlers/meetupSuggestionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import config from '../../bot/config.js';
import userStates from '../../userStates.js'
import { deleteMessage } from '../../utils/helpers.js';
import { isValidDate, isValidTime } from '../../utils/validators.js';

const handleMeetupSuggestion = (bot, msg) => {
if (msg.chat.type !== 'private') {
Expand Down Expand Up @@ -107,7 +108,7 @@ const handleEventCreationStep = async (bot, msg) => {
});
break;
case 'date':
if (!/^\d{4}-\d{2}-\d{2}$/.test(text)) {
if (!isValidDate(text)) {
bot.sendMessage(chatId, 'Ungültiges Datumsformat. Bitte verwende YYYY-MM-DD:\n\nOder tippe /cancel um abzubrechen.', {
disable_notification: true
});
Expand All @@ -120,7 +121,7 @@ const handleEventCreationStep = async (bot, msg) => {
});
break;
case 'time':
if (!/^([01]\d|2[0-3]):([0-5]\d)$/.test(text)) {
if (!isValidTime(text)) {
bot.sendMessage(chatId, 'Ungültiges Zeitformat. Bitte verwende HH:MM:\n\nOder tippe /cancel um abzubrechen.', {
disable_notification: true
});
Expand Down
Empty file added utils/eventUtils.js
Empty file.
4 changes: 4 additions & 0 deletions utils/validators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// utils/validators.js
export const isValidDate = (dateStr) => /^\d{4}-\d{2}-\d{2}$/.test(dateStr);

export const isValidTime = (timeStr) => /^([01]\d|2[0-3]):([0-5]\d)$/.test(timeStr);

0 comments on commit e182ae4

Please sign in to comment.