batchCooking/packages/shared/src/schemas/contact.ts
Nicolas 0c8cda7f3e
All checks were successful
CI / lint (push) Successful in 4m17s
CI / build (push) Successful in 5m11s
CI / intent-service-test (push) Successful in 5m42s
CI / e2e (push) Successful in 11m26s
CI / test (push) Successful in 29m58s
CI / build-android (push) Has been skipped
feat(admin): consultation des messages de contact (#80)
PR 2/2 de l'issue #80 — la vue admin en lecture seule des messages
remontés via le formulaire de contact (PR 1 = #123).

- Contrat partagé : `listContactMessagesQuerySchema` (filtre `type`
  optionnel) + `types/contact.ts` `ContactMessageAdminView` (`author` =
  `{ id, firstName, lastName, email } | null`, `null` = compte supprimé).
- API : `admin-contact.{routes,service}.ts` — `GET /admin/api/contact?type=`
  (`requireAdmin`), tri `createdAt desc`, plafond `CONTACT_MESSAGES_PAGE_SIZE
  = 200` (même esprit que `CORRECTIONS_PAGE_SIZE`). Branché dans
  `admin.routes.ts` (`adminRouter.use(/contact, …)`). Aucune route
  d'écriture.
- Front : page `/admin/messages` (`MessagesPage` + `.scss`) — tableau
  lecture seule (date, expéditeur ou « Compte supprimé », badge de type,
  message, page, user-agent tronqué + titre au survol), un filtre par type.
  Entrée de nav « Messages » (icône `Inbox`) dans `AdminLayout` +
  `adminApiClient.getContactMessages` + i18n `admin.nav.messages` /
  `admin.messages.*`.
- Tests : `apps/api/test/admin-contact.test.ts` (Mocha — 401 sans session
  admin, tri récent d'abord + `author` résolu, filtre `type`, type inconnu →
  400, plafond 200, `author: null` après suppression du compte),
  `apps/web/cypress/e2e/admin-messages.cy.ts` (rendu lecture seule, filtre
  par type via le query param).
- Docs : `backend-architecture.md` (section `admin` + event
  `contact.submitted` dans la liste).

Closes #80.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-08 09:17:45 +02:00

44 lines
1.9 KiB
TypeScript

import { z } from "zod";
// Shared between apps/api (server-side validation, source of truth) and
// apps/web (client-side validation for instant feedback on the contact
// form). Same rationale as schemas/auth.ts — one set of rules, French
// messages surfaced as-is in the form.
/**
* The kind of a contact-form message. A plain `String` in Postgres backed by
* this const (see `ContactMessage.type` in schema.prisma) rather than a
* Postgres enum — adding a value is one line here, no migration. `type`
* structures the admin-side triage; the user picks it from a small select.
*/
export const CONTACT_MESSAGE_TYPES = ["bug", "suggestion", "other"] as const;
export type ContactMessageType = (typeof CONTACT_MESSAGE_TYPES)[number];
/**
* Payload accepted by `POST /contact` (issue #80). `message` is the only
* thing the user actually types; `pageUrl` / `appVersion` are captured
* automatically by the client (`window.location.pathname`, `__APP_VERSION__`)
* and are optional so a direct API call or an older client can omit them.
* `userAgent` is NOT here — the server reads it from the request header,
* never trusting the client for it.
*/
export const submitContactMessageSchema = z.object({
type: z.enum(CONTACT_MESSAGE_TYPES),
message: z
.string()
.trim()
.min(10, "Le message doit faire au moins 10 caractères")
.max(5000, "Le message ne peut pas dépasser 5000 caractères"),
pageUrl: z.string().max(500).optional(),
appVersion: z.string().max(50).optional(),
});
export type SubmitContactMessageInput = z.infer<typeof submitContactMessageSchema>;
/**
* Query params for `GET /admin/api/contact` (issue #80, admin read view).
* `type` is an optional single-value filter — omitted means "all types".
*/
export const listContactMessagesQuerySchema = z.object({
type: z.enum(CONTACT_MESSAGE_TYPES).optional(),
});
export type ListContactMessagesQuery = z.infer<typeof listContactMessagesQuerySchema>;