@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/{Chat-G9w7Bdl9.d.mts → Chat-Ctmtatmi.d.mts} +1 -12
- package/dist/{Chat-G9w7Bdl9.d.ts → Chat-Ctmtatmi.d.ts} +1 -12
- package/dist/{chunk-XT6SQI4D.mjs → chunk-QVELNUI7.mjs} +106 -15
- package/dist/chunk-QVELNUI7.mjs.map +1 -0
- package/dist/index.cjs +213 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1 -12
- package/dist/index.d.ts +1 -12
- package/dist/index.mjs +213 -52
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +104 -15
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.d.mts +2 -2
- package/dist/mongoose/index.d.ts +2 -2
- package/dist/mongoose/index.mjs +1 -3
- package/dist/service/index.cjs +209 -47
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +1 -1
- package/dist/service/index.d.ts +1 -1
- package/dist/service/index.mjs +108 -35
- package/dist/service/index.mjs.map +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +2 -2
- package/dist/chunk-XT6SQI4D.mjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
|
|
2
2
|
import { AdType, ReportChatUser, OwnerType, SocialMediaType, ResourceImageType, Category, UserLicenceType, AssociateType, ResourceContactDetailsType, TermsAgreement, RelationDate, DateTimeType, LocationGeoType, LocationType, PosterUsageType, GoogleImportedMarket, RelationType, ResourceActivityType, UserActivityEvent, UserType, VendorType, VendorInfoType, EventType, StallType, RefundPolicy, EventInfoType, PartnerType, PostType, PostContentType, AppSettingsType, GameType, GameDocType, SchoolType } from '@timardex/cluemart-shared';
|
|
3
3
|
import mongoose from 'mongoose';
|
|
4
|
-
import { O as ObjectId } from '../Chat-
|
|
5
|
-
export { C as ChatModel, N as NotificationModel,
|
|
4
|
+
import { O as ObjectId } from '../Chat-Ctmtatmi.mjs';
|
|
5
|
+
export { C as ChatModel, N as NotificationModel, a as SchemaChatMessageReactionType, S as SchemaChatMessageReplyPreviewType, b as SchemaChatMessageSeenType, c as SchemaChatMessageType, e as SchemaChatType, f as SchemaCreateBulkNotificationInput, g as SchemaNotificationType, d as SchemaParticipantType } from '../Chat-Ctmtatmi.mjs';
|
|
6
6
|
import { EnumOSPlatform } from '@timardex/cluemart-shared/enums';
|
|
7
7
|
import '@timardex/cluemart-shared/types';
|
|
8
8
|
import 'express';
|
package/dist/mongoose/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as _timardex_cluemart_shared from '@timardex/cluemart-shared';
|
|
2
2
|
import { AdType, ReportChatUser, OwnerType, SocialMediaType, ResourceImageType, Category, UserLicenceType, AssociateType, ResourceContactDetailsType, TermsAgreement, RelationDate, DateTimeType, LocationGeoType, LocationType, PosterUsageType, GoogleImportedMarket, RelationType, ResourceActivityType, UserActivityEvent, UserType, VendorType, VendorInfoType, EventType, StallType, RefundPolicy, EventInfoType, PartnerType, PostType, PostContentType, AppSettingsType, GameType, GameDocType, SchoolType } from '@timardex/cluemart-shared';
|
|
3
3
|
import mongoose from 'mongoose';
|
|
4
|
-
import { O as ObjectId } from '../Chat-
|
|
5
|
-
export { C as ChatModel, N as NotificationModel,
|
|
4
|
+
import { O as ObjectId } from '../Chat-Ctmtatmi.js';
|
|
5
|
+
export { C as ChatModel, N as NotificationModel, a as SchemaChatMessageReactionType, S as SchemaChatMessageReplyPreviewType, b as SchemaChatMessageSeenType, c as SchemaChatMessageType, e as SchemaChatType, f as SchemaCreateBulkNotificationInput, g as SchemaNotificationType, d as SchemaParticipantType } from '../Chat-Ctmtatmi.js';
|
|
6
6
|
import { EnumOSPlatform } from '@timardex/cluemart-shared/enums';
|
|
7
7
|
import '@timardex/cluemart-shared/types';
|
|
8
8
|
import 'express';
|
package/dist/mongoose/index.mjs
CHANGED
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
GoogleImportedMarketModel,
|
|
13
13
|
NotificationModel,
|
|
14
14
|
OwnerTypeSchema,
|
|
15
|
-
ParticipantSchema,
|
|
16
15
|
PartnerModel,
|
|
17
16
|
PostModel,
|
|
18
17
|
PushTokenModel,
|
|
@@ -37,7 +36,7 @@ import {
|
|
|
37
36
|
resourceRelationsSchema,
|
|
38
37
|
termsAgreementSchema,
|
|
39
38
|
userLicenseSchema
|
|
40
|
-
} from "../chunk-
|
|
39
|
+
} from "../chunk-QVELNUI7.mjs";
|
|
41
40
|
import "../chunk-3QS3WKRC.mjs";
|
|
42
41
|
export {
|
|
43
42
|
APP_SETTINGS_ID,
|
|
@@ -53,7 +52,6 @@ export {
|
|
|
53
52
|
GoogleImportedMarketModel,
|
|
54
53
|
NotificationModel,
|
|
55
54
|
OwnerTypeSchema,
|
|
56
|
-
ParticipantSchema,
|
|
57
55
|
PartnerModel,
|
|
58
56
|
PostModel,
|
|
59
57
|
PushTokenModel,
|
package/dist/service/index.cjs
CHANGED
|
@@ -9033,6 +9033,7 @@ var CHAT_MESSAGE_FIELDS_FRAGMENT = gql`
|
|
|
9033
9033
|
var CHAT_PARTICIPANT = gql`
|
|
9034
9034
|
fragment ChatParticipantFields on ChatParticipantType {
|
|
9035
9035
|
active
|
|
9036
|
+
isAssociate
|
|
9036
9037
|
userAvatar
|
|
9037
9038
|
userEmail
|
|
9038
9039
|
userId
|
|
@@ -10011,6 +10012,41 @@ var DAILY_CLUE_GAME_DATA_FIELDS_FRAGMENT = gql`
|
|
|
10011
10012
|
}
|
|
10012
10013
|
${DAILY_CLUE_BASE_GAME_FIELDS_FRAGMENT}
|
|
10013
10014
|
`;
|
|
10015
|
+
var MINI_QUIZ_QUESTION_FIELDS_FRAGMENT = gql`
|
|
10016
|
+
fragment MiniQuizQuestionFields on MiniQuizQuestionType {
|
|
10017
|
+
answers {
|
|
10018
|
+
answer
|
|
10019
|
+
correct
|
|
10020
|
+
}
|
|
10021
|
+
question
|
|
10022
|
+
}
|
|
10023
|
+
`;
|
|
10024
|
+
var MINI_QUIZ_BASE_GAME_FIELDS_FRAGMENT = gql`
|
|
10025
|
+
fragment MiniQuizBaseGameFields on MiniQuizBaseGameType {
|
|
10026
|
+
gameDate {
|
|
10027
|
+
...GameDateFields
|
|
10028
|
+
}
|
|
10029
|
+
questions {
|
|
10030
|
+
...MiniQuizQuestionFields
|
|
10031
|
+
}
|
|
10032
|
+
}
|
|
10033
|
+
${GAME_DATE_FIELDS_FRAGMENT}
|
|
10034
|
+
${MINI_QUIZ_QUESTION_FIELDS_FRAGMENT}
|
|
10035
|
+
`;
|
|
10036
|
+
var MINI_QUIZ_GAME_DATA_FIELDS_FRAGMENT = gql`
|
|
10037
|
+
fragment MiniQuizGameDataFields on MiniQuizGameDataType {
|
|
10038
|
+
gameFields {
|
|
10039
|
+
...MiniQuizBaseGameFields
|
|
10040
|
+
}
|
|
10041
|
+
quizInfo {
|
|
10042
|
+
...MiniQuizQuestionFields
|
|
10043
|
+
}
|
|
10044
|
+
points
|
|
10045
|
+
streak
|
|
10046
|
+
}
|
|
10047
|
+
${MINI_QUIZ_BASE_GAME_FIELDS_FRAGMENT}
|
|
10048
|
+
${MINI_QUIZ_QUESTION_FIELDS_FRAGMENT}
|
|
10049
|
+
`;
|
|
10014
10050
|
var GAME_HISTORY_FIELDS_FRAGMENT = gql`
|
|
10015
10051
|
fragment GameHistoryFields on GameHistoryType {
|
|
10016
10052
|
createdAt
|
|
@@ -10028,8 +10064,12 @@ var GAME_DATA_FIELDS_FRAGMENT = gql`
|
|
|
10028
10064
|
dailyClue {
|
|
10029
10065
|
...DailyClueGameDataFields
|
|
10030
10066
|
}
|
|
10067
|
+
miniQuiz {
|
|
10068
|
+
...MiniQuizGameDataFields
|
|
10069
|
+
}
|
|
10031
10070
|
}
|
|
10032
10071
|
${DAILY_CLUE_GAME_DATA_FIELDS_FRAGMENT}
|
|
10072
|
+
${MINI_QUIZ_GAME_DATA_FIELDS_FRAGMENT}
|
|
10033
10073
|
`;
|
|
10034
10074
|
var GAME_FIELDS_FRAGMENT = gql`
|
|
10035
10075
|
fragment GameFields on GameType {
|
|
@@ -10103,8 +10143,12 @@ var BASE_GAME_FIELDS_FRAGMENT = gql`
|
|
|
10103
10143
|
dailyClue {
|
|
10104
10144
|
...DailyClueBaseGameFields
|
|
10105
10145
|
}
|
|
10146
|
+
miniQuiz {
|
|
10147
|
+
...MiniQuizBaseGameFields
|
|
10148
|
+
}
|
|
10106
10149
|
}
|
|
10107
10150
|
${DAILY_CLUE_BASE_GAME_FIELDS_FRAGMENT}
|
|
10151
|
+
${MINI_QUIZ_BASE_GAME_FIELDS_FRAGMENT}
|
|
10108
10152
|
`;
|
|
10109
10153
|
var POST_CONTENT_DATA_FIELDS_FRAGMENT = gql`
|
|
10110
10154
|
fragment PostContentDataFields on PostContentData {
|
|
@@ -11101,6 +11145,7 @@ var EnumGameStatus = /* @__PURE__ */ ((EnumGameStatus2) => {
|
|
|
11101
11145
|
})(EnumGameStatus || {});
|
|
11102
11146
|
var EnumGameType = /* @__PURE__ */ ((EnumGameType2) => {
|
|
11103
11147
|
EnumGameType2["DAILY_CLUE"] = "dailyClue";
|
|
11148
|
+
EnumGameType2["MINI_QUIZ"] = "miniQuiz";
|
|
11104
11149
|
return EnumGameType2;
|
|
11105
11150
|
})(EnumGameType || {});
|
|
11106
11151
|
|
|
@@ -11421,6 +11466,7 @@ var MessageSchema = new MongooseSchema4(
|
|
|
11421
11466
|
var ParticipantSchema = new MongooseSchema4(
|
|
11422
11467
|
{
|
|
11423
11468
|
active: { default: true, required: true, type: Boolean },
|
|
11469
|
+
isAssociate: { default: null, required: false, type: Boolean },
|
|
11424
11470
|
userAvatar: { required: false, type: String },
|
|
11425
11471
|
userEmail: { required: true, type: String },
|
|
11426
11472
|
userId: {
|
|
@@ -12479,6 +12525,9 @@ var AppSettingSchema = new MongooseSchema18(
|
|
|
12479
12525
|
var AppSettingModel = import_mongoose19.default.models.AppSetting || import_mongoose19.default.model("AppSetting", AppSettingSchema);
|
|
12480
12526
|
|
|
12481
12527
|
// src/mongoose/game/Game.ts
|
|
12528
|
+
var import_mongoose23 = __toESM(require("mongoose"));
|
|
12529
|
+
|
|
12530
|
+
// src/mongoose/game/DailyClue.ts
|
|
12482
12531
|
var import_mongoose21 = __toESM(require("mongoose"));
|
|
12483
12532
|
|
|
12484
12533
|
// src/mongoose/game/utils.ts
|
|
@@ -12491,7 +12540,10 @@ var schemaGameDate = new MongooseSchema19(
|
|
|
12491
12540
|
},
|
|
12492
12541
|
{ _id: false }
|
|
12493
12542
|
);
|
|
12494
|
-
|
|
12543
|
+
|
|
12544
|
+
// src/mongoose/game/DailyClue.ts
|
|
12545
|
+
var MongooseSchema20 = import_mongoose21.default.Schema;
|
|
12546
|
+
var schemaLetters = new MongooseSchema20(
|
|
12495
12547
|
{
|
|
12496
12548
|
collected: { required: false, type: [String] },
|
|
12497
12549
|
solutionShuffled: { required: true, type: [String] }
|
|
@@ -12499,14 +12551,14 @@ var schemaLetters = new MongooseSchema19(
|
|
|
12499
12551
|
},
|
|
12500
12552
|
{ _id: false }
|
|
12501
12553
|
);
|
|
12502
|
-
var schemaDailyClueBaseGame = new
|
|
12554
|
+
var schemaDailyClueBaseGame = new MongooseSchema20(
|
|
12503
12555
|
{
|
|
12504
12556
|
gameDate: { required: true, type: schemaGameDate },
|
|
12505
12557
|
gameSolution: { required: true, type: String }
|
|
12506
12558
|
},
|
|
12507
12559
|
{ _id: false }
|
|
12508
12560
|
);
|
|
12509
|
-
var schemaDailyClueGameData = new
|
|
12561
|
+
var schemaDailyClueGameData = new MongooseSchema20(
|
|
12510
12562
|
{
|
|
12511
12563
|
gameFields: { required: true, type: schemaDailyClueBaseGame },
|
|
12512
12564
|
lastFoundDate: { default: null, required: false, type: Date },
|
|
@@ -12520,10 +12572,49 @@ var schemaDailyClueGameData = new MongooseSchema19(
|
|
|
12520
12572
|
{ _id: false }
|
|
12521
12573
|
);
|
|
12522
12574
|
|
|
12575
|
+
// src/mongoose/game/MiniQuiz.ts
|
|
12576
|
+
var import_mongoose22 = __toESM(require("mongoose"));
|
|
12577
|
+
var MongooseSchema21 = import_mongoose22.default.Schema;
|
|
12578
|
+
var schemaMiniQuizAnswers = new MongooseSchema21(
|
|
12579
|
+
{
|
|
12580
|
+
answer: { required: true, type: String },
|
|
12581
|
+
correct: { required: true, type: Boolean }
|
|
12582
|
+
},
|
|
12583
|
+
{ _id: false }
|
|
12584
|
+
);
|
|
12585
|
+
var schemaMiniQuizQuestions = new MongooseSchema21(
|
|
12586
|
+
{
|
|
12587
|
+
answers: { required: true, type: [schemaMiniQuizAnswers] },
|
|
12588
|
+
question: { required: true, type: String }
|
|
12589
|
+
},
|
|
12590
|
+
{ _id: false }
|
|
12591
|
+
);
|
|
12592
|
+
var schemaMiniQuizBaseGame = new MongooseSchema21(
|
|
12593
|
+
{
|
|
12594
|
+
gameDate: { required: true, type: Date },
|
|
12595
|
+
questions: { required: true, type: [schemaMiniQuizQuestions] }
|
|
12596
|
+
},
|
|
12597
|
+
{ _id: false }
|
|
12598
|
+
);
|
|
12599
|
+
var schemaMiniQuizGameData = new MongooseSchema21(
|
|
12600
|
+
{
|
|
12601
|
+
gameFields: { required: true, type: schemaMiniQuizBaseGame },
|
|
12602
|
+
points: { default: 0, required: true, type: Number },
|
|
12603
|
+
quizInfo: {
|
|
12604
|
+
default: null,
|
|
12605
|
+
required: false,
|
|
12606
|
+
type: [schemaMiniQuizQuestions]
|
|
12607
|
+
},
|
|
12608
|
+
streak: { default: 0, required: true, type: Number }
|
|
12609
|
+
},
|
|
12610
|
+
{ _id: false }
|
|
12611
|
+
);
|
|
12612
|
+
|
|
12523
12613
|
// src/mongoose/game/Game.ts
|
|
12524
|
-
var
|
|
12614
|
+
var MongooseSchema22 = import_mongoose23.default.Schema;
|
|
12525
12615
|
var gameDataSchemas = {
|
|
12526
|
-
[EnumGameType.DAILY_CLUE]: schemaDailyClueGameData
|
|
12616
|
+
[EnumGameType.DAILY_CLUE]: schemaDailyClueGameData,
|
|
12617
|
+
[EnumGameType.MINI_QUIZ]: schemaMiniQuizGameData
|
|
12527
12618
|
};
|
|
12528
12619
|
var gameDataDefinition = Object.fromEntries(
|
|
12529
12620
|
Object.entries(gameDataSchemas).map(([key, schema16]) => [
|
|
@@ -12531,7 +12622,7 @@ var gameDataDefinition = Object.fromEntries(
|
|
|
12531
12622
|
{ default: null, required: false, type: schema16 }
|
|
12532
12623
|
])
|
|
12533
12624
|
);
|
|
12534
|
-
var gameHistorySchema = new
|
|
12625
|
+
var gameHistorySchema = new MongooseSchema22(
|
|
12535
12626
|
{
|
|
12536
12627
|
createdAt: { required: true, type: Date },
|
|
12537
12628
|
gameDate: { required: true, type: schemaGameDate },
|
|
@@ -12549,7 +12640,7 @@ var gameHistorySchema = new MongooseSchema20(
|
|
|
12549
12640
|
},
|
|
12550
12641
|
{ _id: false }
|
|
12551
12642
|
);
|
|
12552
|
-
var gameTypeSchema = new
|
|
12643
|
+
var gameTypeSchema = new MongooseSchema22(
|
|
12553
12644
|
{
|
|
12554
12645
|
active: { default: true, required: true, type: Boolean },
|
|
12555
12646
|
gameData: gameDataDefinition,
|
|
@@ -12562,7 +12653,7 @@ var gameTypeSchema = new MongooseSchema20(
|
|
|
12562
12653
|
},
|
|
12563
12654
|
{ timestamps: true }
|
|
12564
12655
|
);
|
|
12565
|
-
var schema14 = new
|
|
12656
|
+
var schema14 = new MongooseSchema22(
|
|
12566
12657
|
{
|
|
12567
12658
|
active: { default: false, required: true, type: Boolean },
|
|
12568
12659
|
deletedAt: { default: null, required: false, type: Date },
|
|
@@ -12575,12 +12666,12 @@ var schema14 = new MongooseSchema20(
|
|
|
12575
12666
|
},
|
|
12576
12667
|
{ timestamps: true }
|
|
12577
12668
|
);
|
|
12578
|
-
var GameModel =
|
|
12669
|
+
var GameModel = import_mongoose23.default.models.Game || import_mongoose23.default.model("Game", schema14);
|
|
12579
12670
|
|
|
12580
12671
|
// src/mongoose/School.ts
|
|
12581
|
-
var
|
|
12582
|
-
var
|
|
12583
|
-
var schema15 = new
|
|
12672
|
+
var import_mongoose24 = __toESM(require("mongoose"));
|
|
12673
|
+
var MongooseSchema23 = import_mongoose24.default.Schema;
|
|
12674
|
+
var schema15 = new MongooseSchema23(
|
|
12584
12675
|
{
|
|
12585
12676
|
// New schools are active by default
|
|
12586
12677
|
active: { default: true, required: true, type: Boolean },
|
|
@@ -12605,7 +12696,7 @@ var schema15 = new MongooseSchema21(
|
|
|
12605
12696
|
},
|
|
12606
12697
|
{ timestamps: true }
|
|
12607
12698
|
);
|
|
12608
|
-
var SchoolModel =
|
|
12699
|
+
var SchoolModel = import_mongoose24.default.models.School || import_mongoose24.default.model("School", schema15);
|
|
12609
12700
|
|
|
12610
12701
|
// src/service/updateAdStatus.ts
|
|
12611
12702
|
async function updateAdStatuses() {
|
|
@@ -12642,10 +12733,44 @@ async function updateAdStatuses() {
|
|
|
12642
12733
|
);
|
|
12643
12734
|
}
|
|
12644
12735
|
|
|
12736
|
+
// src/service/vendor.ts
|
|
12737
|
+
var import_mongoose28 = __toESM(require("mongoose"));
|
|
12738
|
+
|
|
12645
12739
|
// src/service/associate.ts
|
|
12646
|
-
|
|
12740
|
+
var import_mongoose26 = __toESM(require("mongoose"));
|
|
12741
|
+
async function removeAssociateFromResource({
|
|
12742
|
+
resourceId,
|
|
12743
|
+
resourceOwnerId,
|
|
12744
|
+
resourceType
|
|
12745
|
+
}) {
|
|
12647
12746
|
const normalizedResourceId = resourceId.toString();
|
|
12747
|
+
const normalizedOwnerId = typeof resourceOwnerId === "string" ? new import_mongoose26.default.Types.ObjectId(resourceOwnerId) : resourceOwnerId;
|
|
12748
|
+
const session = await import_mongoose26.default.startSession();
|
|
12648
12749
|
try {
|
|
12750
|
+
session.startTransaction();
|
|
12751
|
+
const usersWithAssociates = await UserModel.find(
|
|
12752
|
+
{
|
|
12753
|
+
associates: {
|
|
12754
|
+
$elemMatch: {
|
|
12755
|
+
resourceId: normalizedResourceId,
|
|
12756
|
+
resourceType
|
|
12757
|
+
}
|
|
12758
|
+
}
|
|
12759
|
+
},
|
|
12760
|
+
{
|
|
12761
|
+
associates: 1
|
|
12762
|
+
// Only fetch associates field for efficiency
|
|
12763
|
+
}
|
|
12764
|
+
).lean().session(session);
|
|
12765
|
+
const associateEmails = usersWithAssociates.flatMap(
|
|
12766
|
+
(user) => (user.associates ?? []).filter(
|
|
12767
|
+
(assoc) => assoc.resourceId === normalizedResourceId && assoc.resourceType === resourceType
|
|
12768
|
+
).map((assoc) => assoc.email)
|
|
12769
|
+
);
|
|
12770
|
+
if (associateEmails.length === 0) {
|
|
12771
|
+
await session.commitTransaction();
|
|
12772
|
+
return;
|
|
12773
|
+
}
|
|
12649
12774
|
await UserModel.updateMany(
|
|
12650
12775
|
{
|
|
12651
12776
|
associates: {
|
|
@@ -12662,34 +12787,67 @@ async function removeAssociateFromResource(resourceId, resourceType) {
|
|
|
12662
12787
|
resourceType
|
|
12663
12788
|
}
|
|
12664
12789
|
}
|
|
12790
|
+
},
|
|
12791
|
+
{ session }
|
|
12792
|
+
);
|
|
12793
|
+
await ChatModel.updateMany(
|
|
12794
|
+
{
|
|
12795
|
+
active: true,
|
|
12796
|
+
chatType: EnumChatType.RELATION,
|
|
12797
|
+
deletedAt: null,
|
|
12798
|
+
participants: {
|
|
12799
|
+
$elemMatch: {
|
|
12800
|
+
userId: normalizedOwnerId
|
|
12801
|
+
}
|
|
12802
|
+
}
|
|
12803
|
+
},
|
|
12804
|
+
{
|
|
12805
|
+
$set: {
|
|
12806
|
+
"participants.$[assoc].active": false
|
|
12807
|
+
}
|
|
12808
|
+
},
|
|
12809
|
+
{
|
|
12810
|
+
arrayFilters: [
|
|
12811
|
+
{
|
|
12812
|
+
"assoc.isAssociate": true,
|
|
12813
|
+
"assoc.userEmail": { $in: associateEmails }
|
|
12814
|
+
}
|
|
12815
|
+
],
|
|
12816
|
+
session
|
|
12665
12817
|
}
|
|
12666
|
-
)
|
|
12818
|
+
);
|
|
12819
|
+
await session.commitTransaction();
|
|
12667
12820
|
} catch (error) {
|
|
12821
|
+
await session.abortTransaction();
|
|
12668
12822
|
console.error(
|
|
12669
|
-
`[removeAssociateFromResource] Failed
|
|
12823
|
+
`[removeAssociateFromResource] Failed for resourceId=${normalizedResourceId}, resourceType=${resourceType}`,
|
|
12670
12824
|
error
|
|
12671
12825
|
);
|
|
12672
12826
|
throw error;
|
|
12827
|
+
} finally {
|
|
12828
|
+
session.endSession();
|
|
12673
12829
|
}
|
|
12674
12830
|
}
|
|
12675
12831
|
|
|
12676
12832
|
// src/service/vendor.ts
|
|
12677
12833
|
async function updateVendorBasedOnUserLicense(userId, licenceType) {
|
|
12834
|
+
const session = await import_mongoose28.default.startSession();
|
|
12678
12835
|
try {
|
|
12679
|
-
|
|
12680
|
-
|
|
12836
|
+
session.startTransaction();
|
|
12837
|
+
const user = await UserModel.findById(userId).select("vendor").lean().session(session);
|
|
12838
|
+
if (!user?.vendor) {
|
|
12839
|
+
console.warn(`[updateVendor] No vendor for userId=${userId}`);
|
|
12840
|
+
await session.abortTransaction();
|
|
12681
12841
|
return;
|
|
12682
12842
|
}
|
|
12683
|
-
const
|
|
12684
|
-
if (!
|
|
12685
|
-
|
|
12686
|
-
|
|
12687
|
-
const selectedLicence = licenceType;
|
|
12688
|
-
if (selectedLicence === void 0) {
|
|
12843
|
+
const vendor = await VendorModel.findById(user.vendor).lean().session(session);
|
|
12844
|
+
if (!vendor) {
|
|
12845
|
+
console.warn(`[updateVendor] Vendor not found for id=${user.vendor}`);
|
|
12846
|
+
await session.abortTransaction();
|
|
12689
12847
|
return;
|
|
12690
12848
|
}
|
|
12691
12849
|
const vendorUpdateData = {};
|
|
12692
|
-
if (
|
|
12850
|
+
if (licenceType === EnumUserLicence.STANDARD_VENDOR) {
|
|
12693
12851
|
vendorUpdateData.associates = [];
|
|
12694
12852
|
vendorUpdateData.availability = {
|
|
12695
12853
|
corporate: false,
|
|
@@ -12698,46 +12856,50 @@ async function updateVendorBasedOnUserLicense(userId, licenceType) {
|
|
|
12698
12856
|
};
|
|
12699
12857
|
vendorUpdateData.products = {
|
|
12700
12858
|
active: false,
|
|
12701
|
-
productsList:
|
|
12859
|
+
productsList: vendor.products?.productsList ?? []
|
|
12702
12860
|
};
|
|
12703
12861
|
vendorUpdateData.calendar = {
|
|
12704
12862
|
active: false,
|
|
12705
|
-
calendarData:
|
|
12863
|
+
calendarData: vendor.calendar?.calendarData ?? []
|
|
12706
12864
|
};
|
|
12707
|
-
vendorUpdateData.images = (
|
|
12708
|
-
|
|
12709
|
-
|
|
12710
|
-
source: img.source,
|
|
12711
|
-
title: img.title
|
|
12865
|
+
vendorUpdateData.images = (vendor.images ?? []).map((img, index) => ({
|
|
12866
|
+
...img,
|
|
12867
|
+
active: index < 6
|
|
12712
12868
|
}));
|
|
12713
12869
|
} else {
|
|
12714
|
-
vendorUpdateData.images = (
|
|
12715
|
-
|
|
12716
|
-
|
|
12717
|
-
source: img.source,
|
|
12718
|
-
title: img.title
|
|
12870
|
+
vendorUpdateData.images = (vendor.images ?? []).map((img) => ({
|
|
12871
|
+
...img,
|
|
12872
|
+
active: true
|
|
12719
12873
|
}));
|
|
12720
12874
|
}
|
|
12721
|
-
await VendorModel.
|
|
12722
|
-
|
|
12723
|
-
{
|
|
12724
|
-
|
|
12725
|
-
},
|
|
12726
|
-
{ new: true }
|
|
12875
|
+
await VendorModel.updateOne(
|
|
12876
|
+
{ _id: vendor._id },
|
|
12877
|
+
{ $set: vendorUpdateData },
|
|
12878
|
+
{ session }
|
|
12727
12879
|
);
|
|
12728
|
-
|
|
12880
|
+
if (licenceType === EnumUserLicence.STANDARD_VENDOR) {
|
|
12881
|
+
await removeAssociateFromResource({
|
|
12882
|
+
resourceId: vendor._id,
|
|
12883
|
+
resourceOwnerId: vendor.owner.userId,
|
|
12884
|
+
resourceType: EnumResourceType.VENDOR
|
|
12885
|
+
});
|
|
12886
|
+
}
|
|
12887
|
+
await session.commitTransaction();
|
|
12729
12888
|
} catch (error) {
|
|
12730
|
-
|
|
12889
|
+
await session.abortTransaction();
|
|
12890
|
+
console.error("[updateVendorBasedOnUserLicense] Failed:", error);
|
|
12891
|
+
} finally {
|
|
12892
|
+
session.endSession();
|
|
12731
12893
|
}
|
|
12732
12894
|
}
|
|
12733
12895
|
|
|
12734
12896
|
// src/service/objectIdToString.ts
|
|
12735
|
-
var
|
|
12897
|
+
var import_mongoose30 = __toESM(require("mongoose"));
|
|
12736
12898
|
function convertObjectIdsToStrings(obj) {
|
|
12737
12899
|
if (obj === null || obj === void 0) {
|
|
12738
12900
|
return obj;
|
|
12739
12901
|
}
|
|
12740
|
-
if (obj instanceof
|
|
12902
|
+
if (obj instanceof import_mongoose30.default.Types.ObjectId) {
|
|
12741
12903
|
return obj.toString();
|
|
12742
12904
|
}
|
|
12743
12905
|
if (Array.isArray(obj)) {
|