mirror of
https://github.com/bitwarden/server.git
synced 2025-07-05 01:52:49 -05:00
[AC-2568] Added invoices and transaction history endpoints. Added cursor paging for each (#4692)
* Added invoices and transaction history endpoints. Added cursor paging for each * Removed try/catch since it's handled by middleware. Updated condition to use pattern matching * Added unit tests for PaymentHistoryService * Removed organizationId from account billing controller endpoints
This commit is contained in:
@ -24,7 +24,10 @@ public class TransactionRepository : Repository<Core.Entities.Transaction, Trans
|
||||
return Mapper.Map<Core.Entities.Transaction>(results);
|
||||
}
|
||||
|
||||
public async Task<ICollection<Core.Entities.Transaction>> GetManyByOrganizationIdAsync(Guid organizationId, int? limit = null)
|
||||
public async Task<ICollection<Core.Entities.Transaction>> GetManyByOrganizationIdAsync(
|
||||
Guid organizationId,
|
||||
int? limit = null,
|
||||
DateTime? startAfter = null)
|
||||
{
|
||||
using var scope = ServiceScopeFactory.CreateScope();
|
||||
|
||||
@ -32,6 +35,11 @@ public class TransactionRepository : Repository<Core.Entities.Transaction, Trans
|
||||
var query = dbContext.Transactions
|
||||
.Where(t => t.OrganizationId == organizationId && !t.UserId.HasValue);
|
||||
|
||||
if (startAfter.HasValue)
|
||||
{
|
||||
query = query.Where(t => t.CreationDate < startAfter.Value);
|
||||
}
|
||||
|
||||
if (limit.HasValue)
|
||||
{
|
||||
query = query.OrderByDescending(o => o.CreationDate).Take(limit.Value);
|
||||
@ -41,7 +49,10 @@ public class TransactionRepository : Repository<Core.Entities.Transaction, Trans
|
||||
return Mapper.Map<List<Core.Entities.Transaction>>(results);
|
||||
}
|
||||
|
||||
public async Task<ICollection<Core.Entities.Transaction>> GetManyByUserIdAsync(Guid userId, int? limit = null)
|
||||
public async Task<ICollection<Core.Entities.Transaction>> GetManyByUserIdAsync(
|
||||
Guid userId,
|
||||
int? limit = null,
|
||||
DateTime? startAfter = null)
|
||||
{
|
||||
using var scope = ServiceScopeFactory.CreateScope();
|
||||
|
||||
@ -49,6 +60,11 @@ public class TransactionRepository : Repository<Core.Entities.Transaction, Trans
|
||||
var query = dbContext.Transactions
|
||||
.Where(t => t.UserId == userId);
|
||||
|
||||
if (startAfter.HasValue)
|
||||
{
|
||||
query = query.Where(t => t.CreationDate < startAfter.Value);
|
||||
}
|
||||
|
||||
if (limit.HasValue)
|
||||
{
|
||||
query = query.OrderByDescending(o => o.CreationDate).Take(limit.Value);
|
||||
@ -59,13 +75,21 @@ public class TransactionRepository : Repository<Core.Entities.Transaction, Trans
|
||||
return Mapper.Map<List<Core.Entities.Transaction>>(results);
|
||||
}
|
||||
|
||||
public async Task<ICollection<Core.Entities.Transaction>> GetManyByProviderIdAsync(Guid providerId, int? limit = null)
|
||||
public async Task<ICollection<Core.Entities.Transaction>> GetManyByProviderIdAsync(
|
||||
Guid providerId,
|
||||
int? limit = null,
|
||||
DateTime? startAfter = null)
|
||||
{
|
||||
using var serviceScope = ServiceScopeFactory.CreateScope();
|
||||
var databaseContext = GetDatabaseContext(serviceScope);
|
||||
var query = databaseContext.Transactions
|
||||
.Where(transaction => transaction.ProviderId == providerId);
|
||||
|
||||
if (startAfter.HasValue)
|
||||
{
|
||||
query = query.Where(transaction => transaction.CreationDate < startAfter.Value);
|
||||
}
|
||||
|
||||
if (limit.HasValue)
|
||||
{
|
||||
query = query.Take(limit.Value);
|
||||
|
Reference in New Issue
Block a user