mirror of
https://github.com/bitwarden/server.git
synced 2025-02-11 01:01:36 +01:00
* PM-10563: Notification Center API * PM-10563: continuation token hack * PM-10563: Resolving merge conflicts * PM-10563: Unit Tests * PM-10563: Paging simplification by page number and size in database * PM-10563: Request validation * PM-10563: Read, Deleted status filters change * PM-10563: Plural name for tests * PM-10563: Request validation to always for int type * PM-10563: Continuation Token returns null on response when no more records available * PM-10563: Integration tests for GET * PM-10563: Mark notification read, deleted commands date typos fix * PM-10563: Integration tests for PATCH read, deleted * PM-10563: Request, Response models tests * PM-10563: EditorConfig compliance * PM-10563: Extracting to const * PM-10563: Update db migration script date * PM-10563: Update migration script date
40 lines
1.5 KiB
Transact-SQL
40 lines
1.5 KiB
Transact-SQL
-- Stored Procedure Notification_ReadByUserIdAndStatus
|
|
|
|
CREATE OR ALTER PROCEDURE [dbo].[Notification_ReadByUserIdAndStatus]
|
|
@UserId UNIQUEIDENTIFIER,
|
|
@ClientType TINYINT,
|
|
@Read BIT,
|
|
@Deleted BIT,
|
|
@PageNumber INT = 1,
|
|
@PageSize INT = 10
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON
|
|
|
|
SELECT n.*
|
|
FROM [dbo].[NotificationStatusDetailsView] n
|
|
LEFT JOIN [dbo].[OrganizationUserView] ou ON n.[OrganizationId] = ou.[OrganizationId]
|
|
AND ou.[UserId] = @UserId
|
|
WHERE (n.[NotificationStatusUserId] IS NULL OR n.[NotificationStatusUserId] = @UserId)
|
|
AND [ClientType] IN (0, CASE WHEN @ClientType != 0 THEN @ClientType END)
|
|
AND ([Global] = 1
|
|
OR (n.[UserId] = @UserId
|
|
AND (n.[OrganizationId] IS NULL
|
|
OR ou.[OrganizationId] IS NOT NULL))
|
|
OR (n.[UserId] IS NULL
|
|
AND ou.[OrganizationId] IS NOT NULL))
|
|
AND ((@Read IS NULL AND @Deleted IS NULL)
|
|
OR (n.[NotificationStatusUserId] IS NOT NULL
|
|
AND (@Read IS NULL
|
|
OR IIF((@Read = 1 AND n.[ReadDate] IS NOT NULL) OR
|
|
(@Read = 0 AND n.[ReadDate] IS NULL),
|
|
1, 0) = 1)
|
|
AND (@Deleted IS NULL
|
|
OR IIF((@Deleted = 1 AND n.[DeletedDate] IS NOT NULL) OR
|
|
(@Deleted = 0 AND n.[DeletedDate] IS NULL),
|
|
1, 0) = 1)))
|
|
ORDER BY [Priority] DESC, n.[CreationDate] DESC
|
|
OFFSET @PageSize * (@PageNumber - 1) ROWS FETCH NEXT @PageSize ROWS ONLY
|
|
END
|
|
GO
|