• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

witseie-elen4010 / 2026-group-lab-002 / 25130631138

29 Apr 2026 07:55PM UTC coverage: 82.239% (-17.8%) from 100.0%
25130631138

push

github

web-flow
Merge pull request #54 from witseie-elen4010/fix/lecturer-dashboard

fix(dashboard): repair lecturer dashboard query, auth middleware and …

42 of 59 branches covered (71.19%)

Branch coverage included in aggregate %.

34 of 37 new or added lines in 3 files covered. (91.89%)

171 of 200 relevant lines covered (85.5%)

2.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/src/controllers/availability-controller.js
1
const db = require('../../database/db');
3✔
2
const { generateConstId, validateSlotFields } = require('../services/availability-helpers');
3✔
3

4
const showAvailability = (req, res) => {
3✔
5
  const user = {
2✔
6
    id: req.session.userId,
7
    name: req.session.userName,
8
    role: req.session.userRole,
9
  };
10

11
  const availability = db.prepare('SELECT * FROM consultations WHERE lecturer_id = ?').all(user.id);
2✔
12

13
  res.render('availability', { user, availability, error: null, success: null });
2✔
14
};
15

16
const saveAvailability = (req, res) => {
3✔
17
  const lecturerId = req.session.userId;
3✔
18
  const { consultation_date, consultation_time, venue, duration_min, max_number_of_students } = req.body;
3✔
19

20
  if (!validateSlotFields(req.body)) {
3✔
21
    return res.render('availability', {
1✔
22
      user: { id: lecturerId, name: req.session.userName, role: req.session.userRole },
23
      availability: db.prepare('SELECT * FROM consultations WHERE lecturer_id = ?').all(lecturerId),
24
      error: 'All fields are required.',
25
      success: null
26
    });
27
  }
28

29
  const existing = db.prepare(
2✔
30
    'SELECT const_id FROM consultations WHERE lecturer_id = ? AND consultation_date = ? AND consultation_time = ?'
31
  ).get(lecturerId, consultation_date, consultation_time);
32

33
  if (existing) {
2✔
34
    return res.render('availability', {
1✔
35
      user: { id: lecturerId, name: req.session.userName, role: req.session.userRole },
36
      availability: db.prepare('SELECT * FROM consultations WHERE lecturer_id = ?').all(lecturerId),
37
      error: 'A slot already exists for that date and time.',
38
      success: null
39
    });
40
  }
41

42
  const count = db.prepare(
1✔
43
    'SELECT COUNT(*) AS total FROM consultations WHERE lecturer_id = ? AND consultation_date = ?'
44
  ).get(lecturerId, consultation_date).total;
45

46
  const constId = generateConstId(consultation_date, count);
1✔
47

48
  try {
1✔
49
    db.prepare(`
1✔
50
      INSERT INTO consultations (const_id, consultation_date, consultation_time, lecturer_id, duration_min, max_number_of_students, venue, status)
51
      VALUES (?, ?, ?, ?, ?, ?, ?, 'Available')
52
    `).run(constId, consultation_date, consultation_time, lecturerId, Number(duration_min), Number(max_number_of_students), venue);
53
  } catch (err) {
NEW
54
    console.error('Save availability error:', err);
×
NEW
55
    return res.render('availability', {
×
56
      user: { id: lecturerId, name: req.session.userName, role: req.session.userRole },
57
      availability: db.prepare('SELECT * FROM consultations WHERE lecturer_id = ?').all(lecturerId),
58
      error: 'Could not save slot. Please try again.',
59
      success: null
60
    });
61
  }
62

63
  return res.redirect('/lecturer/dashboard');
1✔
64
};
65

66
module.exports = { showAvailability, saveAvailability };
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc