Skip to content

Commit

Permalink
Prep to be able to search by request id.
Browse files Browse the repository at this point in the history
DB Change
  • Loading branch information
jSylvestre committed Feb 11, 2025
1 parent f6a0e89 commit 1741643
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Sloth.Core/Domain/JournalRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,12 @@ public JournalRequest()
[MinLength(1)]
[Required]
public IList<Transaction> Transactions { get; set; }

/// <summary>
/// Really, a journal request can only have 1 transaction, but if we re-send a JR we loose the tie to the original transaction
/// This doesn't have to be a foreign key, but it should be a unique identifier for the transaction
/// </summary>
[MaxLength(255)]
public string SavedTransactionId { get; set; }
}
}
2 changes: 1 addition & 1 deletion Sloth.Core/Jobs/AggieEnterpriseJournalJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public async Task<AggieEnterpriseJournalJobDetails> UploadTransactions(ILogger l

// here we will store the result of the transaction upload
var journalRequest = new JournalRequest
{ Transactions = new[] { transaction }, Source = source };
{ Transactions = new[] { transaction }, Source = source, SavedTransactionId = transaction.Id };

if (requestStatus.RequestId.HasValue &&
requestStatus.RequestStatus == RequestStatus.Pending)
Expand Down
28 changes: 26 additions & 2 deletions Sloth.Web/Controllers/TransactionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ public async Task<IActionResult> CallWebHook(string id)
[Authorize(Policy = PolicyCodes.TeamAnyRole)]
public async Task<IActionResult> Search(TransactionsFilterModel filter = null)
{

if (string.IsNullOrWhiteSpace(filter?.TrackingNum))
{
return RedirectToAction("Index");
Expand All @@ -684,13 +685,30 @@ public async Task<IActionResult> Search(TransactionsFilterModel filter = null)
var txn = await DbContext.Transactions.Where(t => t.Source.Team.Slug == TeamSlug && t.Id == filter.TrackingNum).FirstOrDefaultAsync();
if (txn != null)
{
Message = $"Transaction found by Id: {filter.TrackingNum}";
return RedirectToAction("Details", new { id = txn.Id });
}
}

//Try to find by request id
if(Guid.TryParse(filter.TrackingNum, out var reqId))
{
var txn = await DbContext.JournalRequests.Include(a => a.Transactions).Where(t => t.Source.Team.Slug == TeamSlug && t.RequestId == reqId).FirstOrDefaultAsync();
if (txn != null && txn.Transactions != null)
{
Message = $"Transaction found by Request Id: {filter.TrackingNum}";
//This will work if we found an "active" journal request, but not if we replaced it.
return RedirectToAction("Details", new { id = txn.Transactions.First().Id });
}
if(txn != null)
{
Message = $"Replaced Journal Request found by Request Id: {filter.TrackingNum}";
return RedirectToAction("Details", "JournalRequests", new { id = txn.SavedTransactionId });
}
}

ErrorMessage = $"Search Returned no results: {filter.TrackingNum}";
return RedirectToAction("Index");
//ErrorMessage = $"Search Returned no results: {filter.TrackingNum}";
//return RedirectToAction("Index");

}

Expand Down Expand Up @@ -735,6 +753,12 @@ public async Task<IActionResult> Search(TransactionsFilterModel filter = null)
return RedirectToAction("Details", new { txns.First(a => a.MerchantTrackingNumber == filter.TrackingNum).Id });
}

if (User.IsInRole(Roles.SystemAdmin))
{
//Allow System Admins to search all transactions for specific types.
}


ErrorMessage = $"Search Returned no results: {filter.TrackingNum}";
return RedirectToAction("Index");

Expand Down

0 comments on commit 1741643

Please sign in to comment.