Exports CSV : envoyés uniquement au dirigeant de la société (contact du magasin)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d2cb351070
commit
a1f6db8819
2 changed files with 12 additions and 9 deletions
|
|
@ -74,7 +74,10 @@ export class StaffStatsController {
|
|||
return this.stats.compute(user.storeId, period(days));
|
||||
}
|
||||
|
||||
/** Le fichier part par e-mail au dirigeant : rien à stocker sur le téléphone. */
|
||||
/**
|
||||
* Le fichier part uniquement par e-mail au dirigeant de la société (contact
|
||||
* légal du magasin), quel que soit le compte qui le demande : rien sur le téléphone.
|
||||
*/
|
||||
@Post('export')
|
||||
@HttpCode(200)
|
||||
@Throttle({ default: { limit: 5, ttl: 10 * 60_000 } })
|
||||
|
|
@ -82,24 +85,24 @@ export class StaffStatsController {
|
|||
if (user.kind !== 'staff') throw new Error('StaffGuard manquant');
|
||||
const config = await this.modules.require(user.storeId, 'stats');
|
||||
if (!config.csvExport) throw new ForbiddenException({ statusCode: 403, code: 'MODULE_DISABLED', message: 'L’export CSV est désactivé dans les réglages du module Statistiques.' });
|
||||
const staff = await this.prisma.staffUser.findUniqueOrThrow({ where: { id: user.sub }, include: { store: { select: { name: true } } } });
|
||||
const store = await this.prisma.store.findUniqueOrThrow({ where: { id: user.storeId }, select: { name: true, contactName: true, contactEmail: true } });
|
||||
const file = dto.kind === 'customers' ? await this.exports.customers(user.storeId) : await this.exports.transactions(user.storeId, dto.days);
|
||||
const what = dto.kind === 'customers' ? 'Fichier clients' : `Opérations des ${dto.days} derniers jours`;
|
||||
const subject = `${what} — ${staff.store.name}`;
|
||||
const text = `Bonjour ${staff.displayName},\n\nVoici votre export « ${what} » (${file.count} lignes), en pièce jointe au format CSV (ouvrable avec Excel).\n\nCe fichier contient des données personnelles de vos clients : conservez-le en lieu sûr et ne le partagez pas.\n\nMonEspacePro`;
|
||||
const subject = `${what} — ${store.name}`;
|
||||
const text = `Bonjour ${store.contactName},\n\nVoici votre export « ${what} » (${file.count} lignes), en pièce jointe au format CSV (ouvrable avec Excel).\n\nCe fichier contient des données personnelles de vos clients : conservez-le en lieu sûr et ne le partagez pas.\n\nMonEspacePro`;
|
||||
const html = emailLayout({
|
||||
webUrl: this.config.get('webUrl')!,
|
||||
preheader: `${what} : ${file.count} lignes en pièce jointe.`,
|
||||
eyebrow: 'Export',
|
||||
title: what,
|
||||
paragraphs: [
|
||||
`Bonjour ${esc(staff.displayName)},`,
|
||||
`Voici votre export pour <strong>${esc(staff.store.name)}</strong> : <strong>${file.count} lignes</strong>, en pièce jointe au format CSV (ouvrable avec Excel).`,
|
||||
`Bonjour ${esc(store.contactName)},`,
|
||||
`Voici votre export pour <strong>${esc(store.name)}</strong> : <strong>${file.count} lignes</strong>, en pièce jointe au format CSV (ouvrable avec Excel).`,
|
||||
'Ce fichier contient des données personnelles de vos clients : conservez-le en lieu sûr et ne le partagez pas.',
|
||||
],
|
||||
});
|
||||
await this.mail.sendWithAttachment(staff.email, subject, text, html, { filename: file.filename, content: file.content });
|
||||
return { sentTo: staff.email, count: file.count };
|
||||
await this.mail.sendWithAttachment(store.contactEmail, subject, text, html, { filename: file.filename, content: file.content });
|
||||
return { sentTo: store.contactEmail, count: file.count };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ export default function StatsScreen() {
|
|||
)}
|
||||
|
||||
<T v="h2">Exports</T>
|
||||
<T v="muted">Le fichier CSV (ouvrable avec Excel) est envoyé sur votre adresse e-mail.</T>
|
||||
<T v="muted">Le fichier CSV (ouvrable avec Excel) est envoyé uniquement par e-mail au dirigeant de la société.</T>
|
||||
<Button label="Recevoir le fichier clients" variant="secondary" loading={sending === 'customers'} disabled={!!sending} onPress={() => exportCsv('customers')} />
|
||||
<Button label="Recevoir les opérations de la période" variant="secondary" loading={sending === 'transactions'} disabled={!!sending} onPress={() => exportCsv('transactions')} />
|
||||
</>
|
||||
|
|
|
|||
Loading…
Reference in a new issue