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) {