Fix: Order creation validation - Support CustomerInfo without IdentityReference

## Issue
Order creation failing with 400 BadRequest when using CustomerInfo (Telegram users).
Validator required IdentityReference to always be populated, but it's null when using CustomerInfo.

## Root Cause
CreateOrderDtoValidator.cs:10-12 enforced NotEmpty() on IdentityReference unconditionally.
TeleBot sends CustomerInfo for identified users, leaving IdentityReference null.

## Solution
Updated validator to accept EITHER IdentityReference OR CustomerInfo:
- New rule: At least one must be provided
- IdentityReference validation only applies when it's provided (.When() condition)
- Maintains backward compatibility with anonymous orders

## Impact
 Telegram bot orders can now be created successfully
 Anonymous orders still require IdentityReference
 Proper validation error messages for both scenarios

## Testing Required
- Create order via Telegram bot (with CustomerInfo)
- Create anonymous order (with IdentityReference)
- Verify both scenarios work correctly

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
SysAdmin 2025-10-03 18:02:23 +01:00
parent 8d9c216c88
commit 68131b6549

View File

@ -7,22 +7,28 @@ public class CreateOrderDtoValidator : AbstractValidator<CreateOrderDto>
{
public CreateOrderDtoValidator()
{
// Either IdentityReference OR CustomerInfo must be provided
RuleFor(x => x)
.Must(x => !string.IsNullOrEmpty(x.IdentityReference) || x.CustomerInfo != null)
.WithMessage("Either IdentityReference or CustomerInfo must be provided");
// IdentityReference validation (when provided)
RuleFor(x => x.IdentityReference)
.NotEmpty().WithMessage("Identity reference is required")
.MaximumLength(100).WithMessage("Identity reference cannot exceed 100 characters");
.MaximumLength(100).WithMessage("Identity reference cannot exceed 100 characters")
.When(x => !string.IsNullOrEmpty(x.IdentityReference));
RuleFor(x => x.ShippingName)
.NotEmpty().WithMessage("Shipping name is required");
RuleFor(x => x.ShippingAddress)
.NotEmpty().WithMessage("Shipping address is required");
RuleFor(x => x.ShippingCity)
.NotEmpty().WithMessage("Shipping city is required");
RuleFor(x => x.ShippingPostCode)
.NotEmpty().WithMessage("Shipping post code is required");
RuleFor(x => x.ShippingCountry)
.NotEmpty().WithMessage("Shipping country is required");