From 2f0d9495dd56bc4ac5c24851a1da25d09f128c2b Mon Sep 17 00:00:00 2001 From: 20chen-7 Date: Thu, 12 Sep 2024 15:49:25 -0600 Subject: [PATCH] chore: check endDate & inactive --- src/controllers/userProfileController.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/controllers/userProfileController.js b/src/controllers/userProfileController.js index c15f970b2..ba66976c9 100644 --- a/src/controllers/userProfileController.js +++ b/src/controllers/userProfileController.js @@ -1156,7 +1156,15 @@ const userProfileController = function (UserProfile, Project) { const activationDate = req.body.reactivationDate; const { endDate } = req.body; const isSet = req.body.isSet === 'FinalDay'; - + let activeStatus = status; + if (endDate && status) { + const dateObject = new Date(endDate); + dateObject.setHours(dateObject.getHours() + 7); + const setEndDate = dateObject; + if (moment().isAfter(moment(setEndDate).add(1, 'days'))) { + activeStatus = false; + } + } if (!mongoose.Types.ObjectId.isValid(userId)) { res.status(400).send({ error: 'Bad Request', @@ -1205,7 +1213,7 @@ const userProfileController = function (UserProfile, Project) { UserProfile.findById(userId, 'isActive email firstName lastName') .then((user) => { user.set({ - isActive: status, + isActive: activeStatus, reactivationDate: activationDate, endDate, isSet,