mirror of
https://github.com/bitwarden/server
synced 2026-01-09 12:03:21 +00:00
37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
using System.Data;
|
|
using Bit.Core.Entities;
|
|
using Bit.Core.Enums;
|
|
using Bit.Core.Repositories;
|
|
using Bit.Core.Settings;
|
|
using Dapper;
|
|
using Microsoft.Data.SqlClient;
|
|
|
|
namespace Bit.Infrastructure.Dapper.Repositories;
|
|
|
|
public class OrganizationConnectionRepository : Repository<OrganizationConnection, Guid>, IOrganizationConnectionRepository
|
|
{
|
|
public OrganizationConnectionRepository(GlobalSettings globalSettings)
|
|
: base(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
|
{ }
|
|
|
|
public async Task<ICollection<OrganizationConnection>> GetByOrganizationIdTypeAsync(Guid organizationId, OrganizationConnectionType type)
|
|
{
|
|
using (var connection = new SqlConnection(ConnectionString))
|
|
{
|
|
var results = await connection.QueryAsync<OrganizationConnection>(
|
|
$"[{Schema}].[OrganizationConnection_ReadByOrganizationIdType]",
|
|
new
|
|
{
|
|
OrganizationId = organizationId,
|
|
Type = type
|
|
},
|
|
commandType: CommandType.StoredProcedure);
|
|
|
|
return results.ToList();
|
|
}
|
|
}
|
|
|
|
public async Task<ICollection<OrganizationConnection>> GetEnabledByOrganizationIdTypeAsync(Guid organizationId, OrganizationConnectionType type) =>
|
|
(await GetByOrganizationIdTypeAsync(organizationId, type)).Where(c => c.Enabled).ToList();
|
|
}
|