feat: integrate consumption metrics into plan usage cycle tracking and UI display
This commit is contained in:
@@ -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 },
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user