Skip to content

Commit

Permalink
Merge pull request #611 from ELEVATE-Project/1233-EF-Enhancement
Browse files Browse the repository at this point in the history
[Bug-1233]- mentor/reports Changes For Front-End
  • Loading branch information
rakeshSgr authored Feb 20, 2024
2 parents 40f21a0 + 5e8a4d8 commit df5f753
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
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

0 comments on commit df5f753

Please sign in to comment.