Fix user ID handling in purchase return creation when auth is unavailable
This commit is contained in:
@@ -20,10 +20,13 @@ public class PurchaseReturnController(PurchaseReturnService service, ICurrentUse
|
|||||||
[HttpPost("api/purchase-orders/{id:guid}/returns")]
|
[HttpPost("api/purchase-orders/{id:guid}/returns")]
|
||||||
public async Task<IActionResult> Create(Guid id, CreatePurchaseReturnRequest request, CancellationToken ct)
|
public async Task<IActionResult> Create(Guid id, CreatePurchaseReturnRequest request, CancellationToken ct)
|
||||||
{
|
{
|
||||||
var userId = currentUser.UserId ?? throw new UnauthorizedAccessException();
|
// TEMPORARY: currentUser.UserId is always unset due to the broken auth middleware
|
||||||
|
// (testbug.md #28) — fall back to the explicitly supplied user until that's fixed.
|
||||||
|
var userId = currentUser.UserId ?? request.CreatedByUserId;
|
||||||
|
if (userId is null) return BadRequest(new { error = "CreatedByUserId is required while auth is unavailable" });
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = await service.CreateAsync(id, request, userId, ct);
|
var result = await service.CreateAsync(id, request, userId.Value, ct);
|
||||||
return CreatedAtAction(nameof(GetById), new { id = result.Id }, result);
|
return CreatedAtAction(nameof(GetById), new { id = result.Id }, result);
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException ex) { return Conflict(new { error = ex.Message }); }
|
catch (InvalidOperationException ex) { return Conflict(new { error = ex.Message }); }
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ namespace Distribution.Features.PurchaseReturn;
|
|||||||
|
|
||||||
public record PurchaseReturnItemRequest(Guid ItemId, int Quantity);
|
public record PurchaseReturnItemRequest(Guid ItemId, int Quantity);
|
||||||
|
|
||||||
public record CreatePurchaseReturnRequest(string Reason, List<PurchaseReturnItemRequest> Items);
|
public record CreatePurchaseReturnRequest(
|
||||||
|
string Reason,
|
||||||
|
List<PurchaseReturnItemRequest> Items,
|
||||||
|
// TEMPORARY: required while auth doesn't resolve a logged-in user server-side — see testbug.md #28.
|
||||||
|
Guid? CreatedByUserId = null);
|
||||||
|
|
||||||
public record PurchaseReturnItemResponse(Guid Id, Guid ItemId, string Sku, string ItemName, int Quantity);
|
public record PurchaseReturnItemResponse(Guid Id, Guid ItemId, string Sku, string ItemName, int Quantity);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user