- Add admin-only authorization for company and projects CRUD operations - Create requireAccountId middleware to eliminate code duplication - Standardize error handling (use next(error) consistently) - Change error messages to Slovak language 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
152 lines
3.0 KiB
JavaScript
152 lines
3.0 KiB
JavaScript
import * as noteService from '../services/note.service.js';
|
|
|
|
/**
|
|
* Get all notes
|
|
* GET /api/notes?search=query&companyId=xxx&projectId=xxx&todoId=xxx&contactId=xxx
|
|
*/
|
|
export const getAllNotes = async (req, res, next) => {
|
|
try {
|
|
const { search, companyId, projectId, todoId, contactId } = req.query;
|
|
|
|
const filters = {
|
|
searchTerm: search,
|
|
companyId,
|
|
projectId,
|
|
todoId,
|
|
contactId,
|
|
};
|
|
|
|
const notes = await noteService.getAllNotes(filters);
|
|
|
|
res.status(200).json({
|
|
success: true,
|
|
count: notes.length,
|
|
data: notes,
|
|
});
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Get note by ID
|
|
* GET /api/notes/:noteId
|
|
*/
|
|
export const getNoteById = async (req, res, next) => {
|
|
try {
|
|
const { noteId } = req.params;
|
|
|
|
const note = await noteService.getNoteById(noteId);
|
|
|
|
res.status(200).json({
|
|
success: true,
|
|
data: note,
|
|
});
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Create new note
|
|
* POST /api/notes
|
|
* Body: { title, content, companyId, projectId, todoId, contactId }
|
|
*/
|
|
export const createNote = async (req, res, next) => {
|
|
try {
|
|
const userId = req.userId;
|
|
const data = req.body;
|
|
|
|
const note = await noteService.createNote(userId, data);
|
|
|
|
res.status(201).json({
|
|
success: true,
|
|
data: note,
|
|
message: 'Poznámka bola vytvorená',
|
|
});
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Update note
|
|
* PATCH /api/notes/:noteId
|
|
* Body: { title, content, companyId, projectId, todoId, contactId }
|
|
*/
|
|
export const updateNote = async (req, res, next) => {
|
|
try {
|
|
const { noteId } = req.params;
|
|
const data = req.body;
|
|
|
|
const note = await noteService.updateNote(noteId, data);
|
|
|
|
res.status(200).json({
|
|
success: true,
|
|
data: note,
|
|
message: 'Poznámka bola aktualizovaná',
|
|
});
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Delete note
|
|
* DELETE /api/notes/:noteId
|
|
*/
|
|
export const deleteNote = async (req, res, next) => {
|
|
try {
|
|
const { noteId } = req.params;
|
|
|
|
const result = await noteService.deleteNote(noteId);
|
|
|
|
res.status(200).json({
|
|
success: true,
|
|
message: result.message,
|
|
});
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Get upcoming reminders for current user
|
|
* GET /api/notes/my-reminders
|
|
*/
|
|
export const getMyReminders = async (req, res, next) => {
|
|
try {
|
|
const userId = req.userId;
|
|
|
|
const reminders = await noteService.getUpcomingRemindersForUser(userId);
|
|
|
|
res.status(200).json({
|
|
success: true,
|
|
count: reminders.length,
|
|
data: reminders,
|
|
});
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Mark reminder as sent
|
|
* POST /api/notes/:noteId/mark-reminder-sent
|
|
*/
|
|
export const markReminderSent = async (req, res, next) => {
|
|
try {
|
|
const { noteId } = req.params;
|
|
|
|
const updated = await noteService.markReminderAsSent(noteId);
|
|
|
|
res.status(200).json({
|
|
success: true,
|
|
data: updated,
|
|
message: 'Reminder označený ako odoslaný',
|
|
});
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|