add reminders notes and notification in sidebar

This commit is contained in:
richardtekula
2025-11-25 11:29:03 +01:00
parent f4397bc0de
commit cf4df9d314
3 changed files with 62 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
import { db } from '../config/database.js';
import { companies, companyReminders } from '../db/schema.js';
import { eq, desc } from 'drizzle-orm';
import { eq, desc, sql } from 'drizzle-orm';
import { NotFoundError, BadRequestError } from '../utils/errors.js';
const ensureCompanyExists = async (companyId) => {
@@ -100,3 +100,34 @@ export const deleteReminder = async (companyId, reminderId) => {
return { success: true, message: 'Reminder bol odstránený' };
};
export const getReminderSummary = async () => {
const [row] = await db
.select({
total: sql`COUNT(*)::int`,
active: sql`COUNT(*) FILTER (WHERE ${companyReminders.isChecked} = false)::int`,
completed: sql`COUNT(*) FILTER (WHERE ${companyReminders.isChecked} = true)::int`,
})
.from(companyReminders);
return {
total: row?.total ?? 0,
active: row?.active ?? 0,
completed: row?.completed ?? 0,
};
};
export const getReminderCountsByCompany = async () => {
const rows = await db
.select({
companyId: companyReminders.companyId,
total: sql`COUNT(*)::int`,
active: sql`COUNT(*) FILTER (WHERE ${companyReminders.isChecked} = false)::int`,
completed: sql`COUNT(*) FILTER (WHERE ${companyReminders.isChecked} = true)::int`,
})
.from(companyReminders)
.groupBy(companyReminders.companyId)
.orderBy(desc(companyReminders.companyId));
return rows;
};