add reminders notes and notification in sidebar
This commit is contained in:
@@ -295,3 +295,29 @@ export const deleteCompanyReminder = async (req, res) => {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,6 +10,10 @@ const router = express.Router();
|
||||
// All company routes require authentication
|
||||
router.use(authenticate);
|
||||
|
||||
// Reminder summaries (must be before :companyId routes)
|
||||
router.get('/reminders/summary', companyController.getReminderSummary);
|
||||
router.get('/reminders/counts', companyController.getReminderCountsByCompany);
|
||||
|
||||
/**
|
||||
* Company management
|
||||
*/
|
||||
|
||||
@@ -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