Skip to content

Conversation

@konard
Copy link
Contributor

@konard konard commented Nov 14, 2025

🐛 Проблема

При создании единовременной задачи (recurrence: "none") из фронтенда TaskMateFrontend, API возвращал ошибки валидации:

  • "The selected recurrence is invalid."
  • "The recurrence time field must match the format H:i:s."

Это происходило потому, что валидация принимала только значения 'daily', 'weekly' и 'monthly', но фронтенд отправляет 'none' для задач без повторения.

🔧 Решение

1. Обновлена валидация в TaskController (app/Http/Controllers/Api/V1/TaskController.php)

Строки 211, 299: Добавлено 'none' в enum валидации

'recurrence' => 'nullable|string|in:none,daily,weekly,monthly',

Строки 223, 313: Пропуск дополнительной валидации для 'none'

if (!empty($validated['recurrence']) && $validated['recurrence'] !== 'none') {
    // Проверка recurrence_time, recurrence_day_of_week и recurrence_day_of_month
}

2. Обновлена swagger документация (swagger.yaml)

Строки 248, 2389, 2540: Добавлено 'none' в enum во всех схемах

recurrence:
  type: string
  enum: [none, daily, weekly, monthly]
  nullable: true

📋 Изменения

TaskController.php

  • ✅ Добавлено 'none' в валидацию recurrence (строки 211, 299)
  • ✅ Пропуск проверки обязательных полей при recurrence='none' (строки 223, 313)

swagger.yaml

  • ✅ Добавлено 'none' в Task schema (строка 248)
  • ✅ Добавлено 'none' в POST /tasks request body (строка 2389)
  • ✅ Добавлено 'none' в PUT /tasks/{id} request body (строка 2540)

🧪 Тестирование

До исправления:

POST /api/v1/tasks
{
  "title": "Test task",
  "recurrence": "none",
  "task_type": "individual",
  "response_type": "acknowledge"
}

Ответ: 422 Unprocessable Entity
{
  "message": "The selected recurrence is invalid.",
  "errors": {
    "recurrence": ["The selected recurrence is invalid."]
  }
}

После исправления:

POST /api/v1/tasks
{
  "title": "Test task",
  "recurrence": "none",
  "task_type": "individual",
  "response_type": "acknowledge"
}

Ответ: 201 Created
{
  "id": 1,
  "title": "Test task",
  "recurrence": "none",
  ...
}

🔗 Связанные задачи

✅ Результат

Теперь API корректно принимает 'none' для единовременных задач, что соответствует ожиданиям фронтенда.


🤖 Generated with Claude Code


Summary by cubic

Accept 'none' as a valid recurrence for one-off tasks to prevent 422 validation errors. Skip recurrence-specific checks when 'none' is used and document the value in Swagger.

  • Bug Fixes
    • TaskController: add 'none' to recurrence enum in store and update.
    • Skip validation for recurrence_time/day_of_week/day_of_month when recurrence='none'.
    • Swagger: include 'none' in recurrence enums for task schema and POST/PUT bodies.

Written for commit df1562a. Summary will update automatically on new commits.

Problem:
When creating a non-recurring task (recurrence: "none") from the frontend,
the API returned validation errors:
- "The selected recurrence is invalid."
- "The recurrence time field must match the format H:i:s."

This happened because the validation only accepted 'daily', 'weekly',
and 'monthly' values, but the frontend sends 'none' for non-recurring tasks.

Solution:
1. Updated TaskController validation to accept 'none' in recurrence enum
2. Modified custom validation logic to skip checks when recurrence is 'none'
3. Updated swagger.yaml to document 'none' as a valid recurrence option

Changes:
- TaskController.php:211,299 - Added 'none' to recurrence validation enum
- TaskController.php:223,313 - Skip validation when recurrence is 'none'
- swagger.yaml:248,2389,2540 - Added 'none' to recurrence enum in all schemas

Related to: xierongchuan/TaskMateClient#54

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@xierongchuan xierongchuan merged commit c6654c3 into xierongchuan:main Nov 14, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants