Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Denish - New Filed Added for gettotalsummariessubmitted #1207

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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