mirror of
https://github.com/bitwarden/server
synced 2025-12-25 20:53:16 +00:00
[PM-20452] - Offloading Stripe Update (#6034)
* Adding job to update stripe subscriptions and increment seat count when inviting a user. * Updating name * Added ef migrations * Fixing script * Fixing procedures. Added repo tests. * Fixed set stored procedure. Fixed parameter name. * Added tests for database calls and updated stored procedures * Fixed build for sql file. * fixing sproc * File is nullsafe * Adding view to select from instead of table. * Updating UpdateSubscriptionStatus to use a CTE and do all the updates in 1 statement. * Setting revision date when incrementing seat count * Added feature flag check for the background job. * Fixing nullable property. * Removing new table and just adding the column to org. Updating to query and command. Updated tests. * Adding migration script rename * Add SyncSeats to Org.sql def * Adding contraint name * Removing old table files. * Added tests * Upped the frequency to be at the top of every 3rd hour. * Updating error message. * Removing extension method * Changed to GuidIdArray * Added xml doc and switched class to record
This commit is contained in:
@@ -403,4 +403,41 @@ public class OrganizationRepository : Repository<Core.AdminConsole.Entities.Orga
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Core.AdminConsole.Entities.Organization>> GetOrganizationsForSubscriptionSyncAsync()
|
||||
{
|
||||
using var scope = ServiceScopeFactory.CreateScope();
|
||||
await using var dbContext = GetDatabaseContext(scope);
|
||||
|
||||
var organizations = await dbContext.Organizations
|
||||
.Where(o => o.SyncSeats == true && o.Seats != null)
|
||||
.ToArrayAsync();
|
||||
|
||||
return organizations;
|
||||
}
|
||||
|
||||
public async Task UpdateSuccessfulOrganizationSyncStatusAsync(IEnumerable<Guid> successfulOrganizations, DateTime syncDate)
|
||||
{
|
||||
using var scope = ServiceScopeFactory.CreateScope();
|
||||
await using var dbContext = GetDatabaseContext(scope);
|
||||
|
||||
await dbContext.Organizations
|
||||
.Where(o => successfulOrganizations.Contains(o.Id))
|
||||
.ExecuteUpdateAsync(o => o
|
||||
.SetProperty(x => x.SyncSeats, false)
|
||||
.SetProperty(x => x.RevisionDate, syncDate.Date));
|
||||
}
|
||||
|
||||
public async Task IncrementSeatCountAsync(Guid organizationId, int increaseAmount, DateTime requestDate)
|
||||
{
|
||||
using var scope = ServiceScopeFactory.CreateScope();
|
||||
await using var dbContext = GetDatabaseContext(scope);
|
||||
|
||||
await dbContext.Organizations
|
||||
.Where(o => o.Id == organizationId)
|
||||
.ExecuteUpdateAsync(s => s
|
||||
.SetProperty(o => o.Seats, o => o.Seats + increaseAmount)
|
||||
.SetProperty(o => o.SyncSeats, true)
|
||||
.SetProperty(o => o.RevisionDate, requestDate));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user