Merge branch 'hotfix/part2' into hotfix/final

This commit is contained in:
richardtekula
2026-01-22 08:00:47 +01:00
3 changed files with 52 additions and 0 deletions

View File

@@ -167,3 +167,23 @@ export const markReminderSent = async (req, res, next) => {
next(error); next(error);
} }
}; };
/**
* Search notes with company and project info
* GET /api/notes/search?q=searchTerm
*/
export const searchNotes = async (req, res, next) => {
try {
const { q } = req.query;
const results = await noteService.searchNotes(q);
res.status(200).json({
success: true,
count: results.length,
data: results,
});
} catch (error) {
next(error);
}
};

View File

@@ -18,6 +18,9 @@ router.use(authenticate);
// Get all notes (admin only - returns all notes system-wide) // Get all notes (admin only - returns all notes system-wide)
router.get('/', requireAdmin, noteController.getAllNotes); router.get('/', requireAdmin, noteController.getAllNotes);
// Search notes with company/project info (must be before /:noteId to avoid route conflict)
router.get('/search', noteController.searchNotes);
// Get my reminders (must be before /:noteId to avoid route conflict) // Get my reminders (must be before /:noteId to avoid route conflict)
router.get('/my-reminders', noteController.getMyReminders); router.get('/my-reminders', noteController.getMyReminders);

View File

@@ -332,3 +332,32 @@ export const getNotesByContactId = async (contactId) => {
.where(eq(notes.contactId, contactId)) .where(eq(notes.contactId, contactId))
.orderBy(desc(notes.createdAt)); .orderBy(desc(notes.createdAt));
}; };
/**
* Search notes with company and project info
* Returns notes matching searchTerm with linked company/project names
*/
export const searchNotes = async (searchTerm) => {
if (!searchTerm || searchTerm.trim().length < 2) {
return [];
}
const results = await db
.select({
id: notes.id,
content: notes.content,
companyId: notes.companyId,
projectId: notes.projectId,
companyName: companies.name,
projectName: projects.name,
createdAt: notes.createdAt,
})
.from(notes)
.leftJoin(companies, eq(notes.companyId, companies.id))
.leftJoin(projects, eq(notes.projectId, projects.id))
.where(ilike(notes.content, `%${searchTerm}%`))
.orderBy(desc(notes.createdAt))
.limit(20);
return results;
};