Files
crm-server/src/routes/timesheet.routes.js
richardtekula a4a81ef88e feat: Multi-feature CRM update
- Add team_leader role with appropriate permissions
- Add lastSeen timestamp for chat online indicator
- Add needsFollowup flag to ucastnici table
- Add getTodayCalendarCount endpoint for calendar badge
- Add company reminders to calendar data
- Enhance company search to include phone and contacts
- Update routes to allow team_leader access to kurzy, services, timesheets

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 17:23:57 +01:00

74 lines
1.9 KiB
JavaScript

import express from 'express';
import * as timesheetController from '../controllers/timesheet.controller.js';
import { authenticate } from '../middlewares/auth/authMiddleware.js';
import { requireTeamLeaderOrAdmin } from '../middlewares/auth/roleMiddleware.js';
import { validateBody, validateParams } from '../middlewares/security/validateInput.js';
import { z } from 'zod';
import { createUpload } from '../config/upload.js';
const router = express.Router();
const upload = createUpload({
maxSizeMB: 5,
allowedTypes: [
'application/pdf',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.ms-excel',
],
errorMessage: 'Neplatný typ súboru. Povolené sú iba PDF a Excel súbory.',
});
/**
* All timesheet routes require authentication
*/
router.use(authenticate);
/**
* Upload timesheet
* POST /api/timesheets/upload
*/
router.post(
'/upload',
upload.single('file'),
validateBody(z.object({
year: z.string().regex(/^\d{4}$/, 'Rok musí byť 4-miestne číslo'),
month: z.string().regex(/^([1-9]|1[0-2])$/, 'Mesiac musí byť číslo od 1 do 12'),
userId: z.string().uuid().optional(), // Optional: admin can upload for other users
})),
timesheetController.uploadTimesheet
);
/**
* Get user's timesheets
* GET /api/timesheets/my
*/
router.get('/my', timesheetController.getMyTimesheets);
/**
* Get all timesheets (admin only)
* GET /api/timesheets/all
*/
router.get('/all', requireTeamLeaderOrAdmin, timesheetController.getAllTimesheets);
/**
* Download timesheet
* GET /api/timesheets/:timesheetId/download
*/
router.get(
'/:timesheetId/download',
validateParams(z.object({ timesheetId: z.string().uuid() })),
timesheetController.downloadTimesheet
);
/**
* Delete timesheet
* DELETE /api/timesheets/:timesheetId
*/
router.delete(
'/:timesheetId',
validateParams(z.object({ timesheetId: z.string().uuid() })),
timesheetController.deleteTimesheet
);
export default router;