mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Refactor how we get storeids list in invoice filter (#3483)
This commit is contained in:
@@ -925,7 +925,7 @@ namespace BTCPayServer.Tests
|
|||||||
private void AssertSearchInvoice(TestAccount acc, bool expected, string invoiceId, string filter, string storeId = null)
|
private void AssertSearchInvoice(TestAccount acc, bool expected, string invoiceId, string filter, string storeId = null)
|
||||||
{
|
{
|
||||||
var result =
|
var result =
|
||||||
(InvoicesModel)((ViewResult)acc.GetController<UIInvoiceController>()
|
(InvoicesModel)((ViewResult)acc.GetController<UIInvoiceController>(storeId is not null)
|
||||||
.ListInvoices(new InvoicesModel { SearchTerm = filter, StoreId = storeId }).Result).Model;
|
.ListInvoices(new InvoicesModel { SearchTerm = filter, StoreId = storeId }).Result).Model;
|
||||||
Assert.Equal(expected, result.Invoices.Any(i => i.InvoiceId == invoiceId));
|
Assert.Equal(expected, result.Invoices.Any(i => i.InvoiceId == invoiceId));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -799,17 +799,23 @@ namespace BTCPayServer.Controllers
|
|||||||
public async Task<IActionResult> ListInvoices(InvoicesModel? model = null)
|
public async Task<IActionResult> ListInvoices(InvoicesModel? model = null)
|
||||||
{
|
{
|
||||||
model = this.ParseListQuery(model ?? new InvoicesModel());
|
model = this.ParseListQuery(model ?? new InvoicesModel());
|
||||||
|
|
||||||
var fs = new SearchString(model.SearchTerm);
|
var fs = new SearchString(model.SearchTerm);
|
||||||
var store = model.StoreId == null || fs.ContainsFilter("storeid") ? null : HttpContext.GetStoreData();
|
string? storeId = (model.StoreId ?? HttpContext.GetStoreData()?.Id);
|
||||||
var storeIds = store == null
|
var storeIds = new HashSet<string>();
|
||||||
? fs.GetFilterArray("storeid") != null ? fs.GetFilterArray("storeid") : new List<string>().ToArray()
|
if (fs.GetFilterArray("storeid") is string[] l)
|
||||||
: new[] { store.Id };
|
{
|
||||||
|
foreach (var i in l)
|
||||||
model.StoreIds = storeIds;
|
storeIds.Add(i);
|
||||||
|
}
|
||||||
|
if (storeId is not null)
|
||||||
|
{
|
||||||
|
storeIds.Add(storeId);
|
||||||
|
model.StoreId = storeId;
|
||||||
|
}
|
||||||
|
model.StoreIds = storeIds.ToArray();
|
||||||
|
|
||||||
InvoiceQuery invoiceQuery = GetInvoiceQuery(model.SearchTerm, model.TimezoneOffset ?? 0);
|
InvoiceQuery invoiceQuery = GetInvoiceQuery(model.SearchTerm, model.TimezoneOffset ?? 0);
|
||||||
invoiceQuery.StoreId = storeIds;
|
invoiceQuery.StoreId = model.StoreIds;
|
||||||
var counting = _InvoiceRepository.GetInvoicesTotal(invoiceQuery);
|
var counting = _InvoiceRepository.GetInvoicesTotal(invoiceQuery);
|
||||||
invoiceQuery.Take = model.Count;
|
invoiceQuery.Take = model.Count;
|
||||||
invoiceQuery.Skip = model.Skip;
|
invoiceQuery.Skip = model.Skip;
|
||||||
|
|||||||
Reference in New Issue
Block a user