@timardex/cluemart-server-shared 1.0.162 → 1.0.164

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.
@@ -36,7 +36,7 @@ import {
36
36
  resourceRelationsSchema,
37
37
  termsAgreementSchema,
38
38
  userLicenseSchema
39
- } from "../chunk-N2SOT77G.mjs";
39
+ } from "../chunk-RGSAG3WZ.mjs";
40
40
  import "../chunk-3QS3WKRC.mjs";
41
41
  export {
42
42
  APP_SETTINGS_ID,
@@ -12451,7 +12451,8 @@ var schema11 = new MongooseSchema15(
12451
12451
  required: false,
12452
12452
  type: [resourceRelationsSchema]
12453
12453
  },
12454
- tags: { required: true, type: [String] }
12454
+ tags: { required: true, type: [String] },
12455
+ unregisteredVendorIds: { default: [], required: false, type: [String] }
12455
12456
  },
12456
12457
  { timestamps: true }
12457
12458
  );
@@ -12805,83 +12806,101 @@ async function updateAdStatuses() {
12805
12806
 
12806
12807
  // src/service/associate.ts
12807
12808
  var import_mongoose26 = __toESM(require("mongoose"));
12808
- async function removeAssociateFromResource({
12809
- resourceId,
12810
- resourceOwnerId,
12809
+ function normalizeObjectId(id) {
12810
+ return typeof id === "string" ? new import_mongoose26.default.Types.ObjectId(id) : id;
12811
+ }
12812
+ async function getAssociateEmailsForResource({
12813
+ normalizedResourceId,
12811
12814
  resourceType
12812
12815
  }) {
12813
- try {
12814
- const normalizedResourceId = resourceId.toString();
12815
- const normalizedOwnerId = typeof resourceOwnerId === "string" ? new import_mongoose26.default.Types.ObjectId(resourceOwnerId) : resourceOwnerId;
12816
- const usersWithAssociates = await UserModel.find(
12817
- {
12818
- associates: {
12819
- $elemMatch: {
12820
- resourceId: normalizedResourceId,
12821
- resourceType
12822
- }
12816
+ const usersWithAssociates = await UserModel.find(
12817
+ {
12818
+ associates: {
12819
+ $elemMatch: {
12820
+ resourceId: normalizedResourceId,
12821
+ resourceType
12823
12822
  }
12824
- },
12825
- {
12826
- associates: 1
12827
- }
12828
- ).lean();
12829
- const associateEmails = [
12830
- ...new Set(
12831
- usersWithAssociates.flatMap(
12832
- (user) => (user.associates ?? []).filter(
12833
- (associate) => associate.resourceId === normalizedResourceId && associate.resourceType === resourceType
12834
- ).map((associate) => associate.email)
12835
- )
12823
+ }
12824
+ },
12825
+ {
12826
+ associates: 1
12827
+ }
12828
+ ).lean();
12829
+ return [
12830
+ ...new Set(
12831
+ usersWithAssociates.flatMap(
12832
+ (user) => (user.associates ?? []).filter(
12833
+ (associate) => associate.resourceId === normalizedResourceId && associate.resourceType === resourceType
12834
+ ).map((associate) => associate.email)
12836
12835
  )
12837
- ];
12838
- if (associateEmails.length === 0) {
12839
- return;
12840
- }
12841
- await UserModel.updateMany(
12842
- {
12836
+ )
12837
+ ];
12838
+ }
12839
+ async function pullAssociatesFromUsers({
12840
+ normalizedResourceId,
12841
+ resourceType
12842
+ }) {
12843
+ await UserModel.updateMany(
12844
+ {
12845
+ associates: {
12846
+ $elemMatch: {
12847
+ resourceId: normalizedResourceId,
12848
+ resourceType
12849
+ }
12850
+ }
12851
+ },
12852
+ {
12853
+ $pull: {
12843
12854
  associates: {
12844
- $elemMatch: {
12845
- resourceId: normalizedResourceId,
12846
- resourceType
12847
- }
12855
+ resourceId: normalizedResourceId,
12856
+ resourceType
12848
12857
  }
12849
- },
12850
- {
12851
- $pull: {
12852
- associates: {
12853
- resourceId: normalizedResourceId,
12854
- resourceType
12855
- }
12858
+ }
12859
+ }
12860
+ );
12861
+ }
12862
+ async function pullAssociateParticipantsFromChats(resourceOwnerId, associateEmails) {
12863
+ await ChatModel.updateMany(
12864
+ {
12865
+ active: true,
12866
+ chatType: EnumChatType.RELATION,
12867
+ deletedAt: null,
12868
+ participants: {
12869
+ $elemMatch: {
12870
+ userId: resourceOwnerId
12856
12871
  }
12857
12872
  }
12858
- );
12859
- await ChatModel.updateMany(
12860
- {
12861
- active: true,
12862
- chatType: EnumChatType.RELATION,
12863
- deletedAt: null,
12873
+ },
12874
+ {
12875
+ $pull: {
12864
12876
  participants: {
12865
- $elemMatch: {
12866
- userId: normalizedOwnerId
12877
+ isAssociate: true,
12878
+ userEmail: {
12879
+ $in: associateEmails
12867
12880
  }
12868
12881
  }
12869
- },
12870
- {
12871
- $set: {
12872
- "participants.$[associate].active": false
12873
- }
12874
- },
12875
- {
12876
- arrayFilters: [
12877
- {
12878
- "associate.isAssociate": true,
12879
- "associate.userEmail": {
12880
- $in: associateEmails
12881
- }
12882
- }
12883
- ]
12884
12882
  }
12883
+ }
12884
+ );
12885
+ }
12886
+ async function removeAssociateFromResource({
12887
+ resourceId,
12888
+ resourceOwnerId,
12889
+ resourceType
12890
+ }) {
12891
+ try {
12892
+ const scope = {
12893
+ normalizedResourceId: resourceId.toString(),
12894
+ resourceType
12895
+ };
12896
+ const associateEmails = await getAssociateEmailsForResource(scope);
12897
+ if (associateEmails.length === 0) {
12898
+ return;
12899
+ }
12900
+ await pullAssociatesFromUsers(scope);
12901
+ await pullAssociateParticipantsFromChats(
12902
+ normalizeObjectId(resourceOwnerId),
12903
+ associateEmails
12885
12904
  );
12886
12905
  } catch (error) {
12887
12906
  console.error(