Skip to content

Commit dd5702e

Browse files
makcimerrrclaude
andcommitted
fix(audit-reports): afficher Prénom Nom de l'auditeur + membres du groupe (fallback groupId)
- callback reply_submitted: « De » résolu en Prénom Nom (getStudentDisplayNames), « Groupe audité » résolu depuis le groupId si le context ne porte pas les membres (getGroupMemberNames via GraphQL group.members). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 1c0be3e commit dd5702e

2 files changed

Lines changed: 53 additions & 4 deletions

File tree

app/api/bot/callback/route.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NextRequest, NextResponse } from 'next/server';
22
import { markRdvConfirmed } from '@/lib/db/services/groupStatuses';
3-
import { markAuditResponded } from '@/lib/db/services/auditReports';
3+
import { markAuditResponded, getStudentDisplayNames, getGroupMemberNames } from '@/lib/db/services/auditReports';
44
import { sendTeamsFormsCard, buildReplyCard, buildBookedCard } from '@/lib/services/teams';
55
import { getPromotionByEventId } from '@/lib/config/promotions';
66

@@ -86,14 +86,24 @@ export async function POST(request: NextRequest) {
8686
if (event === 'reply_submitted') {
8787
const status = body.data?.status ?? '—';
8888
const comment = body.data?.comment ?? '';
89-
const who = context.auditorLogin || context.login || context.captainLogin || 'inconnu';
89+
90+
// « De » = Prénom Nom (résolu depuis le login), fallback login.
91+
const actorLogin = context.auditorLogin || context.login || context.captainLogin;
92+
let who = actorLogin || 'inconnu';
93+
if (actorLogin) {
94+
const names = await getStudentDisplayNames([actorLogin]);
95+
who = names.get(actorLogin) || actorLogin;
96+
}
9097

9198
// (a) Carte Teams (2e canal) — contexte en facts.
9299
const cardContext: { title: string; value: string }[] = [];
93100
if (context.type === 'audit_report') {
94-
// Rapport d'audit : afficher Projet + Membres du groupe audité (jamais l'ID).
101+
// Rapport d'audit : Projet + Membres du groupe audité (jamais l'ID).
102+
// Si le context ne porte pas les membres, on les résout via le groupId.
95103
cardContext.push({ title: 'Projet', value: context.projectName ?? '—' });
96-
cardContext.push({ title: 'Groupe audité', value: context.members ?? '—' });
104+
let members = context.members?.trim();
105+
if (!members && context.groupId) members = await getGroupMemberNames(context.groupId);
106+
cardContext.push({ title: 'Groupe audité', value: members || '—' });
97107
} else {
98108
if (context.projectName) cardContext.push({ title: 'Projet', value: context.projectName });
99109
if (context.groupId) cardContext.push({ title: 'Groupe', value: context.groupId });

lib/db/services/auditReports.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,45 @@ export async function getAuditRequestsToEscalate(): Promise<AuditRequestToEscala
300300
return out;
301301
}
302302

303+
/**
304+
* Résout des logins en « Prénom Nom » via la table `students` (fallback login).
305+
*/
306+
export async function getStudentDisplayNames(logins: string[]): Promise<Map<string, string>> {
307+
const map = new Map<string, string>();
308+
const uniq = [...new Set(logins.filter(Boolean))];
309+
if (uniq.length === 0) return map;
310+
const rows = await db
311+
.select({ login: students.login, firstName: students.first_name, lastName: students.last_name })
312+
.from(students)
313+
.where(inArray(students.login, uniq));
314+
for (const r of rows) {
315+
const name = [r.firstName, r.lastName].filter(Boolean).join(' ').trim();
316+
map.set(r.login, name || r.login);
317+
}
318+
return map;
319+
}
320+
321+
/**
322+
* Membres d'un groupe (groupId Zone01) en « Prénom Nom » — fallback d'affichage
323+
* quand le context ne porte pas déjà les membres. '' si introuvable.
324+
*/
325+
export async function getGroupMemberNames(groupId: string): Promise<string> {
326+
const gid = Number(groupId);
327+
if (!Number.isFinite(gid)) return '';
328+
try {
329+
const data = await zone01Graphql<{ group: { members: { userLogin: string }[] }[] }>(
330+
`query($g: Int!){ group(where:{ id:{_eq:$g} }){ members { userLogin } } }`,
331+
{ g: gid },
332+
);
333+
const logins = data.group?.[0]?.members?.map((m) => m.userLogin).filter(Boolean) ?? [];
334+
if (logins.length === 0) return '';
335+
const names = await getStudentDisplayNames(logins);
336+
return logins.map((l) => names.get(l) ?? l).join(', ');
337+
} catch {
338+
return '';
339+
}
340+
}
341+
303342
/** Feature 7 — marque une demande comme escaladée (Teams envoyé). */
304343
export async function markAuditEscalated(id: number): Promise<void> {
305344
await db

0 commit comments

Comments
 (0)