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:
parent
8d9c216c88
commit
68131b6549
@ -7,22 +7,28 @@ public class CreateOrderDtoValidator : AbstractValidator<CreateOrderDto>
|
|||||||
{
|
{
|
||||||
public CreateOrderDtoValidator()
|
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)
|
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)
|
RuleFor(x => x.ShippingName)
|
||||||
.NotEmpty().WithMessage("Shipping name is required");
|
.NotEmpty().WithMessage("Shipping name is required");
|
||||||
|
|
||||||
RuleFor(x => x.ShippingAddress)
|
RuleFor(x => x.ShippingAddress)
|
||||||
.NotEmpty().WithMessage("Shipping address is required");
|
.NotEmpty().WithMessage("Shipping address is required");
|
||||||
|
|
||||||
RuleFor(x => x.ShippingCity)
|
RuleFor(x => x.ShippingCity)
|
||||||
.NotEmpty().WithMessage("Shipping city is required");
|
.NotEmpty().WithMessage("Shipping city is required");
|
||||||
|
|
||||||
RuleFor(x => x.ShippingPostCode)
|
RuleFor(x => x.ShippingPostCode)
|
||||||
.NotEmpty().WithMessage("Shipping post code is required");
|
.NotEmpty().WithMessage("Shipping post code is required");
|
||||||
|
|
||||||
RuleFor(x => x.ShippingCountry)
|
RuleFor(x => x.ShippingCountry)
|
||||||
.NotEmpty().WithMessage("Shipping country is required");
|
.NotEmpty().WithMessage("Shipping country is required");
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user