Add rejected professionals tab and fix deny to keep record
- deny() now marks is_active:false instead of deleting the record - New GET /professionals/rejected endpoint (pro_state:3) - findPendingApprovals now filters only pro_state:1 - Admin list: third tab 'No aprobados' with approve/review actions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
86c6f3e6b7
commit
3fd7a33fc1
@@ -30,6 +30,15 @@ export class ProfessionalsController {
|
||||
return this.pros.findPendingApprovals(page, limit);
|
||||
}
|
||||
|
||||
@Get('rejected')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
findRejected(@Req() req) {
|
||||
const page = +(req.query.page || 1);
|
||||
const limit = +(req.query.limit || 20);
|
||||
return this.pros.findRejected(page, limit);
|
||||
}
|
||||
|
||||
@Post(':id/approve')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
|
||||
@@ -112,14 +112,30 @@ export class ProfessionalsService {
|
||||
|
||||
async findPendingApprovals(page = 1, limit = 20) {
|
||||
const skip = (page - 1) * limit;
|
||||
const where = { is_active: false, users: { pro_state: 1 } };
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.professionals.findMany({
|
||||
where: { is_active: false },
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
include: { users: { select: { id: true, name: true, email: true, phone: true, created_at: true } } },
|
||||
include: { users: { select: { id: true, name: true, email: true, phone: true, created_at: true, pro_state: true } } },
|
||||
}),
|
||||
this.prisma.professionals.count({ where: { is_active: false } }),
|
||||
this.prisma.professionals.count({ where }),
|
||||
]);
|
||||
return { data, meta: { total, page, limit, totalPages: Math.ceil(total / limit) || 1 } };
|
||||
}
|
||||
|
||||
async findRejected(page = 1, limit = 20) {
|
||||
const skip = (page - 1) * limit;
|
||||
const where = { is_active: false, users: { pro_state: 3 } };
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.professionals.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
include: { users: { select: { id: true, name: true, email: true, phone: true, created_at: true, pro_state: true } } },
|
||||
}),
|
||||
this.prisma.professionals.count({ where }),
|
||||
]);
|
||||
return { data, meta: { total, page, limit, totalPages: Math.ceil(total / limit) || 1 } };
|
||||
}
|
||||
@@ -146,11 +162,8 @@ export class ProfessionalsService {
|
||||
if (!prof) throw new NotFoundException('Profesional no encontrado');
|
||||
|
||||
await this.prisma.$transaction([
|
||||
this.prisma.professionals.delete({ where: { id: professionalId } }),
|
||||
this.prisma.users.update({
|
||||
where: { id: prof.user_id },
|
||||
data: { pro_state: 3 },
|
||||
}),
|
||||
this.prisma.professionals.update({ where: { id: professionalId }, data: { is_active: false } }),
|
||||
this.prisma.users.update({ where: { id: prof.user_id }, data: { pro_state: 3 } }),
|
||||
]);
|
||||
return { message: 'Solicitud rechazada' };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user