UNPKG

skailan-core

Version:

Servicio de autenticación y multitenancy para Skailan.

44 lines 1.65 kB
export const blockIfTrialExpired = async (req, res, next) => { try { const tenantPrisma = req.tenantPrisma; const organization = req.organization; if (!tenantPrisma || !organization) { res.status(500).json({ error: "Tenant Prisma o organización no disponible" }); return; } const org = (await tenantPrisma.organization.findUnique({ where: { id: organization.id }, })); if (!org) { res.status(404).json({ error: "Organización no encontrada" }); return; } // Verificar si el trial ha expirado if (org.trialEnd && new Date() > org.trialEnd && org.isBlocked) { res.status(403).json({ error: "Trial expirado. Por favor, actualiza tu plan.", trialEnd: org.trialEnd, }); return; } // Si el trial expiró pero no está bloqueado, bloquear automáticamente if (org.trialEnd && new Date() > org.trialEnd && !org.isBlocked) { await tenantPrisma.organization.update({ where: { id: organization.id }, data: { isBlocked: true }, }); res.status(403).json({ error: "Trial expirado. Por favor, actualiza tu plan.", trialEnd: org.trialEnd, }); return; } next(); } catch (error) { console.error("Error verificando trial:", error); res.status(500).json({ error: "Error interno del servidor" }); return; } }; //# sourceMappingURL=blockIfTrialExpired.js.map