Add Timesheets API with file upload and role-based access
Backend Features:
- Timesheets database table (id, userId, fileName, filePath, fileType, fileSize, year, month, timestamps)
- File upload with multer (memory storage, 10MB limit, PDF/Excel validation)
- Structured file storage: uploads/timesheets/{userId}/{year}/{month}/
- RESTful API endpoints:
* POST /api/timesheets/upload - Upload timesheet
* GET /api/timesheets/my - Get user's timesheets (with filters)
* GET /api/timesheets/all - Get all timesheets (admin only)
* GET /api/timesheets/:id/download - Download file
* DELETE /api/timesheets/:id - Delete timesheet
- Role-based permissions: users access own files, admins access all
- Proper error handling and file cleanup on errors
- Database migration for timesheets table
Technical:
- Uses req.user.role for permission checks
- Automatic directory creation for user/year/month structure
- Blob URL cleanup and proper file handling
- Integration with existing auth middleware
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,7 @@ import adminRoutes from './routes/admin.routes.js';
|
||||
import contactRoutes from './routes/contact.routes.js';
|
||||
import crmEmailRoutes from './routes/crm-email.routes.js';
|
||||
import emailAccountRoutes from './routes/email-account.routes.js';
|
||||
import timesheetRoutes from './routes/timesheet.routes.js';
|
||||
|
||||
const app = express();
|
||||
|
||||
@@ -72,6 +73,7 @@ app.use('/api/admin', adminRoutes);
|
||||
app.use('/api/contacts', contactRoutes);
|
||||
app.use('/api/emails', crmEmailRoutes);
|
||||
app.use('/api/email-accounts', emailAccountRoutes);
|
||||
app.use('/api/timesheets', timesheetRoutes);
|
||||
|
||||
// Basic route
|
||||
app.get('/', (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user