Files
app/src/config/env.ts
BOHA 6b31b2f74b feat: system settings, dynamic logos, template numbering, permission consolidation
- System settings page with tabs: Security, System, Firma
- Configurable attendance rules (break thresholds, rounding) from DB
- Configurable document numbering with template patterns ({YYYY}/{PREFIX}/{NNN})
- Dynamic logo upload (light/dark variants) served from DB instead of static files
- Email settings (SMTP from/name, alert/leave emails) configurable in UI
- Currency and VAT rate lists configurable, used across all modules
- Permissions simplified: offers.settings + settings.roles + settings.security → settings.manage
- Leaflet bundled locally, removed unpkg.com from CSP
- Silent catch blocks fixed with proper logging
- console.log replaced with app.log.info in server.ts
- Schema renamed: company-settings.schema → settings.schema
- App info section: version, Node.js, uptime, memory, DB status, NAS status

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 10:15:47 +01:00

81 lines
2.5 KiB
TypeScript

import dotenv from "dotenv";
dotenv.config();
// Set timezone for Date operations — all attendance/time records are in Czech local time
process.env.TZ = process.env.TZ || "Europe/Prague";
// Override Date.toJSON so JSON.stringify outputs local time (Europe/Prague).
// Prisma stores UTC in MySQL DATETIME columns. When reading, it creates
// JS Date objects with correct UTC internals. The default toJSON() calls
// toISOString() which returns UTC — this override uses local getters instead,
// so the frontend always receives times in the user's timezone.
Date.prototype.toJSON = function () {
const y = this.getFullYear();
const m = String(this.getMonth() + 1).padStart(2, "0");
const d = String(this.getDate()).padStart(2, "0");
const h = String(this.getHours()).padStart(2, "0");
const min = String(this.getMinutes()).padStart(2, "0");
const s = String(this.getSeconds()).padStart(2, "0");
return `${y}-${m}-${d}T${h}:${min}:${s}`;
};
function required(key: string): string {
const val = process.env[key];
if (!val) throw new Error(`Missing required env variable: ${key}`);
return val;
}
export const config = {
port: parseInt(process.env.PORT || "3001", 10),
host: process.env.HOST || "127.0.0.1",
appEnv: process.env.APP_ENV || "local",
isProduction: process.env.APP_ENV === "production",
db: {
url: required("DATABASE_URL"),
},
jwt: {
secret: required("JWT_SECRET"),
accessTokenExpiry: parseInt(process.env.ACCESS_TOKEN_EXPIRY || "900", 10),
refreshTokenSessionExpiry: parseInt(
process.env.REFRESH_TOKEN_SESSION_EXPIRY || "3600",
10,
),
refreshTokenRememberExpiry: parseInt(
process.env.REFRESH_TOKEN_REMEMBER_EXPIRY || "2592000",
10,
),
},
totp: {
encryptionKey: required("TOTP_ENCRYPTION_KEY"),
},
nas: {
path: process.env.NAS_PATH || "Z:/02_PROJEKTY",
financialsPath: process.env.NAS_FINANCIALS_PATH || "",
offersPath: process.env.NAS_OFFERS_PATH || "",
maxUploadSize: parseInt(process.env.MAX_UPLOAD_SIZE || "52428800", 10),
},
email: {
contactTo: process.env.CONTACT_EMAIL_TO || "",
contactFrom: process.env.CONTACT_EMAIL_FROM || "",
smtpFrom: process.env.SMTP_FROM || "",
smtpFromName: process.env.SMTP_FROM_NAME || "",
leaveNotify: process.env.LEAVE_NOTIFY_EMAIL || "",
invoiceAlert: process.env.INVOICE_ALERT_EMAIL || "",
},
appUrl: process.env.APP_URL || "",
cors: {
origins: (process.env.CORS_ORIGINS || "").split(",").filter(Boolean),
},
security: {
bcryptCost: 12,
},
} as const;