Skip to content

Commit

Permalink
Added targetPoints, earnedPoints, projectLevel to project table
Browse files Browse the repository at this point in the history
  • Loading branch information
entrotech committed Nov 7, 2024
1 parent 7b1218f commit 2d80564
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ export function TdmCalculationContainer({ contentContainerRef }) {
const [rules, setRules] = useState([]);

const [project, setProject] = useState({});
// const [loginId, setLoginId] = useState(0);
// const [dateModified, setDateModified] = useState();
// const [dateSnapshotted, setDateSnapshotted] = useState();
// const [dateSubmitted, setDateSubmitted] = useState();

const toast = useToast();

Expand Down Expand Up @@ -450,6 +446,9 @@ export function TdmCalculationContainer({ contentContainerRef }) {
address: formInputs.PROJECT_ADDRESS,
description: formInputs.PROJECT_DESCRIPTION,
formInputs: JSON.stringify(inputsToSave),
targetPoints: getRuleByCode("TARGET_POINTS_PARK").value,
earnedPoints: getRuleByCode("PTS_EARNED").value,
projectLevel: getRuleByCode("PROJECT_LEVEL").value,
loginId: account.id,
calculationId: TdmCalculationContainer.calculationId
};
Expand Down
9 changes: 9 additions & 0 deletions server/app/schemas/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ module.exports = {
},
calculationId: {
type: "number"
},
targetPoints: {
type: "number"
},
earnedPoints: {
type: "number"
},
projectLevel: {
type: "number"
}
}
};
6 changes: 6 additions & 0 deletions server/app/services/project.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const post = async item => {
request.input("address", mssql.NVarChar, item.address); // 200
request.input("description", mssql.NVarChar, item.description); // max
request.input("formInputs", mssql.NVarChar, item.formInputs); // max
request.input("targetPoints", mssql.Int, item.taretPoints);
request.input("earnedPoints", mssql.Int, item.earnedPoints);
request.input("projectLevel", mssql.Int, item.projectLevel);
request.input("loginId", mssql.Int, item.loginId);
request.input("calculationId", mssql.Int, item.calculationId);
request.output("id", mssql.Int, null);
Expand All @@ -57,6 +60,9 @@ const put = async item => {
request.input("address", mssql.NVarChar, item.address); // 200
request.input("description", mssql.NVarChar, item.description); // max
request.input("formInputs", mssql.NVarChar, item.formInputs); // max
request.input("targetPoints", mssql.Int, item.taretPoints);
request.input("earnedPoints", mssql.Int, item.earnedPoints);
request.input("projectLevel", mssql.Int, item.projectLevel);
request.input("loginId", mssql.Int, item.loginId);
request.input("calculationId", mssql.Int, item.calculationId);
request.input("id", mssql.Int, item.id);
Expand Down
219 changes: 219 additions & 0 deletions server/db/migration/V20241107.1155__add_cols_to_project_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
ALTER TABLE Project ADD
targetPoints int NULL,
earnedPoints int NULL,
projectLevel int NULL

GO

CREATE OR ALTER PROC [dbo].[Project_Insert]
@name nvarchar(200)
, @address nvarchar(200)
, @formInputs nvarchar(max)
, @targetPoints int
, @earnedPoints int
, @projectLevel int
, @loginId int
, @calculationId int
, @description nvarchar(max)
, @id int output
AS
BEGIN

INSERT Project
(
name
, address
, formInputs
, targetPoints
, earnedPoints
, projectLevel
, loginId
, calculationId
, description
)
VALUES
(
@name
, @address
, @formInputs
, @targetPoints
, @earnedPoints
, @projectLevel
, @loginId
, @calculationId
, @description
)

SET @id = SCOPE_IDENTITY()
END
GO

CREATE OR ALTER PROC [dbo].[Project_Update]
@id int
, @name nvarchar(200)
, @address nvarchar(200)
, @formInputs nvarchar(max)
, @targetPoints int
, @earnedPoints int
, @projectLevel int
, @loginId int
, @calculationId int
, @description nvarchar(max)
AS
BEGIN

UPDATE Project SET
name = @name
, address = @address
, formInputs = @formInputs
, targetPoints = @targetPoints
, earnedPoints = @earnedPoints
, projectLevel = @projectLevel
, loginId = @loginId
, calculationId = @calculationId
, description = @description
, DateModified = getutcdate()
WHERE
id = @id

END
GO



CREATE OR ALTER PROC [dbo].[Project_SelectById]
@loginId int = null,
@id int
AS
BEGIN

IF EXISTS(SELECT 1 FROM Login WHERE id = @LoginId AND isAdmin = 1)
BEGIN
SELECT
p.id,
p.name,
p.address,
p.formInputs,
p.targetPoints,
p.earnedPoints,
p.projectLevel,
p.loginId,
p.calculationId,
p.dateCreated,
p.dateModified,
p.description,
l.firstName,
l.lastName,
p.droId, -- New column
p.adminNotes, -- New column
p.dateModifiedAdmin, -- New column
p.dateHidden,
p.dateTrashed,
p.dateSnapshotted,
p.dateSubmitted
FROM Project p
JOIN Login l ON p.loginId = l.id
WHERE p.id = @id;
END
ELSE
BEGIN
SELECT
p.id,
p.name,
p.address,
p.formInputs,
p.targetPoints,
p.earnedPoints,
p.projectLevel,
p.loginId,
p.calculationId,
p.dateCreated,
p.dateModified,
p.description,
l.firstName,
l.lastName,
p.droId, -- New column
p.adminNotes, -- New column
p.dateModifiedAdmin, -- New column
p.dateHidden,
p.dateTrashed,
p.dateSnapshotted,
p.dateSubmitted
FROM Project p
JOIN Login l ON p.loginId = l.id
WHERE p.id = @id AND p.loginId = ISNULL(@loginId, p.loginId);
END
END;
GO

CREATE OR ALTER PROC [dbo].[Project_SelectAll]
@loginId int = null
AS
BEGIN
IF EXISTS(SELECT 1 FROM Login WHERE id = @LoginId AND isAdmin = 1)
BEGIN
-- Admin can see all projects
SELECT
p.id
, p.name
, p.address
, p.formInputs
, p.targetPoints
, p.earnedPoints
, p.projectLevel
, p.loginId
, p.calculationId
, p.dateCreated
, p.dateModified
, p.description
, author.firstName
, author.lastName
, p.dateHidden
, p.dateTrashed
, p.dateSnapshotted
, p.dateSubmitted
, p.droId -- New column
, p.adminNotes -- New column
, p.dateModifiedAdmin -- New column
FROM Project p
JOIN Login author ON p.loginId = author.id;
END
ELSE
BEGIN
-- User can only see their own projects
SELECT
p.id
, p.name
, p.address
, p.formInputs
, p.targetPoints
, p.earnedPoints
, p.projectLevel
, p.loginId
, p.calculationId
, p.dateCreated
, p.dateModified
, p.description
, author.firstName
, author.lastName
, p.dateHidden
, p.dateTrashed
, p.dateSnapshotted
, p.dateSubmitted
, p.droId -- New column
, p.adminNotes -- New column
, p.dateModifiedAdmin -- New column
FROM Project p
JOIN Login author ON p.loginId = author.id
WHERE author.id = ISNULL(@loginId, author.id);
END
END;
GO








0 comments on commit 2d80564

Please sign in to comment.