@blackcode_sa/metaestetics-api 1.5.34 → 1.5.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.5.34",
4
+ "version": "1.5.36",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
package/src/index.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import { UserRole } from "./types";
2
2
  import { Category } from "./backoffice/types/category.types";
3
+ import {
4
+ createAppointmentSchema as appointmentCreateSchema,
5
+ updateAppointmentSchema as appointmentUpdateSchema,
6
+ searchAppointmentsSchema,
7
+ } from "./validations/appointment.schema";
3
8
 
4
9
  // Firebase
5
10
  export {
@@ -27,6 +32,7 @@ export {
27
32
  export { CalendarServiceV2 } from "./services/calendar/calendar-refactored.service";
28
33
  export { SyncedCalendarsService } from "./services/calendar/synced-calendars.service";
29
34
  export { ReviewService } from "./services/reviews/reviews.service";
35
+ export { AppointmentService } from "./services/appointment/appointment.service";
30
36
 
31
37
  // Backoffice services
32
38
  export { BrandService } from "./backoffice/services/brand.service";
@@ -54,6 +60,13 @@ export {
54
60
  } from "./validations/profile-info.schema";
55
61
  export { FirebaseErrorCode } from "./errors/firebase.errors";
56
62
 
63
+ // Appointment schemas
64
+ export {
65
+ appointmentCreateSchema as createAppointmentSchema,
66
+ appointmentUpdateSchema as updateAppointmentSchema,
67
+ searchAppointmentsSchema,
68
+ };
69
+
57
70
  // Notification types
58
71
  export type {
59
72
  Notification,
@@ -110,6 +123,19 @@ export {
110
123
  PATIENT_APPOINTMENTS_COLLECTION,
111
124
  } from "./types/patient";
112
125
 
126
+ // Appointment types
127
+ export type {
128
+ Appointment,
129
+ CreateAppointmentData,
130
+ UpdateAppointmentData,
131
+ SearchAppointmentsParams,
132
+ } from "./types/appointment";
133
+ export {
134
+ AppointmentStatus,
135
+ PaymentStatus,
136
+ APPOINTMENTS_COLLECTION,
137
+ } from "./types/appointment";
138
+
113
139
  // Allergy tipovi
114
140
  export type {
115
141
  AllergyTypeWithSubtype,
@@ -6,6 +6,7 @@ import {
6
6
  } from "firebase/firestore";
7
7
  import { Auth } from "firebase/auth";
8
8
  import { FirebaseApp } from "firebase/app";
9
+ import { Functions, getFunctions, httpsCallable } from "firebase/functions";
9
10
  import { BaseService } from "../base.service";
10
11
  import {
11
12
  Appointment,
@@ -36,6 +37,13 @@ import {
36
37
  searchAppointmentsUtil,
37
38
  } from "./utils/appointment.utils";
38
39
 
40
+ /**
41
+ * Interface for available booking slot
42
+ */
43
+ interface AvailableSlot {
44
+ start: Date;
45
+ }
46
+
39
47
  /**
40
48
  * AppointmentService is responsible for managing appointments,
41
49
  * including creating, updating, retrieving, and searching appointments.
@@ -46,6 +54,7 @@ export class AppointmentService extends BaseService {
46
54
  private patientService: PatientService;
47
55
  private practitionerService: PractitionerService;
48
56
  private clinicService: ClinicService;
57
+ private functions: Functions;
49
58
 
50
59
  /**
51
60
  * Creates a new AppointmentService instance.
@@ -72,6 +81,95 @@ export class AppointmentService extends BaseService {
72
81
  this.patientService = patientService;
73
82
  this.practitionerService = practitionerService;
74
83
  this.clinicService = clinicService;
84
+ this.functions = getFunctions(app, "europe-west6"); // Initialize Firebase Functions with the correct region
85
+ }
86
+
87
+ /**
88
+ * Gets available booking slots for a specific clinic, practitioner, and procedure.
89
+ *
90
+ * @param clinicId ID of the clinic
91
+ * @param practitionerId ID of the practitioner
92
+ * @param procedureId ID of the procedure
93
+ * @param startDate Start date of the time range to check
94
+ * @param endDate End date of the time range to check
95
+ * @returns Array of available booking slots
96
+ */
97
+ async getAvailableBookingSlots(
98
+ clinicId: string,
99
+ practitionerId: string,
100
+ procedureId: string,
101
+ startDate: Date,
102
+ endDate: Date
103
+ ): Promise<AvailableSlot[]> {
104
+ try {
105
+ console.log(
106
+ `[APPOINTMENT_SERVICE] Getting available booking slots for clinic: ${clinicId}, practitioner: ${practitionerId}, procedure: ${procedureId}`
107
+ );
108
+
109
+ // Validate input parameters
110
+ if (
111
+ !clinicId ||
112
+ !practitionerId ||
113
+ !procedureId ||
114
+ !startDate ||
115
+ !endDate
116
+ ) {
117
+ throw new Error(
118
+ "Missing required parameters for booking slots calculation"
119
+ );
120
+ }
121
+
122
+ if (endDate <= startDate) {
123
+ throw new Error("End date must be after start date");
124
+ }
125
+
126
+ // Create a callable function reference
127
+ const getAvailableBookingSlotsFunction = httpsCallable(
128
+ this.functions,
129
+ "getAvailableBookingSlots"
130
+ );
131
+
132
+ // Call the cloud function with required parameters
133
+ const result = await getAvailableBookingSlotsFunction({
134
+ clinicId,
135
+ practitionerId,
136
+ procedureId,
137
+ timeframe: {
138
+ start: startDate.getTime(), // Convert to timestamp
139
+ end: endDate.getTime(),
140
+ },
141
+ });
142
+
143
+ // Process the response
144
+ const response = result.data as {
145
+ success: boolean;
146
+ availableSlots: { start: number }[];
147
+ error?: string;
148
+ };
149
+
150
+ if (!response.success) {
151
+ throw new Error(
152
+ response.error || "Failed to get available booking slots"
153
+ );
154
+ }
155
+
156
+ // Convert timestamp numbers to Date objects
157
+ const slots: AvailableSlot[] = response.availableSlots.map((slot) => ({
158
+ start: new Date(slot.start),
159
+ }));
160
+
161
+ console.log(
162
+ `[APPOINTMENT_SERVICE] Found ${slots.length} available booking slots`
163
+ );
164
+
165
+ return slots;
166
+ } catch (error) {
167
+ console.error(
168
+ "[APPOINTMENT_SERVICE] Error getting available booking slots:",
169
+ error
170
+ );
171
+ throw error;
172
+ }
75
173
  }
76
174
 
77
175
  /**