1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-01 13:43:23 +01:00
bitwarden-server/util/Setup/DbScripts/2018-03-21_00_AdminPortal.sql
2018-03-21 17:41:14 -04:00

69 lines
1.5 KiB
Transact-SQL

IF OBJECT_ID('[dbo].[User_Search]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[User_Search]
END
GO
CREATE PROCEDURE [dbo].[User_Search]
@Email NVARCHAR(50),
@Skip INT = 0,
@Take INT = 25
AS
BEGIN
SET NOCOUNT ON
DECLARE @EmailLikeSearch NVARCHAR(55) = @Email + '%'
SELECT
*
FROM
[dbo].[UserView]
WHERE
(@Email IS NULL OR [Email] LIKE @EmailLikeSearch)
ORDER BY [Email] ASC
OFFSET @Skip ROWS
FETCH NEXT @Take ROWS ONLY
END
GO
IF OBJECT_ID('[dbo].[Organization_Search]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[Organization_Search]
END
GO
CREATE PROCEDURE [dbo].[Organization_Search]
@Name NVARCHAR(50),
@UserEmail NVARCHAR(50),
@Paid BIT,
@Skip INT = 0,
@Take INT = 25
AS
BEGIN
SET NOCOUNT ON
DECLARE @NameLikeSearch NVARCHAR(55) = '%' + @Name + '%'
SELECT
O.*
FROM
[dbo].[OrganizationView] O
INNER JOIN
[dbo].[OrganizationUser] OU ON O.[Id] = OU.[OrganizationId]
INNER JOIN
[dbo].[User] U ON U.[Id] = OU.[UserId]
WHERE
(@Name IS NULL OR O.[Name] LIKE @NameLikeSearch)
AND (@UserEmail IS NULL OR U.[Email] = @UserEmail)
AND
(
@Paid IS NULL OR
(
(@Paid = 1 AND O.[GatewaySubscriptionId] IS NOT NULL) OR
(@Paid = 0 AND O.[GatewaySubscriptionId] IS NULL)
)
)
ORDER BY O.[CreationDate] DESC
OFFSET @Skip ROWS
FETCH NEXT @Take ROWS ONLY
END
GO