Skip to content

TAS-59#23

Merged
maksberegovoi merged 4 commits intodevfrom
feature/TAS-59-configure-api
Apr 2, 2026
Merged

TAS-59#23
maksberegovoi merged 4 commits intodevfrom
feature/TAS-59-configure-api

Conversation

@maksberegovoi
Copy link
Copy Markdown
Collaborator

No description provided.

- Implement unified response wrapping via TransformResponseInterceptor
- Standardize error structure with ApiErrorResponseDto and global filters
- Create ApiResponseHttpCodes custom decorator for automated Swagger documentation
- Add generic Swagger decorators for single (ApiOkResponseDto) and paginated (ApiOkResponsePaginatedDto) responses
- Enhance DTOs with @ApiProperty for detailed OpenAPI/Swagger schemas

Detailed changes:
- TransformResponseInterceptor: wraps all responses in { data: ... } and handles pagination (meta)
- ApiErrorResponseDto: provides a consistent error object (statusCode, message, error, timestamp, path)
- ApiResponseHttpCodes: a reusable helper to document common HTTP errors (400, 401, 403, 404, 409, 500)
- DTOs: fully documented with @ApiProperty
@maksberegovoi maksberegovoi force-pushed the feature/TAS-59-configure-api branch from 3c6cc32 to aaf48bb Compare April 1, 2026 21:01
@maksberegovoi maksberegovoi marked this pull request as ready for review April 1, 2026 21:04
perekljuchatel
perekljuchatel previously approved these changes Apr 2, 2026
Copy link
Copy Markdown
Member

@perekljuchatel perekljuchatel left a comment

Choose a reason for hiding this comment

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

Конфликт статуса 204 (No Content) и Интерсептора
В user.controller.ts методы updatePassword и remove помечены декоратором @httpcode(204) и возвращают void (undefined).
Проблема: Интерсептор ловит этот undefined и согласно логике if (result == null) возвращает { data: null }. Но HTTP статус 204 строго запрещает наличие тела ответа (body). Fastify попытается отправить JSON-объект {"data": null} с 204-м кодом, что может привести к скрытой ошибке сериализации в Fastify или к ошибкам парсинга на клиенте.

Несовместимость CORS и Cookie авторизации
В main.ts настроен CORS со значением origin: ''. При этом в Swagger заявлена аутентификация через Cookie (addCookieAuth).
Проблема: Фронтенд и бэкенд при разработке работают на разных портах (например, 3000 и 3005). Чтобы браузер разрешил отправлять куки (cross-origin), в CORS обязательно должен быть флаг credentials: true. Но браузеры строго запрещают использовать origin: '
' вместе с credentials: true. Если оставить так, фронтенд не сможет отправлять токены авторизации.

- Add handling 204 status code
- Change handling result if result is null
- Add `corsConfig` to centralize CORS setup
- Update `.env` and environment validation to support `CORS_ALLOWED_ORIGINS`
- Replace hardcoded CORS options with dynamic configuration in `main.ts`
- Update CI workflow to include `CORS_ALLOWED_ORIGINS` for tests
- Move Swagger configuration logic from `main.ts` to `swagger.config.ts` for better modularity
Copy link
Copy Markdown
Member

@perekljuchatel perekljuchatel left a comment

Choose a reason for hiding this comment

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

@maksberegovoi maksberegovoi merged commit a76423b into dev Apr 2, 2026
2 checks passed
@maksberegovoi maksberegovoi deleted the feature/TAS-59-configure-api branch April 2, 2026 19:23
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