@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/service/index.cjs
CHANGED
|
@@ -12765,9 +12765,6 @@ async function updateAdStatuses() {
|
|
|
12765
12765
|
);
|
|
12766
12766
|
}
|
|
12767
12767
|
|
|
12768
|
-
// src/service/vendor.ts
|
|
12769
|
-
var import_mongoose28 = __toESM(require("mongoose"));
|
|
12770
|
-
|
|
12771
12768
|
// src/service/associate.ts
|
|
12772
12769
|
var import_mongoose26 = __toESM(require("mongoose"));
|
|
12773
12770
|
async function removeAssociateFromResource({
|
|
@@ -12775,11 +12772,9 @@ async function removeAssociateFromResource({
|
|
|
12775
12772
|
resourceOwnerId,
|
|
12776
12773
|
resourceType
|
|
12777
12774
|
}) {
|
|
12778
|
-
const normalizedResourceId = resourceId.toString();
|
|
12779
|
-
const normalizedOwnerId = typeof resourceOwnerId === "string" ? new import_mongoose26.default.Types.ObjectId(resourceOwnerId) : resourceOwnerId;
|
|
12780
|
-
const session = await import_mongoose26.default.startSession();
|
|
12781
12775
|
try {
|
|
12782
|
-
|
|
12776
|
+
const normalizedResourceId = resourceId.toString();
|
|
12777
|
+
const normalizedOwnerId = typeof resourceOwnerId === "string" ? new import_mongoose26.default.Types.ObjectId(resourceOwnerId) : resourceOwnerId;
|
|
12783
12778
|
const usersWithAssociates = await UserModel.find(
|
|
12784
12779
|
{
|
|
12785
12780
|
associates: {
|
|
@@ -12791,16 +12786,18 @@ async function removeAssociateFromResource({
|
|
|
12791
12786
|
},
|
|
12792
12787
|
{
|
|
12793
12788
|
associates: 1
|
|
12794
|
-
// Only fetch associates field for efficiency
|
|
12795
12789
|
}
|
|
12796
|
-
).lean()
|
|
12797
|
-
const associateEmails =
|
|
12798
|
-
|
|
12799
|
-
(
|
|
12800
|
-
|
|
12801
|
-
|
|
12790
|
+
).lean();
|
|
12791
|
+
const associateEmails = [
|
|
12792
|
+
...new Set(
|
|
12793
|
+
usersWithAssociates.flatMap(
|
|
12794
|
+
(user) => (user.associates ?? []).filter(
|
|
12795
|
+
(associate) => associate.resourceId === normalizedResourceId && associate.resourceType === resourceType
|
|
12796
|
+
).map((associate) => associate.email)
|
|
12797
|
+
)
|
|
12798
|
+
)
|
|
12799
|
+
];
|
|
12802
12800
|
if (associateEmails.length === 0) {
|
|
12803
|
-
await session.commitTransaction();
|
|
12804
12801
|
return;
|
|
12805
12802
|
}
|
|
12806
12803
|
await UserModel.updateMany(
|
|
@@ -12819,8 +12816,7 @@ async function removeAssociateFromResource({
|
|
|
12819
12816
|
resourceType
|
|
12820
12817
|
}
|
|
12821
12818
|
}
|
|
12822
|
-
}
|
|
12823
|
-
{ session }
|
|
12819
|
+
}
|
|
12824
12820
|
);
|
|
12825
12821
|
await ChatModel.updateMany(
|
|
12826
12822
|
{
|
|
@@ -12835,103 +12831,83 @@ async function removeAssociateFromResource({
|
|
|
12835
12831
|
},
|
|
12836
12832
|
{
|
|
12837
12833
|
$set: {
|
|
12838
|
-
"participants.$[
|
|
12834
|
+
"participants.$[associate].active": false
|
|
12839
12835
|
}
|
|
12840
12836
|
},
|
|
12841
12837
|
{
|
|
12842
12838
|
arrayFilters: [
|
|
12843
12839
|
{
|
|
12844
|
-
"
|
|
12845
|
-
"
|
|
12840
|
+
"associate.isAssociate": true,
|
|
12841
|
+
"associate.userEmail": {
|
|
12842
|
+
$in: associateEmails
|
|
12843
|
+
}
|
|
12846
12844
|
}
|
|
12847
|
-
]
|
|
12848
|
-
session
|
|
12845
|
+
]
|
|
12849
12846
|
}
|
|
12850
12847
|
);
|
|
12851
|
-
await session.commitTransaction();
|
|
12852
12848
|
} catch (error) {
|
|
12853
|
-
await session.abortTransaction();
|
|
12854
12849
|
console.error(
|
|
12855
|
-
`[removeAssociateFromResource] Failed for resourceId=${
|
|
12850
|
+
`[removeAssociateFromResource] Failed for resourceId=${resourceId}, resourceType=${resourceType}`,
|
|
12856
12851
|
error
|
|
12857
12852
|
);
|
|
12858
|
-
throw error;
|
|
12859
|
-
} finally {
|
|
12860
|
-
session.endSession();
|
|
12861
12853
|
}
|
|
12862
12854
|
}
|
|
12863
12855
|
|
|
12864
12856
|
// src/service/vendor.ts
|
|
12865
12857
|
async function updateVendorBasedOnUserLicense(userId, licenceType) {
|
|
12866
|
-
const session = await import_mongoose28.default.startSession();
|
|
12867
12858
|
try {
|
|
12868
|
-
|
|
12869
|
-
const user = await UserModel.findById(userId).select("vendor").lean().session(session);
|
|
12859
|
+
const user = await UserModel.findById(userId).select("vendor").lean();
|
|
12870
12860
|
if (!user?.vendor) {
|
|
12871
|
-
console.warn(`[updateVendor] No vendor for userId=${userId}`);
|
|
12872
|
-
await session.abortTransaction();
|
|
12861
|
+
console.warn(`[updateVendor] No vendor found for userId=${userId}`);
|
|
12873
12862
|
return;
|
|
12874
12863
|
}
|
|
12875
|
-
const vendor = await VendorModel.findById(user.vendor).lean()
|
|
12864
|
+
const vendor = await VendorModel.findById(user.vendor).lean();
|
|
12876
12865
|
if (!vendor) {
|
|
12877
12866
|
console.warn(`[updateVendor] Vendor not found for id=${user.vendor}`);
|
|
12878
|
-
await session.abortTransaction();
|
|
12879
12867
|
return;
|
|
12880
12868
|
}
|
|
12881
|
-
const
|
|
12882
|
-
|
|
12883
|
-
|
|
12884
|
-
|
|
12869
|
+
const updateData = {};
|
|
12870
|
+
const isStandardVendor = licenceType === EnumUserLicence.STANDARD_VENDOR;
|
|
12871
|
+
if (isStandardVendor) {
|
|
12872
|
+
updateData.associates = [];
|
|
12873
|
+
updateData.availability = {
|
|
12885
12874
|
corporate: false,
|
|
12886
12875
|
private: false,
|
|
12887
12876
|
school: false
|
|
12888
12877
|
};
|
|
12889
|
-
|
|
12878
|
+
updateData.products = {
|
|
12890
12879
|
active: false,
|
|
12891
12880
|
productsList: vendor.products?.productsList ?? []
|
|
12892
12881
|
};
|
|
12893
|
-
|
|
12882
|
+
updateData.calendar = {
|
|
12894
12883
|
active: false,
|
|
12895
12884
|
calendarData: vendor.calendar?.calendarData ?? []
|
|
12896
12885
|
};
|
|
12897
|
-
vendorUpdateData.images = (vendor.images ?? []).map((img, index) => ({
|
|
12898
|
-
...img,
|
|
12899
|
-
active: index < 6
|
|
12900
|
-
}));
|
|
12901
|
-
} else {
|
|
12902
|
-
vendorUpdateData.images = (vendor.images ?? []).map((img) => ({
|
|
12903
|
-
...img,
|
|
12904
|
-
active: true
|
|
12905
|
-
}));
|
|
12906
12886
|
}
|
|
12907
|
-
|
|
12908
|
-
|
|
12909
|
-
|
|
12910
|
-
|
|
12911
|
-
);
|
|
12912
|
-
if (
|
|
12887
|
+
updateData.images = (vendor.images ?? []).map((image, index) => ({
|
|
12888
|
+
...image,
|
|
12889
|
+
active: isStandardVendor ? index < 6 : true
|
|
12890
|
+
}));
|
|
12891
|
+
await VendorModel.updateOne({ _id: vendor._id }, { $set: updateData });
|
|
12892
|
+
if (isStandardVendor) {
|
|
12913
12893
|
await removeAssociateFromResource({
|
|
12914
12894
|
resourceId: vendor._id,
|
|
12915
12895
|
resourceOwnerId: vendor.owner.userId,
|
|
12916
12896
|
resourceType: EnumResourceType.VENDOR
|
|
12917
12897
|
});
|
|
12918
12898
|
}
|
|
12919
|
-
await session.commitTransaction();
|
|
12920
12899
|
} catch (error) {
|
|
12921
|
-
await session.abortTransaction();
|
|
12922
12900
|
console.error("[updateVendorBasedOnUserLicense] Failed:", error);
|
|
12923
|
-
} finally {
|
|
12924
|
-
session.endSession();
|
|
12925
12901
|
}
|
|
12926
12902
|
}
|
|
12927
12903
|
|
|
12928
12904
|
// src/service/objectIdToString.ts
|
|
12929
|
-
var
|
|
12905
|
+
var import_mongoose29 = __toESM(require("mongoose"));
|
|
12930
12906
|
function convertObjectIdsToStrings(obj) {
|
|
12931
12907
|
if (obj === null || obj === void 0) {
|
|
12932
12908
|
return obj;
|
|
12933
12909
|
}
|
|
12934
|
-
if (obj instanceof
|
|
12910
|
+
if (obj instanceof import_mongoose29.default.Types.ObjectId) {
|
|
12935
12911
|
return obj.toString();
|
|
12936
12912
|
}
|
|
12937
12913
|
if (Array.isArray(obj)) {
|