feat: pasar de la lista de espera a otro grupo del profesor

- `POST /groups/:gid/waitlist/:entryId/promote` acepta `targetGroupId`
  opcional (por defecto, el grupo en el que se anotó). El destino tiene que
  ser del mismo profesor; cupo y teléfono duplicado se validan ahí.
- Detalle de la lista de espera: selector "Asignar a" con los grupos llenos
  deshabilitados.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jose Selesan
2026-11-02 15:39:55 -03:00
parent d397e9663c
commit fc12ec3ae0
7 changed files with 181 additions and 26 deletions

View File

@@ -1,19 +1,26 @@
import { type PromoteGroupWaitlistEntry as PromoteBody, PromoteGroupWaitlistEntrySchema } from '@gruperly/shared';
import { Hono } from 'hono';
import { problemJson, resultJson, unauthorizedProblem } from '@/http/problem-details';
import { validate } from '@/http/validate';
import { PromoteGroupWaitlistEntry } from './use-case';
const route = new Hono();
route.post('/:groupId/waitlist/:entryId/promote', async (c) => {
const user = c.get('user');
if (!user) {
return problemJson(c, unauthorizedProblem(c.req.path));
}
const groupId = c.req.param('groupId');
const entryId = c.req.param('entryId');
const useCase = new PromoteGroupWaitlistEntry();
const result = await useCase.execute(groupId, entryId, user.id);
return resultJson(c, result);
});
route.post(
'/:groupId/waitlist/:entryId/promote',
validate.json(PromoteGroupWaitlistEntrySchema),
async (c) => {
const user = c.get('user');
if (!user) {
return problemJson(c, unauthorizedProblem(c.req.path));
}
const groupId = c.req.param('groupId');
const entryId = c.req.param('entryId');
const body = c.req.valid('json') as PromoteBody;
const useCase = new PromoteGroupWaitlistEntry();
const result = await useCase.execute(groupId, entryId, user.id, body.targetGroupId);
return resultJson(c, result);
},
);
export default route;
export default route;

View File

@@ -23,6 +23,7 @@ export class PromoteGroupWaitlistEntry {
groupId: string,
entryId: string,
userId: string,
targetGroupId?: string,
): Promise<Result<PromoteGroupWaitlistEntryResult, ProblemDetails>> {
const db = this.deps.db ?? prisma;
const unitOfWork = this.deps.unitOfWork ?? new UnitOfWork(prisma);
@@ -39,6 +40,17 @@ export class PromoteGroupWaitlistEntry {
return err(notFoundResourceProblem('GroupWaitlistEntry', entryId));
}
// The entry leaves the waitlist of its own group but can land in another
// group of the same teacher (capacity and duplicates are checked there).
let targetGroup = groupResult.value;
if (targetGroupId && targetGroupId !== groupId) {
const targetResult = await findGroupOwnedByUser(db, targetGroupId, userId);
if (!targetResult.ok) {
return targetResult;
}
targetGroup = targetResult.value;
}
const allowed = await (this.deps.planGuard ?? new PlanGuard()).canAddAttendees(userId);
if (!allowed.ok) {
return allowed;
@@ -48,7 +60,7 @@ export class PromoteGroupWaitlistEntry {
async (tx: Prisma.TransactionClient) => {
const promoteResult = await promoteWaitlistEntryRecord(
tx,
groupResult.value,
targetGroup,
entry as unknown as GroupWaitlistEntryRecord,
);
if (!promoteResult.ok) {