@timardex/cluemart-server-shared 1.0.158 → 1.0.159
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 +40 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +0 -10
- package/dist/index.d.ts +0 -10
- package/dist/index.mjs +40 -64
- package/dist/index.mjs.map +1 -1
- package/dist/service/index.cjs +38 -62
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +0 -10
- package/dist/service/index.d.ts +0 -10
- package/dist/service/index.mjs +38 -62
- package/dist/service/index.mjs.map +1 -1
- package/package.json +1 -1
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: () =>
|
|
1713
|
+
mongoose: () => import_mongoose31.default,
|
|
1714
1714
|
refundPolicySchema: () => refundPolicySchema,
|
|
1715
1715
|
relationDatesSchema: () => relationDatesSchema,
|
|
1716
1716
|
resourceRelationsSchema: () => resourceRelationsSchema,
|
|
@@ -12803,9 +12803,6 @@ async function updateAdStatuses() {
|
|
|
12803
12803
|
);
|
|
12804
12804
|
}
|
|
12805
12805
|
|
|
12806
|
-
// src/service/vendor.ts
|
|
12807
|
-
var import_mongoose28 = __toESM(require("mongoose"));
|
|
12808
|
-
|
|
12809
12806
|
// src/service/associate.ts
|
|
12810
12807
|
var import_mongoose26 = __toESM(require("mongoose"));
|
|
12811
12808
|
async function removeAssociateFromResource({
|
|
@@ -12813,11 +12810,9 @@ async function removeAssociateFromResource({
|
|
|
12813
12810
|
resourceOwnerId,
|
|
12814
12811
|
resourceType
|
|
12815
12812
|
}) {
|
|
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
12813
|
try {
|
|
12820
|
-
|
|
12814
|
+
const normalizedResourceId = resourceId.toString();
|
|
12815
|
+
const normalizedOwnerId = typeof resourceOwnerId === "string" ? new import_mongoose26.default.Types.ObjectId(resourceOwnerId) : resourceOwnerId;
|
|
12821
12816
|
const usersWithAssociates = await UserModel.find(
|
|
12822
12817
|
{
|
|
12823
12818
|
associates: {
|
|
@@ -12829,16 +12824,18 @@ async function removeAssociateFromResource({
|
|
|
12829
12824
|
},
|
|
12830
12825
|
{
|
|
12831
12826
|
associates: 1
|
|
12832
|
-
// Only fetch associates field for efficiency
|
|
12833
12827
|
}
|
|
12834
|
-
).lean()
|
|
12835
|
-
const associateEmails =
|
|
12836
|
-
|
|
12837
|
-
(
|
|
12838
|
-
|
|
12839
|
-
|
|
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
|
+
)
|
|
12836
|
+
)
|
|
12837
|
+
];
|
|
12840
12838
|
if (associateEmails.length === 0) {
|
|
12841
|
-
await session.commitTransaction();
|
|
12842
12839
|
return;
|
|
12843
12840
|
}
|
|
12844
12841
|
await UserModel.updateMany(
|
|
@@ -12857,8 +12854,7 @@ async function removeAssociateFromResource({
|
|
|
12857
12854
|
resourceType
|
|
12858
12855
|
}
|
|
12859
12856
|
}
|
|
12860
|
-
}
|
|
12861
|
-
{ session }
|
|
12857
|
+
}
|
|
12862
12858
|
);
|
|
12863
12859
|
await ChatModel.updateMany(
|
|
12864
12860
|
{
|
|
@@ -12873,103 +12869,83 @@ async function removeAssociateFromResource({
|
|
|
12873
12869
|
},
|
|
12874
12870
|
{
|
|
12875
12871
|
$set: {
|
|
12876
|
-
"participants.$[
|
|
12872
|
+
"participants.$[associate].active": false
|
|
12877
12873
|
}
|
|
12878
12874
|
},
|
|
12879
12875
|
{
|
|
12880
12876
|
arrayFilters: [
|
|
12881
12877
|
{
|
|
12882
|
-
"
|
|
12883
|
-
"
|
|
12878
|
+
"associate.isAssociate": true,
|
|
12879
|
+
"associate.userEmail": {
|
|
12880
|
+
$in: associateEmails
|
|
12881
|
+
}
|
|
12884
12882
|
}
|
|
12885
|
-
]
|
|
12886
|
-
session
|
|
12883
|
+
]
|
|
12887
12884
|
}
|
|
12888
12885
|
);
|
|
12889
|
-
await session.commitTransaction();
|
|
12890
12886
|
} catch (error) {
|
|
12891
|
-
await session.abortTransaction();
|
|
12892
12887
|
console.error(
|
|
12893
|
-
`[removeAssociateFromResource] Failed for resourceId=${
|
|
12888
|
+
`[removeAssociateFromResource] Failed for resourceId=${resourceId}, resourceType=${resourceType}`,
|
|
12894
12889
|
error
|
|
12895
12890
|
);
|
|
12896
|
-
throw error;
|
|
12897
|
-
} finally {
|
|
12898
|
-
session.endSession();
|
|
12899
12891
|
}
|
|
12900
12892
|
}
|
|
12901
12893
|
|
|
12902
12894
|
// src/service/vendor.ts
|
|
12903
12895
|
async function updateVendorBasedOnUserLicense(userId, licenceType) {
|
|
12904
|
-
const session = await import_mongoose28.default.startSession();
|
|
12905
12896
|
try {
|
|
12906
|
-
|
|
12907
|
-
const user = await UserModel.findById(userId).select("vendor").lean().session(session);
|
|
12897
|
+
const user = await UserModel.findById(userId).select("vendor").lean();
|
|
12908
12898
|
if (!user?.vendor) {
|
|
12909
|
-
console.warn(`[updateVendor] No vendor for userId=${userId}`);
|
|
12910
|
-
await session.abortTransaction();
|
|
12899
|
+
console.warn(`[updateVendor] No vendor found for userId=${userId}`);
|
|
12911
12900
|
return;
|
|
12912
12901
|
}
|
|
12913
|
-
const vendor = await VendorModel.findById(user.vendor).lean()
|
|
12902
|
+
const vendor = await VendorModel.findById(user.vendor).lean();
|
|
12914
12903
|
if (!vendor) {
|
|
12915
12904
|
console.warn(`[updateVendor] Vendor not found for id=${user.vendor}`);
|
|
12916
|
-
await session.abortTransaction();
|
|
12917
12905
|
return;
|
|
12918
12906
|
}
|
|
12919
|
-
const
|
|
12920
|
-
|
|
12921
|
-
|
|
12922
|
-
|
|
12907
|
+
const updateData = {};
|
|
12908
|
+
const isStandardVendor = licenceType === EnumUserLicence.STANDARD_VENDOR;
|
|
12909
|
+
if (isStandardVendor) {
|
|
12910
|
+
updateData.associates = [];
|
|
12911
|
+
updateData.availability = {
|
|
12923
12912
|
corporate: false,
|
|
12924
12913
|
private: false,
|
|
12925
12914
|
school: false
|
|
12926
12915
|
};
|
|
12927
|
-
|
|
12916
|
+
updateData.products = {
|
|
12928
12917
|
active: false,
|
|
12929
12918
|
productsList: vendor.products?.productsList ?? []
|
|
12930
12919
|
};
|
|
12931
|
-
|
|
12920
|
+
updateData.calendar = {
|
|
12932
12921
|
active: false,
|
|
12933
12922
|
calendarData: vendor.calendar?.calendarData ?? []
|
|
12934
12923
|
};
|
|
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
12924
|
}
|
|
12945
|
-
|
|
12946
|
-
|
|
12947
|
-
|
|
12948
|
-
|
|
12949
|
-
);
|
|
12950
|
-
if (
|
|
12925
|
+
updateData.images = (vendor.images ?? []).map((image, index) => ({
|
|
12926
|
+
...image,
|
|
12927
|
+
active: isStandardVendor ? index < 6 : true
|
|
12928
|
+
}));
|
|
12929
|
+
await VendorModel.updateOne({ _id: vendor._id }, { $set: updateData });
|
|
12930
|
+
if (isStandardVendor) {
|
|
12951
12931
|
await removeAssociateFromResource({
|
|
12952
12932
|
resourceId: vendor._id,
|
|
12953
12933
|
resourceOwnerId: vendor.owner.userId,
|
|
12954
12934
|
resourceType: EnumResourceType.VENDOR
|
|
12955
12935
|
});
|
|
12956
12936
|
}
|
|
12957
|
-
await session.commitTransaction();
|
|
12958
12937
|
} catch (error) {
|
|
12959
|
-
await session.abortTransaction();
|
|
12960
12938
|
console.error("[updateVendorBasedOnUserLicense] Failed:", error);
|
|
12961
|
-
} finally {
|
|
12962
|
-
session.endSession();
|
|
12963
12939
|
}
|
|
12964
12940
|
}
|
|
12965
12941
|
|
|
12966
12942
|
// src/service/objectIdToString.ts
|
|
12967
|
-
var
|
|
12943
|
+
var import_mongoose29 = __toESM(require("mongoose"));
|
|
12968
12944
|
function convertObjectIdsToStrings(obj) {
|
|
12969
12945
|
if (obj === null || obj === void 0) {
|
|
12970
12946
|
return obj;
|
|
12971
12947
|
}
|
|
12972
|
-
if (obj instanceof
|
|
12948
|
+
if (obj instanceof import_mongoose29.default.Types.ObjectId) {
|
|
12973
12949
|
return obj.toString();
|
|
12974
12950
|
}
|
|
12975
12951
|
if (Array.isArray(obj)) {
|
|
@@ -13000,7 +12976,7 @@ async function findEventOrImportedMarketById(resourceId) {
|
|
|
13000
12976
|
|
|
13001
12977
|
// src/types/index.ts
|
|
13002
12978
|
var import_express = __toESM(require("express"));
|
|
13003
|
-
var
|
|
12979
|
+
var import_mongoose31 = __toESM(require("mongoose"));
|
|
13004
12980
|
var EnumPubSubEvents = /* @__PURE__ */ ((EnumPubSubEvents2) => {
|
|
13005
12981
|
EnumPubSubEvents2["GET_CHAT_MESSAGE"] = "GET_CHAT_MESSAGE";
|
|
13006
12982
|
EnumPubSubEvents2["GET_NOTIFICATIONS"] = "GET_NOTIFICATIONS";
|