API+App: powiadomienie feed o komentarzu trenera pod cwiczeniem - typ TRAINER_COMMENT (schemat + migracja), createNotification w addTraineeComment, widok w feedzie podopiecznego (swagger, testy integracyjne i e2e)
This commit is contained in:
@@ -674,6 +674,7 @@ export function createTrainerRoutes({ prisma }: AppDeps) {
|
||||
* /trainer/trainees/{userId}/comments:
|
||||
* post:
|
||||
* summary: Trainer comment on the trainee (anchored to a session / exercise)
|
||||
* description: Creates the comment and a TRAINER_COMMENT feed notification for the trainee.
|
||||
* tags: [Trainer]
|
||||
* responses:
|
||||
* 201: { description: Created }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { PrismaClient } from '@prisma/client';
|
||||
import { badRequest, notFound } from '../lib/errors.js';
|
||||
import { assertActiveTrainee } from './trainer.js';
|
||||
import { createNotification } from './feed.js';
|
||||
|
||||
export interface CommentInput {
|
||||
body: string;
|
||||
@@ -47,6 +48,24 @@ export async function addTraineeComment(
|
||||
body: input.body,
|
||||
},
|
||||
});
|
||||
// Notification for the trainee ("Aktualności" feed). The payload is a
|
||||
// self-contained snapshot (GYM_DELETED pattern) so it survives comment deletion.
|
||||
const trainer = await prisma.user.findUnique({
|
||||
where: { id: trainerId },
|
||||
select: { firstName: true, lastName: true, nickname: true },
|
||||
});
|
||||
const trainerName =
|
||||
(trainer ? [trainer.firstName, trainer.lastName].join(' ').trim() : '') ||
|
||||
trainer?.nickname ||
|
||||
'';
|
||||
await createNotification(prisma, {
|
||||
userId: traineeId,
|
||||
type: 'TRAINER_COMMENT',
|
||||
title: trainerName
|
||||
? `Trener ${trainerName} dodał komentarz do treningu`
|
||||
: 'Trener dodał komentarz do treningu',
|
||||
payload: { sessionId: input.sessionId ?? null, trainerName },
|
||||
});
|
||||
return { comment };
|
||||
}
|
||||
|
||||
|
||||
@@ -1003,7 +1003,7 @@ export const openapi: Record<string, unknown> = {
|
||||
summary:
|
||||
'Merged feed of personal notifications and gym/global announcements (cursor = createdAt)',
|
||||
description:
|
||||
'Announcement items carry author attribution: authorId, authorName, authorRole (ADMIN | OWNER | TRAINER; null for system-generated).',
|
||||
'Announcement items carry author attribution: authorId, authorName, authorRole (ADMIN | OWNER | TRAINER; null for system-generated). Notification types: PLAN_READY, PLAN_SHARED, GYM_DELETED, TRAINER_COMMENT (payload: sessionId, trainerName; deeplink /profile/history).',
|
||||
security: [{ bearerAuth: [] }],
|
||||
parameters: [
|
||||
{ name: 'limit', in: 'query', schema: { type: 'integer', default: 20 } },
|
||||
|
||||
Reference in New Issue
Block a user