add reminders notes and notification in sidebar
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user