|
| 1 | +import { NextFunction, Request, Response } from 'express'; |
| 2 | +import AttendanceService from '../services/attendance.services.js'; |
| 3 | + |
| 4 | +export default class AttendanceController { |
| 5 | + static async takeAttendance(req: Request, res: Response, next: NextFunction) { |
| 6 | + try { |
| 7 | + const { teamId, message } = req.body; |
| 8 | + const attendance = await AttendanceService.takeAttendance(req.currentUser, teamId, message, req.organization); |
| 9 | + res.status(200).json(attendance); |
| 10 | + } catch (error: unknown) { |
| 11 | + next(error); |
| 12 | + } |
| 13 | + } |
| 14 | + |
| 15 | + static async getAllAttendances(req: Request, res: Response, next: NextFunction) { |
| 16 | + try { |
| 17 | + const attendances = await AttendanceService.getAllAttendances(req.organization); |
| 18 | + res.status(200).json(attendances); |
| 19 | + } catch (error: unknown) { |
| 20 | + next(error); |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + static async getAttendanceById(req: Request, res: Response, next: NextFunction) { |
| 25 | + try { |
| 26 | + const { meetingAttendanceId } = req.params as Record<string, string>; |
| 27 | + const attendance = await AttendanceService.getAttendanceById(meetingAttendanceId, req.organization); |
| 28 | + res.status(200).json(attendance); |
| 29 | + } catch (error: unknown) { |
| 30 | + next(error); |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + static async getOngoingAttendance(req: Request, res: Response, next: NextFunction) { |
| 35 | + try { |
| 36 | + const { teamId } = req.params as Record<string, string>; |
| 37 | + const attendance = await AttendanceService.getOngoingAttendance(teamId, req.organization); |
| 38 | + res.status(200).json(attendance); |
| 39 | + } catch (error: unknown) { |
| 40 | + next(error); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + static async closeOngoingAttendance(req: Request, res: Response, next: NextFunction) { |
| 45 | + try { |
| 46 | + const { teamId } = req.params as Record<string, string>; |
| 47 | + await AttendanceService.closeOngoingAttendance(teamId, req.currentUser, req.organization); |
| 48 | + res.status(200).json({ message: 'Attendance closed successfully' }); |
| 49 | + } catch (error: unknown) { |
| 50 | + next(error); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + static async checkChannel(req: Request, res: Response, next: NextFunction) { |
| 55 | + try { |
| 56 | + const { teamId } = req.params as Record<string, string>; |
| 57 | + const result = await AttendanceService.checkTeamChannel(teamId, req.organization); |
| 58 | + res.status(200).json(result); |
| 59 | + } catch (error: unknown) { |
| 60 | + next(error); |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments