From 78ee86ac484557b708335e94c462053f3224d984 Mon Sep 17 00:00:00 2001 From: Horacio Daniel Ros Date: Sat, 18 Jul 2026 22:02:48 -0300 Subject: [PATCH] feat: integrate consumption metrics into plan usage cycle tracking and UI display --- .../PlanUsageCycle/PlanUsageCycle.Adapter.Mongoose.ts | 2 -- .../Models/PlanUsageCycle/PlanUsageCycle.Interface.ts | 5 +++++ .../PlanUsageCycle/SysAdminPlanUsageCycle.Service.ts | 9 +++++++++ sysadmin-cli/src/api/sysadmin.ts | 5 +++++ .../src/components/ui/RecalculationToolsModal.tsx | 7 ++++++- sysadmin/src/models/Users.Model.ts | 5 +++++ txclient/src/app/landing/current-plan/page.tsx | 2 +- 7 files changed, 31 insertions(+), 4 deletions(-) diff --git a/server/src/Models/PlanUsageCycle/PlanUsageCycle.Adapter.Mongoose.ts b/server/src/Models/PlanUsageCycle/PlanUsageCycle.Adapter.Mongoose.ts index 8acd838..539d7cb 100644 --- a/server/src/Models/PlanUsageCycle/PlanUsageCycle.Adapter.Mongoose.ts +++ b/server/src/Models/PlanUsageCycle/PlanUsageCycle.Adapter.Mongoose.ts @@ -58,7 +58,6 @@ export class PlanUsageCycleAdapterMongoose implements IPlanUsageCycleAdapter { planId: data.planId, cycleStart: data.cycleStart, cycleEnd: data.cycleEnd, - appointmentsCount: 0, creationDate: now, }, $set: { updateDate: now }, @@ -85,7 +84,6 @@ export class PlanUsageCycleAdapterMongoose implements IPlanUsageCycleAdapter { planId: data.planId, cycleStart: data.cycleStart, cycleEnd: data.cycleEnd, - appointmentsCount: 0, creationDate: now, }, $inc: { appointmentsCount: data.quantity }, diff --git a/server/src/Models/PlanUsageCycle/PlanUsageCycle.Interface.ts b/server/src/Models/PlanUsageCycle/PlanUsageCycle.Interface.ts index 9640f59..1f6548e 100644 --- a/server/src/Models/PlanUsageCycle/PlanUsageCycle.Interface.ts +++ b/server/src/Models/PlanUsageCycle/PlanUsageCycle.Interface.ts @@ -49,6 +49,11 @@ export type SysAdminRecalculatePlanUsageCycleResult = { planId: string; cycleStart: Date; cycleEnd: Date; + organizationsCount: number; + employeesCount: number; + servicesCount: number; + clientsCount: number; + repeatsCount: number; appointmentsCount: number; }; diff --git a/server/src/api/SysAdmin/PlanUsageCycle/SysAdminPlanUsageCycle.Service.ts b/server/src/api/SysAdmin/PlanUsageCycle/SysAdminPlanUsageCycle.Service.ts index 016b03f..c32a1c6 100644 --- a/server/src/api/SysAdmin/PlanUsageCycle/SysAdminPlanUsageCycle.Service.ts +++ b/server/src/api/SysAdmin/PlanUsageCycle/SysAdminPlanUsageCycle.Service.ts @@ -2,6 +2,7 @@ import { connect } from "mongoose"; import dayjs from "dayjs"; import AppointmentList from "../../../Models/Appointments/Appointments"; import CompaniesList from "../../../Models/Companies/Companies"; +import MetricsList from "../../../Models/Metrics/Metrics"; import PlanUsageCycleList from "../../../Models/PlanUsageCycle/PlanUsageCycle"; import { SysAdminRecalculatePlanUsageCycleParams, @@ -37,12 +38,20 @@ export class SysAdminPlanUsageCycleService { throw new Error("No se pudo recalcular el uso del plan."); } + await MetricsList.calculateMetrics({ userId: params.userId }); + const metrics = await MetricsList.getMetrics(params.userId); + return { userId: params.userId, subscriptionId: String(updatedCycle.subscriptionId), planId: String(updatedCycle.planId), cycleStart: updatedCycle.cycleStart, cycleEnd: updatedCycle.cycleEnd, + organizationsCount: metrics.organizationsCount, + employeesCount: metrics.employeesCount, + servicesCount: metrics.servicesCount, + clientsCount: metrics.clientsCount, + repeatsCount: metrics.repeatsCount || 0, appointmentsCount: updatedCycle.appointmentsCount, }; } diff --git a/sysadmin-cli/src/api/sysadmin.ts b/sysadmin-cli/src/api/sysadmin.ts index 1ea6323..f60f255 100644 --- a/sysadmin-cli/src/api/sysadmin.ts +++ b/sysadmin-cli/src/api/sysadmin.ts @@ -39,6 +39,11 @@ export type RecalculatePlanUsageCycleResult = { planId: string; cycleStart: string; cycleEnd: string; + organizationsCount: number; + employeesCount: number; + servicesCount: number; + clientsCount: number; + repeatsCount: number; appointmentsCount: number; }; diff --git a/sysadmin-cli/src/components/ui/RecalculationToolsModal.tsx b/sysadmin-cli/src/components/ui/RecalculationToolsModal.tsx index e7dccd3..d43cd04 100644 --- a/sysadmin-cli/src/components/ui/RecalculationToolsModal.tsx +++ b/sysadmin-cli/src/components/ui/RecalculationToolsModal.tsx @@ -53,7 +53,7 @@ export const RecalculationToolsModal = ({ initialUserId = '', onClose }: { initi

Recalcular uso del plan

-

Recuenta las reservas del ciclo actual para el userId seleccionado.

+

Recuenta las reservas del ciclo actual y los contadores stock del userId seleccionado.

{ e.preventDefault(); handleRecalculatePlanUsage(); }} style={{ display: 'flex', gap: '0.75rem', flexWrap: 'wrap', alignItems: 'flex-end' }}> @@ -82,6 +82,11 @@ export const RecalculationToolsModal = ({ initialUserId = '', onClose }: { initi
Cycle Start
{formatDateTime(usageResult.cycleStart)}
Cycle End
{formatDateTime(usageResult.cycleEnd)}
+
Organizations
{usageResult.organizationsCount}
+
Collaborators
{usageResult.employeesCount}
+
Services
{usageResult.servicesCount}
+
Clients
{usageResult.clientsCount}
+
Repeats
{usageResult.repeatsCount}
Appointments
{usageResult.appointmentsCount}
diff --git a/sysadmin/src/models/Users.Model.ts b/sysadmin/src/models/Users.Model.ts index 318ad8c..40e2ea2 100644 --- a/sysadmin/src/models/Users.Model.ts +++ b/sysadmin/src/models/Users.Model.ts @@ -63,6 +63,11 @@ export type SysAdminRecalculatePlanUsageCycleResult = { planId: string; cycleStart: string; cycleEnd: string; + organizationsCount: number; + employeesCount: number; + servicesCount: number; + clientsCount: number; + repeatsCount: number; appointmentsCount: number; }; diff --git a/txclient/src/app/landing/current-plan/page.tsx b/txclient/src/app/landing/current-plan/page.tsx index 531f43d..6a59d8f 100644 --- a/txclient/src/app/landing/current-plan/page.tsx +++ b/txclient/src/app/landing/current-plan/page.tsx @@ -44,7 +44,7 @@ const getLimitCards = (plan: ISubscriptionInfo["plan"], metrics: DashboardMetric { label: "Organizaciones", limit: plan.limitOrganizations, current: metrics?.organizationsCount }, { label: "Colaboradores", limit: plan.limitEmployees, current: metrics?.employeesCount }, { label: "Servicios", limit: plan.limitServices, current: metrics?.servicesCount }, - { label: "Turnos", limit: plan.limitAppointments, current: metrics?.appointmentsCount }, + { label: "Turnos del Ășltimo mes", limit: plan.limitAppointments, current: metrics?.appointmentsCount }, { label: "Clientes", limit: plan.limitClients, current: metrics?.clientsCount }, { label: "Repeticiones", limit: plan.limitRepeats, current: metrics?.repeatsCount }, ];