@@ -8,6 +8,10 @@ import {
88 createTeamValidation ,
99 updateTeamValidation ,
1010} from '../validations/team.validation.js' ;
11+ import {
12+ createActivityLog ,
13+ generateActivityDetails ,
14+ } from '../utils/activityLogs.utils.js' ;
1115
1216/**
1317 * Helper function to validate required params
@@ -268,6 +272,19 @@ export const createTeam = async (req, res, next) => {
268272 return { team, leaderMember, allTeamMembers } ;
269273 } ) ;
270274
275+ await createActivityLog ( {
276+ entityType : 'TEAM' ,
277+ action : 'CREATED' ,
278+ userId : req . user . id ,
279+ organizationId,
280+ teamId : result . team . id ,
281+ details : generateActivityDetails ( 'CREATED' , null , {
282+ teamName : result . team . name ,
283+ teamDescription : result . team . description ,
284+ createdBy : req . user . id ,
285+ } ) ,
286+ } ) ;
287+
271288 return res . status ( 201 ) . json ( {
272289 success : true ,
273290 message : `Team created successfully.` ,
@@ -436,6 +453,18 @@ export const addTeamMember = async (req, res, next) => {
436453 return { newMembers, allTeamMembers } ;
437454 } ) ;
438455
456+ await createActivityLog ( {
457+ entityType : 'TEAM' ,
458+ action : 'MEMBER_ADDED' ,
459+ userId : req . user . id ,
460+ organizationId,
461+ teamId,
462+ details : generateActivityDetails ( 'MEMBER_ADDED' , null , {
463+ newMembers : result . newMembers ,
464+ addedBy : req . user . id ,
465+ } ) ,
466+ } ) ;
467+
439468 return res . status ( 200 ) . json ( {
440469 success : true ,
441470 message : `Members added successfully.` ,
@@ -577,6 +606,19 @@ export const removeTeamMember = async (req, res, next) => {
577606 } ,
578607 } ) ;
579608
609+ await createActivityLog ( {
610+ entityType : 'TEAM' ,
611+ action : 'MEMBER_REMOVED' ,
612+ userId : req . user . id ,
613+ organizationId,
614+ teamId,
615+ details : generateActivityDetails ( 'MEMBER_REMOVED' , null , {
616+ removedMember,
617+ removedBy : req . user . id ,
618+ removedAt : new Date ( ) ,
619+ } ) ,
620+ } ) ;
621+
580622 return res . status ( 200 ) . json ( {
581623 success : true ,
582624 message : `Team member ${ removedMember . user . firstName } ${ removedMember . user . lastName } removed successfully` ,
@@ -700,6 +742,15 @@ export const updateTeam = async (req, res, next) => {
700742 data : { name, description, avatar } ,
701743 } ) ;
702744
745+ await createActivityLog ( {
746+ entityType : 'TEAM' ,
747+ action : 'UPDATED' ,
748+ userId : req . user . id ,
749+ organizationId,
750+ teamId,
751+ details : generateActivityDetails ( 'UPDATED' , existingOrg , updatedTeam ) ,
752+ } ) ;
753+
703754 res . status ( 200 ) . json ( {
704755 success : true ,
705756 team : updatedTeam ,
@@ -789,6 +840,18 @@ export const uploadTeamAvatar = async (req, res, next) => {
789840 data : { avatar } ,
790841 } ) ;
791842
843+ await createActivityLog ( {
844+ entityType : 'TEAM' ,
845+ action : 'UPDATED' ,
846+ userId : req . user . id ,
847+ organizationId,
848+ teamId,
849+ details : {
850+ action : 'AVATAR_UPLOADED' ,
851+ uploadedAt : new Date ( ) ,
852+ } ,
853+ } ) ;
854+
792855 res . status ( 200 ) . json ( {
793856 success : true ,
794857 message : 'Team avatar uploaded successfully' ,
@@ -868,6 +931,19 @@ export const deleteTeamAvatar = async (req, res, next) => {
868931 data : { avatar : null } ,
869932 } ) ;
870933
934+ await createActivityLog ( {
935+ entityType : 'TEAM' ,
936+ action : 'UPDATED' ,
937+ userId : req . user . id ,
938+ organizationId,
939+ teamId,
940+ details : {
941+ action : 'AVATAR_REMOVED' ,
942+ removedAt : new Date ( ) ,
943+ removedBy : req . user . id ,
944+ } ,
945+ } ) ;
946+
871947 res . status ( 200 ) . json ( {
872948 message : 'Team avatar deleted successfully' ,
873949 team : updatedTeam ,
@@ -943,6 +1019,19 @@ export const deleteTeam = async (req, res, next) => {
9431019 data : { deletedAt : new Date ( ) } ,
9441020 } ) ;
9451021
1022+ await createActivityLog ( {
1023+ entityType : 'TEAM' ,
1024+ action : 'DELETED' ,
1025+ userId : req . user . id ,
1026+ organizationId,
1027+ teamId : team . id ,
1028+ details : generateActivityDetails ( 'DELETED' , team , {
1029+ deletedAt : new Date ( ) ,
1030+ deletedBy : req . user . id ,
1031+ teamName : team . name ,
1032+ } ) ,
1033+ } ) ;
1034+
9461035 return res . status ( 200 ) . json ( {
9471036 success : true ,
9481037 message : 'Team deleted successfully' ,
0 commit comments