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

@@ -295,3 +295,29 @@ export const deleteCompanyReminder = async (req, res) => {
res.status(error.statusCode || 500).json(errorResponse); res.status(error.statusCode || 500).json(errorResponse);
} }
}; };
export const getReminderSummary = async (_req, res) => {
try {
const summary = await companyReminderService.getReminderSummary();
res.status(200).json({
success: true,
data: summary,
});
} catch (error) {
const errorResponse = formatErrorResponse(error, process.env.NODE_ENV === 'development');
res.status(error.statusCode || 500).json(errorResponse);
}
};
export const getReminderCountsByCompany = async (_req, res) => {
try {
const counts = await companyReminderService.getReminderCountsByCompany();
res.status(200).json({
success: true,
data: counts,
});
} catch (error) {
const errorResponse = formatErrorResponse(error, process.env.NODE_ENV === 'development');
res.status(error.statusCode || 500).json(errorResponse);
}
};

View File

@@ -10,6 +10,10 @@ const router = express.Router();
// All company routes require authentication // All company routes require authentication
router.use(authenticate); router.use(authenticate);
// Reminder summaries (must be before :companyId routes)
router.get('/reminders/summary', companyController.getReminderSummary);
router.get('/reminders/counts', companyController.getReminderCountsByCompany);
/** /**
* Company management * Company management
*/ */

View File

@@ -1,6 +1,6 @@
import { db } from '../config/database.js'; import { db } from '../config/database.js';
import { companies, companyReminders } from '../db/schema.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'; import { NotFoundError, BadRequestError } from '../utils/errors.js';
const ensureCompanyExists = async (companyId) => { const ensureCompanyExists = async (companyId) => {
@@ -100,3 +100,34 @@ export const deleteReminder = async (companyId, reminderId) => {
return { success: true, message: 'Reminder bol odstránený' }; 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;
};