@blackcode_sa/metaestetics-api 1.4.7 → 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 CHANGED
@@ -3781,14 +3781,23 @@ async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdm
3781
3781
  const validatedData = createClinicGroupSchema.parse(data);
3782
3782
  try {
3783
3783
  console.log("[CLINIC_GROUP] Checking if owner exists", { ownerId });
3784
- const owner = await clinicAdminService.getClinicAdmin(ownerId);
3785
- if (!owner) {
3786
- console.error("[CLINIC_GROUP] Owner not found or is not a clinic admin", {
3787
- ownerId
3788
- });
3789
- throw new Error("Owner not found or is not a clinic admin");
3784
+ if (isDefault) {
3785
+ console.log(
3786
+ "[CLINIC_GROUP] Skipping owner verification for default group creation"
3787
+ );
3788
+ } else {
3789
+ const owner = await clinicAdminService.getClinicAdmin(ownerId);
3790
+ if (!owner) {
3791
+ console.error(
3792
+ "[CLINIC_GROUP] Owner not found or is not a clinic admin",
3793
+ {
3794
+ ownerId
3795
+ }
3796
+ );
3797
+ throw new Error("Owner not found or is not a clinic admin");
3798
+ }
3799
+ console.log("[CLINIC_GROUP] Owner verified as clinic admin");
3790
3800
  }
3791
- console.log("[CLINIC_GROUP] Owner verified as clinic admin");
3792
3801
  } catch (ownerError) {
3793
3802
  console.error("[CLINIC_GROUP] Error verifying owner:", ownerError);
3794
3803
  throw ownerError;
@@ -4759,6 +4768,25 @@ var AuthService = class extends BaseService {
4759
4768
  "Clinic group data is required when creating a new group"
4760
4769
  );
4761
4770
  }
4771
+ console.log("[AUTH] Creating clinic admin first");
4772
+ const createClinicAdminData = {
4773
+ userRef: firebaseUser.uid,
4774
+ isGroupOwner: true,
4775
+ clinicsManaged: [],
4776
+ contactInfo: contactPerson,
4777
+ roleTitle: data.title,
4778
+ isActive: true
4779
+ };
4780
+ try {
4781
+ await clinicAdminService.createClinicAdmin(createClinicAdminData);
4782
+ console.log("[AUTH] Clinic admin created successfully");
4783
+ } catch (adminCreationError) {
4784
+ console.error(
4785
+ "[AUTH] Clinic admin creation failed:",
4786
+ adminCreationError
4787
+ );
4788
+ throw adminCreationError;
4789
+ }
4762
4790
  const createClinicGroupData = {
4763
4791
  name: data.clinicGroupData.name,
4764
4792
  hqLocation: data.clinicGroupData.hqLocation,
package/dist/index.mjs CHANGED
@@ -3731,14 +3731,23 @@ async function createClinicGroup(db, data, ownerId, isDefault = false, clinicAdm
3731
3731
  const validatedData = createClinicGroupSchema.parse(data);
3732
3732
  try {
3733
3733
  console.log("[CLINIC_GROUP] Checking if owner exists", { ownerId });
3734
- const owner = await clinicAdminService.getClinicAdmin(ownerId);
3735
- if (!owner) {
3736
- console.error("[CLINIC_GROUP] Owner not found or is not a clinic admin", {
3737
- ownerId
3738
- });
3739
- throw new Error("Owner not found or is not a clinic admin");
3734
+ if (isDefault) {
3735
+ console.log(
3736
+ "[CLINIC_GROUP] Skipping owner verification for default group creation"
3737
+ );
3738
+ } else {
3739
+ const owner = await clinicAdminService.getClinicAdmin(ownerId);
3740
+ if (!owner) {
3741
+ console.error(
3742
+ "[CLINIC_GROUP] Owner not found or is not a clinic admin",
3743
+ {
3744
+ ownerId
3745
+ }
3746
+ );
3747
+ throw new Error("Owner not found or is not a clinic admin");
3748
+ }
3749
+ console.log("[CLINIC_GROUP] Owner verified as clinic admin");
3740
3750
  }
3741
- console.log("[CLINIC_GROUP] Owner verified as clinic admin");
3742
3751
  } catch (ownerError) {
3743
3752
  console.error("[CLINIC_GROUP] Error verifying owner:", ownerError);
3744
3753
  throw ownerError;
@@ -4729,6 +4738,25 @@ var AuthService = class extends BaseService {
4729
4738
  "Clinic group data is required when creating a new group"
4730
4739
  );
4731
4740
  }
4741
+ console.log("[AUTH] Creating clinic admin first");
4742
+ const createClinicAdminData = {
4743
+ userRef: firebaseUser.uid,
4744
+ isGroupOwner: true,
4745
+ clinicsManaged: [],
4746
+ contactInfo: contactPerson,
4747
+ roleTitle: data.title,
4748
+ isActive: true
4749
+ };
4750
+ try {
4751
+ await clinicAdminService.createClinicAdmin(createClinicAdminData);
4752
+ console.log("[AUTH] Clinic admin created successfully");
4753
+ } catch (adminCreationError) {
4754
+ console.error(
4755
+ "[AUTH] Clinic admin creation failed:",
4756
+ adminCreationError
4757
+ );
4758
+ throw adminCreationError;
4759
+ }
4732
4760
  const createClinicGroupData = {
4733
4761
  name: data.clinicGroupData.name,
4734
4762
  hqLocation: data.clinicGroupData.hqLocation,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackcode_sa/metaestetics-api",
3
3
  "private": false,
4
- "version": "1.4.7",
4
+ "version": "1.4.8",
5
5
  "description": "Firebase authentication service with anonymous upgrade support",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -208,7 +208,29 @@ export class AuthService extends BaseService {
208
208
  );
209
209
  }
210
210
 
211
- // Create clinic group
211
+ // First create the clinic admin
212
+ console.log("[AUTH] Creating clinic admin first");
213
+ const createClinicAdminData: CreateClinicAdminData = {
214
+ userRef: firebaseUser.uid,
215
+ isGroupOwner: true,
216
+ clinicsManaged: [],
217
+ contactInfo: contactPerson,
218
+ roleTitle: data.title,
219
+ isActive: true,
220
+ };
221
+
222
+ try {
223
+ await clinicAdminService.createClinicAdmin(createClinicAdminData);
224
+ console.log("[AUTH] Clinic admin created successfully");
225
+ } catch (adminCreationError) {
226
+ console.error(
227
+ "[AUTH] Clinic admin creation failed:",
228
+ adminCreationError
229
+ );
230
+ throw adminCreationError;
231
+ }
232
+
233
+ // Then create clinic group
212
234
  const createClinicGroupData: CreateClinicGroupData = {
213
235
  name: data.clinicGroupData.name,
214
236
  hqLocation: data.clinicGroupData.hqLocation,
@@ -79,14 +79,24 @@ export async function createClinicGroup(
79
79
  // Proveravamo da li owner postoji i da li je clinic admin
80
80
  try {
81
81
  console.log("[CLINIC_GROUP] Checking if owner exists", { ownerId });
82
- const owner = await clinicAdminService.getClinicAdmin(ownerId);
83
- if (!owner) {
84
- console.error("[CLINIC_GROUP] Owner not found or is not a clinic admin", {
85
- ownerId,
86
- });
87
- throw new Error("Owner not found or is not a clinic admin");
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");
88
99
  }
89
- console.log("[CLINIC_GROUP] Owner verified as clinic admin");
90
100
  } catch (ownerError) {
91
101
  console.error("[CLINIC_GROUP] Error verifying owner:", ownerError);
92
102
  throw ownerError;