@timardex/cluemart-server-shared 1.0.149 → 1.0.150
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-YNM5IJGO.mjs} +4 -2
- package/dist/chunk-YNM5IJGO.mjs.map +1 -0
- package/dist/index.cjs +109 -38
- 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 +109 -37
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +2 -2
- 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 +107 -34
- 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
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: () =>
|
|
1713
|
+
mongoose: () => import_mongoose30.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
|
|
@@ -11243,6 +11243,7 @@ var MessageSchema = new MongooseSchema2(
|
|
|
11243
11243
|
var ParticipantSchema = new MongooseSchema2(
|
|
11244
11244
|
{
|
|
11245
11245
|
active: { default: true, required: true, type: Boolean },
|
|
11246
|
+
isAssociate: { default: null, required: false, type: Boolean },
|
|
11246
11247
|
userAvatar: { required: false, type: String },
|
|
11247
11248
|
userEmail: { required: true, type: String },
|
|
11248
11249
|
userId: {
|
|
@@ -12681,10 +12682,44 @@ async function updateAdStatuses() {
|
|
|
12681
12682
|
);
|
|
12682
12683
|
}
|
|
12683
12684
|
|
|
12685
|
+
// src/service/vendor.ts
|
|
12686
|
+
var import_mongoose26 = __toESM(require("mongoose"));
|
|
12687
|
+
|
|
12684
12688
|
// src/service/associate.ts
|
|
12685
|
-
|
|
12689
|
+
var import_mongoose24 = __toESM(require("mongoose"));
|
|
12690
|
+
async function removeAssociateFromResource({
|
|
12691
|
+
resourceId,
|
|
12692
|
+
resourceOwnerId,
|
|
12693
|
+
resourceType
|
|
12694
|
+
}) {
|
|
12686
12695
|
const normalizedResourceId = resourceId.toString();
|
|
12696
|
+
const normalizedOwnerId = typeof resourceOwnerId === "string" ? new import_mongoose24.default.Types.ObjectId(resourceOwnerId) : resourceOwnerId;
|
|
12697
|
+
const session = await import_mongoose24.default.startSession();
|
|
12687
12698
|
try {
|
|
12699
|
+
session.startTransaction();
|
|
12700
|
+
const usersWithAssociates = await UserModel.find(
|
|
12701
|
+
{
|
|
12702
|
+
associates: {
|
|
12703
|
+
$elemMatch: {
|
|
12704
|
+
resourceId: normalizedResourceId,
|
|
12705
|
+
resourceType
|
|
12706
|
+
}
|
|
12707
|
+
}
|
|
12708
|
+
},
|
|
12709
|
+
{
|
|
12710
|
+
associates: 1
|
|
12711
|
+
// Only fetch associates field for efficiency
|
|
12712
|
+
}
|
|
12713
|
+
).lean().session(session);
|
|
12714
|
+
const associateEmails = usersWithAssociates.flatMap(
|
|
12715
|
+
(user) => (user.associates ?? []).filter(
|
|
12716
|
+
(assoc) => assoc.resourceId === normalizedResourceId && assoc.resourceType === resourceType
|
|
12717
|
+
).map((assoc) => assoc.email)
|
|
12718
|
+
);
|
|
12719
|
+
if (associateEmails.length === 0) {
|
|
12720
|
+
await session.commitTransaction();
|
|
12721
|
+
return;
|
|
12722
|
+
}
|
|
12688
12723
|
await UserModel.updateMany(
|
|
12689
12724
|
{
|
|
12690
12725
|
associates: {
|
|
@@ -12701,34 +12736,67 @@ async function removeAssociateFromResource(resourceId, resourceType) {
|
|
|
12701
12736
|
resourceType
|
|
12702
12737
|
}
|
|
12703
12738
|
}
|
|
12739
|
+
},
|
|
12740
|
+
{ session }
|
|
12741
|
+
);
|
|
12742
|
+
await ChatModel.updateMany(
|
|
12743
|
+
{
|
|
12744
|
+
active: true,
|
|
12745
|
+
chatType: EnumChatType.RELATION,
|
|
12746
|
+
deletedAt: null,
|
|
12747
|
+
participants: {
|
|
12748
|
+
$elemMatch: {
|
|
12749
|
+
userId: normalizedOwnerId
|
|
12750
|
+
}
|
|
12751
|
+
}
|
|
12752
|
+
},
|
|
12753
|
+
{
|
|
12754
|
+
$set: {
|
|
12755
|
+
"participants.$[assoc].active": false
|
|
12756
|
+
}
|
|
12757
|
+
},
|
|
12758
|
+
{
|
|
12759
|
+
arrayFilters: [
|
|
12760
|
+
{
|
|
12761
|
+
"assoc.isAssociate": true,
|
|
12762
|
+
"assoc.userEmail": { $in: associateEmails }
|
|
12763
|
+
}
|
|
12764
|
+
],
|
|
12765
|
+
session
|
|
12704
12766
|
}
|
|
12705
|
-
)
|
|
12767
|
+
);
|
|
12768
|
+
await session.commitTransaction();
|
|
12706
12769
|
} catch (error) {
|
|
12770
|
+
await session.abortTransaction();
|
|
12707
12771
|
console.error(
|
|
12708
|
-
`[removeAssociateFromResource] Failed
|
|
12772
|
+
`[removeAssociateFromResource] Failed for resourceId=${normalizedResourceId}, resourceType=${resourceType}`,
|
|
12709
12773
|
error
|
|
12710
12774
|
);
|
|
12711
12775
|
throw error;
|
|
12776
|
+
} finally {
|
|
12777
|
+
session.endSession();
|
|
12712
12778
|
}
|
|
12713
12779
|
}
|
|
12714
12780
|
|
|
12715
12781
|
// src/service/vendor.ts
|
|
12716
12782
|
async function updateVendorBasedOnUserLicense(userId, licenceType) {
|
|
12783
|
+
const session = await import_mongoose26.default.startSession();
|
|
12717
12784
|
try {
|
|
12718
|
-
|
|
12719
|
-
|
|
12785
|
+
session.startTransaction();
|
|
12786
|
+
const user = await UserModel.findById(userId).select("vendor").lean().session(session);
|
|
12787
|
+
if (!user?.vendor) {
|
|
12788
|
+
console.warn(`[updateVendor] No vendor for userId=${userId}`);
|
|
12789
|
+
await session.abortTransaction();
|
|
12720
12790
|
return;
|
|
12721
12791
|
}
|
|
12722
|
-
const
|
|
12723
|
-
if (!
|
|
12724
|
-
|
|
12725
|
-
|
|
12726
|
-
const selectedLicence = licenceType;
|
|
12727
|
-
if (selectedLicence === void 0) {
|
|
12792
|
+
const vendor = await VendorModel.findById(user.vendor).lean().session(session);
|
|
12793
|
+
if (!vendor) {
|
|
12794
|
+
console.warn(`[updateVendor] Vendor not found for id=${user.vendor}`);
|
|
12795
|
+
await session.abortTransaction();
|
|
12728
12796
|
return;
|
|
12729
12797
|
}
|
|
12730
12798
|
const vendorUpdateData = {};
|
|
12731
|
-
if (
|
|
12799
|
+
if (licenceType === EnumUserLicence.STANDARD_VENDOR) {
|
|
12732
12800
|
vendorUpdateData.associates = [];
|
|
12733
12801
|
vendorUpdateData.availability = {
|
|
12734
12802
|
corporate: false,
|
|
@@ -12737,46 +12805,50 @@ async function updateVendorBasedOnUserLicense(userId, licenceType) {
|
|
|
12737
12805
|
};
|
|
12738
12806
|
vendorUpdateData.products = {
|
|
12739
12807
|
active: false,
|
|
12740
|
-
productsList:
|
|
12808
|
+
productsList: vendor.products?.productsList ?? []
|
|
12741
12809
|
};
|
|
12742
12810
|
vendorUpdateData.calendar = {
|
|
12743
12811
|
active: false,
|
|
12744
|
-
calendarData:
|
|
12812
|
+
calendarData: vendor.calendar?.calendarData ?? []
|
|
12745
12813
|
};
|
|
12746
|
-
vendorUpdateData.images = (
|
|
12747
|
-
|
|
12748
|
-
|
|
12749
|
-
source: img.source,
|
|
12750
|
-
title: img.title
|
|
12814
|
+
vendorUpdateData.images = (vendor.images ?? []).map((img, index) => ({
|
|
12815
|
+
...img,
|
|
12816
|
+
active: index < 6
|
|
12751
12817
|
}));
|
|
12752
12818
|
} else {
|
|
12753
|
-
vendorUpdateData.images = (
|
|
12754
|
-
|
|
12755
|
-
|
|
12756
|
-
source: img.source,
|
|
12757
|
-
title: img.title
|
|
12819
|
+
vendorUpdateData.images = (vendor.images ?? []).map((img) => ({
|
|
12820
|
+
...img,
|
|
12821
|
+
active: true
|
|
12758
12822
|
}));
|
|
12759
12823
|
}
|
|
12760
|
-
await VendorModel.
|
|
12761
|
-
|
|
12762
|
-
{
|
|
12763
|
-
|
|
12764
|
-
},
|
|
12765
|
-
{ new: true }
|
|
12824
|
+
await VendorModel.updateOne(
|
|
12825
|
+
{ _id: vendor._id },
|
|
12826
|
+
{ $set: vendorUpdateData },
|
|
12827
|
+
{ session }
|
|
12766
12828
|
);
|
|
12767
|
-
|
|
12829
|
+
if (licenceType === EnumUserLicence.STANDARD_VENDOR) {
|
|
12830
|
+
await removeAssociateFromResource({
|
|
12831
|
+
resourceId: vendor._id,
|
|
12832
|
+
resourceOwnerId: vendor.owner.userId,
|
|
12833
|
+
resourceType: EnumResourceType.VENDOR
|
|
12834
|
+
});
|
|
12835
|
+
}
|
|
12836
|
+
await session.commitTransaction();
|
|
12768
12837
|
} catch (error) {
|
|
12769
|
-
|
|
12838
|
+
await session.abortTransaction();
|
|
12839
|
+
console.error("[updateVendorBasedOnUserLicense] Failed:", error);
|
|
12840
|
+
} finally {
|
|
12841
|
+
session.endSession();
|
|
12770
12842
|
}
|
|
12771
12843
|
}
|
|
12772
12844
|
|
|
12773
12845
|
// src/service/objectIdToString.ts
|
|
12774
|
-
var
|
|
12846
|
+
var import_mongoose28 = __toESM(require("mongoose"));
|
|
12775
12847
|
function convertObjectIdsToStrings(obj) {
|
|
12776
12848
|
if (obj === null || obj === void 0) {
|
|
12777
12849
|
return obj;
|
|
12778
12850
|
}
|
|
12779
|
-
if (obj instanceof
|
|
12851
|
+
if (obj instanceof import_mongoose28.default.Types.ObjectId) {
|
|
12780
12852
|
return obj.toString();
|
|
12781
12853
|
}
|
|
12782
12854
|
if (Array.isArray(obj)) {
|
|
@@ -12807,7 +12879,7 @@ async function findEventOrImportedMarketById(resourceId) {
|
|
|
12807
12879
|
|
|
12808
12880
|
// src/types/index.ts
|
|
12809
12881
|
var import_express = __toESM(require("express"));
|
|
12810
|
-
var
|
|
12882
|
+
var import_mongoose30 = __toESM(require("mongoose"));
|
|
12811
12883
|
var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
|
|
12812
12884
|
EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
|
|
12813
12885
|
EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
|
|
@@ -12831,7 +12903,6 @@ var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
|
|
|
12831
12903
|
GoogleImportedMarketModel,
|
|
12832
12904
|
NotificationModel,
|
|
12833
12905
|
OwnerTypeSchema,
|
|
12834
|
-
ParticipantSchema,
|
|
12835
12906
|
PartnerModel,
|
|
12836
12907
|
PostModel,
|
|
12837
12908
|
PushTokenModel,
|