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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
0899105a52
commit
5f02c45759
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user