Skip to content

Commit

Permalink
New Filed Added
Browse files Browse the repository at this point in the history
  • Loading branch information
Dk-21 committed Jan 25, 2025
1 parent eb0f908 commit 656bc6a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/controllers/reportsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const reportsController = function () {
taskAndProjectStats,
volunteersOverAssignedTime,
completedAssignedHours,
totalSummariesSubmitted,
] = await Promise.all([
overviewReportHelper.getVolunteerNumberStats(
isoStartDate,
Expand Down Expand Up @@ -158,6 +159,12 @@ const reportsController = function () {
isoComparisonStartDate,
isoComparisonEndDate,
),
overviewReportHelper.getTotalSummariesSubmitted(
isoStartDate,
isoEndDate,
isoComparisonStartDate,
isoComparisonEndDate,
),
]);
res.status(200).send({
volunteerNumberStats,
Expand All @@ -176,6 +183,7 @@ const reportsController = function () {
taskAndProjectStats,
volunteersOverAssignedTime,
completedAssignedHours,
totalSummariesSubmitted,
});
} catch (err) {
console.log(err);
Expand Down
62 changes: 62 additions & 0 deletions src/helpers/overviewReportHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,67 @@ const overviewReportHelper = function () {
return { count: currentCount };
}

const getTotalSummariesSubmitted = async (startDate, endDate, comparisonStartDate, comparisonEndDate) => {
// Helper function to count summaries submitted within a date range
const getSummariesCount = async (start, end) => {
return await UserProfile.aggregate([
{
$match: {
summarySubmissionDates: {
$elemMatch: {
$gte: new Date(start),
$lte: new Date(end),
},
},
},
},
{
$project: {
totalSummaries: {
$size: {
$filter: {
input: '$summarySubmissionDates',
as: 'date',
cond: {
$and: [
{ $gte: ['$$date', new Date(start)] },
{ $lte: ['$$date', new Date(end)] },
],
},
},
},
},
},
},
{
$group: {
_id: null,
totalSummaries: { $sum: '$totalSummaries' },
},
},
]);
};

// Get summaries count for the current date range
const currentSummaries = await getSummariesCount(startDate, endDate);
const totalCurrentSummaries = currentSummaries[0]?.totalSummaries || 0;

// If comparison dates are provided, calculate the comparison percentage
if (comparisonStartDate && comparisonEndDate) {
const comparisonSummaries = await getSummariesCount(comparisonStartDate, comparisonEndDate);
const totalComparisonSummaries = comparisonSummaries[0]?.totalSummaries || 0;
const comparisonPercentage = calculateGrowthPercentage(totalCurrentSummaries, totalComparisonSummaries);

return { count: totalCurrentSummaries, comparisonPercentage };
}

// If no comparison dates, return only the count
return { count: totalCurrentSummaries };
};




return {
getVolunteerTrends,
getMapLocations,
Expand All @@ -1846,6 +1907,7 @@ const overviewReportHelper = function () {
getTeamsWithActiveMembers,
getVolunteersOverAssignedTime,
getVolunteersCompletedAssignedHours,
getTotalSummariesSubmitted,
};
};

Expand Down
2 changes: 2 additions & 0 deletions src/models/userProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const SALT_ROUNDS = 10;
const today = new Date();

const userProfileSchema = new Schema({
// Updated filed
summarySubmissionDates: [{ type: Date }],
password: {
type: String,
required: true,
Expand Down

0 comments on commit 656bc6a

Please sign in to comment.