Commit Graph

115 Commits

Author SHA1 Message Date
richardtekula
8166b341ce fix: Allow no-origin requests for file downloads
CORS was blocking direct browser navigation/downloads in production.
Auth is still enforced by JWT/cookies on protected routes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 10:37:34 +01:00
richardtekula
fc2cf1acc2 fix: Add Chromium to Docker for PDF certificate generation
- Install chromium in Alpine Dockerfile
- Add PUPPETEER_EXECUTABLE_PATH env var support
- Fallback to system Chrome paths if bundled Chrome not found

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 10:31:51 +01:00
richardtekula
d282c0b359 fix: Handle duplicate email in createUcastnik
If participant with same email exists, update their data and
return existing record instead of throwing duplicate key error.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 08:55:18 +01:00
richardtekula
7213f9bab1 fix: Move drizzle-kit to dependencies for production use
drizzle.config.js imports from drizzle-kit, so it must be
installed in production for db:push to work on Coolify.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 08:53:03 +01:00
richardtekula
f2dee47252 fix: Use npx for drizzle-kit commands
Fixes "drizzle-kit: not found" error on production where
devDependencies are not installed.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 08:52:13 +01:00
richardtekula
a97a84b4f9 fix: Rewrite JMAP attachment upload to use HTTP POST
- Use proper HTTP POST to upload blob to JMAP server
- Truemail JMAP requires /upload/{accountId}/ endpoint
- Simplified email creation with correct bodyStructure
- Better error logging for debugging

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 08:45:50 +01:00
richardtekula
9bc8e2084a fix: Add explicit Content-Type and Content-Disposition headers for downloads
Improves browser compatibility for PDF file downloads by setting
proper MIME type and filename encoding.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 08:42:02 +01:00
richardtekula
de327d4d7d fix: Use userEmailAccounts join table for email account lookup
The emailAccounts table doesn't have a userId column - it uses a
many-to-many relationship through userEmailAccounts table.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 08:35:58 +01:00
richardtekula
6eced7263a feat: Add certificate email sending feature
- Create certificate-email.service.js with HTML email template
- Add beautiful gradient email template with course details
- Support PDF attachment via JMAP
- Add POST /prilohy/:prilohaId/send-email endpoint
- Add sendCertificateEmail controller function

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 08:22:22 +01:00
richardtekula
09f4c72acb feat: Add IČO and DIČ fields to companies
- Add ico and dic columns to companies table schema
- Add validation for ico and dic in createCompanySchema and updateCompanySchema
- Update company.service.js to include ico and dic in all CRUD operations
- Include migration file for database changes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 07:47:22 +01:00
richardtekula
159c22da16 fix: Use background-blue.jpeg for AIcertifikatGablas (signatures baked in)
Same approach as ScrumMaster - signatures are already in the background image,
no need to overlay separate PNG files which had quality issues.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 17:37:54 +01:00
richardtekula
ac429deba3 fix: Remove left artifact from Gablas signature
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 17:34:11 +01:00
richardtekula
d48813b082 fix: Clean up Gablas signature - remove line artifact
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 17:30:11 +01:00
richardtekula
e923e42a65 feat: Add 8 certificate templates with different courses and lecturers
Templates:
- AIcertifikat (Zdarílek), AIcertifikatGablas, AIcertifikatPatrik
- ScrumMaster, ScrumProductOwner (blue background)
- ITILFoundation (green background)
- PRINCE2Foundation, PRINCE2Practitioner (orange background)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 17:15:44 +01:00
richardtekula
f7d252ee7b fix: Center course info below participant name in certificates
Layout now:
1. Participant name (centered)
2. Course title (centered, below name)
3. Date range (centered, below course title)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 17:07:36 +01:00
richardtekula
68905787ce fix: Correct positioning of elements in certificate templates
- Position course title below header, not overlapping
- Center participant name above the horizontal line
- Position issue date above "Dátum" text at bottom left
- Use Bahnschrift font for course titles

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 14:35:50 +01:00
richardtekula
f2af7ffe22 feat: Add certificate templates for Scrum, ITIL, and PRINCE2 courses
- Add 3 new HTML templates: ScrumGeneric, ITIL, PRINCE2
- Add 3 background images: blue (Scrum), green (ITIL), orange (PRINCE2)
- Extract and add signatures: Gablas, Husam
- Update certificate.service.js to support multiple templates with different backgrounds

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 14:22:03 +01:00
richardtekula
12acd68156 refactor: Move course dates from registracie to kurzy table
- Add datumOd and datumDo columns to kurzy table
- Remove datumOd, datumDo, pocetUcastnikov from registracie table
- Update schema, validators, and services accordingly
- Certificate generation now uses course dates
- Migration preserves existing data by copying most recent dates

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 12:52:56 +01:00
richardtekula
2fee1f39bc refactor: Extract certificate template to separate file with template selection
- Move HTML template to src/templates/certificates/AIcertifikat.html
- Add template rendering with {{variable}} and {{#if}} syntax
- Add CERTIFICATE_TEMPLATES registry for multiple templates
- Accept templateName parameter in generateCertificate
- Add hasCertificate check to prevent duplicate certificates
- Add hasCertificate field to getCombinedTableData query

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 11:24:14 +01:00
richardtekula
225936e64a feat: Team leader role permissions, certificate generation, and bug fixes
- Add team_leader access to /admin/users endpoint for user list viewing
- Add PDF certificate generation for AI Kurzy with Puppeteer
- Add certificate assets (background, signatures)
- Add getPrilohaById and download endpoint for attachments
- Fix time tracking service permissions for team_leader
- Fix timesheet controller/service permissions for team_leader
- Fix calendar badge to include reminders in count
- Add lastSeen to message service for online indicator

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 10:58:42 +01:00
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
richardtekula
c3c42ec1e4 docs: Add README with full backend documentation and smoke test checklist
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 10:39:44 +01:00
richardtekula
57e6a2ea45 refactor: Split ai-kurzy.service.js into domain-specific files
Split 445-line monolith into:
- ai-kurzy/kurzy.service.js: course CRUD + stats
- ai-kurzy/ucastnici.service.js: participant CRUD
- ai-kurzy/registracie.service.js: registration CRUD, combined table,
  field updates, and document (prilohy) operations

Original ai-kurzy.service.js becomes a barrel export preserving all
existing import paths.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 07:43:32 +01:00
richardtekula
37dbf1b177 refactor: Extract notification logic from todo.service.js
Create todo-notification.service.js with:
- notifyNewTodoAssignment(): push notification for new todo assignments
- notifyUpdatedTodoAssignment(): push notification for updated assignments

todo.service.js now delegates to the notification service instead of
containing inline push notification logic with error handling.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 07:42:14 +01:00
richardtekula
240dd5f4c8 refactor: Split company.controller.js into focused controllers
Split company.controller.js (461 lines, 5 concerns) into:
- company.controller.js: CRUD + email (134 lines)
- company-note.controller.js: note operations
- company-reminder.controller.js: reminder operations
- company-team.controller.js: user assignment operations

Update company.routes.js to import from new controllers.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 07:41:31 +01:00
richardtekula
3aba6c2955 refactor: Move audit logging from controllers into services
Add auditContext parameter to service mutating functions. Services now
call audit log functions internally when auditContext is provided.
Controllers pass { userId, ipAddress, userAgent } and no longer import
audit service or fetch extra data for audit purposes.

Files modified:
- 10 service files: added audit imports and auditContext parameter
- 9 controller files: removed audit imports and calls

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 07:39:41 +01:00
richardtekula
caab86079e refactor: Deduplicate event-notifier.js (603 -> 418 lines)
Extract shared helpers:
- getEventsInRange(start, end) replaces getTomorrowEvents + getUpcomingEvents
- groupEventsByUser() deduplicates event grouping logic from 3 functions
- sendNotificationsToUsers() deduplicates notification loop from 3 functions
- buildJmapConfig() removes repeated JMAP config construction

Remove unused standalone range helper functions (getTomorrowRange,
getOneHourRange) — date ranges computed inline where needed.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 07:25:35 +01:00
richardtekula
d4883480b2 refactor: Deduplicate time-tracking.service.js (1045 -> 876 lines)
Extract shared helpers:
- validateProjectExists, validateTodoExists, validateCompanyExists,
  validateRelatedEntities (replaces 4x copy-pasted validation blocks)
- generateTimesheetWorkbook (shared workbook creation logic)
- addDailySummary (shared daily totals section)
- saveTimesheetFile (shared file save + DB insert)
- computeDailyTotals, getUserNamePrefix

generateMonthlyTimesheet and generateCompanyTimesheet now use shared
helpers instead of duplicating ~370 lines each.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 07:24:23 +01:00
richardtekula
4629f1903b refactor: Move inline Zod schemas from routes to validator files
Create ai-kurzy.validators.js and service.validators.js with schemas
extracted from their respective route files. Routes now import schemas
instead of defining them inline.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 07:22:33 +01:00
richardtekula
f463467264 refactor: Extract shared multer/upload config from routes
Create src/config/upload.js with createUpload() factory and shared
ALLOWED_FILE_TYPES constant. Replace duplicated multer configs in 5
route files with calls to the shared factory.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 07:21:35 +01:00
richardtekula
01ce2fc7ad refactor: Remove unused exports
Remove setPrimaryAccountSchema from email-account.validators.js and
requireOwnerOrAdmin from roleMiddleware.js — both have zero imports.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 07:20:00 +01:00
richardtekula
938a8d1478 refactor: Delete unused utility files
Remove queryBuilder.js and pagination.js — zero imports anywhere in codebase.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 07:19:39 +01:00
richardtekula
883d3fa533 chore: Commit current state before refactoring
Includes deleted sql/ files, seeds, and documentation files.
Prepares master for refactoring branch.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 07:19:23 +01:00
richardtekula
95688be45b feat: Add pause/resume functionality to time tracking
Add pausedAt and pausedDuration columns to time_entries table.
New pause/resume endpoints with audit logging. Duration calculations
now correctly exclude paused time across start, stop, auto-stop,
and edit flows.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 07:15:57 +01:00
richardtekula
d26e537244 fix: Harden security - CORS, XSS, file uploads, error handling
- Restrict no-origin CORS bypass to development only
- Activate xss-clean middleware for input sanitization
- Add MIME type whitelist and filename sanitization to file uploads
- Reduce project upload limit from 50MB to 20MB
- Stop leaking stack traces in error responses

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-26 15:21:44 +01:00
richardtekula
929d0b461f fix: Allow project team members to update projects, handle empty companyId
- Relax project PATCH route from requireAdmin to checkProjectAccess
- Normalize empty string companyId to null in updateProject service to prevent UUID parse error

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-26 11:41:36 +01:00
richardtekula
dd15be93a9 feat: Add refresh token endpoint and remember me support
- Add POST /auth/refresh endpoint for token renewal
- Only set refresh token cookie when rememberMe is true
- Add rememberMe field to login validator schema

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 07:21:58 +01:00
richardtekula
d85f6761cf fix validator in create cpompany schema 2026-01-23 06:28:56 +01:00
richardtekula
4c4c9accae fix: Add pricingTiers to service Zod validators
- pricingTiers field was missing from createServiceSchema
- pricingTiers field was missing from updateServiceSchema
- This caused the field to be stripped during validation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 11:40:48 +01:00
richardtekula
5dde025855 fix: Services pricing tiers and timesheet naming
- Add pricingTiers field handling in createService/updateService
- Fix timesheet filename to use firstName-lastName-vykazprace-YYYY-MM.xlsx
- Fix company timesheet filename format similarly
- Removed timestamp from filename for cleaner naming

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 11:30:17 +01:00
richardtekula
5ade261cb2 fix: Timesheet naming and todo auto-assign fixes
- Fix timesheet filename to use firstName-lastName format with username fallback
- Remove auto-assign creator to todos (user must manually select assignees)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 11:20:10 +01:00
richardtekula
e5a88c36a9 Merge branch 'hotfix/part2' into hotfix/final 2026-01-22 08:00:47 +01:00
richardtekula
284d905d18 feat: Add notes search endpoint for enhanced global search
- Add searchNotes service function with company/project info
- Add /notes/search endpoint for searching notes content
- Returns matching notes with linked company/project names

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 07:49:10 +01:00
richardtekula
a0a6656a49 feat: Hotfix Part1 - Backend support for company postal code, service tiers, timesheet naming
- Add postal_code column to companies table
- Add pricing_tiers column to services table for tiered pricing
- Update timesheet upload to generate filename in format {firstname}-{lastname}-timesheet-{date}

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 07:46:50 +01:00
richardtekula
826fd467bc feat: Add farba field and company details to AI Kurzy module
- Add farba (color) field to kurzy schema and Zod validation
- Add company detail fields (firma_ico, firma_dic, firma_ic_dph, firma_sidlo) to ucastnici
- Remove console logs from ai-kurzy service
- Add SQL migration scripts for schema updates and data

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-21 14:27:03 +01:00
richardtekula
4089bb4be2 feat: AI Kurzy module, project/service documents, services SQL import
- Add AI Kurzy module with courses, participants, and registrations management
- Add project documents and service documents features
- Add service folders for document organization
- Add SQL import queries for services from firmy.slovensko.ai
- Update todo notifications and group messaging
- Various API improvements and bug fixes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-21 11:32:49 +01:00
richardtekula
d9f16ad0a6 feat: Group chat and push notifications
- Add group chat tables (chat_groups, chat_group_members, group_messages)
- Add push subscriptions table for web push notifications
- Add group service, controller, routes
- Add push service, controller, routes
- Integrate push notifications with todos, messages, group messages

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 07:27:13 +01:00
richardtekula
73a3c6bf95 hotfix: Security, performance, and code cleanup
- Remove hardcoded database password fallback
- Add encryption salt validation (min 32 chars)
- Separate EMAIL_ENCRYPTION_KEY from JWT_SECRET
- Fix command injection in status.service.js (use execFileSync)
- Remove unnecessary SQL injection regex middleware
- Create shared utilities (queryBuilder, pagination, emailAccountHelper)
- Fix N+1 query problems in contact and todo services
- Merge duplicate JMAP config functions
- Add database indexes migration
- Standardize error responses with error codes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-19 07:17:23 +01:00
richardtekula
0523087961 feat: Add email signature feature
- Add email_signatures table to schema
- Add email signature service, controller, routes
- Users can create/edit signature in Profile
- Toggle to include signature when sending email replies

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-17 19:11:51 +01:00
richardtekula
514b6c8a92 feat: Add services, company documents, company timesheet export
- Add services table and CRUD endpoints (/api/services)
- Add company documents upload/download functionality
- Add company timesheet XLSX export endpoint
- Remove admin requirement from event routes (all authenticated users can manage events)
- Add service validators

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