100 lines
3.0 KiB
TypeScript
100 lines
3.0 KiB
TypeScript
import { IPlanUsageCycleDocument } from "./PlanUsageCycle.Adapter.Mongoose";
|
|
|
|
export interface IPlanUsageCycle {
|
|
id?: string;
|
|
userId: string;
|
|
subscriptionId?: string;
|
|
planId: string;
|
|
cycleStart: Date;
|
|
cycleEnd: Date;
|
|
appointmentsCount: number;
|
|
creationDate: Date;
|
|
updateDate: Date;
|
|
}
|
|
|
|
export type FindPlanUsageCycleParams = {
|
|
userId?: string;
|
|
subscriptionId?: string;
|
|
planId?: string;
|
|
cycleStart?: Date;
|
|
cycleEnd?: Date;
|
|
};
|
|
|
|
export type CreatePlanUsageCycleParams = {
|
|
userId: string;
|
|
subscriptionId?: string;
|
|
planId: string;
|
|
cycleStart: Date;
|
|
cycleEnd: Date;
|
|
appointmentsCount?: number;
|
|
};
|
|
|
|
export type CurrentPlanUsageCycleParams = {
|
|
userId: string;
|
|
now?: Date;
|
|
limit?: number;
|
|
};
|
|
|
|
export type SetPlanUsageCycleAppointmentsParams = CurrentPlanUsageCycleParams & {
|
|
appointmentsCount: number;
|
|
};
|
|
|
|
export type SysAdminRecalculatePlanUsageCycleParams = {
|
|
userId: string;
|
|
};
|
|
|
|
export type SysAdminRecalculatePlanUsageCycleResult = {
|
|
userId: string;
|
|
subscriptionId: string;
|
|
planId: string;
|
|
cycleStart: Date;
|
|
cycleEnd: Date;
|
|
organizationsCount: number;
|
|
employeesCount: number;
|
|
servicesCount: number;
|
|
clientsCount: number;
|
|
repeatsCount: number;
|
|
appointmentsCount: number;
|
|
};
|
|
|
|
export type UpdatePlanUsageCycleParams = {
|
|
userId: string;
|
|
subscriptionId: string;
|
|
planId: string;
|
|
cycleStart: Date;
|
|
cycleEnd: Date;
|
|
};
|
|
|
|
export type CalculateCurrentCycleParams = {
|
|
subscriptionStartDate: Date;
|
|
now?: Date;
|
|
};
|
|
|
|
export type PlanUsageCycleRange = {
|
|
cycleStart: Date;
|
|
cycleEnd: Date;
|
|
};
|
|
|
|
export interface IPlanUsageCycleAdapter {
|
|
findOne(filters: FindPlanUsageCycleParams): Promise<IPlanUsageCycleDocument | null>;
|
|
create(data: CreatePlanUsageCycleParams): Promise<IPlanUsageCycleDocument>;
|
|
getOrCreateCurrent(data: UpdatePlanUsageCycleParams): Promise<IPlanUsageCycleDocument>;
|
|
incrementAppointments(data: UpdatePlanUsageCycleParams & { quantity: number }): Promise<IPlanUsageCycleDocument | null>;
|
|
incrementAppointmentsIfWithinLimit(
|
|
data: UpdatePlanUsageCycleParams & { quantity: number; limit: number }
|
|
): Promise<IPlanUsageCycleDocument | null>;
|
|
setAppointmentsCount(
|
|
data: UpdatePlanUsageCycleParams & { appointmentsCount: number }
|
|
): Promise<IPlanUsageCycleDocument | null>;
|
|
}
|
|
|
|
export interface IPlanUsageCycleManager {
|
|
planUsageCycle: IPlanUsageCycleAdapter;
|
|
getCurrentCycle(data: CurrentPlanUsageCycleParams): Promise<IPlanUsageCycleDocument>;
|
|
addAppointment(data: CurrentPlanUsageCycleParams & { quantity?: number }): Promise<void>;
|
|
reserveAppointment(data: CurrentPlanUsageCycleParams & { quantity?: number }): Promise<boolean>;
|
|
releaseAppointment(data: CurrentPlanUsageCycleParams & { quantity?: number }): Promise<void>;
|
|
getAppointmentsCount(data: CurrentPlanUsageCycleParams): Promise<number>;
|
|
setAppointmentsCount(data: SetPlanUsageCycleAppointmentsParams): Promise<IPlanUsageCycleDocument | null>;
|
|
}
|