@timardex/cluemart-server-shared 1.0.158 → 1.0.159

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.d.mts CHANGED
@@ -694,16 +694,6 @@ declare function sendPushNotifications({ data, message, title, userIds, }: Schem
694
694
  */
695
695
  declare function updateAdStatuses(): Promise<void>;
696
696
 
697
- /**
698
- *
699
- * This function updates the vendor's features based on the user's license.
700
- * It checks the type of license and updates the vendor's associates and availability accordingly.
701
- * If the user has a Pro Vendor license, they can have multiple associates and access to all availability types.
702
- * If they have a Standard Vendor license, their associates are removed and availability is restricted.
703
- * @param userId
704
- * @param licenceType
705
- * @returns
706
- */
707
697
  declare function updateVendorBasedOnUserLicense(userId: ObjectId, licenceType: EnumUserLicence): Promise<void>;
708
698
 
709
699
  /**
package/dist/index.d.ts CHANGED
@@ -694,16 +694,6 @@ declare function sendPushNotifications({ data, message, title, userIds, }: Schem
694
694
  */
695
695
  declare function updateAdStatuses(): Promise<void>;
696
696
 
697
- /**
698
- *
699
- * This function updates the vendor's features based on the user's license.
700
- * It checks the type of license and updates the vendor's associates and availability accordingly.
701
- * If the user has a Pro Vendor license, they can have multiple associates and access to all availability types.
702
- * If they have a Standard Vendor license, their associates are removed and availability is restricted.
703
- * @param userId
704
- * @param licenceType
705
- * @returns
706
- */
707
697
  declare function updateVendorBasedOnUserLicense(userId: ObjectId, licenceType: EnumUserLicence): Promise<void>;
708
698
 
709
699
  /**
package/dist/index.mjs CHANGED
@@ -12744,9 +12744,6 @@ async function updateAdStatuses() {
12744
12744
  );
12745
12745
  }
12746
12746
 
12747
- // src/service/vendor.ts
12748
- import mongoose26 from "mongoose";
12749
-
12750
12747
  // src/service/associate.ts
12751
12748
  import mongoose25 from "mongoose";
12752
12749
  async function removeAssociateFromResource({
@@ -12754,11 +12751,9 @@ async function removeAssociateFromResource({
12754
12751
  resourceOwnerId,
12755
12752
  resourceType
12756
12753
  }) {
12757
- const normalizedResourceId = resourceId.toString();
12758
- const normalizedOwnerId = typeof resourceOwnerId === "string" ? new mongoose25.Types.ObjectId(resourceOwnerId) : resourceOwnerId;
12759
- const session = await mongoose25.startSession();
12760
12754
  try {
12761
- session.startTransaction();
12755
+ const normalizedResourceId = resourceId.toString();
12756
+ const normalizedOwnerId = typeof resourceOwnerId === "string" ? new mongoose25.Types.ObjectId(resourceOwnerId) : resourceOwnerId;
12762
12757
  const usersWithAssociates = await UserModel.find(
12763
12758
  {
12764
12759
  associates: {
@@ -12770,16 +12765,18 @@ async function removeAssociateFromResource({
12770
12765
  },
12771
12766
  {
12772
12767
  associates: 1
12773
- // Only fetch associates field for efficiency
12774
12768
  }
12775
- ).lean().session(session);
12776
- const associateEmails = usersWithAssociates.flatMap(
12777
- (user) => (user.associates ?? []).filter(
12778
- (assoc) => assoc.resourceId === normalizedResourceId && assoc.resourceType === resourceType
12779
- ).map((assoc) => assoc.email)
12780
- );
12769
+ ).lean();
12770
+ const associateEmails = [
12771
+ ...new Set(
12772
+ usersWithAssociates.flatMap(
12773
+ (user) => (user.associates ?? []).filter(
12774
+ (associate) => associate.resourceId === normalizedResourceId && associate.resourceType === resourceType
12775
+ ).map((associate) => associate.email)
12776
+ )
12777
+ )
12778
+ ];
12781
12779
  if (associateEmails.length === 0) {
12782
- await session.commitTransaction();
12783
12780
  return;
12784
12781
  }
12785
12782
  await UserModel.updateMany(
@@ -12798,8 +12795,7 @@ async function removeAssociateFromResource({
12798
12795
  resourceType
12799
12796
  }
12800
12797
  }
12801
- },
12802
- { session }
12798
+ }
12803
12799
  );
12804
12800
  await ChatModel.updateMany(
12805
12801
  {
@@ -12814,103 +12810,83 @@ async function removeAssociateFromResource({
12814
12810
  },
12815
12811
  {
12816
12812
  $set: {
12817
- "participants.$[assoc].active": false
12813
+ "participants.$[associate].active": false
12818
12814
  }
12819
12815
  },
12820
12816
  {
12821
12817
  arrayFilters: [
12822
12818
  {
12823
- "assoc.isAssociate": true,
12824
- "assoc.userEmail": { $in: associateEmails }
12819
+ "associate.isAssociate": true,
12820
+ "associate.userEmail": {
12821
+ $in: associateEmails
12822
+ }
12825
12823
  }
12826
- ],
12827
- session
12824
+ ]
12828
12825
  }
12829
12826
  );
12830
- await session.commitTransaction();
12831
12827
  } catch (error) {
12832
- await session.abortTransaction();
12833
12828
  console.error(
12834
- `[removeAssociateFromResource] Failed for resourceId=${normalizedResourceId}, resourceType=${resourceType}`,
12829
+ `[removeAssociateFromResource] Failed for resourceId=${resourceId}, resourceType=${resourceType}`,
12835
12830
  error
12836
12831
  );
12837
- throw error;
12838
- } finally {
12839
- session.endSession();
12840
12832
  }
12841
12833
  }
12842
12834
 
12843
12835
  // src/service/vendor.ts
12844
12836
  async function updateVendorBasedOnUserLicense(userId, licenceType) {
12845
- const session = await mongoose26.startSession();
12846
12837
  try {
12847
- session.startTransaction();
12848
- const user = await UserModel.findById(userId).select("vendor").lean().session(session);
12838
+ const user = await UserModel.findById(userId).select("vendor").lean();
12849
12839
  if (!user?.vendor) {
12850
- console.warn(`[updateVendor] No vendor for userId=${userId}`);
12851
- await session.abortTransaction();
12840
+ console.warn(`[updateVendor] No vendor found for userId=${userId}`);
12852
12841
  return;
12853
12842
  }
12854
- const vendor = await VendorModel.findById(user.vendor).lean().session(session);
12843
+ const vendor = await VendorModel.findById(user.vendor).lean();
12855
12844
  if (!vendor) {
12856
12845
  console.warn(`[updateVendor] Vendor not found for id=${user.vendor}`);
12857
- await session.abortTransaction();
12858
12846
  return;
12859
12847
  }
12860
- const vendorUpdateData = {};
12861
- if (licenceType === EnumUserLicence.STANDARD_VENDOR) {
12862
- vendorUpdateData.associates = [];
12863
- vendorUpdateData.availability = {
12848
+ const updateData = {};
12849
+ const isStandardVendor = licenceType === EnumUserLicence.STANDARD_VENDOR;
12850
+ if (isStandardVendor) {
12851
+ updateData.associates = [];
12852
+ updateData.availability = {
12864
12853
  corporate: false,
12865
12854
  private: false,
12866
12855
  school: false
12867
12856
  };
12868
- vendorUpdateData.products = {
12857
+ updateData.products = {
12869
12858
  active: false,
12870
12859
  productsList: vendor.products?.productsList ?? []
12871
12860
  };
12872
- vendorUpdateData.calendar = {
12861
+ updateData.calendar = {
12873
12862
  active: false,
12874
12863
  calendarData: vendor.calendar?.calendarData ?? []
12875
12864
  };
12876
- vendorUpdateData.images = (vendor.images ?? []).map((img, index) => ({
12877
- ...img,
12878
- active: index < 6
12879
- }));
12880
- } else {
12881
- vendorUpdateData.images = (vendor.images ?? []).map((img) => ({
12882
- ...img,
12883
- active: true
12884
- }));
12885
12865
  }
12886
- await VendorModel.updateOne(
12887
- { _id: vendor._id },
12888
- { $set: vendorUpdateData },
12889
- { session }
12890
- );
12891
- if (licenceType === EnumUserLicence.STANDARD_VENDOR) {
12866
+ updateData.images = (vendor.images ?? []).map((image, index) => ({
12867
+ ...image,
12868
+ active: isStandardVendor ? index < 6 : true
12869
+ }));
12870
+ await VendorModel.updateOne({ _id: vendor._id }, { $set: updateData });
12871
+ if (isStandardVendor) {
12892
12872
  await removeAssociateFromResource({
12893
12873
  resourceId: vendor._id,
12894
12874
  resourceOwnerId: vendor.owner.userId,
12895
12875
  resourceType: EnumResourceType.VENDOR
12896
12876
  });
12897
12877
  }
12898
- await session.commitTransaction();
12899
12878
  } catch (error) {
12900
- await session.abortTransaction();
12901
12879
  console.error("[updateVendorBasedOnUserLicense] Failed:", error);
12902
- } finally {
12903
- session.endSession();
12904
12880
  }
12905
12881
  }
12906
12882
 
12907
12883
  // src/service/objectIdToString.ts
12908
- import mongoose27 from "mongoose";
12884
+ import mongoose26 from "mongoose";
12909
12885
  function convertObjectIdsToStrings(obj) {
12910
12886
  if (obj === null || obj === void 0) {
12911
12887
  return obj;
12912
12888
  }
12913
- if (obj instanceof mongoose27.Types.ObjectId) {
12889
+ if (obj instanceof mongoose26.Types.ObjectId) {
12914
12890
  return obj.toString();
12915
12891
  }
12916
12892
  if (Array.isArray(obj)) {
@@ -12941,7 +12917,7 @@ async function findEventOrImportedMarketById(resourceId) {
12941
12917
 
12942
12918
  // src/types/index.ts
12943
12919
  import express from "express";
12944
- import mongoose28 from "mongoose";
12920
+ import mongoose27 from "mongoose";
12945
12921
  var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
12946
12922
  EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
12947
12923
  EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
@@ -12987,7 +12963,7 @@ export {
12987
12963
  findEventOrImportedMarketById,
12988
12964
  locationGeoSchema,
12989
12965
  locationsSchema,
12990
- mongoose28 as mongoose,
12966
+ mongoose27 as mongoose,
12991
12967
  refundPolicySchema,
12992
12968
  relationDatesSchema,
12993
12969
  resourceRelationsSchema,