feat: Add email signature feature
- Add email_signatures table to schema - Add email signature service, controller, routes - Users can create/edit signature in Profile - Toggle to include signature when sending email replies Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
93
src/controllers/email-signature.controller.js
Normal file
93
src/controllers/email-signature.controller.js
Normal file
@@ -0,0 +1,93 @@
|
||||
import * as emailSignatureService from '../services/email-signature.service.js';
|
||||
|
||||
/**
|
||||
* Get current user's email signature
|
||||
* GET /api/email-signature
|
||||
*/
|
||||
export const getSignature = async (req, res, next) => {
|
||||
try {
|
||||
const signature = await emailSignatureService.getSignature(req.userId);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: signature,
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create or update email signature
|
||||
* POST /api/email-signature
|
||||
*/
|
||||
export const upsertSignature = async (req, res, next) => {
|
||||
try {
|
||||
const signature = await emailSignatureService.upsertSignature(req.userId, req.body);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: signature,
|
||||
message: 'Podpis bol uložený',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggle signature on/off
|
||||
* PATCH /api/email-signature/toggle
|
||||
*/
|
||||
export const toggleSignature = async (req, res, next) => {
|
||||
try {
|
||||
const { isEnabled } = req.body;
|
||||
const signature = await emailSignatureService.toggleSignature(req.userId, isEnabled);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: signature,
|
||||
message: isEnabled ? 'Podpis zapnutý' : 'Podpis vypnutý',
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get formatted signature text for email
|
||||
* GET /api/email-signature/formatted
|
||||
*/
|
||||
export const getFormattedSignature = async (req, res, next) => {
|
||||
try {
|
||||
const signature = await emailSignatureService.getSignature(req.userId);
|
||||
const formatted = emailSignatureService.formatSignatureText(signature);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: {
|
||||
text: formatted,
|
||||
isEnabled: signature?.isEnabled || false,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete email signature
|
||||
* DELETE /api/email-signature
|
||||
*/
|
||||
export const deleteSignature = async (req, res, next) => {
|
||||
try {
|
||||
const result = await emailSignatureService.deleteSignature(req.userId);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: result.message,
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user