@timardex/cluemart-server-shared 1.0.149 → 1.0.151

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
@@ -1687,7 +1687,6 @@ __export(index_exports, {
1687
1687
  GoogleImportedMarketModel: () => GoogleImportedMarketModel,
1688
1688
  NotificationModel: () => NotificationModel,
1689
1689
  OwnerTypeSchema: () => OwnerTypeSchema,
1690
- ParticipantSchema: () => ParticipantSchema,
1691
1690
  PartnerModel: () => PartnerModel,
1692
1691
  PostModel: () => PostModel,
1693
1692
  PushTokenModel: () => PushTokenModel,
@@ -1711,7 +1710,7 @@ __export(index_exports, {
1711
1710
  findEventOrImportedMarketById: () => findEventOrImportedMarketById,
1712
1711
  locationGeoSchema: () => locationGeoSchema,
1713
1712
  locationsSchema: () => locationsSchema,
1714
- mongoose: () => import_mongoose28.default,
1713
+ mongoose: () => import_mongoose32.default,
1715
1714
  refundPolicySchema: () => refundPolicySchema,
1716
1715
  relationDatesSchema: () => relationDatesSchema,
1717
1716
  resourceRelationsSchema: () => resourceRelationsSchema,
@@ -9049,6 +9048,7 @@ var CHAT_MESSAGE_FIELDS_FRAGMENT = gql`
9049
9048
  var CHAT_PARTICIPANT = gql`
9050
9049
  fragment ChatParticipantFields on ChatParticipantType {
9051
9050
  active
9051
+ isAssociate
9052
9052
  userAvatar
9053
9053
  userEmail
9054
9054
  userId
@@ -10027,6 +10027,41 @@ var DAILY_CLUE_GAME_DATA_FIELDS_FRAGMENT = gql`
10027
10027
  }
10028
10028
  ${DAILY_CLUE_BASE_GAME_FIELDS_FRAGMENT}
10029
10029
  `;
10030
+ var MINI_QUIZ_QUESTION_FIELDS_FRAGMENT = gql`
10031
+ fragment MiniQuizQuestionFields on MiniQuizQuestionType {
10032
+ answers {
10033
+ answer
10034
+ correct
10035
+ }
10036
+ question
10037
+ }
10038
+ `;
10039
+ var MINI_QUIZ_BASE_GAME_FIELDS_FRAGMENT = gql`
10040
+ fragment MiniQuizBaseGameFields on MiniQuizBaseGameType {
10041
+ gameDate {
10042
+ ...GameDateFields
10043
+ }
10044
+ questions {
10045
+ ...MiniQuizQuestionFields
10046
+ }
10047
+ }
10048
+ ${GAME_DATE_FIELDS_FRAGMENT}
10049
+ ${MINI_QUIZ_QUESTION_FIELDS_FRAGMENT}
10050
+ `;
10051
+ var MINI_QUIZ_GAME_DATA_FIELDS_FRAGMENT = gql`
10052
+ fragment MiniQuizGameDataFields on MiniQuizGameDataType {
10053
+ gameFields {
10054
+ ...MiniQuizBaseGameFields
10055
+ }
10056
+ quizInfo {
10057
+ ...MiniQuizQuestionFields
10058
+ }
10059
+ points
10060
+ streak
10061
+ }
10062
+ ${MINI_QUIZ_BASE_GAME_FIELDS_FRAGMENT}
10063
+ ${MINI_QUIZ_QUESTION_FIELDS_FRAGMENT}
10064
+ `;
10030
10065
  var GAME_HISTORY_FIELDS_FRAGMENT = gql`
10031
10066
  fragment GameHistoryFields on GameHistoryType {
10032
10067
  createdAt
@@ -10044,8 +10079,12 @@ var GAME_DATA_FIELDS_FRAGMENT = gql`
10044
10079
  dailyClue {
10045
10080
  ...DailyClueGameDataFields
10046
10081
  }
10082
+ miniQuiz {
10083
+ ...MiniQuizGameDataFields
10084
+ }
10047
10085
  }
10048
10086
  ${DAILY_CLUE_GAME_DATA_FIELDS_FRAGMENT}
10087
+ ${MINI_QUIZ_GAME_DATA_FIELDS_FRAGMENT}
10049
10088
  `;
10050
10089
  var GAME_FIELDS_FRAGMENT = gql`
10051
10090
  fragment GameFields on GameType {
@@ -10119,8 +10158,12 @@ var BASE_GAME_FIELDS_FRAGMENT = gql`
10119
10158
  dailyClue {
10120
10159
  ...DailyClueBaseGameFields
10121
10160
  }
10161
+ miniQuiz {
10162
+ ...MiniQuizBaseGameFields
10163
+ }
10122
10164
  }
10123
10165
  ${DAILY_CLUE_BASE_GAME_FIELDS_FRAGMENT}
10166
+ ${MINI_QUIZ_BASE_GAME_FIELDS_FRAGMENT}
10124
10167
  `;
10125
10168
  var POST_CONTENT_DATA_FIELDS_FRAGMENT = gql`
10126
10169
  fragment PostContentDataFields on PostContentData {
@@ -11117,6 +11160,7 @@ var EnumGameStatus = /* @__PURE__ */ ((EnumGameStatus2) => {
11117
11160
  })(EnumGameStatus || {});
11118
11161
  var EnumGameType = /* @__PURE__ */ ((EnumGameType2) => {
11119
11162
  EnumGameType2["DAILY_CLUE"] = "dailyClue";
11163
+ EnumGameType2["MINI_QUIZ"] = "miniQuiz";
11120
11164
  return EnumGameType2;
11121
11165
  })(EnumGameType || {});
11122
11166
 
@@ -11243,6 +11287,7 @@ var MessageSchema = new MongooseSchema2(
11243
11287
  var ParticipantSchema = new MongooseSchema2(
11244
11288
  {
11245
11289
  active: { default: true, required: true, type: Boolean },
11290
+ isAssociate: { default: null, required: false, type: Boolean },
11246
11291
  userAvatar: { required: false, type: String },
11247
11292
  userEmail: { required: true, type: String },
11248
11293
  userId: {
@@ -12361,6 +12406,9 @@ var AppSettingSchema = new MongooseSchema18(
12361
12406
  var AppSettingModel = import_mongoose18.default.models.AppSetting || import_mongoose18.default.model("AppSetting", AppSettingSchema);
12362
12407
 
12363
12408
  // src/mongoose/game/Game.ts
12409
+ var import_mongoose22 = __toESM(require("mongoose"));
12410
+
12411
+ // src/mongoose/game/DailyClue.ts
12364
12412
  var import_mongoose20 = __toESM(require("mongoose"));
12365
12413
 
12366
12414
  // src/mongoose/game/utils.ts
@@ -12373,7 +12421,10 @@ var schemaGameDate = new MongooseSchema19(
12373
12421
  },
12374
12422
  { _id: false }
12375
12423
  );
12376
- var schemaLetters = new MongooseSchema19(
12424
+
12425
+ // src/mongoose/game/DailyClue.ts
12426
+ var MongooseSchema20 = import_mongoose20.default.Schema;
12427
+ var schemaLetters = new MongooseSchema20(
12377
12428
  {
12378
12429
  collected: { required: false, type: [String] },
12379
12430
  solutionShuffled: { required: true, type: [String] }
@@ -12381,14 +12432,14 @@ var schemaLetters = new MongooseSchema19(
12381
12432
  },
12382
12433
  { _id: false }
12383
12434
  );
12384
- var schemaDailyClueBaseGame = new MongooseSchema19(
12435
+ var schemaDailyClueBaseGame = new MongooseSchema20(
12385
12436
  {
12386
12437
  gameDate: { required: true, type: schemaGameDate },
12387
12438
  gameSolution: { required: true, type: String }
12388
12439
  },
12389
12440
  { _id: false }
12390
12441
  );
12391
- var schemaDailyClueGameData = new MongooseSchema19(
12442
+ var schemaDailyClueGameData = new MongooseSchema20(
12392
12443
  {
12393
12444
  gameFields: { required: true, type: schemaDailyClueBaseGame },
12394
12445
  lastFoundDate: { default: null, required: false, type: Date },
@@ -12402,10 +12453,49 @@ var schemaDailyClueGameData = new MongooseSchema19(
12402
12453
  { _id: false }
12403
12454
  );
12404
12455
 
12456
+ // src/mongoose/game/MiniQuiz.ts
12457
+ var import_mongoose21 = __toESM(require("mongoose"));
12458
+ var MongooseSchema21 = import_mongoose21.default.Schema;
12459
+ var schemaMiniQuizAnswers = new MongooseSchema21(
12460
+ {
12461
+ answer: { required: true, type: String },
12462
+ correct: { required: true, type: Boolean }
12463
+ },
12464
+ { _id: false }
12465
+ );
12466
+ var schemaMiniQuizQuestions = new MongooseSchema21(
12467
+ {
12468
+ answers: { required: true, type: [schemaMiniQuizAnswers] },
12469
+ question: { required: true, type: String }
12470
+ },
12471
+ { _id: false }
12472
+ );
12473
+ var schemaMiniQuizBaseGame = new MongooseSchema21(
12474
+ {
12475
+ gameDate: { required: true, type: Date },
12476
+ questions: { required: true, type: [schemaMiniQuizQuestions] }
12477
+ },
12478
+ { _id: false }
12479
+ );
12480
+ var schemaMiniQuizGameData = new MongooseSchema21(
12481
+ {
12482
+ gameFields: { required: true, type: schemaMiniQuizBaseGame },
12483
+ points: { default: 0, required: true, type: Number },
12484
+ quizInfo: {
12485
+ default: null,
12486
+ required: false,
12487
+ type: [schemaMiniQuizQuestions]
12488
+ },
12489
+ streak: { default: 0, required: true, type: Number }
12490
+ },
12491
+ { _id: false }
12492
+ );
12493
+
12405
12494
  // src/mongoose/game/Game.ts
12406
- var MongooseSchema20 = import_mongoose20.default.Schema;
12495
+ var MongooseSchema22 = import_mongoose22.default.Schema;
12407
12496
  var gameDataSchemas = {
12408
- [EnumGameType.DAILY_CLUE]: schemaDailyClueGameData
12497
+ [EnumGameType.DAILY_CLUE]: schemaDailyClueGameData,
12498
+ [EnumGameType.MINI_QUIZ]: schemaMiniQuizGameData
12409
12499
  };
12410
12500
  var gameDataDefinition = Object.fromEntries(
12411
12501
  Object.entries(gameDataSchemas).map(([key, schema16]) => [
@@ -12413,7 +12503,7 @@ var gameDataDefinition = Object.fromEntries(
12413
12503
  { default: null, required: false, type: schema16 }
12414
12504
  ])
12415
12505
  );
12416
- var gameHistorySchema = new MongooseSchema20(
12506
+ var gameHistorySchema = new MongooseSchema22(
12417
12507
  {
12418
12508
  createdAt: { required: true, type: Date },
12419
12509
  gameDate: { required: true, type: schemaGameDate },
@@ -12431,7 +12521,7 @@ var gameHistorySchema = new MongooseSchema20(
12431
12521
  },
12432
12522
  { _id: false }
12433
12523
  );
12434
- var gameTypeSchema = new MongooseSchema20(
12524
+ var gameTypeSchema = new MongooseSchema22(
12435
12525
  {
12436
12526
  active: { default: true, required: true, type: Boolean },
12437
12527
  gameData: gameDataDefinition,
@@ -12444,7 +12534,7 @@ var gameTypeSchema = new MongooseSchema20(
12444
12534
  },
12445
12535
  { timestamps: true }
12446
12536
  );
12447
- var schema14 = new MongooseSchema20(
12537
+ var schema14 = new MongooseSchema22(
12448
12538
  {
12449
12539
  active: { default: false, required: true, type: Boolean },
12450
12540
  deletedAt: { default: null, required: false, type: Date },
@@ -12457,12 +12547,12 @@ var schema14 = new MongooseSchema20(
12457
12547
  },
12458
12548
  { timestamps: true }
12459
12549
  );
12460
- var GameModel = import_mongoose20.default.models.Game || import_mongoose20.default.model("Game", schema14);
12550
+ var GameModel = import_mongoose22.default.models.Game || import_mongoose22.default.model("Game", schema14);
12461
12551
 
12462
12552
  // src/mongoose/School.ts
12463
- var import_mongoose21 = __toESM(require("mongoose"));
12464
- var MongooseSchema21 = import_mongoose21.default.Schema;
12465
- var schema15 = new MongooseSchema21(
12553
+ var import_mongoose23 = __toESM(require("mongoose"));
12554
+ var MongooseSchema23 = import_mongoose23.default.Schema;
12555
+ var schema15 = new MongooseSchema23(
12466
12556
  {
12467
12557
  // New schools are active by default
12468
12558
  active: { default: true, required: true, type: Boolean },
@@ -12487,10 +12577,10 @@ var schema15 = new MongooseSchema21(
12487
12577
  },
12488
12578
  { timestamps: true }
12489
12579
  );
12490
- var SchoolModel = import_mongoose21.default.models.School || import_mongoose21.default.model("School", schema15);
12580
+ var SchoolModel = import_mongoose23.default.models.School || import_mongoose23.default.model("School", schema15);
12491
12581
 
12492
12582
  // src/service/database.ts
12493
- var import_mongoose22 = __toESM(require("mongoose"));
12583
+ var import_mongoose24 = __toESM(require("mongoose"));
12494
12584
  var connectToDatabase = async ({
12495
12585
  appName,
12496
12586
  dbName,
@@ -12503,7 +12593,7 @@ var connectToDatabase = async ({
12503
12593
  // Fallback to MongoDB Atlas connection string
12504
12594
  `mongodb+srv://${dbUser}:${dbPassword}@${dbName}.mongodb.net/?retryWrites=true&w=majority&appName=${appName}`
12505
12595
  );
12506
- await import_mongoose22.default.connect(mongoUri);
12596
+ await import_mongoose24.default.connect(mongoUri);
12507
12597
  const connectionType = mongodbUri ? "Local MongoDB" : "MongoDB Atlas";
12508
12598
  console.log(
12509
12599
  `${connectionType} connected from server/src/service/database.ts`
@@ -12681,10 +12771,44 @@ async function updateAdStatuses() {
12681
12771
  );
12682
12772
  }
12683
12773
 
12774
+ // src/service/vendor.ts
12775
+ var import_mongoose28 = __toESM(require("mongoose"));
12776
+
12684
12777
  // src/service/associate.ts
12685
- async function removeAssociateFromResource(resourceId, resourceType) {
12778
+ var import_mongoose26 = __toESM(require("mongoose"));
12779
+ async function removeAssociateFromResource({
12780
+ resourceId,
12781
+ resourceOwnerId,
12782
+ resourceType
12783
+ }) {
12686
12784
  const normalizedResourceId = resourceId.toString();
12785
+ const normalizedOwnerId = typeof resourceOwnerId === "string" ? new import_mongoose26.default.Types.ObjectId(resourceOwnerId) : resourceOwnerId;
12786
+ const session = await import_mongoose26.default.startSession();
12687
12787
  try {
12788
+ session.startTransaction();
12789
+ const usersWithAssociates = await UserModel.find(
12790
+ {
12791
+ associates: {
12792
+ $elemMatch: {
12793
+ resourceId: normalizedResourceId,
12794
+ resourceType
12795
+ }
12796
+ }
12797
+ },
12798
+ {
12799
+ associates: 1
12800
+ // Only fetch associates field for efficiency
12801
+ }
12802
+ ).lean().session(session);
12803
+ const associateEmails = usersWithAssociates.flatMap(
12804
+ (user) => (user.associates ?? []).filter(
12805
+ (assoc) => assoc.resourceId === normalizedResourceId && assoc.resourceType === resourceType
12806
+ ).map((assoc) => assoc.email)
12807
+ );
12808
+ if (associateEmails.length === 0) {
12809
+ await session.commitTransaction();
12810
+ return;
12811
+ }
12688
12812
  await UserModel.updateMany(
12689
12813
  {
12690
12814
  associates: {
@@ -12701,34 +12825,67 @@ async function removeAssociateFromResource(resourceId, resourceType) {
12701
12825
  resourceType
12702
12826
  }
12703
12827
  }
12828
+ },
12829
+ { session }
12830
+ );
12831
+ await ChatModel.updateMany(
12832
+ {
12833
+ active: true,
12834
+ chatType: EnumChatType.RELATION,
12835
+ deletedAt: null,
12836
+ participants: {
12837
+ $elemMatch: {
12838
+ userId: normalizedOwnerId
12839
+ }
12840
+ }
12841
+ },
12842
+ {
12843
+ $set: {
12844
+ "participants.$[assoc].active": false
12845
+ }
12846
+ },
12847
+ {
12848
+ arrayFilters: [
12849
+ {
12850
+ "assoc.isAssociate": true,
12851
+ "assoc.userEmail": { $in: associateEmails }
12852
+ }
12853
+ ],
12854
+ session
12704
12855
  }
12705
- ).exec();
12856
+ );
12857
+ await session.commitTransaction();
12706
12858
  } catch (error) {
12859
+ await session.abortTransaction();
12707
12860
  console.error(
12708
- `[removeAssociateFromResource] Failed to remove associates for resourceId=${normalizedResourceId}, resourceType=${resourceType}`,
12861
+ `[removeAssociateFromResource] Failed for resourceId=${normalizedResourceId}, resourceType=${resourceType}`,
12709
12862
  error
12710
12863
  );
12711
12864
  throw error;
12865
+ } finally {
12866
+ session.endSession();
12712
12867
  }
12713
12868
  }
12714
12869
 
12715
12870
  // src/service/vendor.ts
12716
12871
  async function updateVendorBasedOnUserLicense(userId, licenceType) {
12872
+ const session = await import_mongoose28.default.startSession();
12717
12873
  try {
12718
- const user = await UserModel.findById(userId).exec();
12719
- if (!user) {
12720
- return;
12721
- }
12722
- const userVendor = await VendorModel.findById(user.vendor).exec();
12723
- if (!userVendor) {
12874
+ session.startTransaction();
12875
+ const user = await UserModel.findById(userId).select("vendor").lean().session(session);
12876
+ if (!user?.vendor) {
12877
+ console.warn(`[updateVendor] No vendor for userId=${userId}`);
12878
+ await session.abortTransaction();
12724
12879
  return;
12725
12880
  }
12726
- const selectedLicence = licenceType;
12727
- if (selectedLicence === void 0) {
12881
+ const vendor = await VendorModel.findById(user.vendor).lean().session(session);
12882
+ if (!vendor) {
12883
+ console.warn(`[updateVendor] Vendor not found for id=${user.vendor}`);
12884
+ await session.abortTransaction();
12728
12885
  return;
12729
12886
  }
12730
12887
  const vendorUpdateData = {};
12731
- if (selectedLicence === EnumUserLicence.STANDARD_VENDOR) {
12888
+ if (licenceType === EnumUserLicence.STANDARD_VENDOR) {
12732
12889
  vendorUpdateData.associates = [];
12733
12890
  vendorUpdateData.availability = {
12734
12891
  corporate: false,
@@ -12737,46 +12894,50 @@ async function updateVendorBasedOnUserLicense(userId, licenceType) {
12737
12894
  };
12738
12895
  vendorUpdateData.products = {
12739
12896
  active: false,
12740
- productsList: userVendor.products?.productsList || []
12897
+ productsList: vendor.products?.productsList ?? []
12741
12898
  };
12742
12899
  vendorUpdateData.calendar = {
12743
12900
  active: false,
12744
- calendarData: userVendor.calendar?.calendarData || []
12901
+ calendarData: vendor.calendar?.calendarData ?? []
12745
12902
  };
12746
- vendorUpdateData.images = (userVendor.images || []).map((img, index) => ({
12747
- active: index < 6,
12748
- // first 6 will be true, the rest false
12749
- source: img.source,
12750
- title: img.title
12903
+ vendorUpdateData.images = (vendor.images ?? []).map((img, index) => ({
12904
+ ...img,
12905
+ active: index < 6
12751
12906
  }));
12752
12907
  } else {
12753
- vendorUpdateData.images = (userVendor.images || []).map((img) => ({
12754
- active: true,
12755
- // all images will be true
12756
- source: img.source,
12757
- title: img.title
12908
+ vendorUpdateData.images = (vendor.images ?? []).map((img) => ({
12909
+ ...img,
12910
+ active: true
12758
12911
  }));
12759
12912
  }
12760
- await VendorModel.findByIdAndUpdate(
12761
- userVendor._id,
12762
- {
12763
- $set: vendorUpdateData
12764
- },
12765
- { new: true }
12913
+ await VendorModel.updateOne(
12914
+ { _id: vendor._id },
12915
+ { $set: vendorUpdateData },
12916
+ { session }
12766
12917
  );
12767
- await removeAssociateFromResource(userVendor._id, EnumResourceType.VENDOR);
12918
+ if (licenceType === EnumUserLicence.STANDARD_VENDOR) {
12919
+ await removeAssociateFromResource({
12920
+ resourceId: vendor._id,
12921
+ resourceOwnerId: vendor.owner.userId,
12922
+ resourceType: EnumResourceType.VENDOR
12923
+ });
12924
+ }
12925
+ await session.commitTransaction();
12768
12926
  } catch (error) {
12769
- console.error("Error updating vendor based on user license:", error);
12927
+ await session.abortTransaction();
12928
+ console.error("[updateVendorBasedOnUserLicense] Failed:", error);
12929
+ } finally {
12930
+ session.endSession();
12770
12931
  }
12771
12932
  }
12772
12933
 
12773
12934
  // src/service/objectIdToString.ts
12774
- var import_mongoose26 = __toESM(require("mongoose"));
12935
+ var import_mongoose30 = __toESM(require("mongoose"));
12775
12936
  function convertObjectIdsToStrings(obj) {
12776
12937
  if (obj === null || obj === void 0) {
12777
12938
  return obj;
12778
12939
  }
12779
- if (obj instanceof import_mongoose26.default.Types.ObjectId) {
12940
+ if (obj instanceof import_mongoose30.default.Types.ObjectId) {
12780
12941
  return obj.toString();
12781
12942
  }
12782
12943
  if (Array.isArray(obj)) {
@@ -12807,7 +12968,7 @@ async function findEventOrImportedMarketById(resourceId) {
12807
12968
 
12808
12969
  // src/types/index.ts
12809
12970
  var import_express = __toESM(require("express"));
12810
- var import_mongoose28 = __toESM(require("mongoose"));
12971
+ var import_mongoose32 = __toESM(require("mongoose"));
12811
12972
  var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
12812
12973
  EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
12813
12974
  EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
@@ -12831,7 +12992,6 @@ var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
12831
12992
  GoogleImportedMarketModel,
12832
12993
  NotificationModel,
12833
12994
  OwnerTypeSchema,
12834
- ParticipantSchema,
12835
12995
  PartnerModel,
12836
12996
  PostModel,
12837
12997
  PushTokenModel,