From 5f02c45759564451ceda251a1e1a0e391ae5ed35 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Mon, 29 Jun 2026 10:00:38 -0500 Subject: [PATCH] Fix retry flow: reset pro_state without deleting professional record - resetRejected: only set pro_state=0, no DELETE (avoids FK constraint errors from services/reputations with onDelete: NoAction) - upsert: detect re-submission after rejection (pro_state=0) and set pro_state=1 so the request appears in admin pending list Co-Authored-By: Claude Sonnet 4.6 --- .../src/professionals/professionals.service.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/backend/src/professionals/professionals.service.ts b/backend/src/professionals/professionals.service.ts index bb5b185..add597e 100644 --- a/backend/src/professionals/professionals.service.ts +++ b/backend/src/professionals/professionals.service.ts @@ -75,6 +75,16 @@ export class ProfessionalsService { return this.prisma.professionals.create({ data: { user_id: userId, is_active: false, ...data } }); } + // Re-submitting after rejection reset (pro_state=0): move back to pending + const user = await this.prisma.users.findUnique({ where: { id: userId }, select: { pro_state: true } }); + if (user?.pro_state === 0) { + await this.prisma.$transaction([ + this.prisma.professionals.update({ where: { user_id: userId }, data: { ...data, is_active: false } }), + this.prisma.users.update({ where: { id: userId }, data: { pro_state: 1 } }), + ]); + return this.prisma.professionals.findUnique({ where: { user_id: userId } }); + } + return this.prisma.professionals.update({ where: { user_id: userId }, data }); } @@ -171,11 +181,9 @@ export class ProfessionalsService { async resetRejected(userId: string) { const prof = await this.prisma.professionals.findUnique({ where: { user_id: userId } }); if (!prof) throw new NotFoundException('No se encontrĂ³ solicitud'); - await this.prisma.$transaction([ - this.prisma.professionals.delete({ where: { user_id: userId } }), - this.prisma.users.update({ where: { id: userId }, data: { pro_state: 0 } }), - ]); - return { message: 'Solicitud eliminada' }; + // Reset to 0 without deleting — avoids FK constraint errors from services/reputations + await this.prisma.users.update({ where: { id: userId }, data: { pro_state: 0 } }); + return { message: 'Solicitud reiniciada' }; } async deactivate(id: string) {