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

[Bug-1233]- mentor/reports Changes For Front-End #611

Merged
merged 4 commits into from
Feb 20, 2024
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
39 changes: 39 additions & 0 deletions src/database/queries/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,45 @@ exports.getCreatedSessionsCountInDateRange = async (mentorId, startDate, endDate
created_at: {
[Op.between]: [startDate, endDate],
},
mentor_id: mentorId, // Check mentor_id
created_by: mentorId, // Check created_by
},
})
return count
} catch (error) {
throw error
}
}

/**
* Get the count of mentoring sessions within a date range for a specific mentor.
* @param {number} mentorId - The ID of the mentor.
* @param {Date} startDate - The start date of the date range.
* @param {Date} endDate - The end date of the date range.
* @returns {Promise<number>} - The count of mentoring sessions.
* @throws {Error} - If an error occurs during the process.
*/

exports.getAssignedSessionsCountInDateRange = async (mentorId, startDate, endDate) => {
try {
const filter = {
user_id: mentorId,
type: common.SESSION_OWNERSHIP_TYPE.MENTOR,
}

const option = {
attributes: ['session_id'],
}
const sessionIds = await sessionOwnership.findAll(filter, option, true)

const count = await Session.count({
where: {
id: { [Op.in]: sessionIds },
created_at: {
[Op.between]: [startDate, endDate],
},
mentor_id: mentorId,
created_by: { [Op.ne]: mentorId },
},
})
return count
Expand Down
12 changes: 11 additions & 1 deletion src/services/mentors.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,23 @@ module.exports = class MentorsHelper {
filterEndDate.toISOString()
)

const totalSessionsAssigned = await sessionQueries.getAssignedSessionsCountInDateRange(
userId,
filterStartDate.toISOString(),
filterEndDate.toISOString()
)

const totalSessionsHosted = await sessionQueries.getHostedSessionsCountInDateRange(
userId,
Date.parse(filterStartDate) / 1000, // Converts milliseconds to seconds
Date.parse(filterEndDate) / 1000
)

const result = { total_session_created: totalSessionsCreated, total_session_hosted: totalSessionsHosted }
const result = {
total_session_created: totalSessionsCreated,
total_session_hosted: totalSessionsHosted,
total_session_assigned: totalSessionsAssigned,
}
return responses.successResponse({
statusCode: httpStatusCode.ok,
message: 'MENTORS_REPORT_FETCHED_SUCCESSFULLY',
Expand Down