Plany: PATCH z startDate (aktywacja przy zapisie) i udostepnianie planow trener-podopieczny (PlanShare, sekcja Udostepnione mi, widok read-only)
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
updateProfile,
|
||||
} from '../services/me.js';
|
||||
import { getFocusChain } from '../services/focusChain.js';
|
||||
import { getMyTrainers } from '../services/plans.js';
|
||||
import { getActiveSession } from '../services/sessions.js';
|
||||
import { addMyComment, deleteMyComment } from '../services/comments.js';
|
||||
import { getExerciseProgress } from '../services/exerciseProgress.js';
|
||||
@@ -107,6 +108,23 @@ export function createMeRoutes({ prisma }: AppDeps) {
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /me/trainers:
|
||||
* get:
|
||||
* summary: My trainers (ACTIVE coaching relations where I am the trainee)
|
||||
* tags: [Profile]
|
||||
* responses:
|
||||
* 200: { description: OK }
|
||||
*/
|
||||
router.get(
|
||||
'/trainers',
|
||||
asyncHandler(async (req, res) => {
|
||||
const result = await getMyTrainers(prisma, req.user!.id);
|
||||
res.json(result);
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /me/focus-chain:
|
||||
|
||||
@@ -50,10 +50,23 @@ export const createPlanSchema = planBaseSchema
|
||||
message: 'weeks must have exactly weeksCount entries',
|
||||
});
|
||||
|
||||
export const updatePlanSchema = planBaseSchema.refine((d) => d.weeks.length === d.weeksCount, {
|
||||
message: 'weeks must have exactly weeksCount entries',
|
||||
});
|
||||
export const updatePlanSchema = planBaseSchema
|
||||
.extend({
|
||||
// Opcjonalna data startu (poniedziałek) — zapis = aktualizacja struktury + aktywacja
|
||||
// planu w jednym kroku (plan musi być DRAFT).
|
||||
startDate: z
|
||||
.string()
|
||||
.refine((v) => !Number.isNaN(new Date(v).getTime()), 'Invalid date')
|
||||
.optional(),
|
||||
})
|
||||
.refine((d) => d.weeks.length === d.weeksCount, {
|
||||
message: 'weeks must have exactly weeksCount entries',
|
||||
});
|
||||
|
||||
export const activateSchema = z.object({
|
||||
startDate: z.string().refine((v) => !Number.isNaN(new Date(v).getTime()), 'Invalid date'),
|
||||
});
|
||||
|
||||
export const sharePlanSchema = z.object({
|
||||
userId: z.string().min(1),
|
||||
});
|
||||
|
||||
@@ -6,16 +6,25 @@ import { validate } from '../middleware/validate.js';
|
||||
import {
|
||||
abandonPlan,
|
||||
activatePlan,
|
||||
assertPlanOwner,
|
||||
completePlan,
|
||||
createPlan,
|
||||
deletePlan,
|
||||
getPlan,
|
||||
listPlans,
|
||||
listSharedWithMe,
|
||||
sharePlan,
|
||||
unsharePlan,
|
||||
updatePlan,
|
||||
} from '../services/plans.js';
|
||||
import { logActivity } from '../services/audit.js';
|
||||
import { asyncHandler } from '../lib/asyncHandler.js';
|
||||
import { activateSchema, createPlanSchema, updatePlanSchema } from './plans-schemas.js';
|
||||
import {
|
||||
activateSchema,
|
||||
createPlanSchema,
|
||||
sharePlanSchema,
|
||||
updatePlanSchema,
|
||||
} from './plans-schemas.js';
|
||||
|
||||
export function createPlanRoutes({ prisma }: AppDeps) {
|
||||
const router = Router();
|
||||
@@ -67,11 +76,29 @@ export function createPlanRoutes({ prisma }: AppDeps) {
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /plans/shared-with-me:
|
||||
* get:
|
||||
* summary: Plans explicitly shared with the user (read-only)
|
||||
* tags: [Plans]
|
||||
* responses:
|
||||
* 200: { description: OK }
|
||||
*/
|
||||
router.get(
|
||||
'/shared-with-me',
|
||||
asyncHandler(async (req, res) => {
|
||||
const result = await listSharedWithMe(prisma, req.user!.id);
|
||||
res.json(result);
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /plans/{id}:
|
||||
* get:
|
||||
* summary: Plan details (weeks -> days -> exercises -> sets)
|
||||
* summary: Plan details (weeks -> days -> exercises -> sets). Access: owner,
|
||||
* trainer with an ACTIVE coaching relation, or a share recipient (read-only).
|
||||
* tags: [Plans]
|
||||
* responses:
|
||||
* 200: { description: OK }
|
||||
@@ -89,15 +116,21 @@ export function createPlanRoutes({ prisma }: AppDeps) {
|
||||
* @openapi
|
||||
* /plans/{id}:
|
||||
* patch:
|
||||
* summary: Replace plan structure (draft only)
|
||||
* summary: Replace plan structure (draft only). Optional startDate (a Monday,
|
||||
* current or future week) updates and activates the plan in one step.
|
||||
* tags: [Plans]
|
||||
* responses:
|
||||
* 200: { description: OK }
|
||||
* 400: { description: Not a draft / start date not a Monday / start week in the past }
|
||||
* 409: { description: User already has an active plan }
|
||||
*/
|
||||
router.patch(
|
||||
'/:id',
|
||||
validate(updatePlanSchema),
|
||||
asyncHandler(async (req, res) => {
|
||||
// mutacje trasy właściciela = tylko właściciel (trener ma trasy /trainer/...,
|
||||
// odbiorca share'a jest read-only)
|
||||
await assertPlanOwner(prisma, req.params.id, req.user!.id);
|
||||
const data = req.body as z.infer<typeof updatePlanSchema>;
|
||||
const result = await updatePlan(prisma, req.params.id, req.user!.id, data);
|
||||
await logActivity(prisma, {
|
||||
@@ -123,6 +156,7 @@ export function createPlanRoutes({ prisma }: AppDeps) {
|
||||
router.delete(
|
||||
'/:id',
|
||||
asyncHandler(async (req, res) => {
|
||||
await assertPlanOwner(prisma, req.params.id, req.user!.id);
|
||||
const result = await deletePlan(prisma, req.params.id, req.user!.id);
|
||||
await logActivity(prisma, {
|
||||
actorId: req.user!.id,
|
||||
@@ -150,6 +184,7 @@ export function createPlanRoutes({ prisma }: AppDeps) {
|
||||
'/:id/activate',
|
||||
validate(activateSchema),
|
||||
asyncHandler(async (req, res) => {
|
||||
await assertPlanOwner(prisma, req.params.id, req.user!.id);
|
||||
const { startDate } = req.body as z.infer<typeof activateSchema>;
|
||||
const result = await activatePlan(prisma, req.params.id, req.user!.id, startDate);
|
||||
await logActivity(prisma, {
|
||||
@@ -175,6 +210,7 @@ export function createPlanRoutes({ prisma }: AppDeps) {
|
||||
router.post(
|
||||
'/:id/abandon',
|
||||
asyncHandler(async (req, res) => {
|
||||
await assertPlanOwner(prisma, req.params.id, req.user!.id);
|
||||
const result = await abandonPlan(prisma, req.params.id, req.user!.id);
|
||||
await logActivity(prisma, {
|
||||
actorId: req.user!.id,
|
||||
@@ -199,6 +235,7 @@ export function createPlanRoutes({ prisma }: AppDeps) {
|
||||
router.post(
|
||||
'/:id/complete',
|
||||
asyncHandler(async (req, res) => {
|
||||
await assertPlanOwner(prisma, req.params.id, req.user!.id);
|
||||
const result = await completePlan(prisma, req.params.id, req.user!.id);
|
||||
await logActivity(prisma, {
|
||||
actorId: req.user!.id,
|
||||
@@ -211,5 +248,62 @@ export function createPlanRoutes({ prisma }: AppDeps) {
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /plans/{id}/share:
|
||||
* post:
|
||||
* summary: Share the plan with a user in an ACTIVE coaching relation
|
||||
* (trainer <-> trainee). Owner only; recipients get read-only access.
|
||||
* tags: [Plans]
|
||||
* responses:
|
||||
* 201: { description: Shared }
|
||||
* 400: { description: Self-share / no active coaching relation }
|
||||
* 403: { description: Not the plan owner }
|
||||
* 404: { description: Plan not found }
|
||||
* 409: { description: Already shared with this user }
|
||||
*/
|
||||
router.post(
|
||||
'/:id/share',
|
||||
validate(sharePlanSchema),
|
||||
asyncHandler(async (req, res) => {
|
||||
const { userId } = req.body as z.infer<typeof sharePlanSchema>;
|
||||
const result = await sharePlan(prisma, req.params.id, req.user!.id, userId);
|
||||
await logActivity(prisma, {
|
||||
actorId: req.user!.id,
|
||||
action: 'plan.shared',
|
||||
entityType: 'plan',
|
||||
entityId: req.params.id,
|
||||
details: { userId },
|
||||
});
|
||||
res.status(201).json(result);
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /plans/{id}/share/{userId}:
|
||||
* delete:
|
||||
* summary: Revoke a plan share. Owner only.
|
||||
* tags: [Plans]
|
||||
* responses:
|
||||
* 204: { description: Unshared }
|
||||
* 403: { description: Not the plan owner }
|
||||
* 404: { description: Plan not found / not shared with this user }
|
||||
*/
|
||||
router.delete(
|
||||
'/:id/share/:userId',
|
||||
asyncHandler(async (req, res) => {
|
||||
await unsharePlan(prisma, req.params.id, req.user!.id, req.params.userId);
|
||||
await logActivity(prisma, {
|
||||
actorId: req.user!.id,
|
||||
action: 'plan.unshared',
|
||||
entityType: 'plan',
|
||||
entityId: req.params.id,
|
||||
details: { userId: req.params.userId },
|
||||
});
|
||||
res.status(204).end();
|
||||
}),
|
||||
);
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
@@ -488,13 +488,15 @@ export function createTrainerRoutes({ prisma }: AppDeps) {
|
||||
* @openapi
|
||||
* /trainer/trainees/{userId}/plans/{planId}:
|
||||
* patch:
|
||||
* summary: Replace plan structure (draft only). Same body as POST (gymId, weeks[].customName)
|
||||
* summary: Replace plan structure (draft only). Same body as POST (gymId, weeks[].customName).
|
||||
* Optional startDate (a Monday, current or future week) updates and activates the plan in one step.
|
||||
* tags: [Trainer]
|
||||
* responses:
|
||||
* 200: { description: OK }
|
||||
* 400: { description: Not a draft / gym not a trainee membership }
|
||||
* 400: { description: Not a draft / gym not a trainee membership / start date not a Monday / start week in the past }
|
||||
* 403: { description: Trainer role required }
|
||||
* 404: { description: Trainee or plan not found }
|
||||
* 409: { description: Trainee already has an active plan }
|
||||
*/
|
||||
router.patch(
|
||||
'/trainees/:userId/plans/:planId',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { PrismaClient } from '@prisma/client';
|
||||
import { badRequest, conflict, notFound } from '../lib/errors.js';
|
||||
import { badRequest, conflict, forbidden, notFound } from '../lib/errors.js';
|
||||
import { isPrismaUnique } from '../lib/prisma.js';
|
||||
|
||||
export interface PlanSetInput {
|
||||
@@ -43,9 +43,10 @@ export interface CreatePlanInput {
|
||||
}
|
||||
|
||||
/**
|
||||
* The requester may access the plan when they are its owner (the trainee) or a
|
||||
* trainer with an ACTIVE coaching relation to the owner. Anything else — and a
|
||||
* missing plan — is a 404 (no existence leak, matches assertActiveTrainee).
|
||||
* The requester may access the plan when they are its owner (the trainee), a
|
||||
* trainer with an ACTIVE coaching relation to the owner, or a recipient of an
|
||||
* explicit plan share (read-only). Anything else — and a missing plan — is a
|
||||
* 404 (no existence leak, matches assertActiveTrainee).
|
||||
*/
|
||||
async function assertPlanAccess(prisma: PrismaClient, planId: string, requesterId: string) {
|
||||
const plan = await prisma.trainingPlan.findUnique({ where: { id: planId } });
|
||||
@@ -54,7 +55,24 @@ async function assertPlanAccess(prisma: PrismaClient, planId: string, requesterI
|
||||
const coaching = await prisma.coaching.findUnique({
|
||||
where: { trainerId_userId: { trainerId: requesterId, userId: plan.userId } },
|
||||
});
|
||||
if (!coaching || coaching.status !== 'ACTIVE') throw notFound('Plan not found');
|
||||
if (coaching && coaching.status === 'ACTIVE') return plan;
|
||||
const share = await prisma.planShare.findUnique({
|
||||
where: { planId_sharedWithId: { planId, sharedWithId: requesterId } },
|
||||
});
|
||||
if (!share) throw notFound('Plan not found');
|
||||
return plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Owner-only access for the owner-scoped mutation routes (PATCH/DELETE
|
||||
* /plans/:id, activate/complete/abandon). A trainer keeps mutation rights via
|
||||
* the /trainer/... routes (same services, no owner check there), and a share
|
||||
* recipient is read-only — so the check lives on the route, not the service.
|
||||
*/
|
||||
export async function assertPlanOwner(prisma: PrismaClient, planId: string, userId: string) {
|
||||
const plan = await prisma.trainingPlan.findUnique({ where: { id: planId } });
|
||||
if (!plan) throw notFound('Plan not found');
|
||||
if (plan.userId !== userId) throw notFound('Plan not found');
|
||||
return plan;
|
||||
}
|
||||
|
||||
@@ -173,11 +191,26 @@ export async function createPlan(
|
||||
}
|
||||
|
||||
export async function getPlan(prisma: PrismaClient, planId: string, userId: string) {
|
||||
await assertPlanAccess(prisma, planId, userId);
|
||||
const plan = await assertPlanAccess(prisma, planId, userId);
|
||||
// `shares` eksponowane tylko dla właściciela (lista odbiorców do dialogu
|
||||
// „Udostępnij”); trener i odbiorca share'a dostają ten sam widok bez tej sekcji.
|
||||
const isOwner = plan.userId === userId;
|
||||
// canManage: właściciel lub trener z AKTYWNYM coachingiem; odbiorca share'a = read-only.
|
||||
let canManage = isOwner;
|
||||
if (!isOwner) {
|
||||
const coaching = await prisma.coaching.findUnique({
|
||||
where: { trainerId_userId: { trainerId: userId, userId: plan.userId } },
|
||||
});
|
||||
canManage = coaching?.status === 'ACTIVE';
|
||||
}
|
||||
const full = await prisma.trainingPlan.findUnique({
|
||||
where: { id: planId },
|
||||
include: {
|
||||
gym: { select: { id: true, name: true } },
|
||||
shares: {
|
||||
orderBy: { createdAt: 'asc' },
|
||||
include: { sharedWith: { select: { id: true, firstName: true, lastName: true } } },
|
||||
},
|
||||
weeks: {
|
||||
orderBy: { index: 'asc' },
|
||||
include: {
|
||||
@@ -195,7 +228,17 @@ export async function getPlan(prisma: PrismaClient, planId: string, userId: stri
|
||||
},
|
||||
},
|
||||
});
|
||||
return { plan: full };
|
||||
if (!full) throw notFound('Plan not found');
|
||||
return {
|
||||
plan: {
|
||||
...full,
|
||||
canManage,
|
||||
// frontend shape: { userId, user: { id, firstName, lastName } }
|
||||
shares: isOwner
|
||||
? full.shares.map((s) => ({ userId: s.sharedWithId, user: s.sharedWith }))
|
||||
: undefined,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export async function updatePlan(
|
||||
@@ -208,6 +251,9 @@ export async function updatePlan(
|
||||
if (plan.status !== 'DRAFT') throw badRequest('Only draft plans can be edited');
|
||||
await validateExercises(prisma, data.weeks);
|
||||
await validateGymMembership(prisma, data.gymId, plan.userId);
|
||||
// Data startu (opcjonalna): walidacja (poniedziałek) przed aktualizacją struktury.
|
||||
const startOfStart = data.startDate ? parseStartMonday(data.startDate) : null;
|
||||
if (startOfStart) await assertNoActivePlan(prisma, plan.userId);
|
||||
await prisma.$transaction(async (tx) => {
|
||||
await tx.planWeek.deleteMany({ where: { planId: plan.id } });
|
||||
await tx.trainingPlan.update({
|
||||
@@ -220,6 +266,9 @@ export async function updatePlan(
|
||||
},
|
||||
});
|
||||
});
|
||||
// Zapis = aktualizacja + aktywacja w jednym kroku: applyStartDate musi działać PO
|
||||
// rekolekcji tygodni (wylicza daty dla nowych ID dni).
|
||||
if (startOfStart) await applyStartDate(prisma, plan.id, plan.userId, startOfStart);
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
@@ -336,3 +385,106 @@ export async function completePlan(prisma: PrismaClient, planId: string, userId:
|
||||
});
|
||||
return { ok: true, title: plan.title };
|
||||
}
|
||||
|
||||
/**
|
||||
* The owner shares the plan with a user in an ACTIVE coaching relation
|
||||
* (trainer <-> trainee, either direction). Recipients get read-only access.
|
||||
* The share survives the coaching ending; the owner can unshare anytime.
|
||||
*/
|
||||
export async function sharePlan(
|
||||
prisma: PrismaClient,
|
||||
planId: string,
|
||||
requesterId: string,
|
||||
userId: string,
|
||||
) {
|
||||
const plan = await assertPlanAccess(prisma, planId, requesterId);
|
||||
if (plan.userId !== requesterId) throw forbidden('Only the plan owner can share the plan');
|
||||
if (userId === requesterId) throw badRequest('Cannot share a plan with yourself');
|
||||
const coaching =
|
||||
(await prisma.coaching.findUnique({
|
||||
where: { trainerId_userId: { trainerId: plan.userId, userId } },
|
||||
})) ??
|
||||
(await prisma.coaching.findUnique({
|
||||
where: { trainerId_userId: { trainerId: userId, userId: plan.userId } },
|
||||
}));
|
||||
if (!coaching || coaching.status !== 'ACTIVE')
|
||||
throw badRequest('No active coaching relation with this user');
|
||||
try {
|
||||
const share = await prisma.planShare.create({
|
||||
data: { planId, sharedById: plan.userId, sharedWithId: userId },
|
||||
});
|
||||
return { share };
|
||||
} catch (e) {
|
||||
if (isPrismaUnique(e)) throw conflict('Plan is already shared with this user');
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/** The owner revokes a share (idempotent 404 when the share does not exist). */
|
||||
export async function unsharePlan(
|
||||
prisma: PrismaClient,
|
||||
planId: string,
|
||||
requesterId: string,
|
||||
userId: string,
|
||||
) {
|
||||
const plan = await assertPlanAccess(prisma, planId, requesterId);
|
||||
if (plan.userId !== requesterId) throw forbidden('Only the plan owner can unshare the plan');
|
||||
const result = await prisma.planShare.deleteMany({
|
||||
where: { planId, sharedWithId: userId },
|
||||
});
|
||||
if (result.count === 0) throw notFound('Plan is not shared with this user');
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
/** Plans explicitly shared with the user (read-only), with the sharer's name. */
|
||||
export async function listSharedWithMe(prisma: PrismaClient, userId: string) {
|
||||
const shares = await prisma.planShare.findMany({
|
||||
where: { sharedWithId: userId },
|
||||
include: {
|
||||
sharedBy: { select: { id: true, firstName: true, lastName: true } },
|
||||
plan: {
|
||||
include: {
|
||||
gym: { select: { id: true, name: true } },
|
||||
weeks: { select: { days: { select: { status: true } } } },
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
return {
|
||||
plans: shares.map((s) => {
|
||||
const days = (s.plan.weeks ?? []).flatMap((w) => w.days);
|
||||
const completed = days.filter((d) => d.status === 'COMPLETED').length;
|
||||
const total = days.length;
|
||||
const { weeks: _weeks, ...rest } = s.plan;
|
||||
return {
|
||||
...rest,
|
||||
sharedBy: s.sharedBy,
|
||||
progress: {
|
||||
completed,
|
||||
total,
|
||||
percent: total > 0 ? Math.round((completed / total) * 100) : 0,
|
||||
},
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
/** The user's trainers (ACTIVE coachings where the user is the trainee). */
|
||||
export async function getMyTrainers(prisma: PrismaClient, userId: string) {
|
||||
const coachings = await prisma.coaching.findMany({
|
||||
where: { userId, status: 'ACTIVE' },
|
||||
include: {
|
||||
trainer: { select: { id: true, firstName: true, lastName: true, nickname: true } },
|
||||
},
|
||||
orderBy: { createdAt: 'asc' },
|
||||
});
|
||||
return {
|
||||
trainers: coachings.map((c) => ({
|
||||
id: c.trainer.id,
|
||||
firstName: c.trainer.firstName,
|
||||
lastName: c.trainer.lastName,
|
||||
nickname: c.trainer.nickname,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -127,6 +127,13 @@ export const openapi: Record<string, unknown> = {
|
||||
security: [{ bearerAuth: [] }],
|
||||
},
|
||||
},
|
||||
'/me/trainers': {
|
||||
get: {
|
||||
tags: ['Profile'],
|
||||
summary: 'My trainers (ACTIVE coaching relations where I am the trainee)',
|
||||
security: [{ bearerAuth: [] }],
|
||||
},
|
||||
},
|
||||
'/me/body-parameters': {
|
||||
get: {
|
||||
tags: ['Profile'],
|
||||
@@ -538,19 +545,42 @@ export const openapi: Record<string, unknown> = {
|
||||
},
|
||||
},
|
||||
},
|
||||
'/plans/shared-with-me': {
|
||||
get: {
|
||||
tags: ['Plans'],
|
||||
summary: 'Plans explicitly shared with the user (read-only)',
|
||||
security: [{ bearerAuth: [] }],
|
||||
},
|
||||
},
|
||||
'/plans/{id}': {
|
||||
get: {
|
||||
tags: ['Plans'],
|
||||
summary: 'Plan details',
|
||||
summary:
|
||||
'Plan details. Access: owner, trainer with an ACTIVE coaching relation, or a share recipient (read-only)',
|
||||
security: [{ bearerAuth: [] }],
|
||||
parameters: [{ name: 'id', in: 'path', required: true, schema: { type: 'string' } }],
|
||||
},
|
||||
patch: {
|
||||
tags: ['Plans'],
|
||||
summary:
|
||||
'Replace plan structure (draft only). Same body as POST /plans (gymId and weeks[].customName included)',
|
||||
'Replace plan structure (draft only). Same body as POST /plans (gymId and weeks[].customName included). Optional startDate (a Monday of the current or a future week) updates and activates the plan in one step',
|
||||
security: [{ bearerAuth: [] }],
|
||||
parameters: [{ name: 'id', in: 'path', required: true, schema: { type: 'string' } }],
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
$ref: '#/paths/~1plans/post/requestBody/content/application~1json/schema',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
200: { description: 'OK' },
|
||||
400: { description: 'Not a draft / start date not a Monday / start week in the past' },
|
||||
409: { description: 'User already has an active plan' },
|
||||
},
|
||||
},
|
||||
delete: {
|
||||
tags: ['Plans'],
|
||||
@@ -595,6 +625,50 @@ export const openapi: Record<string, unknown> = {
|
||||
parameters: [{ name: 'id', in: 'path', required: true, schema: { type: 'string' } }],
|
||||
},
|
||||
},
|
||||
'/plans/{id}/share': {
|
||||
post: {
|
||||
tags: ['Plans'],
|
||||
summary:
|
||||
'Share the plan with a user in an ACTIVE coaching relation (trainer <-> trainee). Owner only; recipients get read-only access',
|
||||
security: [{ bearerAuth: [] }],
|
||||
parameters: [{ name: 'id', in: 'path', required: true, schema: { type: 'string' } }],
|
||||
requestBody: {
|
||||
required: true,
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
required: ['userId'],
|
||||
properties: { userId: { type: 'string' } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: {
|
||||
201: { description: 'Shared' },
|
||||
400: { description: 'Self-share / no active coaching relation' },
|
||||
403: { description: 'Not the plan owner' },
|
||||
404: { description: 'Plan not found' },
|
||||
409: { description: 'Already shared with this user' },
|
||||
},
|
||||
},
|
||||
},
|
||||
'/plans/{id}/share/{userId}': {
|
||||
delete: {
|
||||
tags: ['Plans'],
|
||||
summary: 'Revoke a plan share (owner only)',
|
||||
security: [{ bearerAuth: [] }],
|
||||
parameters: [
|
||||
{ name: 'id', in: 'path', required: true, schema: { type: 'string' } },
|
||||
{ name: 'userId', in: 'path', required: true, schema: { type: 'string' } },
|
||||
],
|
||||
responses: {
|
||||
204: { description: 'Unshared' },
|
||||
403: { description: 'Not the plan owner' },
|
||||
404: { description: 'Plan not found / not shared with this user' },
|
||||
},
|
||||
},
|
||||
},
|
||||
'/days/{dayId}/sessions': {
|
||||
post: {
|
||||
tags: ['Sessions'],
|
||||
|
||||
Reference in New Issue
Block a user