diff --git a/client/src/components/ProjectWizard/TdmCalculationContainer.jsx b/client/src/components/ProjectWizard/TdmCalculationContainer.jsx index 87eb8832..b77d2056 100644 --- a/client/src/components/ProjectWizard/TdmCalculationContainer.jsx +++ b/client/src/components/ProjectWizard/TdmCalculationContainer.jsx @@ -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(); @@ -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 }; diff --git a/server/app/schemas/project.js b/server/app/schemas/project.js index 48e10e73..98af7962 100644 --- a/server/app/schemas/project.js +++ b/server/app/schemas/project.js @@ -19,6 +19,15 @@ module.exports = { }, calculationId: { type: "number" + }, + targetPoints: { + type: "number" + }, + earnedPoints: { + type: "number" + }, + projectLevel: { + type: "number" } } }; diff --git a/server/app/services/project.service.js b/server/app/services/project.service.js index ffb430bb..e277c628 100644 --- a/server/app/services/project.service.js +++ b/server/app/services/project.service.js @@ -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); @@ -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); diff --git a/server/db/migration/V20241107.1155__add_cols_to_project_table.sql b/server/db/migration/V20241107.1155__add_cols_to_project_table.sql new file mode 100644 index 00000000..4bcd1e6a --- /dev/null +++ b/server/db/migration/V20241107.1155__add_cols_to_project_table.sql @@ -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 + + + + + + + +