@blackcode_sa/metaestetics-api 1.12.19 → 1.12.21
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/dist/admin/index.d.mts +13 -0
- package/dist/admin/index.d.ts +13 -0
- package/dist/admin/index.js +194 -180
- package/dist/admin/index.mjs +194 -180
- package/dist/index.d.mts +48 -1
- package/dist/index.d.ts +48 -1
- package/dist/index.js +2080 -1847
- package/dist/index.mjs +2146 -1913
- package/package.json +1 -1
- package/src/admin/aggregation/appointment/appointment.aggregation.service.ts +459 -457
- package/src/services/appointment/appointment.service.ts +297 -0
- package/src/types/appointment/index.ts +11 -0
- package/src/validations/appointment.schema.ts +38 -18
|
@@ -28,12 +28,15 @@ import {
|
|
|
28
28
|
AppointmentMediaItem,
|
|
29
29
|
PatientReviewInfo,
|
|
30
30
|
type CreateAppointmentHttpData,
|
|
31
|
+
type ZonePhotoUploadData,
|
|
32
|
+
BeforeAfterPerZone,
|
|
31
33
|
APPOINTMENTS_COLLECTION,
|
|
32
34
|
} from '../../types/appointment';
|
|
33
35
|
import {
|
|
34
36
|
updateAppointmentSchema,
|
|
35
37
|
searchAppointmentsSchema,
|
|
36
38
|
rescheduleAppointmentSchema,
|
|
39
|
+
zonePhotoUploadSchema,
|
|
37
40
|
} from '../../validations/appointment.schema';
|
|
38
41
|
|
|
39
42
|
// Import other services needed (dependency injection pattern)
|
|
@@ -42,6 +45,7 @@ import { PatientService } from '../patient/patient.service';
|
|
|
42
45
|
import { PractitionerService } from '../practitioner/practitioner.service';
|
|
43
46
|
import { ClinicService } from '../clinic/clinic.service';
|
|
44
47
|
import { FilledDocumentService } from '../documentation-templates/filled-document.service';
|
|
48
|
+
import { MediaService, MediaAccessLevel, MediaMetadata } from '../media/media.service';
|
|
45
49
|
|
|
46
50
|
// Import utility functions
|
|
47
51
|
import {
|
|
@@ -68,6 +72,7 @@ export class AppointmentService extends BaseService {
|
|
|
68
72
|
private practitionerService: PractitionerService;
|
|
69
73
|
private clinicService: ClinicService;
|
|
70
74
|
private filledDocumentService: FilledDocumentService;
|
|
75
|
+
private mediaService: MediaService;
|
|
71
76
|
private functions: Functions;
|
|
72
77
|
|
|
73
78
|
/**
|
|
@@ -80,6 +85,7 @@ export class AppointmentService extends BaseService {
|
|
|
80
85
|
* @param patientService Patient service instance
|
|
81
86
|
* @param practitionerService Practitioner service instance
|
|
82
87
|
* @param clinicService Clinic service instance
|
|
88
|
+
* @param filledDocumentService Filled document service instance
|
|
83
89
|
*/
|
|
84
90
|
constructor(
|
|
85
91
|
db: Firestore,
|
|
@@ -97,6 +103,7 @@ export class AppointmentService extends BaseService {
|
|
|
97
103
|
this.practitionerService = practitionerService;
|
|
98
104
|
this.clinicService = clinicService;
|
|
99
105
|
this.filledDocumentService = filledDocumentService;
|
|
106
|
+
this.mediaService = new MediaService(db, auth, app);
|
|
100
107
|
this.functions = getFunctions(app, 'europe-west6'); // Initialize Firebase Functions with the correct region
|
|
101
108
|
}
|
|
102
109
|
|
|
@@ -1144,4 +1151,294 @@ export class AppointmentService extends BaseService {
|
|
|
1144
1151
|
throw error;
|
|
1145
1152
|
}
|
|
1146
1153
|
}
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* Uploads a zone photo and updates appointment metadata
|
|
1157
|
+
*
|
|
1158
|
+
* @param uploadData Zone photo upload data containing appointment ID, zone ID, photo type, file, and optional notes
|
|
1159
|
+
* @returns The uploaded media metadata
|
|
1160
|
+
*/
|
|
1161
|
+
async uploadZonePhoto(uploadData: ZonePhotoUploadData): Promise<MediaMetadata> {
|
|
1162
|
+
try {
|
|
1163
|
+
console.log(
|
|
1164
|
+
`[APPOINTMENT_SERVICE] Uploading ${uploadData.photoType} photo for zone ${uploadData.zoneId} in appointment ${uploadData.appointmentId}`,
|
|
1165
|
+
);
|
|
1166
|
+
|
|
1167
|
+
// Validate input data
|
|
1168
|
+
const validatedData = await zonePhotoUploadSchema.parseAsync(uploadData);
|
|
1169
|
+
|
|
1170
|
+
// Check if user is authenticated
|
|
1171
|
+
const currentUser = this.auth.currentUser;
|
|
1172
|
+
if (!currentUser) {
|
|
1173
|
+
throw new Error('User must be authenticated to upload zone photos');
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
// Get the appointment to verify it exists and user has access
|
|
1177
|
+
const appointment = await this.getAppointmentById(validatedData.appointmentId);
|
|
1178
|
+
if (!appointment) {
|
|
1179
|
+
throw new Error(`Appointment with ID ${validatedData.appointmentId} not found`);
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
// Generate collection name for the media
|
|
1183
|
+
const collectionName = `appointment_${validatedData.appointmentId}_zone_photos`;
|
|
1184
|
+
|
|
1185
|
+
// Generate filename with zone and photo type info
|
|
1186
|
+
const timestamp = Date.now();
|
|
1187
|
+
const fileExtension = validatedData.file.type?.split('/')[1] || 'jpg';
|
|
1188
|
+
const fileName = `${validatedData.photoType}_${validatedData.zoneId}_${timestamp}.${fileExtension}`;
|
|
1189
|
+
|
|
1190
|
+
console.log(
|
|
1191
|
+
`[APPOINTMENT_SERVICE] Uploading file: ${fileName} to collection: ${collectionName}`,
|
|
1192
|
+
);
|
|
1193
|
+
|
|
1194
|
+
// Upload the media file using MediaService
|
|
1195
|
+
const uploadedMedia = await this.mediaService.uploadMedia(
|
|
1196
|
+
validatedData.file,
|
|
1197
|
+
validatedData.appointmentId, // ownerId is the appointment ID
|
|
1198
|
+
MediaAccessLevel.PRIVATE, // Zone photos are private
|
|
1199
|
+
collectionName,
|
|
1200
|
+
fileName,
|
|
1201
|
+
);
|
|
1202
|
+
|
|
1203
|
+
console.log(`[APPOINTMENT_SERVICE] Media uploaded successfully with ID: ${uploadedMedia.id}`);
|
|
1204
|
+
|
|
1205
|
+
// Update appointment metadata with the new photo
|
|
1206
|
+
await this.updateAppointmentZonePhoto(
|
|
1207
|
+
validatedData.appointmentId,
|
|
1208
|
+
validatedData.zoneId,
|
|
1209
|
+
validatedData.photoType,
|
|
1210
|
+
uploadedMedia,
|
|
1211
|
+
validatedData.notes,
|
|
1212
|
+
);
|
|
1213
|
+
|
|
1214
|
+
console.log(
|
|
1215
|
+
`[APPOINTMENT_SERVICE] Successfully uploaded and linked ${validatedData.photoType} photo for zone ${validatedData.zoneId}`,
|
|
1216
|
+
);
|
|
1217
|
+
|
|
1218
|
+
return uploadedMedia;
|
|
1219
|
+
} catch (error) {
|
|
1220
|
+
console.error('[APPOINTMENT_SERVICE] Error uploading zone photo:', error);
|
|
1221
|
+
throw error;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
* Updates appointment metadata with zone photo information
|
|
1227
|
+
*
|
|
1228
|
+
* @param appointmentId ID of the appointment
|
|
1229
|
+
* @param zoneId ID of the zone
|
|
1230
|
+
* @param photoType Type of photo ('before' or 'after')
|
|
1231
|
+
* @param mediaMetadata Uploaded media metadata
|
|
1232
|
+
* @param notes Optional notes for the photo
|
|
1233
|
+
* @returns The updated appointment
|
|
1234
|
+
*/
|
|
1235
|
+
private async updateAppointmentZonePhoto(
|
|
1236
|
+
appointmentId: string,
|
|
1237
|
+
zoneId: string,
|
|
1238
|
+
photoType: 'before' | 'after',
|
|
1239
|
+
mediaMetadata: MediaMetadata,
|
|
1240
|
+
notes?: string,
|
|
1241
|
+
): Promise<Appointment> {
|
|
1242
|
+
try {
|
|
1243
|
+
console.log(
|
|
1244
|
+
`[APPOINTMENT_SERVICE] Updating appointment metadata for ${photoType} photo in zone ${zoneId}`,
|
|
1245
|
+
);
|
|
1246
|
+
|
|
1247
|
+
// Get current appointment
|
|
1248
|
+
const appointment = await this.getAppointmentById(appointmentId);
|
|
1249
|
+
if (!appointment) {
|
|
1250
|
+
throw new Error(`Appointment with ID ${appointmentId} not found`);
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
// Initialize metadata if it doesn't exist
|
|
1254
|
+
const currentMetadata = appointment.metadata || {
|
|
1255
|
+
selectedZones: null,
|
|
1256
|
+
zonePhotos: null,
|
|
1257
|
+
zoneBilling: null,
|
|
1258
|
+
finalbilling: null,
|
|
1259
|
+
finalizationNotes: null,
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1262
|
+
// Initialize zonePhotos if it doesn't exist
|
|
1263
|
+
const currentZonePhotos = currentMetadata.zonePhotos || {};
|
|
1264
|
+
|
|
1265
|
+
// Initialize the zone entry if it doesn't exist
|
|
1266
|
+
if (!currentZonePhotos[zoneId]) {
|
|
1267
|
+
currentZonePhotos[zoneId] = {
|
|
1268
|
+
before: null,
|
|
1269
|
+
after: null,
|
|
1270
|
+
beforeNote: null,
|
|
1271
|
+
afterNote: null,
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
// Update the specific photo type
|
|
1276
|
+
if (photoType === 'before') {
|
|
1277
|
+
currentZonePhotos[zoneId].before = mediaMetadata.url;
|
|
1278
|
+
if (notes) {
|
|
1279
|
+
currentZonePhotos[zoneId].beforeNote = notes;
|
|
1280
|
+
}
|
|
1281
|
+
} else {
|
|
1282
|
+
currentZonePhotos[zoneId].after = mediaMetadata.url;
|
|
1283
|
+
if (notes) {
|
|
1284
|
+
currentZonePhotos[zoneId].afterNote = notes;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
// Update the appointment with new metadata
|
|
1289
|
+
const updateData: UpdateAppointmentData = {
|
|
1290
|
+
metadata: {
|
|
1291
|
+
selectedZones: currentMetadata.selectedZones,
|
|
1292
|
+
zonePhotos: currentZonePhotos,
|
|
1293
|
+
zoneBilling: currentMetadata.zoneBilling,
|
|
1294
|
+
finalbilling: currentMetadata.finalbilling,
|
|
1295
|
+
finalizationNotes: currentMetadata.finalizationNotes,
|
|
1296
|
+
},
|
|
1297
|
+
updatedAt: serverTimestamp(),
|
|
1298
|
+
};
|
|
1299
|
+
|
|
1300
|
+
const updatedAppointment = await this.updateAppointment(appointmentId, updateData);
|
|
1301
|
+
|
|
1302
|
+
console.log(
|
|
1303
|
+
`[APPOINTMENT_SERVICE] Successfully updated appointment metadata for ${photoType} photo in zone ${zoneId}`,
|
|
1304
|
+
);
|
|
1305
|
+
|
|
1306
|
+
return updatedAppointment;
|
|
1307
|
+
} catch (error) {
|
|
1308
|
+
console.error(
|
|
1309
|
+
`[APPOINTMENT_SERVICE] Error updating appointment metadata for zone photo:`,
|
|
1310
|
+
error,
|
|
1311
|
+
);
|
|
1312
|
+
throw error;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
/**
|
|
1317
|
+
* Gets zone photos for a specific appointment and zone
|
|
1318
|
+
*
|
|
1319
|
+
* @param appointmentId ID of the appointment
|
|
1320
|
+
* @param zoneId ID of the zone (optional - if not provided, returns all zones)
|
|
1321
|
+
* @returns Zone photos data
|
|
1322
|
+
*/
|
|
1323
|
+
async getZonePhotos(
|
|
1324
|
+
appointmentId: string,
|
|
1325
|
+
zoneId?: string,
|
|
1326
|
+
): Promise<Record<string, BeforeAfterPerZone> | BeforeAfterPerZone | null> {
|
|
1327
|
+
try {
|
|
1328
|
+
console.log(`[APPOINTMENT_SERVICE] Getting zone photos for appointment ${appointmentId}`);
|
|
1329
|
+
|
|
1330
|
+
const appointment = await this.getAppointmentById(appointmentId);
|
|
1331
|
+
if (!appointment) {
|
|
1332
|
+
throw new Error(`Appointment with ID ${appointmentId} not found`);
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
const zonePhotos = appointment.metadata?.zonePhotos;
|
|
1336
|
+
if (!zonePhotos) {
|
|
1337
|
+
return null;
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
// If specific zone requested, return only that zone's photos
|
|
1341
|
+
if (zoneId) {
|
|
1342
|
+
return zonePhotos[zoneId] || null;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
// Return all zone photos
|
|
1346
|
+
return zonePhotos;
|
|
1347
|
+
} catch (error) {
|
|
1348
|
+
console.error(`[APPOINTMENT_SERVICE] Error getting zone photos:`, error);
|
|
1349
|
+
throw error;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
/**
|
|
1354
|
+
* Deletes a zone photo and updates appointment metadata
|
|
1355
|
+
*
|
|
1356
|
+
* @param appointmentId ID of the appointment
|
|
1357
|
+
* @param zoneId ID of the zone
|
|
1358
|
+
* @param photoType Type of photo to delete ('before' or 'after')
|
|
1359
|
+
* @returns The updated appointment
|
|
1360
|
+
*/
|
|
1361
|
+
async deleteZonePhoto(
|
|
1362
|
+
appointmentId: string,
|
|
1363
|
+
zoneId: string,
|
|
1364
|
+
photoType: 'before' | 'after',
|
|
1365
|
+
): Promise<Appointment> {
|
|
1366
|
+
try {
|
|
1367
|
+
console.log(
|
|
1368
|
+
`[APPOINTMENT_SERVICE] Deleting ${photoType} photo for zone ${zoneId} in appointment ${appointmentId}`,
|
|
1369
|
+
);
|
|
1370
|
+
|
|
1371
|
+
// Get current appointment
|
|
1372
|
+
const appointment = await this.getAppointmentById(appointmentId);
|
|
1373
|
+
if (!appointment) {
|
|
1374
|
+
throw new Error(`Appointment with ID ${appointmentId} not found`);
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
const zonePhotos = appointment.metadata?.zonePhotos;
|
|
1378
|
+
if (!zonePhotos || !zonePhotos[zoneId]) {
|
|
1379
|
+
throw new Error(`No photos found for zone ${zoneId} in appointment ${appointmentId}`);
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
const photoUrl =
|
|
1383
|
+
photoType === 'before' ? zonePhotos[zoneId].before : zonePhotos[zoneId].after;
|
|
1384
|
+
if (!photoUrl) {
|
|
1385
|
+
throw new Error(`No ${photoType} photo found for zone ${zoneId}`);
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
// Try to find and delete the media from storage
|
|
1389
|
+
try {
|
|
1390
|
+
// Only try to delete if photoUrl is a string (URL)
|
|
1391
|
+
if (typeof photoUrl === 'string') {
|
|
1392
|
+
const mediaMetadata = await this.mediaService.getMediaMetadataByUrl(photoUrl);
|
|
1393
|
+
if (mediaMetadata) {
|
|
1394
|
+
await this.mediaService.deleteMedia(mediaMetadata.id);
|
|
1395
|
+
console.log(`[APPOINTMENT_SERVICE] Deleted media file with ID: ${mediaMetadata.id}`);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
} catch (mediaError) {
|
|
1399
|
+
console.warn(
|
|
1400
|
+
`[APPOINTMENT_SERVICE] Could not delete media file for URL ${photoUrl}:`,
|
|
1401
|
+
mediaError,
|
|
1402
|
+
);
|
|
1403
|
+
// Continue with metadata update even if media deletion fails
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
// Update appointment metadata to remove the photo reference
|
|
1407
|
+
const updatedZonePhotos = { ...zonePhotos };
|
|
1408
|
+
if (photoType === 'before') {
|
|
1409
|
+
updatedZonePhotos[zoneId].before = null;
|
|
1410
|
+
updatedZonePhotos[zoneId].beforeNote = null;
|
|
1411
|
+
} else {
|
|
1412
|
+
updatedZonePhotos[zoneId].after = null;
|
|
1413
|
+
updatedZonePhotos[zoneId].afterNote = null;
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
// If both photos are null, we could optionally remove the zone entry entirely
|
|
1417
|
+
if (!updatedZonePhotos[zoneId].before && !updatedZonePhotos[zoneId].after) {
|
|
1418
|
+
delete updatedZonePhotos[zoneId];
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
const updateData: UpdateAppointmentData = {
|
|
1422
|
+
metadata: {
|
|
1423
|
+
selectedZones: appointment.metadata?.selectedZones || null,
|
|
1424
|
+
zonePhotos: updatedZonePhotos,
|
|
1425
|
+
zoneBilling: appointment.metadata?.zoneBilling || null,
|
|
1426
|
+
finalbilling: appointment.metadata?.finalbilling || null,
|
|
1427
|
+
finalizationNotes: appointment.metadata?.finalizationNotes || null,
|
|
1428
|
+
},
|
|
1429
|
+
updatedAt: serverTimestamp(),
|
|
1430
|
+
};
|
|
1431
|
+
|
|
1432
|
+
const updatedAppointment = await this.updateAppointment(appointmentId, updateData);
|
|
1433
|
+
|
|
1434
|
+
console.log(
|
|
1435
|
+
`[APPOINTMENT_SERVICE] Successfully deleted ${photoType} photo for zone ${zoneId}`,
|
|
1436
|
+
);
|
|
1437
|
+
|
|
1438
|
+
return updatedAppointment;
|
|
1439
|
+
} catch (error) {
|
|
1440
|
+
console.error(`[APPOINTMENT_SERVICE] Error deleting zone photo:`, error);
|
|
1441
|
+
throw error;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1147
1444
|
}
|
|
@@ -120,6 +120,17 @@ export interface BeforeAfterPerZone {
|
|
|
120
120
|
beforeNote?: string | null;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Interface for zone photo upload data
|
|
125
|
+
*/
|
|
126
|
+
export interface ZonePhotoUploadData {
|
|
127
|
+
appointmentId: string;
|
|
128
|
+
zoneId: string;
|
|
129
|
+
photoType: 'before' | 'after';
|
|
130
|
+
file: File | Blob;
|
|
131
|
+
notes?: string;
|
|
132
|
+
}
|
|
133
|
+
|
|
123
134
|
/**
|
|
124
135
|
* Interface for billing information per zone
|
|
125
136
|
*/
|
|
@@ -25,7 +25,7 @@ export const appointmentMediaItemSchema = z.object({
|
|
|
25
25
|
uploadedAt: z
|
|
26
26
|
.any()
|
|
27
27
|
.refine(
|
|
28
|
-
|
|
28
|
+
val =>
|
|
29
29
|
val instanceof Date ||
|
|
30
30
|
val?._seconds !== undefined ||
|
|
31
31
|
val?.seconds !== undefined ||
|
|
@@ -69,7 +69,7 @@ export const linkedFormInfoSchema = z.object({
|
|
|
69
69
|
submittedAt: z
|
|
70
70
|
.any()
|
|
71
71
|
.refine(
|
|
72
|
-
|
|
72
|
+
val =>
|
|
73
73
|
val === undefined ||
|
|
74
74
|
val instanceof Date ||
|
|
75
75
|
val?._seconds !== undefined ||
|
|
@@ -83,7 +83,7 @@ export const linkedFormInfoSchema = z.object({
|
|
|
83
83
|
completedAt: z
|
|
84
84
|
.any()
|
|
85
85
|
.refine(
|
|
86
|
-
|
|
86
|
+
val =>
|
|
87
87
|
val === undefined ||
|
|
88
88
|
val instanceof Date ||
|
|
89
89
|
val?._seconds !== undefined ||
|
|
@@ -103,7 +103,7 @@ export const patientReviewInfoSchema = z.object({
|
|
|
103
103
|
reviewedAt: z
|
|
104
104
|
.any()
|
|
105
105
|
.refine(
|
|
106
|
-
|
|
106
|
+
val =>
|
|
107
107
|
val instanceof Date ||
|
|
108
108
|
val?._seconds !== undefined ||
|
|
109
109
|
val?.seconds !== undefined ||
|
|
@@ -119,7 +119,7 @@ export const finalizedDetailsSchema = z.object({
|
|
|
119
119
|
at: z
|
|
120
120
|
.any()
|
|
121
121
|
.refine(
|
|
122
|
-
|
|
122
|
+
val =>
|
|
123
123
|
val instanceof Date ||
|
|
124
124
|
val?._seconds !== undefined ||
|
|
125
125
|
val?.seconds !== undefined ||
|
|
@@ -194,7 +194,7 @@ export const createAppointmentSchema = z
|
|
|
194
194
|
appointmentStartTime: z
|
|
195
195
|
.any()
|
|
196
196
|
.refine(
|
|
197
|
-
|
|
197
|
+
val =>
|
|
198
198
|
val instanceof Date ||
|
|
199
199
|
val?._seconds !== undefined ||
|
|
200
200
|
val?.seconds !== undefined ||
|
|
@@ -206,7 +206,7 @@ export const createAppointmentSchema = z
|
|
|
206
206
|
appointmentEndTime: z
|
|
207
207
|
.any()
|
|
208
208
|
.refine(
|
|
209
|
-
|
|
209
|
+
val =>
|
|
210
210
|
val instanceof Date ||
|
|
211
211
|
val?._seconds !== undefined ||
|
|
212
212
|
val?.seconds !== undefined ||
|
|
@@ -222,7 +222,7 @@ export const createAppointmentSchema = z
|
|
|
222
222
|
initialPaymentStatus: paymentStatusSchema.optional().default(PaymentStatus.UNPAID),
|
|
223
223
|
clinic_tz: z.string().min(1, 'Timezone is required'),
|
|
224
224
|
})
|
|
225
|
-
.refine(
|
|
225
|
+
.refine(data => data.appointmentEndTime > data.appointmentStartTime, {
|
|
226
226
|
message: 'Appointment end time must be after start time',
|
|
227
227
|
path: ['appointmentEndTime'],
|
|
228
228
|
});
|
|
@@ -263,7 +263,7 @@ export const updateAppointmentSchema = z
|
|
|
263
263
|
appointmentStartTime: z
|
|
264
264
|
.any()
|
|
265
265
|
.refine(
|
|
266
|
-
|
|
266
|
+
val =>
|
|
267
267
|
val === undefined ||
|
|
268
268
|
val instanceof Date ||
|
|
269
269
|
val?._seconds !== undefined ||
|
|
@@ -277,7 +277,7 @@ export const updateAppointmentSchema = z
|
|
|
277
277
|
appointmentEndTime: z
|
|
278
278
|
.any()
|
|
279
279
|
.refine(
|
|
280
|
-
|
|
280
|
+
val =>
|
|
281
281
|
val === undefined ||
|
|
282
282
|
val instanceof Date ||
|
|
283
283
|
val?._seconds !== undefined ||
|
|
@@ -302,7 +302,7 @@ export const updateAppointmentSchema = z
|
|
|
302
302
|
metadata: appointmentMetadataSchema.optional(),
|
|
303
303
|
})
|
|
304
304
|
.refine(
|
|
305
|
-
|
|
305
|
+
data => {
|
|
306
306
|
if (
|
|
307
307
|
data.status === AppointmentStatus.CANCELED_CLINIC ||
|
|
308
308
|
data.status === AppointmentStatus.CANCELED_PATIENT ||
|
|
@@ -319,7 +319,7 @@ export const updateAppointmentSchema = z
|
|
|
319
319
|
},
|
|
320
320
|
)
|
|
321
321
|
.refine(
|
|
322
|
-
|
|
322
|
+
data => {
|
|
323
323
|
if (data.appointmentStartTime && data.appointmentEndTime) {
|
|
324
324
|
return data.appointmentEndTime > data.appointmentStartTime;
|
|
325
325
|
}
|
|
@@ -342,7 +342,7 @@ export const searchAppointmentsSchema = z
|
|
|
342
342
|
startDate: z
|
|
343
343
|
.any()
|
|
344
344
|
.refine(
|
|
345
|
-
|
|
345
|
+
val =>
|
|
346
346
|
val === undefined ||
|
|
347
347
|
val instanceof Date ||
|
|
348
348
|
val?._seconds !== undefined ||
|
|
@@ -356,7 +356,7 @@ export const searchAppointmentsSchema = z
|
|
|
356
356
|
endDate: z
|
|
357
357
|
.any()
|
|
358
358
|
.refine(
|
|
359
|
-
|
|
359
|
+
val =>
|
|
360
360
|
val === undefined ||
|
|
361
361
|
val instanceof Date ||
|
|
362
362
|
val?._seconds !== undefined ||
|
|
@@ -374,7 +374,7 @@ export const searchAppointmentsSchema = z
|
|
|
374
374
|
startAfter: z.any().optional(),
|
|
375
375
|
})
|
|
376
376
|
.refine(
|
|
377
|
-
|
|
377
|
+
data => {
|
|
378
378
|
if (!data.startDate && !data.endDate && !data.status) {
|
|
379
379
|
return !!(data.patientId || data.practitionerId || data.clinicBranchId);
|
|
380
380
|
}
|
|
@@ -387,7 +387,7 @@ export const searchAppointmentsSchema = z
|
|
|
387
387
|
},
|
|
388
388
|
)
|
|
389
389
|
.refine(
|
|
390
|
-
|
|
390
|
+
data => {
|
|
391
391
|
if (data.startDate && data.endDate) {
|
|
392
392
|
return data.endDate >= data.startDate;
|
|
393
393
|
}
|
|
@@ -407,7 +407,7 @@ export const rescheduleAppointmentSchema = z.object({
|
|
|
407
407
|
newStartTime: z
|
|
408
408
|
.any()
|
|
409
409
|
.refine(
|
|
410
|
-
|
|
410
|
+
val =>
|
|
411
411
|
val instanceof Date ||
|
|
412
412
|
val?._seconds !== undefined ||
|
|
413
413
|
val?.seconds !== undefined ||
|
|
@@ -419,7 +419,7 @@ export const rescheduleAppointmentSchema = z.object({
|
|
|
419
419
|
newEndTime: z
|
|
420
420
|
.any()
|
|
421
421
|
.refine(
|
|
422
|
-
|
|
422
|
+
val =>
|
|
423
423
|
val instanceof Date ||
|
|
424
424
|
val?._seconds !== undefined ||
|
|
425
425
|
val?.seconds !== undefined ||
|
|
@@ -429,3 +429,23 @@ export const rescheduleAppointmentSchema = z.object({
|
|
|
429
429
|
'New end time must be a valid timestamp, Date object, number, or string',
|
|
430
430
|
),
|
|
431
431
|
});
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Schema for validating zone photo upload data
|
|
435
|
+
*/
|
|
436
|
+
export const zonePhotoUploadSchema = z.object({
|
|
437
|
+
appointmentId: z.string().min(MIN_STRING_LENGTH, 'Appointment ID is required'),
|
|
438
|
+
zoneId: z.string().min(MIN_STRING_LENGTH, 'Zone ID is required'),
|
|
439
|
+
photoType: z.enum(['before', 'after'], {
|
|
440
|
+
required_error: 'Photo type must be either "before" or "after"',
|
|
441
|
+
}),
|
|
442
|
+
file: z.any().refine(file => {
|
|
443
|
+
// Check if it's a File or Blob object
|
|
444
|
+
return (
|
|
445
|
+
file instanceof File ||
|
|
446
|
+
file instanceof Blob ||
|
|
447
|
+
(file && typeof file.size === 'number' && typeof file.type === 'string')
|
|
448
|
+
);
|
|
449
|
+
}, 'File must be a valid File or Blob object'),
|
|
450
|
+
notes: z.string().max(MAX_STRING_LENGTH_LONG, 'Notes too long').optional(),
|
|
451
|
+
});
|