@blackcode_sa/metaestetics-api 1.12.39 → 1.12.40

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/index.js CHANGED
@@ -2337,8 +2337,40 @@ var AppointmentService = class extends BaseService {
2337
2337
  * @returns The updated appointment
2338
2338
  */
2339
2339
  async updateAppointment(appointmentId, data) {
2340
+ var _a, _b;
2340
2341
  try {
2341
2342
  console.log(`[APPOINTMENT_SERVICE] Updating appointment with ID: ${appointmentId}`);
2343
+ if ((_a = data.metadata) == null ? void 0 : _a.zonePhotos) {
2344
+ const migratedZonePhotos = {};
2345
+ for (const [key, value] of Object.entries(data.metadata.zonePhotos)) {
2346
+ if (Array.isArray(value)) {
2347
+ migratedZonePhotos[key] = value;
2348
+ } else {
2349
+ console.log(`[APPOINTMENT_SERVICE] Auto-migrating ${key} from object to array format`);
2350
+ const oldData = value;
2351
+ migratedZonePhotos[key] = [
2352
+ {
2353
+ before: oldData.before || null,
2354
+ after: oldData.after || null,
2355
+ beforeNote: null,
2356
+ afterNote: null
2357
+ }
2358
+ ];
2359
+ }
2360
+ }
2361
+ data.metadata.zonePhotos = migratedZonePhotos;
2362
+ }
2363
+ if (((_b = data.metadata) == null ? void 0 : _b.recommendedProcedures) && Array.isArray(data.metadata.recommendedProcedures)) {
2364
+ const validRecommendations = data.metadata.recommendedProcedures.filter(
2365
+ (rec) => rec.note && typeof rec.note === "string" && rec.note.trim().length > 0
2366
+ );
2367
+ if (validRecommendations.length !== data.metadata.recommendedProcedures.length) {
2368
+ console.log(
2369
+ `[APPOINTMENT_SERVICE] Removing ${data.metadata.recommendedProcedures.length - validRecommendations.length} invalid recommended procedures with empty notes`
2370
+ );
2371
+ data.metadata.recommendedProcedures = validRecommendations;
2372
+ }
2373
+ }
2342
2374
  const validatedData = await updateAppointmentSchema.parseAsync(data);
2343
2375
  const updatedAppointment = await updateAppointmentUtil(this.db, appointmentId, validatedData);
2344
2376
  console.log(`[APPOINTMENT_SERVICE] Appointment ${appointmentId} updated successfully`);
@@ -2977,7 +3009,25 @@ var AppointmentService = class extends BaseService {
2977
3009
  finalbilling: null,
2978
3010
  finalizationNotes: null
2979
3011
  };
2980
- const currentZonePhotos = currentMetadata.zonePhotos || {};
3012
+ let currentZonePhotos = {};
3013
+ if (currentMetadata.zonePhotos) {
3014
+ for (const [key, value] of Object.entries(currentMetadata.zonePhotos)) {
3015
+ if (Array.isArray(value)) {
3016
+ currentZonePhotos[key] = value;
3017
+ } else {
3018
+ console.log(`[APPOINTMENT_SERVICE] Auto-migrating ${key} from object to array format`);
3019
+ const oldData = value;
3020
+ currentZonePhotos[key] = [
3021
+ {
3022
+ before: oldData.before || null,
3023
+ after: oldData.after || null,
3024
+ beforeNote: null,
3025
+ afterNote: null
3026
+ }
3027
+ ];
3028
+ }
3029
+ }
3030
+ }
2981
3031
  if (!currentZonePhotos[zoneId]) {
2982
3032
  currentZonePhotos[zoneId] = [];
2983
3033
  }
@@ -3376,7 +3426,13 @@ var AppointmentService = class extends BaseService {
3376
3426
  console.log(
3377
3427
  `[APPOINTMENT_SERVICE] Adding recommended procedure ${procedureId} to appointment ${appointmentId}`
3378
3428
  );
3379
- return await addRecommendedProcedureUtil(this.db, appointmentId, procedureId, note, timeframe);
3429
+ return await addRecommendedProcedureUtil(
3430
+ this.db,
3431
+ appointmentId,
3432
+ procedureId,
3433
+ note,
3434
+ timeframe
3435
+ );
3380
3436
  } catch (error) {
3381
3437
  console.error(`[APPOINTMENT_SERVICE] Error adding recommended procedure:`, error);
3382
3438
  throw error;
@@ -3413,7 +3469,12 @@ var AppointmentService = class extends BaseService {
3413
3469
  console.log(
3414
3470
  `[APPOINTMENT_SERVICE] Updating recommended procedure at index ${recommendationIndex} in appointment ${appointmentId}`
3415
3471
  );
3416
- return await updateRecommendedProcedureUtil(this.db, appointmentId, recommendationIndex, updates);
3472
+ return await updateRecommendedProcedureUtil(
3473
+ this.db,
3474
+ appointmentId,
3475
+ recommendationIndex,
3476
+ updates
3477
+ );
3417
3478
  } catch (error) {
3418
3479
  console.error(`[APPOINTMENT_SERVICE] Error updating recommended procedure:`, error);
3419
3480
  throw error;
package/dist/index.mjs CHANGED
@@ -2236,8 +2236,40 @@ var AppointmentService = class extends BaseService {
2236
2236
  * @returns The updated appointment
2237
2237
  */
2238
2238
  async updateAppointment(appointmentId, data) {
2239
+ var _a, _b;
2239
2240
  try {
2240
2241
  console.log(`[APPOINTMENT_SERVICE] Updating appointment with ID: ${appointmentId}`);
2242
+ if ((_a = data.metadata) == null ? void 0 : _a.zonePhotos) {
2243
+ const migratedZonePhotos = {};
2244
+ for (const [key, value] of Object.entries(data.metadata.zonePhotos)) {
2245
+ if (Array.isArray(value)) {
2246
+ migratedZonePhotos[key] = value;
2247
+ } else {
2248
+ console.log(`[APPOINTMENT_SERVICE] Auto-migrating ${key} from object to array format`);
2249
+ const oldData = value;
2250
+ migratedZonePhotos[key] = [
2251
+ {
2252
+ before: oldData.before || null,
2253
+ after: oldData.after || null,
2254
+ beforeNote: null,
2255
+ afterNote: null
2256
+ }
2257
+ ];
2258
+ }
2259
+ }
2260
+ data.metadata.zonePhotos = migratedZonePhotos;
2261
+ }
2262
+ if (((_b = data.metadata) == null ? void 0 : _b.recommendedProcedures) && Array.isArray(data.metadata.recommendedProcedures)) {
2263
+ const validRecommendations = data.metadata.recommendedProcedures.filter(
2264
+ (rec) => rec.note && typeof rec.note === "string" && rec.note.trim().length > 0
2265
+ );
2266
+ if (validRecommendations.length !== data.metadata.recommendedProcedures.length) {
2267
+ console.log(
2268
+ `[APPOINTMENT_SERVICE] Removing ${data.metadata.recommendedProcedures.length - validRecommendations.length} invalid recommended procedures with empty notes`
2269
+ );
2270
+ data.metadata.recommendedProcedures = validRecommendations;
2271
+ }
2272
+ }
2241
2273
  const validatedData = await updateAppointmentSchema.parseAsync(data);
2242
2274
  const updatedAppointment = await updateAppointmentUtil(this.db, appointmentId, validatedData);
2243
2275
  console.log(`[APPOINTMENT_SERVICE] Appointment ${appointmentId} updated successfully`);
@@ -2876,7 +2908,25 @@ var AppointmentService = class extends BaseService {
2876
2908
  finalbilling: null,
2877
2909
  finalizationNotes: null
2878
2910
  };
2879
- const currentZonePhotos = currentMetadata.zonePhotos || {};
2911
+ let currentZonePhotos = {};
2912
+ if (currentMetadata.zonePhotos) {
2913
+ for (const [key, value] of Object.entries(currentMetadata.zonePhotos)) {
2914
+ if (Array.isArray(value)) {
2915
+ currentZonePhotos[key] = value;
2916
+ } else {
2917
+ console.log(`[APPOINTMENT_SERVICE] Auto-migrating ${key} from object to array format`);
2918
+ const oldData = value;
2919
+ currentZonePhotos[key] = [
2920
+ {
2921
+ before: oldData.before || null,
2922
+ after: oldData.after || null,
2923
+ beforeNote: null,
2924
+ afterNote: null
2925
+ }
2926
+ ];
2927
+ }
2928
+ }
2929
+ }
2880
2930
  if (!currentZonePhotos[zoneId]) {
2881
2931
  currentZonePhotos[zoneId] = [];
2882
2932
  }
@@ -3275,7 +3325,13 @@ var AppointmentService = class extends BaseService {
3275
3325
  console.log(
3276
3326
  `[APPOINTMENT_SERVICE] Adding recommended procedure ${procedureId} to appointment ${appointmentId}`
3277
3327
  );
3278
- return await addRecommendedProcedureUtil(this.db, appointmentId, procedureId, note, timeframe);
3328
+ return await addRecommendedProcedureUtil(
3329
+ this.db,
3330
+ appointmentId,
3331
+ procedureId,
3332
+ note,
3333
+ timeframe
3334
+ );
3279
3335
  } catch (error) {
3280
3336
  console.error(`[APPOINTMENT_SERVICE] Error adding recommended procedure:`, error);
3281
3337
  throw error;
@@ -3312,7 +3368,12 @@ var AppointmentService = class extends BaseService {
3312
3368
  console.log(
3313
3369
  `[APPOINTMENT_SERVICE] Updating recommended procedure at index ${recommendationIndex} in appointment ${appointmentId}`
3314
3370
  );
3315
- return await updateRecommendedProcedureUtil(this.db, appointmentId, recommendationIndex, updates);
3371
+ return await updateRecommendedProcedureUtil(
3372
+ this.db,
3373
+ appointmentId,
3374
+ recommendationIndex,
3375
+ updates
3376
+ );
3316
3377
  } catch (error) {
3317
3378
  console.error(`[APPOINTMENT_SERVICE] Error updating recommended procedure:`, error);
3318
3379
  throw error;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.12.39",
4
+ "version": "1.12.40",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -49,7 +49,12 @@ import { PatientService } from '../patient/patient.service';
49
49
  import { PractitionerService } from '../practitioner/practitioner.service';
50
50
  import { ClinicService } from '../clinic/clinic.service';
51
51
  import { FilledDocumentService } from '../documentation-templates/filled-document.service';
52
- import { MediaService, MediaAccessLevel, MediaMetadata, MediaResource } from '../media/media.service';
52
+ import {
53
+ MediaService,
54
+ MediaAccessLevel,
55
+ MediaMetadata,
56
+ MediaResource,
57
+ } from '../media/media.service';
53
58
 
54
59
  // Import utility functions
55
60
  import {
@@ -379,6 +384,46 @@ export class AppointmentService extends BaseService {
379
384
  try {
380
385
  console.log(`[APPOINTMENT_SERVICE] Updating appointment with ID: ${appointmentId}`);
381
386
 
387
+ // AUTO-MIGRATION: Convert old zonePhotos format to new array format BEFORE validation
388
+ if (data.metadata?.zonePhotos) {
389
+ const migratedZonePhotos: Record<string, BeforeAfterPerZone[]> = {};
390
+
391
+ for (const [key, value] of Object.entries(data.metadata.zonePhotos)) {
392
+ if (Array.isArray(value)) {
393
+ // Already in new format
394
+ migratedZonePhotos[key] = value as BeforeAfterPerZone[];
395
+ } else {
396
+ // Old format - convert to array
397
+ console.log(`[APPOINTMENT_SERVICE] Auto-migrating ${key} from object to array format`);
398
+ const oldData = value as any;
399
+ migratedZonePhotos[key] = [
400
+ {
401
+ before: oldData.before || null,
402
+ after: oldData.after || null,
403
+ beforeNote: null,
404
+ afterNote: null,
405
+ },
406
+ ];
407
+ }
408
+ }
409
+
410
+ // Replace with migrated data
411
+ data.metadata.zonePhotos = migratedZonePhotos;
412
+ }
413
+
414
+ // AUTO-CLEANUP: Remove invalid recommendedProcedures with empty notes BEFORE validation
415
+ if (data.metadata?.recommendedProcedures && Array.isArray(data.metadata.recommendedProcedures)) {
416
+ const validRecommendations = data.metadata.recommendedProcedures.filter(
417
+ (rec: any) => rec.note && typeof rec.note === 'string' && rec.note.trim().length > 0
418
+ );
419
+ if (validRecommendations.length !== data.metadata.recommendedProcedures.length) {
420
+ console.log(
421
+ `[APPOINTMENT_SERVICE] Removing ${data.metadata.recommendedProcedures.length - validRecommendations.length} invalid recommended procedures with empty notes`
422
+ );
423
+ data.metadata.recommendedProcedures = validRecommendations;
424
+ }
425
+ }
426
+
382
427
  // Validate input data
383
428
  const validatedData = await updateAppointmentSchema.parseAsync(data);
384
429
 
@@ -1294,8 +1339,29 @@ export class AppointmentService extends BaseService {
1294
1339
  };
1295
1340
 
1296
1341
  // Initialize zonePhotos if it doesn't exist (array model per zone)
1297
- const currentZonePhotos: Record<string, BeforeAfterPerZone[]> =
1298
- (currentMetadata.zonePhotos as Record<string, BeforeAfterPerZone[]>) || {};
1342
+ let currentZonePhotos: Record<string, BeforeAfterPerZone[]> = {};
1343
+
1344
+ // AUTO-MIGRATION: Convert old object format to new array format
1345
+ if (currentMetadata.zonePhotos) {
1346
+ for (const [key, value] of Object.entries(currentMetadata.zonePhotos)) {
1347
+ if (Array.isArray(value)) {
1348
+ // Already in new format
1349
+ currentZonePhotos[key] = value as BeforeAfterPerZone[];
1350
+ } else {
1351
+ // Old format - convert to array
1352
+ console.log(`[APPOINTMENT_SERVICE] Auto-migrating ${key} from object to array format`);
1353
+ const oldData = value as any;
1354
+ currentZonePhotos[key] = [
1355
+ {
1356
+ before: oldData.before || null,
1357
+ after: oldData.after || null,
1358
+ beforeNote: null,
1359
+ afterNote: null,
1360
+ },
1361
+ ];
1362
+ }
1363
+ }
1364
+ }
1299
1365
 
1300
1366
  // Initialize the zone array if it doesn't exist
1301
1367
  if (!currentZonePhotos[zoneId]) {
@@ -1306,8 +1372,8 @@ export class AppointmentService extends BaseService {
1306
1372
  const newEntry: BeforeAfterPerZone = {
1307
1373
  before: photoType === 'before' ? mediaMetadata.url : null,
1308
1374
  after: photoType === 'after' ? mediaMetadata.url : null,
1309
- beforeNote: photoType === 'before' ? (notes || null) : null,
1310
- afterNote: photoType === 'after' ? (notes || null) : null,
1375
+ beforeNote: photoType === 'before' ? notes || null : null,
1376
+ afterNote: photoType === 'after' ? notes || null : null,
1311
1377
  };
1312
1378
 
1313
1379
  // Append to the zone's photo list
@@ -1778,13 +1844,19 @@ export class AppointmentService extends BaseService {
1778
1844
  appointmentId: string,
1779
1845
  procedureId: string,
1780
1846
  note: string,
1781
- timeframe: { value: number; unit: 'day' | 'week' | 'month' | 'year' }
1847
+ timeframe: { value: number; unit: 'day' | 'week' | 'month' | 'year' },
1782
1848
  ): Promise<Appointment> {
1783
1849
  try {
1784
1850
  console.log(
1785
1851
  `[APPOINTMENT_SERVICE] Adding recommended procedure ${procedureId} to appointment ${appointmentId}`,
1786
1852
  );
1787
- return await addRecommendedProcedureUtil(this.db, appointmentId, procedureId, note, timeframe);
1853
+ return await addRecommendedProcedureUtil(
1854
+ this.db,
1855
+ appointmentId,
1856
+ procedureId,
1857
+ note,
1858
+ timeframe,
1859
+ );
1788
1860
  } catch (error) {
1789
1861
  console.error(`[APPOINTMENT_SERVICE] Error adding recommended procedure:`, error);
1790
1862
  throw error;
@@ -1798,7 +1870,10 @@ export class AppointmentService extends BaseService {
1798
1870
  * @param recommendationIndex Index of the recommendation to remove
1799
1871
  * @returns The updated appointment
1800
1872
  */
1801
- async removeRecommendedProcedure(appointmentId: string, recommendationIndex: number): Promise<Appointment> {
1873
+ async removeRecommendedProcedure(
1874
+ appointmentId: string,
1875
+ recommendationIndex: number,
1876
+ ): Promise<Appointment> {
1802
1877
  try {
1803
1878
  console.log(
1804
1879
  `[APPOINTMENT_SERVICE] Removing recommended procedure at index ${recommendationIndex} from appointment ${appointmentId}`,
@@ -1824,13 +1899,18 @@ export class AppointmentService extends BaseService {
1824
1899
  updates: {
1825
1900
  note?: string;
1826
1901
  timeframe?: { value: number; unit: 'day' | 'week' | 'month' | 'year' };
1827
- }
1902
+ },
1828
1903
  ): Promise<Appointment> {
1829
1904
  try {
1830
1905
  console.log(
1831
1906
  `[APPOINTMENT_SERVICE] Updating recommended procedure at index ${recommendationIndex} in appointment ${appointmentId}`,
1832
1907
  );
1833
- return await updateRecommendedProcedureUtil(this.db, appointmentId, recommendationIndex, updates);
1908
+ return await updateRecommendedProcedureUtil(
1909
+ this.db,
1910
+ appointmentId,
1911
+ recommendationIndex,
1912
+ updates,
1913
+ );
1834
1914
  } catch (error) {
1835
1915
  console.error(`[APPOINTMENT_SERVICE] Error updating recommended procedure:`, error);
1836
1916
  throw error;
@@ -1869,7 +1949,7 @@ export class AppointmentService extends BaseService {
1869
1949
  appointmentId: string,
1870
1950
  zoneId: string,
1871
1951
  photoIndex: number,
1872
- updates: Partial<BeforeAfterPerZone>
1952
+ updates: Partial<BeforeAfterPerZone>,
1873
1953
  ): Promise<Appointment> {
1874
1954
  try {
1875
1955
  console.log(
@@ -1897,7 +1977,7 @@ export class AppointmentService extends BaseService {
1897
1977
  zoneId: string,
1898
1978
  photoIndex: number,
1899
1979
  afterPhotoUrl: MediaResource,
1900
- afterNote?: string
1980
+ afterNote?: string,
1901
1981
  ): Promise<Appointment> {
1902
1982
  try {
1903
1983
  console.log(
@@ -1909,7 +1989,7 @@ export class AppointmentService extends BaseService {
1909
1989
  zoneId,
1910
1990
  photoIndex,
1911
1991
  afterPhotoUrl,
1912
- afterNote
1992
+ afterNote,
1913
1993
  );
1914
1994
  } catch (error) {
1915
1995
  console.error(`[APPOINTMENT_SERVICE] Error adding after photo to entry:`, error);
@@ -1932,7 +2012,7 @@ export class AppointmentService extends BaseService {
1932
2012
  zoneId: string,
1933
2013
  photoIndex: number,
1934
2014
  beforeNote?: string,
1935
- afterNote?: string
2015
+ afterNote?: string,
1936
2016
  ): Promise<Appointment> {
1937
2017
  try {
1938
2018
  console.log(
@@ -1944,7 +2024,7 @@ export class AppointmentService extends BaseService {
1944
2024
  zoneId,
1945
2025
  photoIndex,
1946
2026
  beforeNote,
1947
- afterNote
2027
+ afterNote,
1948
2028
  );
1949
2029
  } catch (error) {
1950
2030
  console.error(`[APPOINTMENT_SERVICE] Error updating zone photo notes:`, error);
@@ -1963,7 +2043,7 @@ export class AppointmentService extends BaseService {
1963
2043
  async getZonePhotoEntry(
1964
2044
  appointmentId: string,
1965
2045
  zoneId: string,
1966
- photoIndex: number
2046
+ photoIndex: number,
1967
2047
  ): Promise<BeforeAfterPerZone> {
1968
2048
  try {
1969
2049
  console.log(