@@ -25,6 +25,7 @@ import { IControl } from "../domain.layer/interfaces/i.control";
2525import { IControlCategory } from "../domain.layer/interfaces/i.controlCategory" ;
2626import { logProcessing , logSuccess , logFailure } from "../utils/logger/logHelper" ;
2727import { createISO27001FrameworkQuery } from "../utils/iso27001.utils" ;
28+ import { ProjectStatus } from "../domain.layer/enums/project-status.enum" ;
2829
2930export async function getAllProjects ( req : Request , res : Response ) : Promise < any > {
3031 logProcessing ( {
@@ -725,3 +726,74 @@ export async function allProjectsAssessmentProgress(req: Request, res: Response)
725726 return res . status ( 500 ) . json ( STATUS_CODE [ 500 ] ( ( error as Error ) . message ) ) ;
726727 }
727728}
729+
730+ export async function updateProjectStatus ( req : Request , res : Response ) : Promise < any > {
731+ const transaction = await sequelize . transaction ( ) ;
732+ const projectId = parseInt ( req . params . id ) ;
733+ const { status } = req . body ;
734+
735+ logProcessing ( {
736+ description : `starting updateProjectStatus for ID ${ projectId } ` ,
737+ functionName : "updateProjectStatus" ,
738+ fileName : "project.ctrl.ts" ,
739+ } ) ;
740+
741+ try {
742+ // Validate status value
743+ if ( ! status || ! Object . values ( ProjectStatus ) . includes ( status ) ) {
744+ return res . status ( 400 ) . json (
745+ STATUS_CODE [ 400 ] ( { message : "Valid status is required" } )
746+ ) ;
747+ }
748+
749+ // Check if project exists
750+ const existingProject = await getProjectByIdQuery ( projectId , req . tenantId ! ) ;
751+ if ( ! existingProject ) {
752+ await logSuccess ( {
753+ eventType : "Update" ,
754+ description : `Project not found for status update: ID ${ projectId } ` ,
755+ functionName : "updateProjectStatus" ,
756+ fileName : "project.ctrl.ts" ,
757+ } ) ;
758+
759+ return res . status ( 404 ) . json ( STATUS_CODE [ 404 ] ( { } ) ) ;
760+ }
761+
762+ // Update project status
763+ const updatedProject = await updateProjectByIdQuery (
764+ projectId ,
765+ { status, last_updated : new Date ( ) , last_updated_by : req . userId ! } ,
766+ [ ] , // no members update
767+ req . tenantId ! ,
768+ transaction
769+ ) ;
770+
771+ if ( updatedProject ) {
772+ await transaction . commit ( ) ;
773+
774+ await logSuccess ( {
775+ eventType : "Update" ,
776+ description : `Updated project status to ${ status } for ID ${ projectId } ` ,
777+ functionName : "updateProjectStatus" ,
778+ fileName : "project.ctrl.ts" ,
779+ } ) ;
780+
781+ return res . status ( 200 ) . json ( STATUS_CODE [ 200 ] ( updatedProject ) ) ;
782+ }
783+
784+ await transaction . rollback ( ) ;
785+ return res . status ( 500 ) . json ( STATUS_CODE [ 500 ] ( "Failed to update project status" ) ) ;
786+ } catch ( error ) {
787+ await transaction . rollback ( ) ;
788+
789+ await logFailure ( {
790+ eventType : "Update" ,
791+ description : "Failed to update project status" ,
792+ functionName : "updateProjectStatus" ,
793+ fileName : "project.ctrl.ts" ,
794+ error : error as Error ,
795+ } ) ;
796+
797+ return res . status ( 500 ) . json ( STATUS_CODE [ 500 ] ( ( error as Error ) . message ) ) ;
798+ }
799+ }
0 commit comments