Geburtstag-Management-Modal mit Reset + Send + Auto-Flag
Neuer Cake-Button neben dem Geburtsdatum in den Stammdaten öffnet ein Modal mit drei Funktionen: 1. **Gruß-Marker zurücksetzen** (lastBirthdayGreetingYear → null) - Für Debugging oder als Fallback, wenn der Kunde den Gruß erneut sehen soll - Mit Bestätigungsdialog 2. **Geburtstagsgruß jetzt senden** (Email / WhatsApp / Telegram / Signal) - Email: direkt via System-SMTP mit HTML-Template (Du/Sie-abhängig) - WhatsApp/Telegram/Signal: öffnet vorbefülltes Fenster mit Gruß-Text - Text beachtet Du/Sie-Verhältnis (pronomen, possessiv, etc.) - Mit Bestätigungsdialog 3. **Automatisch senden** – neue Einstellung am Customer - autoBirthdayGreeting (Boolean) + autoBirthdayChannel (String) - Für späteren Cron-basierten Automatik-Versand vorbereitet Backend: - birthday.service.ts: resetBirthdayGreeting, buildBirthdayGreetingText, getBirthdayGreetingData - birthday.controller.ts: resetBirthdayGreeting, sendBirthdayGreeting - Routes: POST /birthdays/:customerId/reset + /send - Audit-Log bei beiden Aktionen Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -214,3 +214,123 @@ export async function acknowledgeBirthdayGreeting(customerId: number): Promise<v
|
||||
data: { lastBirthdayGreetingYear: thisYear },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt den Gruß-Marker zurück, damit das Modal beim nächsten Login wieder erscheint.
|
||||
* (Für Mitarbeiter – nützlich zum Debuggen und als Fallback wenn etwas schief ging.)
|
||||
*/
|
||||
export async function resetBirthdayGreeting(customerId: number): Promise<void> {
|
||||
await prisma.customer.update({
|
||||
where: { id: customerId },
|
||||
data: { lastBirthdayGreetingYear: null },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generiert den persönlichen Geburtstagsgruß-Text (Du/Sie-abhängig).
|
||||
*/
|
||||
export function buildBirthdayGreetingText(
|
||||
customer: {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
salutation: string | null;
|
||||
useInformalAddress: boolean;
|
||||
},
|
||||
age: number,
|
||||
): { subject: string; plain: string; html: string } {
|
||||
const name = customer.useInformalAddress
|
||||
? customer.firstName
|
||||
: [customer.salutation, customer.lastName].filter(Boolean).join(' ') || customer.firstName;
|
||||
const du = customer.useInformalAddress;
|
||||
const pronoun = du ? 'dir' : 'Ihnen';
|
||||
const possessive = du ? 'deinem' : 'Ihrem';
|
||||
const yourLower = du ? 'dein' : 'Ihr';
|
||||
|
||||
const subject = du
|
||||
? `Alles Gute zum Geburtstag, ${customer.firstName}! 🎉`
|
||||
: 'Herzlichen Glückwunsch zum Geburtstag 🎉';
|
||||
|
||||
const plain = [
|
||||
`Herzlichen Glückwunsch, ${name}!`,
|
||||
'',
|
||||
age > 0
|
||||
? `Alles Gute zu ${possessive} ${age}. Geburtstag!`
|
||||
: `Alles Gute zu ${possessive} Geburtstag!`,
|
||||
'',
|
||||
`Wir wünschen ${pronoun} einen wunderschönen Tag und alles Gute für ${yourLower} neues Lebensjahr. 🌟`,
|
||||
'',
|
||||
'Herzliche Grüße',
|
||||
'Hacker-Net Telekommunikation',
|
||||
].join('\n');
|
||||
|
||||
const html = `
|
||||
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
|
||||
<div style="background: linear-gradient(135deg, #ec4899 0%, #8b5cf6 50%, #6366f1 100%); padding: 40px 20px; text-align: center; border-radius: 12px 12px 0 0;">
|
||||
<div style="font-size: 64px; margin-bottom: 8px;">🎉🎂🎈</div>
|
||||
</div>
|
||||
<div style="padding: 32px; background: #ffffff; border: 1px solid #e5e7eb; border-top: none; border-radius: 0 0 12px 12px;">
|
||||
<h2 style="color: #1f2937; margin-top: 0;">Herzlichen Glückwunsch, ${name}!</h2>
|
||||
<p style="color: #4b5563; font-size: 16px; line-height: 1.6;">
|
||||
${age > 0 ? `Alles Gute zu ${possessive} <strong>${age}. Geburtstag</strong>!` : `Alles Gute zu ${possessive} Geburtstag!`}
|
||||
</p>
|
||||
<p style="color: #6b7280; font-size: 14px; line-height: 1.6;">
|
||||
Wir wünschen ${pronoun} einen wunderschönen Tag und alles Gute für ${yourLower} neues Lebensjahr. 🌟
|
||||
</p>
|
||||
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 24px 0;">
|
||||
<p style="color: #9ca3af; font-size: 12px; margin: 0;">
|
||||
Herzliche Grüße<br>
|
||||
<strong>Hacker-Net Telekommunikation</strong><br>
|
||||
Am Wunderburgpark 5b, 26135 Oldenburg<br>
|
||||
info@hacker-net.de
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
return { subject, plain, html };
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt die für den Gruß benötigten Kundendaten inkl. aktuellem Alter heute.
|
||||
*/
|
||||
export async function getBirthdayGreetingData(customerId: number): Promise<{
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
salutation: string | null;
|
||||
useInformalAddress: boolean;
|
||||
email: string | null;
|
||||
phone: string | null;
|
||||
mobile: string | null;
|
||||
age: number;
|
||||
} | null> {
|
||||
const c = await prisma.customer.findUnique({
|
||||
where: { id: customerId },
|
||||
select: {
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
salutation: true,
|
||||
useInformalAddress: true,
|
||||
email: true,
|
||||
phone: true,
|
||||
mobile: true,
|
||||
birthDate: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!c?.birthDate) return null;
|
||||
|
||||
const today = new Date();
|
||||
today.setHours(0, 0, 0, 0);
|
||||
const age = calculateAge(c.birthDate, today);
|
||||
|
||||
return {
|
||||
firstName: c.firstName,
|
||||
lastName: c.lastName,
|
||||
salutation: c.salutation,
|
||||
useInformalAddress: c.useInformalAddress,
|
||||
email: c.email,
|
||||
phone: c.phone,
|
||||
mobile: c.mobile,
|
||||
age,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user