@timardex/cluemart-server-shared 1.0.158 → 1.0.160

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.cjs CHANGED
@@ -1710,7 +1710,7 @@ __export(index_exports, {
1710
1710
  findEventOrImportedMarketById: () => findEventOrImportedMarketById,
1711
1711
  locationGeoSchema: () => locationGeoSchema,
1712
1712
  locationsSchema: () => locationsSchema,
1713
- mongoose: () => import_mongoose32.default,
1713
+ mongoose: () => import_mongoose31.default,
1714
1714
  refundPolicySchema: () => refundPolicySchema,
1715
1715
  relationDatesSchema: () => relationDatesSchema,
1716
1716
  resourceRelationsSchema: () => resourceRelationsSchema,
@@ -8550,6 +8550,21 @@ var EVENT_LIST_ITEM = gql`
8550
8550
  ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
8551
8551
  ${RELATION_DATES_FRAGMENT}
8552
8552
  `;
8553
+ var UNREGISTERED_VENDOR_LIST_ITEM_FIELDS_FRAGMENT = gql`
8554
+ fragment UnregisteredVendorListItemFields on UnregisteredVendorListItemType {
8555
+ _id
8556
+ categoryIds
8557
+ email
8558
+ invitations {
8559
+ dateTime {
8560
+ ...DateTimeFields
8561
+ }
8562
+ eventId
8563
+ }
8564
+ name
8565
+ }
8566
+ ${DATETIME_FIELDS_FRAGMENT}
8567
+ `;
8553
8568
  var EVENT_INFO = gql`
8554
8569
  fragment EventInfoFields on EventInfoType {
8555
8570
  _id
@@ -8638,10 +8653,11 @@ var EVENT = gql`
8638
8653
  }
8639
8654
  rating
8640
8655
  reviewCount
8656
+ rainOrShine
8657
+ unregisteredVendorIds
8641
8658
  socialMedia {
8642
8659
  ...SocialMediaFields
8643
8660
  }
8644
- rainOrShine
8645
8661
  tags
8646
8662
  termsAgreement {
8647
8663
  ...TermsAgreementFields
@@ -8872,23 +8888,19 @@ var VENDOR_INFO = gql`
8872
8888
  `;
8873
8889
  var UNREGISTERED_VENDOR_INVITATION_FRAGMENT = gql`
8874
8890
  fragment UnregisteredVendorInvitationFields on UnregisteredVendorInvitationType {
8875
- dateTime {
8876
- ...DateTimeFields
8877
- }
8878
- eventId
8879
- location {
8880
- ...LocationFields
8891
+ invitations {
8892
+ dateTime {
8893
+ ...DateTimeFields
8894
+ }
8895
+ eventId
8881
8896
  }
8882
8897
  }
8883
8898
  ${DATETIME_FIELDS_FRAGMENT}
8884
- ${LOCATION_FIELDS_FRAGMENT}
8885
8899
  `;
8886
8900
  var UNREGISTERED_VENDOR = gql`
8887
8901
  fragment UnregisteredVendorFields on UnregisteredVendorType {
8888
8902
  _id
8889
- categories {
8890
- ...CategoryFields
8891
- }
8903
+ categoryIds
8892
8904
  createdAt
8893
8905
  deletedAt
8894
8906
  email
@@ -8896,10 +8908,8 @@ var UNREGISTERED_VENDOR = gql`
8896
8908
  ...UnregisteredVendorInvitationFields
8897
8909
  }
8898
8910
  name
8899
- region
8900
8911
  updatedAt
8901
8912
  }
8902
- ${CATEGORY_FIELDS_FRAGMENT}
8903
8913
  ${UNREGISTERED_VENDOR_INVITATION_FRAGMENT}
8904
8914
  `;
8905
8915
  var GET_VENDORS = gql`
@@ -10365,10 +10375,20 @@ var SCHOOL_REGISTERED_USERS_FIELDS_FRAGMENT = gql`
10365
10375
  }
10366
10376
  ${RESOURCE_IMAGE_FIELDS_FRAGMENT}
10367
10377
  `;
10378
+ var SCHOOL_CAMPAIGN_FIELDS_FRAGMENT = gql`
10379
+ fragment SchoolCampaignFields on SchoolCampaignType {
10380
+ endDate
10381
+ name
10382
+ startDate
10383
+ }
10384
+ `;
10368
10385
  var SCHOOL = gql`
10369
10386
  fragment SchoolFields on SchoolType {
10370
10387
  _id
10371
10388
  active
10389
+ campaigns {
10390
+ ...SchoolCampaignFields
10391
+ }
10372
10392
  contactDetails {
10373
10393
  ...ContactDetailsFields
10374
10394
  }
@@ -10403,6 +10423,7 @@ var SCHOOL = gql`
10403
10423
  ${CONTACT_DETAILS_FIELDS_FRAGMENT}
10404
10424
  ${TERMS_AGREEMENT_FIELDS_FRAGMENT}
10405
10425
  ${SOCIAL_MEDIA_FIELDS_FRAGMENT}
10426
+ ${SCHOOL_CAMPAIGN_FIELDS_FRAGMENT}
10406
10427
  `;
10407
10428
  var GET_SCHOOL = gql`
10408
10429
  query getSchool($_id: ID!) {
@@ -10745,17 +10766,9 @@ var vendorSchema = globalResourceSchema.shape({
10745
10766
  vendorType: create$8().oneOf(Object.values(EnumVendorType)).required("Please select a Vendor type")
10746
10767
  });
10747
10768
  var unregisteredVendorSchema = create$3().shape({
10748
- categories: categorySchema.min(1, "Category list must contain at least one item").required("Categories are required"),
10749
- email: emailRequiredSchema,
10750
- invitations: create$2().of(
10751
- create$3({
10752
- dateTime: create$2().of(dateTimeSchema).required("DateTime is required"),
10753
- eventId: create$6().required("Event ID is required"),
10754
- location: locationSchema
10755
- })
10756
- ).nullable().default(null),
10757
- name: create$6().label("Name").trim().min(3).max(40).required("Name is required"),
10758
- region: create$6().label("Region").required("Region is required")
10769
+ categoryIds: create$2().of(create$6().defined()).min(1, "Category list must contain at least one item").required("Categories are required"),
10770
+ email: emailOptionalSchema,
10771
+ name: create$6().label("Stallholder Name").trim().min(3, "Name must be at least 3 characters").required("Name is required")
10759
10772
  });
10760
10773
  var vendorInfoSchema = create$3().shape({
10761
10774
  product: create$3().shape({
@@ -11094,7 +11107,12 @@ var posterIds = [
11094
11107
  "mini-market5",
11095
11108
  "poster1",
11096
11109
  "poster2",
11097
- "poster3"
11110
+ "poster3",
11111
+ // New
11112
+ "poster4",
11113
+ "poster5",
11114
+ "poster6",
11115
+ "poster7"
11098
11116
  ];
11099
11117
  var posterFiles = Object.fromEntries(
11100
11118
  posterIds.map((id) => [id, `${id}${IMAGE_EXTENSION}`])
@@ -12584,10 +12602,19 @@ var GameModel = import_mongoose22.default.models.Game || import_mongoose22.defau
12584
12602
  // src/mongoose/School.ts
12585
12603
  var import_mongoose23 = __toESM(require("mongoose"));
12586
12604
  var MongooseSchema23 = import_mongoose23.default.Schema;
12605
+ var campaignsSchema = new MongooseSchema23(
12606
+ {
12607
+ endDate: { required: true, type: Date },
12608
+ name: { required: true, type: String },
12609
+ startDate: { required: true, type: Date }
12610
+ },
12611
+ { _id: false }
12612
+ );
12587
12613
  var schema15 = new MongooseSchema23(
12588
12614
  {
12589
12615
  // New schools are active by default
12590
12616
  active: { default: true, required: true, type: Boolean },
12617
+ campaigns: { required: false, type: [campaignsSchema] },
12591
12618
  contactDetails: { required: false, type: ContactDetailsSchema },
12592
12619
  deletedAt: { default: null, required: false, type: Date },
12593
12620
  location: {
@@ -12803,9 +12830,6 @@ async function updateAdStatuses() {
12803
12830
  );
12804
12831
  }
12805
12832
 
12806
- // src/service/vendor.ts
12807
- var import_mongoose28 = __toESM(require("mongoose"));
12808
-
12809
12833
  // src/service/associate.ts
12810
12834
  var import_mongoose26 = __toESM(require("mongoose"));
12811
12835
  async function removeAssociateFromResource({
@@ -12813,11 +12837,9 @@ async function removeAssociateFromResource({
12813
12837
  resourceOwnerId,
12814
12838
  resourceType
12815
12839
  }) {
12816
- const normalizedResourceId = resourceId.toString();
12817
- const normalizedOwnerId = typeof resourceOwnerId === "string" ? new import_mongoose26.default.Types.ObjectId(resourceOwnerId) : resourceOwnerId;
12818
- const session = await import_mongoose26.default.startSession();
12819
12840
  try {
12820
- session.startTransaction();
12841
+ const normalizedResourceId = resourceId.toString();
12842
+ const normalizedOwnerId = typeof resourceOwnerId === "string" ? new import_mongoose26.default.Types.ObjectId(resourceOwnerId) : resourceOwnerId;
12821
12843
  const usersWithAssociates = await UserModel.find(
12822
12844
  {
12823
12845
  associates: {
@@ -12829,16 +12851,18 @@ async function removeAssociateFromResource({
12829
12851
  },
12830
12852
  {
12831
12853
  associates: 1
12832
- // Only fetch associates field for efficiency
12833
12854
  }
12834
- ).lean().session(session);
12835
- const associateEmails = usersWithAssociates.flatMap(
12836
- (user) => (user.associates ?? []).filter(
12837
- (assoc) => assoc.resourceId === normalizedResourceId && assoc.resourceType === resourceType
12838
- ).map((assoc) => assoc.email)
12839
- );
12855
+ ).lean();
12856
+ const associateEmails = [
12857
+ ...new Set(
12858
+ usersWithAssociates.flatMap(
12859
+ (user) => (user.associates ?? []).filter(
12860
+ (associate) => associate.resourceId === normalizedResourceId && associate.resourceType === resourceType
12861
+ ).map((associate) => associate.email)
12862
+ )
12863
+ )
12864
+ ];
12840
12865
  if (associateEmails.length === 0) {
12841
- await session.commitTransaction();
12842
12866
  return;
12843
12867
  }
12844
12868
  await UserModel.updateMany(
@@ -12857,8 +12881,7 @@ async function removeAssociateFromResource({
12857
12881
  resourceType
12858
12882
  }
12859
12883
  }
12860
- },
12861
- { session }
12884
+ }
12862
12885
  );
12863
12886
  await ChatModel.updateMany(
12864
12887
  {
@@ -12873,103 +12896,83 @@ async function removeAssociateFromResource({
12873
12896
  },
12874
12897
  {
12875
12898
  $set: {
12876
- "participants.$[assoc].active": false
12899
+ "participants.$[associate].active": false
12877
12900
  }
12878
12901
  },
12879
12902
  {
12880
12903
  arrayFilters: [
12881
12904
  {
12882
- "assoc.isAssociate": true,
12883
- "assoc.userEmail": { $in: associateEmails }
12905
+ "associate.isAssociate": true,
12906
+ "associate.userEmail": {
12907
+ $in: associateEmails
12908
+ }
12884
12909
  }
12885
- ],
12886
- session
12910
+ ]
12887
12911
  }
12888
12912
  );
12889
- await session.commitTransaction();
12890
12913
  } catch (error) {
12891
- await session.abortTransaction();
12892
12914
  console.error(
12893
- `[removeAssociateFromResource] Failed for resourceId=${normalizedResourceId}, resourceType=${resourceType}`,
12915
+ `[removeAssociateFromResource] Failed for resourceId=${resourceId}, resourceType=${resourceType}`,
12894
12916
  error
12895
12917
  );
12896
- throw error;
12897
- } finally {
12898
- session.endSession();
12899
12918
  }
12900
12919
  }
12901
12920
 
12902
12921
  // src/service/vendor.ts
12903
12922
  async function updateVendorBasedOnUserLicense(userId, licenceType) {
12904
- const session = await import_mongoose28.default.startSession();
12905
12923
  try {
12906
- session.startTransaction();
12907
- const user = await UserModel.findById(userId).select("vendor").lean().session(session);
12924
+ const user = await UserModel.findById(userId).select("vendor").lean();
12908
12925
  if (!user?.vendor) {
12909
- console.warn(`[updateVendor] No vendor for userId=${userId}`);
12910
- await session.abortTransaction();
12926
+ console.warn(`[updateVendor] No vendor found for userId=${userId}`);
12911
12927
  return;
12912
12928
  }
12913
- const vendor = await VendorModel.findById(user.vendor).lean().session(session);
12929
+ const vendor = await VendorModel.findById(user.vendor).lean();
12914
12930
  if (!vendor) {
12915
12931
  console.warn(`[updateVendor] Vendor not found for id=${user.vendor}`);
12916
- await session.abortTransaction();
12917
12932
  return;
12918
12933
  }
12919
- const vendorUpdateData = {};
12920
- if (licenceType === EnumUserLicence.STANDARD_VENDOR) {
12921
- vendorUpdateData.associates = [];
12922
- vendorUpdateData.availability = {
12934
+ const updateData = {};
12935
+ const isStandardVendor = licenceType === EnumUserLicence.STANDARD_VENDOR;
12936
+ if (isStandardVendor) {
12937
+ updateData.associates = [];
12938
+ updateData.availability = {
12923
12939
  corporate: false,
12924
12940
  private: false,
12925
12941
  school: false
12926
12942
  };
12927
- vendorUpdateData.products = {
12943
+ updateData.products = {
12928
12944
  active: false,
12929
12945
  productsList: vendor.products?.productsList ?? []
12930
12946
  };
12931
- vendorUpdateData.calendar = {
12947
+ updateData.calendar = {
12932
12948
  active: false,
12933
12949
  calendarData: vendor.calendar?.calendarData ?? []
12934
12950
  };
12935
- vendorUpdateData.images = (vendor.images ?? []).map((img, index) => ({
12936
- ...img,
12937
- active: index < 6
12938
- }));
12939
- } else {
12940
- vendorUpdateData.images = (vendor.images ?? []).map((img) => ({
12941
- ...img,
12942
- active: true
12943
- }));
12944
12951
  }
12945
- await VendorModel.updateOne(
12946
- { _id: vendor._id },
12947
- { $set: vendorUpdateData },
12948
- { session }
12949
- );
12950
- if (licenceType === EnumUserLicence.STANDARD_VENDOR) {
12952
+ updateData.images = (vendor.images ?? []).map((image, index) => ({
12953
+ ...image,
12954
+ active: isStandardVendor ? index < 6 : true
12955
+ }));
12956
+ await VendorModel.updateOne({ _id: vendor._id }, { $set: updateData });
12957
+ if (isStandardVendor) {
12951
12958
  await removeAssociateFromResource({
12952
12959
  resourceId: vendor._id,
12953
12960
  resourceOwnerId: vendor.owner.userId,
12954
12961
  resourceType: EnumResourceType.VENDOR
12955
12962
  });
12956
12963
  }
12957
- await session.commitTransaction();
12958
12964
  } catch (error) {
12959
- await session.abortTransaction();
12960
12965
  console.error("[updateVendorBasedOnUserLicense] Failed:", error);
12961
- } finally {
12962
- session.endSession();
12963
12966
  }
12964
12967
  }
12965
12968
 
12966
12969
  // src/service/objectIdToString.ts
12967
- var import_mongoose30 = __toESM(require("mongoose"));
12970
+ var import_mongoose29 = __toESM(require("mongoose"));
12968
12971
  function convertObjectIdsToStrings(obj) {
12969
12972
  if (obj === null || obj === void 0) {
12970
12973
  return obj;
12971
12974
  }
12972
- if (obj instanceof import_mongoose30.default.Types.ObjectId) {
12975
+ if (obj instanceof import_mongoose29.default.Types.ObjectId) {
12973
12976
  return obj.toString();
12974
12977
  }
12975
12978
  if (Array.isArray(obj)) {
@@ -13000,7 +13003,7 @@ async function findEventOrImportedMarketById(resourceId) {
13000
13003
 
13001
13004
  // src/types/index.ts
13002
13005
  var import_express = __toESM(require("express"));
13003
- var import_mongoose32 = __toESM(require("mongoose"));
13006
+ var import_mongoose31 = __toESM(require("mongoose"));
13004
13007
  var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
13005
13008
  EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
13006
13009
  EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";