@blackcode_sa/metaestetics-api 1.7.21 → 1.7.22

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.
@@ -4468,32 +4468,21 @@ var FilledFormsAggregationService = class {
4468
4468
  );
4469
4469
  }
4470
4470
  let updateData = {};
4471
- let existingFormIndex = -1;
4471
+ let updatedLinkedForms = [];
4472
4472
  if (appointment.linkedForms && appointment.linkedForms.length > 0) {
4473
- existingFormIndex = appointment.linkedForms.findIndex(
4474
- (form) => form.formId === filledDocument.id
4473
+ updatedLinkedForms = appointment.linkedForms.filter(
4474
+ (form) => form.formId !== filledDocument.id
4475
4475
  );
4476
4476
  }
4477
- if (existingFormIndex >= 0 && appointment.linkedForms) {
4478
- updateData = {
4479
- linkedForms: admin11.firestore.FieldValue.arrayRemove(
4480
- appointment.linkedForms[existingFormIndex]
4481
- ),
4482
- updatedAt: admin11.firestore.FieldValue.serverTimestamp()
4483
- };
4484
- await appointmentRef.update(updateData);
4485
- updateData = {
4486
- linkedForms: admin11.firestore.FieldValue.arrayUnion(linkedFormInfo),
4487
- updatedAt: admin11.firestore.FieldValue.serverTimestamp()
4488
- };
4489
- } else {
4490
- updateData = {
4491
- linkedForms: appointment.linkedForms ? admin11.firestore.FieldValue.arrayUnion(linkedFormInfo) : [linkedFormInfo],
4492
- // If linkedForms doesn't exist, create a new array
4493
- linkedFormIds: appointment.linkedFormIds ? admin11.firestore.FieldValue.arrayUnion(filledDocument.id) : [filledDocument.id],
4494
- // If linkedFormIds doesn't exist, create a new array
4495
- updatedAt: admin11.firestore.FieldValue.serverTimestamp()
4496
- };
4477
+ updatedLinkedForms.push(linkedFormInfo);
4478
+ updateData = {
4479
+ linkedForms: updatedLinkedForms,
4480
+ updatedAt: admin11.firestore.FieldValue.serverTimestamp()
4481
+ };
4482
+ let updatedLinkedFormIds = appointment.linkedFormIds || [];
4483
+ if (!updatedLinkedFormIds.includes(filledDocument.id)) {
4484
+ updatedLinkedFormIds.push(filledDocument.id);
4485
+ updateData.linkedFormIds = updatedLinkedFormIds;
4497
4486
  }
4498
4487
  if (filledDocument.isUserForm && filledDocument.isRequired && (filledDocument.status === "completed" /* COMPLETED */ || filledDocument.status === "signed" /* SIGNED */)) {
4499
4488
  if (appointment.pendingUserFormsIds && appointment.pendingUserFormsIds.includes(filledDocument.id)) {
@@ -4411,32 +4411,21 @@ var FilledFormsAggregationService = class {
4411
4411
  );
4412
4412
  }
4413
4413
  let updateData = {};
4414
- let existingFormIndex = -1;
4414
+ let updatedLinkedForms = [];
4415
4415
  if (appointment.linkedForms && appointment.linkedForms.length > 0) {
4416
- existingFormIndex = appointment.linkedForms.findIndex(
4417
- (form) => form.formId === filledDocument.id
4416
+ updatedLinkedForms = appointment.linkedForms.filter(
4417
+ (form) => form.formId !== filledDocument.id
4418
4418
  );
4419
4419
  }
4420
- if (existingFormIndex >= 0 && appointment.linkedForms) {
4421
- updateData = {
4422
- linkedForms: admin11.firestore.FieldValue.arrayRemove(
4423
- appointment.linkedForms[existingFormIndex]
4424
- ),
4425
- updatedAt: admin11.firestore.FieldValue.serverTimestamp()
4426
- };
4427
- await appointmentRef.update(updateData);
4428
- updateData = {
4429
- linkedForms: admin11.firestore.FieldValue.arrayUnion(linkedFormInfo),
4430
- updatedAt: admin11.firestore.FieldValue.serverTimestamp()
4431
- };
4432
- } else {
4433
- updateData = {
4434
- linkedForms: appointment.linkedForms ? admin11.firestore.FieldValue.arrayUnion(linkedFormInfo) : [linkedFormInfo],
4435
- // If linkedForms doesn't exist, create a new array
4436
- linkedFormIds: appointment.linkedFormIds ? admin11.firestore.FieldValue.arrayUnion(filledDocument.id) : [filledDocument.id],
4437
- // If linkedFormIds doesn't exist, create a new array
4438
- updatedAt: admin11.firestore.FieldValue.serverTimestamp()
4439
- };
4420
+ updatedLinkedForms.push(linkedFormInfo);
4421
+ updateData = {
4422
+ linkedForms: updatedLinkedForms,
4423
+ updatedAt: admin11.firestore.FieldValue.serverTimestamp()
4424
+ };
4425
+ let updatedLinkedFormIds = appointment.linkedFormIds || [];
4426
+ if (!updatedLinkedFormIds.includes(filledDocument.id)) {
4427
+ updatedLinkedFormIds.push(filledDocument.id);
4428
+ updateData.linkedFormIds = updatedLinkedFormIds;
4440
4429
  }
4441
4430
  if (filledDocument.isUserForm && filledDocument.isRequired && (filledDocument.status === "completed" /* COMPLETED */ || filledDocument.status === "signed" /* SIGNED */)) {
4442
4431
  if (appointment.pendingUserFormsIds && appointment.pendingUserFormsIds.includes(filledDocument.id)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.7.21",
4
+ "version": "1.7.22",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -94,45 +94,31 @@ export class FilledFormsAggregationService {
94
94
  ) as unknown as Timestamp;
95
95
  }
96
96
 
97
- // 3. Check if the appointment already has linkedForms array and this form is in it
97
+ // 3. Handle linkedForms array - use direct array manipulation to avoid arrayRemove issues
98
98
  let updateData: any = {};
99
- let existingFormIndex = -1;
99
+ let updatedLinkedForms: LinkedFormInfo[] = [];
100
100
 
101
101
  if (appointment.linkedForms && appointment.linkedForms.length > 0) {
102
- existingFormIndex = appointment.linkedForms.findIndex(
103
- (form) => form.formId === filledDocument.id
102
+ // Filter out any existing entries for this form ID to prevent duplicates
103
+ updatedLinkedForms = appointment.linkedForms.filter(
104
+ (form) => form.formId !== filledDocument.id
104
105
  );
105
106
  }
106
107
 
107
- // 4. Update the appointment with the new/updated LinkedFormInfo
108
- if (existingFormIndex >= 0 && appointment.linkedForms) {
109
- // Form exists, update it using arrayRemove + arrayUnion
110
- updateData = {
111
- linkedForms: admin.firestore.FieldValue.arrayRemove(
112
- appointment.linkedForms[existingFormIndex]
113
- ),
114
- updatedAt: admin.firestore.FieldValue.serverTimestamp(),
115
- };
116
-
117
- // First remove the old form info
118
- await appointmentRef.update(updateData);
108
+ // Add the new/updated form info
109
+ updatedLinkedForms.push(linkedFormInfo);
119
110
 
120
- // Then add the updated form info
121
- updateData = {
122
- linkedForms: admin.firestore.FieldValue.arrayUnion(linkedFormInfo),
123
- updatedAt: admin.firestore.FieldValue.serverTimestamp(),
124
- };
125
- } else {
126
- // Form doesn't exist, add it to the array or create the array
127
- updateData = {
128
- linkedForms: appointment.linkedForms
129
- ? admin.firestore.FieldValue.arrayUnion(linkedFormInfo)
130
- : [linkedFormInfo], // If linkedForms doesn't exist, create a new array
131
- linkedFormIds: appointment.linkedFormIds
132
- ? admin.firestore.FieldValue.arrayUnion(filledDocument.id)
133
- : [filledDocument.id], // If linkedFormIds doesn't exist, create a new array
134
- updatedAt: admin.firestore.FieldValue.serverTimestamp(),
135
- };
111
+ // Prepare the update data
112
+ updateData = {
113
+ linkedForms: updatedLinkedForms,
114
+ updatedAt: admin.firestore.FieldValue.serverTimestamp(),
115
+ };
116
+
117
+ // 4. Handle linkedFormIds array
118
+ let updatedLinkedFormIds: string[] = appointment.linkedFormIds || [];
119
+ if (!updatedLinkedFormIds.includes(filledDocument.id)) {
120
+ updatedLinkedFormIds.push(filledDocument.id);
121
+ updateData.linkedFormIds = updatedLinkedFormIds;
136
122
  }
137
123
 
138
124
  // 5. Handle pendingUserFormsIds for required user forms