annoucement banners, calendar pdf export, vehicle booking quck-add, even quick-add

This commit is contained in:
Matthias Hochmeister
2026-03-12 11:47:08 +01:00
parent 71a04aee89
commit cd68bd3795
15 changed files with 997 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
import pool from '../config/database';
import logger from '../utils/logger';
export interface Banner {
id: string;
message: string;
level: 'info' | 'important' | 'critical';
starts_at: string;
ends_at: string | null;
created_by: string | null;
created_at: string;
}
export interface CreateBannerInput {
message: string;
level: 'info' | 'important' | 'critical';
starts_at?: string;
ends_at?: string | null;
}
class BannerService {
async getActive(): Promise<Banner[]> {
const result = await pool.query(
`SELECT * FROM announcement_banners
WHERE starts_at <= NOW()
AND (ends_at IS NULL OR ends_at > NOW())
ORDER BY
CASE level WHEN 'critical' THEN 0 WHEN 'important' THEN 1 ELSE 2 END,
created_at DESC`
);
return result.rows;
}
async getAll(): Promise<Banner[]> {
const result = await pool.query(
'SELECT * FROM announcement_banners ORDER BY created_at DESC'
);
return result.rows;
}
async create(data: CreateBannerInput, userId: string): Promise<Banner> {
const result = await pool.query(
`INSERT INTO announcement_banners (message, level, starts_at, ends_at, created_by)
VALUES ($1, $2, $3, $4, $5) RETURNING *`,
[data.message, data.level, data.starts_at ?? new Date().toISOString(), data.ends_at ?? null, userId]
);
return result.rows[0];
}
async delete(id: string): Promise<boolean> {
const result = await pool.query(
'DELETE FROM announcement_banners WHERE id = $1',
[id]
);
return (result.rowCount ?? 0) > 0;
}
}
export default new BannerService();