Skip to content

Commit

Permalink
refactor: Update Application tbl and item sps
Browse files Browse the repository at this point in the history
Signed-off-by: Jerrico Dela Cruz <[email protected]>
  • Loading branch information
jerricotandelacruz committed Sep 2, 2024
1 parent fd9ac35 commit bb54cf7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 23 deletions.
18 changes: 11 additions & 7 deletions src/sqldb/Stored Procedures/PR_Application_Select_ById.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ CREATE PROCEDURE PR_Applications_Select_ById
@Id UNIQUEIDENTIFIER

AS

SELECT
dbo.UidToString(Id) [Id], [Name]
FROM Applications
WHERE
IsActive = 1
AND Id = @Id
BEGIN
SELECT
dbo.UidToString(Id) [Id],
[Name],
[ExportUrl],
[OrganizationTypesUrl]
FROM
Applications
WHERE
IsActive = 1 AND Id = @Id
END
32 changes: 27 additions & 5 deletions src/sqldb/Stored Procedures/PR_Items_Select.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ CREATE PROCEDURE [dbo].[PR_Items_Select]
@ItemType bit = NULL, -- NULL - ALL / 0 - REQUESTOR / 1 - APPROVER
@User varchar(100) = NULL,
@IsApproved int = 4,
@RequestType varchar(100) = NULL
@RequestType varchar(100) = NULL,
@Organization varchar(100) = NULL
)
AS
BEGIN
SELECT
DISTINCT dbo.UidToString(i.Id) AS ItemId
dbo.UidToString(i.Id) AS ItemId
, dbo.UidToString(a.Id) AS ApplicationId
, a.Name AS Application
, dbo.UidToString(am.Id) AS ApplicationModuleId
Expand All @@ -27,14 +28,14 @@ BEGIN
, T.ApproveText
, T.RejectText
, isnull(AllowReassign,'') as AllowReassign
, COUNT(*) AS Score
FROM [dbo].[Items] i
INNER JOIN ApplicationModules am ON i.ApplicationModuleId = am.Id
INNER JOIN Applications a ON am.ApplicationId = a.Id
INNER JOIN ApprovalTypes t ON t.Id = am.ApprovalTypeId
INNER JOIN ApprovalRequestApprovers ara ON i.Id = ara.ItemId
INNER JOIN STRING_SPLIT(@Search, ' ') AS ss ON (i.Subject LIKE '%'+ss.value+'%' OR i.CreatedBy LIKE '%'+ss.value+'%')
WHERE
Subject LIKE '%'+@Search+'%'
AND
(
@ItemType IS NULL
OR
Expand All @@ -52,8 +53,29 @@ BEGIN
(
@RequestType IS NULL OR
(@RequestType IS NOT NULL AND i.ApplicationModuleId = @RequestType)
) AND
(
@Organization IS NULL OR
(@Organization IS NOT NULL AND i.Body LIKE '%'+@Organization+'%')
)
ORDER BY I.Created DESC
GROUP BY
i.Id,
a.Id,
a.Name,
am.Id,
am.Name,
RespondedBy,
Subject,
Body,
DateSent,
DateResponded,
IsApproved,
ApproverRemarks,
I.Created,
T.ApproveText,
T.RejectText,
AllowReassign
ORDER BY Score, I.Created DESC
OFFSET @Offset ROWS
FETCH NEXT @Filter ROWS ONLY
END
9 changes: 7 additions & 2 deletions src/sqldb/Stored Procedures/PR_Items_Total.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ CREATE PROCEDURE [dbo].[PR_Items_Total]
@ItemType bit = NULL, -- NULL - ALL / 0 - REQUESTOR / 1 - APPROVER,
@User varchar(100) = NULL,
@IsApproved int = 4,
@RequestType varchar(100) = NULL
@RequestType varchar(100) = NULL,
@Organization varchar(100) = NULL
)
AS
BEGIN
Expand All @@ -18,8 +19,8 @@ BEGIN
INNER JOIN Applications a ON am.ApplicationId = a.Id
INNER JOIN ApprovalTypes t ON t.Id = am.ApprovalTypeId
INNER JOIN ApprovalRequestApprovers ara ON i.Id = ara.ItemId
INNER JOIN STRING_SPLIT(@Search, ' ') AS ss ON (i.Subject LIKE '%'+ss.value+'%' OR i.CreatedBy LIKE '%'+ss.value+'%')
WHERE
Subject LIKE '%'+@Search+'%' AND
(
@ItemType IS NULL
OR
Expand All @@ -43,6 +44,10 @@ BEGIN
(
@RequestType IS NULL OR
(@RequestType IS NOT NULL AND i.ApplicationModuleId = @RequestType)
) AND
(
@Organization IS NULL OR
(@Organization IS NOT NULL AND i.Body LIKE '%'+@Organization+'%')
)
) AS Items
END
19 changes: 10 additions & 9 deletions src/sqldb/Tables/Applications.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
CREATE TABLE [dbo].[Applications] (
[Id] UNIQUEIDENTIFIER CONSTRAINT [DF_Applications_Id] DEFAULT (newid()) NOT NULL,
[Name] VARCHAR (100) NOT NULL,
[IsActive] BIT CONSTRAINT [DF_Applications_IsActive] DEFAULT ((1)) NOT NULL,
[Created] DATETIME CONSTRAINT [DF_Applications_Created] DEFAULT (getdate()) NOT NULL,
[CreatedBy] VARCHAR (255) NULL,
[Modified] DATETIME CONSTRAINT [DF_Applications_Modified] DEFAULT (getdate()) NOT NULL,
[ModifiedBy] VARCHAR (255) NULL,
[Id] UNIQUEIDENTIFIER CONSTRAINT [DF_Applications_Id] DEFAULT (newid()) NOT NULL,
[Name] VARCHAR (100) NOT NULL,
[IsActive] BIT CONSTRAINT [DF_Applications_IsActive] DEFAULT ((1)) NOT NULL,
[ExportUrl] VARCHAR (255) NULL,
[OrganizationTypeUrl] VARCHAR (255) NULL,
[Created] DATETIME CONSTRAINT [DF_Applications_Created] DEFAULT (getdate()) NOT NULL,
[CreatedBy] VARCHAR (255) NULL,
[Modified] DATETIME CONSTRAINT [DF_Applications_Modified] DEFAULT (getdate()) NOT NULL,
[ModifiedBy] VARCHAR (255) NULL,
CONSTRAINT [PK_Applications] PRIMARY KEY CLUSTERED ([Id] ASC)
);

);

0 comments on commit bb54cf7

Please sign in to comment.