@blackcode_sa/metaestetics-api 1.4.6 → 1.4.8
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 +402 -69
- package/dist/index.mjs +402 -69
- package/package.json +1 -1
- package/src/services/auth.service.ts +161 -29
- package/src/services/clinic/utils/admin.utils.ts +155 -34
- package/src/services/clinic/utils/clinic-group.utils.ts +109 -12
|
@@ -59,24 +59,75 @@ export async function createClinicGroup(
|
|
|
59
59
|
isDefault: boolean = false,
|
|
60
60
|
clinicAdminService: any
|
|
61
61
|
): Promise<ClinicGroup> {
|
|
62
|
+
console.log("[CLINIC_GROUP] Starting clinic group creation", {
|
|
63
|
+
ownerId,
|
|
64
|
+
isDefault,
|
|
65
|
+
});
|
|
66
|
+
console.log("[CLINIC_GROUP] Input data:", JSON.stringify(data, null, 2));
|
|
67
|
+
|
|
62
68
|
// Validacija podataka
|
|
69
|
+
try {
|
|
70
|
+
const validatedData = createClinicGroupSchema.parse(data);
|
|
71
|
+
console.log("[CLINIC_GROUP] Data validation passed");
|
|
72
|
+
} catch (validationError) {
|
|
73
|
+
console.error("[CLINIC_GROUP] Data validation failed:", validationError);
|
|
74
|
+
throw validationError;
|
|
75
|
+
}
|
|
76
|
+
|
|
63
77
|
const validatedData = createClinicGroupSchema.parse(data);
|
|
64
78
|
|
|
65
79
|
// Proveravamo da li owner postoji i da li je clinic admin
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
80
|
+
try {
|
|
81
|
+
console.log("[CLINIC_GROUP] Checking if owner exists", { ownerId });
|
|
82
|
+
// Skip owner verification for default groups since the admin profile doesn't exist yet
|
|
83
|
+
if (isDefault) {
|
|
84
|
+
console.log(
|
|
85
|
+
"[CLINIC_GROUP] Skipping owner verification for default group creation"
|
|
86
|
+
);
|
|
87
|
+
} else {
|
|
88
|
+
const owner = await clinicAdminService.getClinicAdmin(ownerId);
|
|
89
|
+
if (!owner) {
|
|
90
|
+
console.error(
|
|
91
|
+
"[CLINIC_GROUP] Owner not found or is not a clinic admin",
|
|
92
|
+
{
|
|
93
|
+
ownerId,
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
throw new Error("Owner not found or is not a clinic admin");
|
|
97
|
+
}
|
|
98
|
+
console.log("[CLINIC_GROUP] Owner verified as clinic admin");
|
|
99
|
+
}
|
|
100
|
+
} catch (ownerError) {
|
|
101
|
+
console.error("[CLINIC_GROUP] Error verifying owner:", ownerError);
|
|
102
|
+
throw ownerError;
|
|
69
103
|
}
|
|
70
104
|
|
|
71
105
|
// Generišemo geohash za lokaciju
|
|
106
|
+
console.log("[CLINIC_GROUP] Generating geohash for location");
|
|
72
107
|
if (validatedData.hqLocation) {
|
|
73
|
-
|
|
74
|
-
validatedData.hqLocation.
|
|
75
|
-
|
|
76
|
-
|
|
108
|
+
try {
|
|
109
|
+
validatedData.hqLocation.geohash = geohashForLocation([
|
|
110
|
+
validatedData.hqLocation.latitude,
|
|
111
|
+
validatedData.hqLocation.longitude,
|
|
112
|
+
]);
|
|
113
|
+
console.log("[CLINIC_GROUP] Geohash generated successfully", {
|
|
114
|
+
geohash: validatedData.hqLocation.geohash,
|
|
115
|
+
});
|
|
116
|
+
} catch (geohashError) {
|
|
117
|
+
console.error("[CLINIC_GROUP] Error generating geohash:", geohashError);
|
|
118
|
+
throw geohashError;
|
|
119
|
+
}
|
|
77
120
|
}
|
|
78
121
|
|
|
79
122
|
const now = Timestamp.now();
|
|
123
|
+
console.log("[CLINIC_GROUP] Preparing clinic group data object");
|
|
124
|
+
|
|
125
|
+
// Log the logo value to debug null vs undefined issue
|
|
126
|
+
console.log("[CLINIC_GROUP] Logo value:", {
|
|
127
|
+
logoValue: validatedData.logo,
|
|
128
|
+
logoType: validatedData.logo === null ? "null" : typeof validatedData.logo,
|
|
129
|
+
});
|
|
130
|
+
|
|
80
131
|
const groupData: ClinicGroup = {
|
|
81
132
|
...validatedData,
|
|
82
133
|
id: doc(collection(db, CLINIC_GROUPS_COLLECTION)).id,
|
|
@@ -107,22 +158,68 @@ export async function createClinicGroup(
|
|
|
107
158
|
|
|
108
159
|
try {
|
|
109
160
|
// Validiramo kompletan objekat
|
|
110
|
-
|
|
161
|
+
console.log("[CLINIC_GROUP] Validating complete clinic group object");
|
|
162
|
+
try {
|
|
163
|
+
clinicGroupSchema.parse(groupData);
|
|
164
|
+
console.log("[CLINIC_GROUP] Clinic group validation passed");
|
|
165
|
+
} catch (schemaError) {
|
|
166
|
+
console.error(
|
|
167
|
+
"[CLINIC_GROUP] Clinic group validation failed:",
|
|
168
|
+
JSON.stringify(schemaError, null, 2)
|
|
169
|
+
);
|
|
170
|
+
throw schemaError;
|
|
171
|
+
}
|
|
111
172
|
|
|
112
173
|
// Čuvamo u Firestore
|
|
113
|
-
|
|
174
|
+
console.log("[CLINIC_GROUP] Saving clinic group to Firestore", {
|
|
175
|
+
groupId: groupData.id,
|
|
176
|
+
});
|
|
177
|
+
try {
|
|
178
|
+
await setDoc(doc(db, CLINIC_GROUPS_COLLECTION, groupData.id), groupData);
|
|
179
|
+
console.log("[CLINIC_GROUP] Clinic group saved successfully");
|
|
180
|
+
} catch (firestoreError) {
|
|
181
|
+
console.error(
|
|
182
|
+
"[CLINIC_GROUP] Error saving to Firestore:",
|
|
183
|
+
firestoreError
|
|
184
|
+
);
|
|
185
|
+
throw firestoreError;
|
|
186
|
+
}
|
|
114
187
|
|
|
115
188
|
// Ažuriramo clinic admin profil vlasnika
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
isGroupOwner: true,
|
|
189
|
+
console.log("[CLINIC_GROUP] Updating clinic admin profile for owner", {
|
|
190
|
+
ownerId,
|
|
119
191
|
});
|
|
192
|
+
try {
|
|
193
|
+
await clinicAdminService.updateClinicAdmin(ownerId, {
|
|
194
|
+
clinicGroupId: groupData.id,
|
|
195
|
+
isGroupOwner: true,
|
|
196
|
+
});
|
|
197
|
+
console.log("[CLINIC_GROUP] Clinic admin profile updated successfully");
|
|
198
|
+
} catch (updateError) {
|
|
199
|
+
console.error(
|
|
200
|
+
"[CLINIC_GROUP] Error updating clinic admin profile:",
|
|
201
|
+
updateError
|
|
202
|
+
);
|
|
203
|
+
throw updateError;
|
|
204
|
+
}
|
|
120
205
|
|
|
206
|
+
console.log("[CLINIC_GROUP] Clinic group creation completed successfully", {
|
|
207
|
+
groupId: groupData.id,
|
|
208
|
+
groupName: groupData.name,
|
|
209
|
+
});
|
|
121
210
|
return groupData;
|
|
122
211
|
} catch (error) {
|
|
123
212
|
if (error instanceof z.ZodError) {
|
|
213
|
+
console.error(
|
|
214
|
+
"[CLINIC_GROUP] Zod validation error:",
|
|
215
|
+
JSON.stringify(error.errors, null, 2)
|
|
216
|
+
);
|
|
124
217
|
throw new Error("Invalid clinic group data: " + error.message);
|
|
125
218
|
}
|
|
219
|
+
console.error(
|
|
220
|
+
"[CLINIC_GROUP] Unhandled error in createClinicGroup:",
|
|
221
|
+
error
|
|
222
|
+
);
|
|
126
223
|
throw error;
|
|
127
224
|
}
|
|
128
225
|
}
|