API: - AuthModule: register, login, refresh, logout, MFA/TOTP setup+verify - JwtStrategy + JwtAuthGuard + RolesGuard + CurrentUser decorator - PackagesModule: CRUD paquetes + historial de estados - PreAlertsModule: pre-alertas por usuario - UsersModule: gestión de usuarios + roles + activación - B2BModule: solicitudes de carga pesada/cotización - ValidationPipe global + CORS configurado Web (Next.js 15): - globals.css completo (design system + utility classes) - Layout raíz con WhatsApp flotante - /login + /registro funcionales con JWT y redirección por rol - /portal: dashboard, mi-casillero, mis-paquetes, pre-alerta, calculadora, perfil - /admin: dashboard, usuarios (gestión roles/activación), tarifas, reportes, auditoría - /bodega: dashboard, paquetes (crear+actualizar estado), verificación, despacho - /tracking: tracking real con progreso visual + historial - /calculadora: calculadora interactiva real (API SENAE §15) - /como-funciona, /tarifas, /quienes-somos, /casillero - /carga-pesada + /carga-pesada/cotizacion (formulario B2B) - lib/api.ts: cliente HTTP con auto-refresh de token Roles sincronizados con schema: SUPER_ADMIN, ADMIN_EMPRESA, OPERADOR_BODEGA, AGENTE_ADUANERO, CLIENTE, SOPORTE
46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
import { Injectable, NotFoundException, ForbiddenException } from "@nestjs/common";
|
|
import { PrismaService } from "../prisma/prisma.service";
|
|
import { CreatePreAlertDto, UpdatePreAlertStatusDto } from "./dto/pre-alert.dto";
|
|
|
|
@Injectable()
|
|
export class PreAlertsService {
|
|
constructor(private prisma: PrismaService) {}
|
|
|
|
async findAll(user: any): Promise<any[]> {
|
|
const where: any = { tenantId: user.tenantId };
|
|
if (user.role === "CLIENTE") where.userId = user.id;
|
|
return this.prisma.client.preAlert.findMany({
|
|
where,
|
|
include: { user: { select: { firstName: true, lastName: true, email: true } } },
|
|
orderBy: { createdAt: "desc" },
|
|
});
|
|
}
|
|
|
|
async create(dto: CreatePreAlertDto, user: any): Promise<any> {
|
|
return this.prisma.client.preAlert.create({
|
|
data: {
|
|
tenantId: user.tenantId,
|
|
userId: user.id,
|
|
store: dto.store,
|
|
description: dto.description,
|
|
declaredValue: dto.declaredValue ?? 0,
|
|
vendorTracking: dto.vendorTracking,
|
|
status: "PENDIENTE",
|
|
},
|
|
});
|
|
}
|
|
|
|
async updateStatus(id: string, dto: UpdatePreAlertStatusDto): Promise<any> {
|
|
const alert = await this.prisma.client.preAlert.findUnique({ where: { id } });
|
|
if (!alert) throw new NotFoundException("Pre-alerta no encontrada.");
|
|
return this.prisma.client.preAlert.update({ where: { id }, data: { status: dto.status as any } });
|
|
}
|
|
|
|
async remove(id: string, user: any): Promise<any> {
|
|
const alert = await this.prisma.client.preAlert.findUnique({ where: { id } });
|
|
if (!alert) throw new NotFoundException("Pre-alerta no encontrada.");
|
|
if (user.role === "CLIENTE" && alert.userId !== user.id) throw new ForbiddenException();
|
|
return this.prisma.client.preAlert.delete({ where: { id } });
|
|
}
|
|
}
|