From 43f63de9a36ad09b5eb535e02c431d718c1dcb5a Mon Sep 17 00:00:00 2001 From: Tony AVERTY Date: Fri, 9 Oct 2026 16:00:23 +0200 Subject: [PATCH] =?UTF-8?q?Mot=20de=20passe=20oubli=C3=A9=20(app),=20annul?= =?UTF-8?q?ation=20d'un=20cr=C3=A9dit=20ou=20d'une=20r=C3=A9compense=20(30?= =?UTF-8?q?=20min,=20auteur=20ou=20dirigeant),=20accord=20de=20sous-traita?= =?UTF-8?q?nce=20RGPD=20int=C3=A9gr=C3=A9=20aux=20CGV,=20mode=20comptoir?= =?UTF-8?q?=20(bip,=20=C3=A9cran=20allum=C3=A9),=20Face=20ID=20pour=20les?= =?UTF-8?q?=20actions=20sensibles,=20invitation=20par=20e-mail=20dans=20l'?= =?UTF-8?q?administration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- admin/src/api.ts | 2 + admin/src/pages/StaffTab.tsx | 42 +++-- backend/prisma/schema.prisma | 4 + backend/src/counter/counter.controller.ts | 7 + backend/src/counter/counter.service.ts | 102 +++++++++-- backend/src/reviews/reviews.service.ts | 2 +- .../src/staff/password-setup.controller.ts | 14 ++ backend/src/staff/password-setup.service.ts | 18 +- backend/src/staff/staff.controller.ts | 24 ++- backend/src/stats/export.service.ts | 2 +- backend/src/stats/stats.service.ts | 4 +- pro/app/account.tsx | 22 ++- pro/app/campaigns.tsx | 2 + pro/app/client/[serial]/credit.tsx | 4 +- pro/app/client/[serial]/rewards.tsx | 4 +- pro/app/done.tsx | 46 ++++- pro/app/history.tsx | 48 ++++- pro/app/login.tsx | 31 ++++ pro/app/scan.tsx | 5 + pro/app/team.tsx | 9 +- pro/assets/sounds/scan-ok.wav | Bin 0 -> 14156 bytes pro/src/api.ts | 8 + pro/src/biometrics.ts | 16 ++ pro/src/prefs.ts | 32 ++++ pro/src/sounds.ts | 20 +++ site-src/dpa.js | 71 ++++++++ site-src/seo.js | 13 ++ site/404.html | 2 +- site/a-propos/index.html | 2 +- site/abonnement/merci/index.html | 2 +- .../{index-H4FokPx0.js => index-B7T6CQqW.js} | 2 +- .../boucherie-charcuterie/index.html | 2 +- site/carte-de-fidelite/boulangerie/index.html | 2 +- site/carte-de-fidelite/boutique/index.html | 2 +- site/carte-de-fidelite/cafe-bar/index.html | 2 +- .../coiffeur-barbier/index.html | 2 +- .../epicerie-primeur/index.html | 2 +- site/carte-de-fidelite/fleuriste/index.html | 2 +- site/carte-de-fidelite/index.html | 2 +- .../institut-beaute/index.html | 2 +- site/carte-de-fidelite/pizzeria/index.html | 2 +- site/carte-de-fidelite/pressing/index.html | 2 +- site/carte-de-fidelite/restaurant/index.html | 2 +- .../carte-de-fidelite/sandwicherie/index.html | 2 +- site/cgv/index.html | 4 +- site/comment-ca-marche/index.html | 2 +- site/confidentialite/index.html | 2 +- site/contact/index.html | 2 +- site/espace/affichette/index.html | 2 +- site/espace/index.html | 2 +- site/faq/index.html | 2 +- site/fonctionnalites/index.html | 2 +- .../index.html | 2 +- .../index.html | 2 +- .../guides/creer-carte-de-fidelite/index.html | 2 +- .../faire-revenir-ses-clients/index.html | 2 +- site/guides/fidelite-rgpd/index.html | 2 +- .../idees-recompenses-fidelite/index.html | 2 +- site/guides/index.html | 2 +- site/guides/tampons-ou-points/index.html | 2 +- site/index.html | 2 +- site/inscription/index.html | 2 +- site/mentions-legales/index.html | 2 +- site/sitemap.xml | 1 + site/sous-traitance/index.html | 170 ++++++++++++++++++ site/tarif/index.html | 2 +- 66 files changed, 705 insertions(+), 94 deletions(-) create mode 100644 pro/assets/sounds/scan-ok.wav create mode 100644 pro/src/biometrics.ts create mode 100644 pro/src/prefs.ts create mode 100644 pro/src/sounds.ts create mode 100644 site-src/dpa.js rename site/assets/espace/{index-H4FokPx0.js => index-B7T6CQqW.js} (94%) create mode 100644 site/sous-traitance/index.html diff --git a/admin/src/api.ts b/admin/src/api.ts index 800f815..7c4cfa1 100644 --- a/admin/src/api.ts +++ b/admin/src/api.ts @@ -226,4 +226,6 @@ export interface StaffUser { active: boolean; createdAt: string; provisionalPassword?: string; + /** Adresse à laquelle le lien de création du mot de passe a été envoyé (null : échec de l’envoi). */ + invitationSentTo?: string | null; } diff --git a/admin/src/pages/StaffTab.tsx b/admin/src/pages/StaffTab.tsx index 7b435ca..9e09962 100644 --- a/admin/src/pages/StaffTab.tsx +++ b/admin/src/pages/StaffTab.tsx @@ -7,18 +7,19 @@ export function StaffTab({ storeId }: { storeId: string }) { const base = `/api/admin/stores/${storeId}/staff`; const [staff, setStaff] = useState([]); const [error, setError] = useState(null); - const [created, setCreated] = useState(null); + const [sent, setSent] = useState<{ name: string; email: string | null; reset: boolean } | null>(null); const formDialog = useRef(null); - const passwordDialog = useRef(null); + const sentDialog = useRef(null); const reload = useCallback(() => { api.get(base).then(setStaff).catch((e) => setError(e.message)); }, [base]); useEffect(reload, [reload]); - function showPassword(user: StaffUser) { - setCreated(user); - passwordDialog.current?.showModal(); + /** Invitation envoyée par e-mail (création ou nouveau mot de passe). */ + function showSent(name: string, email: string | null, reset: boolean) { + setSent({ name, email, reset }); + sentDialog.current?.showModal(); reload(); } @@ -32,9 +33,10 @@ export function StaffTab({ storeId }: { storeId: string }) { } async function reset(u: StaffUser) { - if (!window.confirm(`Générer un nouveau mot de passe pour ${u.displayName} ? Ses sessions seront fermées.`)) return; + if (!window.confirm(`Envoyer à ${u.displayName} (${u.email}) un lien pour choisir un nouveau mot de passe ?`)) return; try { - showPassword(await api.post(`${base}/${u.id}/reset-password`)); + const r = await api.post<{ invitationSentTo: string }>(`${base}/${u.id}/reset-password`); + showSent(u.displayName, r.invitationSentTo, true); } catch (e) { setError((e as Error).message); } @@ -97,7 +99,7 @@ export function StaffTab({ storeId }: { storeId: string }) {
- +
@@ -111,21 +113,25 @@ export function StaffTab({ storeId }: { storeId: string }) { onCancel={() => formDialog.current?.close()} onCreated={(u) => { formDialog.current?.close(); - showPassword(u); + showSent(u.displayName, u.invitationSentTo ?? null, false); }} /> - +
-

Mot de passe provisoire

-

- Communiquez-le à {created?.displayName} ({created?.email}). Il ne sera plus affiché ensuite. -

-
{created?.provisionalPassword}
+

{sent?.email ? (sent.reset ? 'Lien envoyé' : 'Compte créé') : 'Compte créé, e-mail non envoyé'}

+ {sent?.email ? ( +

+ {sent.name} a reçu à {sent.email} un lien pour choisir {sent.reset ? 'un nouveau' : 'son'} mot de passe (valable 7 jours, utilisable une fois). +

+ ) : ( +
+ L’e-mail d’invitation n’a pas pu partir. Utilisez « Envoyer un lien de mot de passe » sur la fiche de {sent?.name} pour réessayer. +
+ )}
- - +
@@ -185,7 +191,7 @@ function NewStaffForm({ base, onCancel, onCreated }: { base: string; onCancel: ( ))} -

Un mot de passe provisoire sera généré à la création.

+

La personne recevra un e-mail pour choisir son mot de passe.

diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 51a055c..74f9aad 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -204,6 +204,10 @@ model Transaction { rejectReason RejectReason? rewardId String? reward Reward? @relation(fields: [rewardId], references: [id]) + /// Annulation (opération ADJUST) : identifiant de l'opération annulée. Unique : une opération ne s'annule qu'une fois. + cancelOf String? @unique + cancelled Transaction? @relation("Cancellation", fields: [cancelOf], references: [id]) + cancelledBy Transaction? @relation("Cancellation") createdAt DateTime @default(now()) @@index([storeId, createdAt]) diff --git a/backend/src/counter/counter.controller.ts b/backend/src/counter/counter.controller.ts index 80b1417..8b01f78 100644 --- a/backend/src/counter/counter.controller.ts +++ b/backend/src/counter/counter.controller.ts @@ -81,6 +81,13 @@ export class CounterController { return this.counter.useGift(ctx(user), serial, giftId); } + /** Annulation d'un crédit ou d'une récompense (erreur de saisie). */ + @Post('transactions/:id/cancel') + @HttpCode(200) + cancel(@CurrentUser() user: JwtPayload, @Param('id') id: string) { + return this.counter.cancel(ctx(user), id); + } + @Get('transactions') history(@CurrentUser() user: JwtPayload, @Query() q: HistoryQuery) { return this.counter.history(ctx(user), q.period ?? 'today', q.cursor); diff --git a/backend/src/counter/counter.service.ts b/backend/src/counter/counter.service.ts index 141e50a..c7d9af0 100644 --- a/backend/src/counter/counter.service.ts +++ b/backend/src/counter/counter.service.ts @@ -1,4 +1,4 @@ -import { BadRequestException, ForbiddenException, HttpException, HttpStatus, Injectable, NotFoundException } from '@nestjs/common'; +import { BadRequestException, ConflictException, ForbiddenException, HttpException, HttpStatus, Injectable, NotFoundException } from '@nestjs/common'; import { Prisma, RejectReason, StaffRole } from '@prisma/client'; import { PrismaService } from '../prisma/prisma.service'; import { CardUpdatesService } from '../wallet/card-updates.service'; @@ -123,10 +123,10 @@ export class CounterService { }); if (updated.count === 0) return null; const { balance } = await tx.loyaltyCard.findUniqueOrThrow({ where: { id: card.id }, select: { balance: true } }); - await tx.transaction.create({ + const op = await tx.transaction.create({ data: { storeId: ctx.storeId, cardId: card.id, staffId: ctx.staffId, type: 'CREDIT', amountCents, points, balanceAfter: balance }, }); - return balance; + return { balance, transactionId: op.id }; }); if (result === null) { @@ -142,7 +142,7 @@ export class CounterService { this.cardUpdates.notify(card.id); // Premier passage d'un filleul : récompenses du parrainage (en arrière-plan). this.referrals.onCredit(card.id); - return { points, balance: result, firstName: card.customer.firstName }; + return { points, balance: result.balance, transactionId: result.transactionId, cancellableUntil: cancelDeadline(new Date()), firstName: card.customer.firstName }; } async redeem(ctx: StaffContext, serial: string, rewardId: string) { @@ -157,10 +157,10 @@ export class CounterService { }); if (updated.count === 0) return null; const { balance } = await tx.loyaltyCard.findUniqueOrThrow({ where: { id: card.id }, select: { balance: true } }); - await tx.transaction.create({ + const op = await tx.transaction.create({ data: { storeId: ctx.storeId, cardId: card.id, staffId: ctx.staffId, type: 'REDEEM', points: -reward.cost, rewardId: reward.id, balanceAfter: balance }, }); - return balance; + return { balance, transactionId: op.id }; }); if (balance === null) { await this.reject(ctx, card, 'INSUFFICIENT_BALANCE'); @@ -169,7 +169,7 @@ export class CounterService { }); } this.cardUpdates.notify(card.id); - return { reward: { id: reward.id, label: reward.label, cost: reward.cost }, balance, firstName: card.customer.firstName }; + return { reward: { id: reward.id, label: reward.label, cost: reward.cost }, balance: balance.balance, transactionId: balance.transactionId, cancellableUntil: cancelDeadline(new Date()), firstName: card.customer.firstName }; } /** Le dirigeant voit tout le magasin ; l'employé, seulement ses opérations. */ @@ -191,11 +191,18 @@ export class CounterService { reward: { select: { label: true } }, staff: { select: { id: true, displayName: true } }, card: { select: { customer: { select: { firstName: true } } } }, + cancelOf: true, + cancelledBy: { select: { createdAt: true, staff: { select: { displayName: true } } } }, }, }); const hasMore = items.length > 50; return { - items: items.slice(0, 50).map(({ card, ...t }) => ({ ...t, customerFirstName: card.customer.firstName })), + items: items.slice(0, 50).map(({ card, cancelledBy, ...t }) => ({ + ...t, + customerFirstName: card.customer.firstName, + cancelled: cancelledBy ? { at: cancelledBy.createdAt, by: cancelledBy.staff.displayName } : null, + cancellable: !cancelledBy && canCancel(ctx, t), + })), nextCursor: hasMore ? items[49].id : null, }; } @@ -203,8 +210,8 @@ export class CounterService { async summary(ctx: StaffContext) { const where = this.scope(ctx, 'today'); const [credits, redeems] = await Promise.all([ - this.prisma.transaction.aggregate({ where: { ...where, type: 'CREDIT' }, _count: true, _sum: { points: true } }), - this.prisma.transaction.count({ where: { ...where, type: 'REDEEM' } }), + this.prisma.transaction.aggregate({ where: { ...where, type: 'CREDIT', ...{ cancelledBy: { is: null } } }, _count: true, _sum: { points: true } }), + this.prisma.transaction.count({ where: { ...where, type: 'REDEEM', ...{ cancelledBy: { is: null } } } }), ]); return { operations: credits._count + redeems, pointsGiven: credits._sum.points ?? 0, rewards: redeems }; } @@ -244,6 +251,67 @@ export class CounterService { })); } + /** + * Annule un crédit ou une récompense (erreur de saisie au comptoir) : une opération ADJUST de sens inverse + * est ajoutée au journal, qui reste immuable. Possible pendant ${CANCEL_WINDOW_MIN} minutes, par l'auteur de + * l'opération ou un Dirigeant, une seule fois, et seulement si le client n'a pas déjà utilisé les points. + */ + async cancel(ctx: StaffContext, transactionId: string) { + const t = await this.prisma.transaction.findUnique({ + where: { id: transactionId }, + include: { cancelledBy: { select: { id: true } }, card: { select: { id: true, customer: { select: { firstName: true } } } } }, + }); + if (!t || t.storeId !== ctx.storeId) throw new NotFoundException('Opération introuvable'); + if (t.type !== 'CREDIT' && t.type !== 'REDEEM') throw new BadRequestException('Seuls un crédit ou une récompense peuvent être annulés.'); + if (t.cancelledBy) throw new ConflictException('Cette opération a déjà été annulée.'); + if (ctx.role !== 'MANAGER' && t.staffId !== ctx.staffId) throw new ForbiddenException('Seul l’auteur de l’opération ou un dirigeant peut l’annuler.'); + if (Date.now() > cancelDeadline(t.createdAt).getTime()) { + throw new BadRequestException(`Une opération ne peut être annulée que pendant ${CANCEL_WINDOW_MIN} minutes. Demandez à votre dirigeant.`); + } + + const delta = -t.points; + // Crédit annulé : si c'était le dernier crédit de la carte, le délai anti-triche repart du précédent, + // pour pouvoir ressaisir aussitôt le bon montant. + let lastCreditAt: Date | null | undefined; + if (t.type === 'CREDIT') { + const later = await this.prisma.transaction.count({ where: { cardId: t.cardId, type: 'CREDIT', createdAt: { gt: t.createdAt }, cancelledBy: { is: null } } }); + if (later === 0) { + const previous = await this.prisma.transaction.findFirst({ + where: { cardId: t.cardId, type: 'CREDIT', createdAt: { lt: t.createdAt }, cancelledBy: { is: null } }, + orderBy: { createdAt: 'desc' }, + select: { createdAt: true }, + }); + lastCreditAt = previous?.createdAt ?? null; + } + } + + let balance: number | null; + try { + balance = await this.prisma.$transaction(async (tx) => { + // Un crédit annulé retire des points : impossible si le client les a déjà dépensés. + const updated = await tx.loyaltyCard.updateMany({ + where: { id: t.cardId, ...(delta < 0 && { balance: { gte: -delta } }) }, + data: { balance: { increment: delta }, ...(lastCreditAt !== undefined && { lastCreditAt }) }, + }); + if (updated.count === 0) return null; + const { balance } = await tx.loyaltyCard.findUniqueOrThrow({ where: { id: t.cardId }, select: { balance: true } }); + await tx.transaction.create({ + data: { storeId: ctx.storeId, cardId: t.cardId, staffId: ctx.staffId, type: 'ADJUST', points: delta, rewardId: t.rewardId, balanceAfter: balance, cancelOf: t.id }, + }); + return balance; + }); + } catch (e) { + // Deux annulations simultanées : la contrainte d'unicité n'en laisse passer qu'une. + if (e instanceof Prisma.PrismaClientKnownRequestError && e.code === 'P2002') throw new ConflictException('Cette opération a déjà été annulée.'); + throw e; + } + if (balance === null) { + throw new ConflictException('Le client a déjà utilisé ces points : l’opération ne peut plus être annulée.'); + } + this.cardUpdates.notify(t.cardId); + return { balance, firstName: t.card.customer.firstName }; + } + private async cardOfStore(ctx: StaffContext, serial: string) { const card = await this.prisma.loyaltyCard.findUnique({ where: { serial: serial.trim().toUpperCase() }, @@ -301,3 +369,17 @@ function maskEmail(email: string) { const [user, domain] = email.split('@'); return `${user.slice(0, 2)}•••@${domain ?? ''}`; } + +/** Délai pendant lequel une opération peut être annulée (erreur de saisie). */ +export const CANCEL_WINDOW_MIN = 30; + +function cancelDeadline(createdAt: Date) { + return new Date(createdAt.getTime() + CANCEL_WINDOW_MIN * 60_000); +} + +/** Droit d'annuler (affiché dans l'historique) : crédit ou récompense récent, par son auteur ou un Dirigeant. */ +function canCancel(ctx: StaffContext, t: { type: string; createdAt: Date; staff: { id: string } }) { + if (t.type !== 'CREDIT' && t.type !== 'REDEEM') return false; + if (ctx.role !== 'MANAGER' && t.staff.id !== ctx.staffId) return false; + return Date.now() <= cancelDeadline(t.createdAt).getTime(); +} diff --git a/backend/src/reviews/reviews.service.ts b/backend/src/reviews/reviews.service.ts index ac85c9a..6b83b65 100644 --- a/backend/src/reviews/reviews.service.ts +++ b/backend/src/reviews/reviews.service.ts @@ -112,7 +112,7 @@ export class ReviewsService implements OnModuleInit, OnApplicationBootstrap, OnA if (!recent.length) return 0; const visits = await this.prisma.transaction.groupBy({ by: ['cardId'], - where: { cardId: { in: recent.map((c) => c.id) }, type: 'CREDIT' }, + where: { cardId: { in: recent.map((c) => c.id) }, type: 'CREDIT', ...{ cancelledBy: { is: null } } }, _count: { _all: true }, }); let sent = 0; diff --git a/backend/src/staff/password-setup.controller.ts b/backend/src/staff/password-setup.controller.ts index 16863d8..7d39f0d 100644 --- a/backend/src/staff/password-setup.controller.ts +++ b/backend/src/staff/password-setup.controller.ts @@ -1,10 +1,16 @@ import { Body, Controller, Get, Header, HttpCode, Post, Query } from '@nestjs/common'; +import { IsEmail, MaxLength } from 'class-validator'; import { Throttle } from '@nestjs/throttler'; import { escapeHtml as e } from '../enrollment/pages'; import { PasswordSetupService, SetupOutcome } from './password-setup.service'; const MIN_LENGTH = 10; +class ForgotDto { + @IsEmail({}, { message: 'Adresse e-mail invalide' }) @MaxLength(200) + email!: string; +} + /** * Page publique du lien reçu par e-mail : https://monespacepro.eu/api/public/mot-de-passe?token=… * (le chemin /api/public est déjà transmis à l'API par nginx sur monespacepro.eu). @@ -22,6 +28,14 @@ export class PasswordSetupController { return outcome.ok ? formPage(token, outcome.staff) : problemPage(outcome.reason); } + /** « Mot de passe oublié » (app, écran de connexion) : envoie le lien si le compte existe. */ + @Post('oubli') + @HttpCode(200) + @Throttle({ default: { limit: 5, ttl: 15 * 60_000 } }) + forgot(@Body() dto: ForgotDto) { + return this.setup.requestReset(dto.email); + } + @Post() @HttpCode(200) @Throttle({ default: { limit: 10, ttl: 10 * 60_000 } }) diff --git a/backend/src/staff/password-setup.service.ts b/backend/src/staff/password-setup.service.ts index 4159b84..21d3265 100644 --- a/backend/src/staff/password-setup.service.ts +++ b/backend/src/staff/password-setup.service.ts @@ -46,7 +46,7 @@ export class PasswordSetupService { } /** Envoie le lien au titulaire du compte. `reason` : création du compte ou nouveau mot de passe. */ - async sendInvitation(staffId: string, invitedByName: string, reason: 'invite' | 'reset') { + async sendInvitation(staffId: string, invitedByName: string, reason: 'invite' | 'reset' | 'self') { const staff = await this.prisma.staffUser.findUniqueOrThrow({ where: { id: staffId }, include: { store: { select: { name: true } } } }); const payload: SetupPayload = { sub: staff.id, purpose: 'password-setup', v: staff.tokenVersion }; const token = await this.jwt.signAsync(payload, { secret: this.secret, expiresIn: LINK_TTL }); @@ -56,7 +56,9 @@ export class PasswordSetupService { const subject = invite ? `Votre accès à MonEspacePro — ${staff.store.name}` : `Nouveau mot de passe MonEspacePro — ${staff.store.name}`; const intro = invite ? `${invitedByName} vous a créé un compte ${role} pour « ${staff.store.name} » sur MonEspacePro, l’app qui sert à créditer les cartes de fidélité des clients au comptoir.` - : `${invitedByName} vous envoie un lien pour choisir un nouveau mot de passe pour votre compte ${role} de « ${staff.store.name} ».`; + : reason === 'self' + ? `Vous avez demandé à choisir un nouveau mot de passe pour votre compte ${role} de « ${staff.store.name} ». Votre mot de passe actuel reste valable tant que vous n’en avez pas choisi un nouveau.` + : `${invitedByName} vous envoie un lien pour choisir un nouveau mot de passe pour votre compte ${role} de « ${staff.store.name} ».`; await this.mail.send( staff.email, subject, @@ -80,6 +82,18 @@ export class PasswordSetupService { return { invitationSentTo: staff.email }; } + /** + * « Mot de passe oublié » depuis l'écran de connexion. Même réponse que le compte existe ou non + * (aucune information sur les comptes existants) ; rien n'est envoyé pour un compte désactivé ou supprimé. + */ + async requestReset(email: string) { + const staff = await this.prisma.staffUser.findUnique({ where: { email: email.trim().toLowerCase() }, select: { id: true, active: true, email: true } }); + if (staff && staff.active && !staff.email.endsWith(`@${DELETED_EMAIL_DOMAIN}`)) { + await this.sendInvitation(staff.id, 'MonEspacePro', 'self'); + } + return { ok: true }; + } + /** Vérifie un lien sans le consommer (affichage du formulaire). */ async check(token: string): Promise { let p: SetupPayload; diff --git a/backend/src/staff/staff.controller.ts b/backend/src/staff/staff.controller.ts index ad0fd38..ea3aeb5 100644 --- a/backend/src/staff/staff.controller.ts +++ b/backend/src/staff/staff.controller.ts @@ -1,21 +1,31 @@ -import { Body, Controller, Get, HttpCode, Param, Patch, Post, UseGuards } from '@nestjs/common'; +import { Body, Controller, Get, HttpCode, NotFoundException, Param, Patch, Post, UseGuards } from '@nestjs/common'; import { AdminGuard, JwtAuthGuard } from '../common/guards'; import { CreateStaffDto, UpdateStaffDto } from './dto/staff.dto'; import { StaffService } from './staff.service'; +import { PasswordSetupService } from './password-setup.service'; @Controller('admin/stores/:storeId/staff') @UseGuards(JwtAuthGuard, AdminGuard) export class StaffController { - constructor(private staff: StaffService) {} + constructor( + private staff: StaffService, + private passwordSetup: PasswordSetupService, + ) {} @Get() list(@Param('storeId') storeId: string) { return this.staff.list(storeId); } + /** Le nouveau compte reçoit par e-mail un lien pour choisir son mot de passe (comme depuis l'app). */ @Post() - create(@Param('storeId') storeId: string, @Body() dto: CreateStaffDto) { - return this.staff.create(storeId, dto); + async create(@Param('storeId') storeId: string, @Body() dto: CreateStaffDto) { + const { provisionalPassword: _unused, ...created } = await this.staff.create(storeId, dto); + try { + return { ...created, ...(await this.passwordSetup.sendInvitation(created.id, 'L’équipe MonEspacePro', 'invite')) }; + } catch { + return { ...created, invitationSentTo: null }; + } } @Patch(':id') @@ -25,7 +35,9 @@ export class StaffController { @Post(':id/reset-password') @HttpCode(200) - resetPassword(@Param('storeId') storeId: string, @Param('id') id: string) { - return this.staff.resetPassword(storeId, id); + async resetPassword(@Param('storeId') storeId: string, @Param('id') id: string) { + const member = (await this.staff.list(storeId)).find((m) => m.id === id); + if (!member) throw new NotFoundException('Employé introuvable'); + return this.passwordSetup.sendInvitation(id, 'L’équipe MonEspacePro', 'reset'); } } diff --git a/backend/src/stats/export.service.ts b/backend/src/stats/export.service.ts index 6112584..3fa0f62 100644 --- a/backend/src/stats/export.service.ts +++ b/backend/src/stats/export.service.ts @@ -50,7 +50,7 @@ export class ExportService { }); const totals = await this.prisma.transaction.groupBy({ by: ['cardId'], - where: { storeId, type: 'CREDIT' }, + where: { storeId, type: 'CREDIT', ...{ cancelledBy: { is: null } } }, _count: { _all: true }, _sum: { amountCents: true }, }); diff --git a/backend/src/stats/stats.service.ts b/backend/src/stats/stats.service.ts index 435d62d..5e5c9d7 100644 --- a/backend/src/stats/stats.service.ts +++ b/backend/src/stats/stats.service.ts @@ -60,13 +60,13 @@ export class StatsService { const [txs, cardsTotal, newCards, prevNewCards, prevVisits, appleCards, cardsCreated] = await Promise.all([ this.prisma.transaction.findMany({ - where: { storeId, createdAt: { gte: from }, type: { in: ['CREDIT', 'REDEEM'] } }, + where: { storeId, createdAt: { gte: from }, type: { in: ['CREDIT', 'REDEEM'] }, ...{ cancelledBy: { is: null } } }, select: { cardId: true, type: true, amountCents: true, points: true, createdAt: true }, }), this.prisma.loyaltyCard.count({ where: { storeId } }), this.prisma.loyaltyCard.count({ where: { storeId, createdAt: { gte: from } } }), this.prisma.loyaltyCard.count({ where: { storeId, createdAt: { gte: prevFrom, lt: from } } }), - this.prisma.transaction.count({ where: { storeId, type: 'CREDIT', createdAt: { gte: prevFrom, lt: from } } }), + this.prisma.transaction.count({ where: { storeId, type: 'CREDIT', createdAt: { gte: prevFrom, lt: from }, ...{ cancelledBy: { is: null } } } }), this.prisma.loyaltyCard.count({ where: { storeId, devices: { some: {} } } }), this.prisma.loyaltyCard.findMany({ where: { storeId, createdAt: { gte: from } }, select: { createdAt: true } }), ]); diff --git a/pro/app/account.tsx b/pro/app/account.tsx index 8bd1ba3..d47a73e 100644 --- a/pro/app/account.tsx +++ b/pro/app/account.tsx @@ -1,10 +1,12 @@ import { useState } from 'react'; -import { Alert, Pressable, ScrollView, TextInput, View } from 'react-native'; +import { Alert, Pressable, ScrollView, Switch, TextInput, View } from 'react-native'; import { api, ApiError } from '../src/api'; import { describe } from '../src/errors'; import { useSession } from '../src/session'; import { Banner, Button, Card, T } from '../src/ui'; import { font, useColors } from '../src/theme'; +import { useScanSound } from '../src/prefs'; +import { confirmIdentity } from '../src/biometrics'; /** Mon compte : profil, changement du mot de passe, déconnexion (tous les rôles). */ export default function Account() { @@ -34,6 +36,7 @@ export default function Account() { } const [requested, setRequested] = useState(false); + const [sound, setSound] = useScanSound(); /** Suppression de son compte. Le dernier dirigeant ne peut pas laisser le magasin sans dirigeant : * il envoie alors une demande de suppression du compte et du magasin. */ @@ -43,7 +46,13 @@ export default function Account() { 'Suppression définitive : vous ne pourrez plus vous connecter, et votre nom et votre e-mail sont effacés. Les opérations déjà faites restent dans l’historique du magasin, de façon anonyme.', [ { text: 'Annuler', style: 'cancel' }, - { text: 'Supprimer', style: 'destructive', onPress: remove }, + { + text: 'Supprimer', + style: 'destructive', + onPress: async () => { + if (await confirmIdentity('Supprimer votre compte')) remove(); + }, + }, ], ); } @@ -147,6 +156,15 @@ export default function Account() { +
+ +
+
+

Légal

Accord de sous-traitance (RGPD)

Dernière mise à jour : 9 octobre 2026

+
+
+
+ + + + + + + + diff --git a/site/tarif/index.html b/site/tarif/index.html index f621971..4970181 100644 --- a/site/tarif/index.html +++ b/site/tarif/index.html @@ -316,7 +316,7 @@

La carte de fidélité dématérialisée pour les commerces indépendants.

- +
© MonEspacePro — EI Tony AvertyTVA non applicable, art. 293 B du CGI