File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -69,7 +69,49 @@ const menteeViewHours = async (req, res) => {
6969 }
7070} ;
7171
72+ // function for storing and retrieving mentee hours from the database
73+ // unique identifier for each mentee, full name
74+ // total required hours, sum of logged hours, timestamp of last log update
75+
76+ const menteeLogSummary = async ( req , res ) => {
77+ const zid = verifyToken ( req . headers [ "authorization" ] , res ) ;
78+ if ( zid instanceof Object ) return ;
79+
80+ try {
81+ const query = `
82+ SELECT
83+ u.zid,
84+ u.firstname,
85+ u.lastname,
86+ COALESCE(SUM(h.num_hours), 0) AS total_logged_hours,
87+ MAX(h.timestamp) AS last_log_timestamp
88+ FROM users u
89+ LEFT JOIN hours h ON u.zid = h.zid AND h.status = 'approved'
90+ WHERE u.zid = $1
91+ GROUP BY u.zid, u.firstname, u.lastname
92+ ` ;
93+
94+ const { rows } = await db . query ( query , [ zid ] ) ;
95+
96+ if ( rows . length === 0 ) {
97+ return res . status ( 404 ) . json ( { message : "Mentee not found" } ) ;
98+ }
99+
100+ const result = {
101+ ...rows [ 0 ] ,
102+ total_required_hours : 20
103+ } ;
104+
105+ res . status ( 200 ) . json ( result ) ;
106+ } catch ( err ) {
107+
108+ res . status ( 500 ) . json ( { message : "Internal server error" } ) ;
109+ }
110+ } ;
111+
112+
72113module . exports = {
73114 requestHours,
74115 menteeViewHours,
116+ menteeLogSummary,
75117} ;
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ app.post("/user/forgot-password", auth.forgotPassword);
2626// -------- Mentee --------//
2727app . post ( "/mentee/request-hours" , mentee . requestHours ) ;
2828app . get ( "/mentee/view-hours" , mentee . menteeViewHours ) ;
29+ app . get ( "/mentee/log-summary" , mentee . menteeLogSummary ) ;
2930
3031// -------- Admin --------//
3132app . patch ( "/admin/approve-hours" , admin . approveHours ) ;
You can’t perform that action at this time.
0 commit comments