@timardex/cluemart-server-shared 1.0.162 → 1.0.164
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/{chunk-N2SOT77G.mjs → chunk-RGSAG3WZ.mjs} +3 -2
- package/dist/{chunk-N2SOT77G.mjs.map → chunk-RGSAG3WZ.mjs.map} +1 -1
- package/dist/index.cjs +85 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +85 -66
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +2 -1
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.mjs +1 -1
- package/dist/service/index.cjs +85 -66
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.mjs +83 -65
- package/dist/service/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -12272,7 +12272,8 @@ var schema11 = new MongooseSchema15(
|
|
|
12272
12272
|
required: false,
|
|
12273
12273
|
type: [resourceRelationsSchema]
|
|
12274
12274
|
},
|
|
12275
|
-
tags: { required: true, type: [String] }
|
|
12275
|
+
tags: { required: true, type: [String] },
|
|
12276
|
+
unregisteredVendorIds: { default: [], required: false, type: [String] }
|
|
12276
12277
|
},
|
|
12277
12278
|
{ timestamps: true }
|
|
12278
12279
|
);
|
|
@@ -12783,83 +12784,101 @@ async function updateAdStatuses() {
|
|
|
12783
12784
|
|
|
12784
12785
|
// src/service/associate.ts
|
|
12785
12786
|
import mongoose25 from "mongoose";
|
|
12786
|
-
|
|
12787
|
-
|
|
12788
|
-
|
|
12787
|
+
function normalizeObjectId(id) {
|
|
12788
|
+
return typeof id === "string" ? new mongoose25.Types.ObjectId(id) : id;
|
|
12789
|
+
}
|
|
12790
|
+
async function getAssociateEmailsForResource({
|
|
12791
|
+
normalizedResourceId,
|
|
12789
12792
|
resourceType
|
|
12790
12793
|
}) {
|
|
12791
|
-
|
|
12792
|
-
|
|
12793
|
-
|
|
12794
|
-
|
|
12795
|
-
|
|
12796
|
-
|
|
12797
|
-
$elemMatch: {
|
|
12798
|
-
resourceId: normalizedResourceId,
|
|
12799
|
-
resourceType
|
|
12800
|
-
}
|
|
12794
|
+
const usersWithAssociates = await UserModel.find(
|
|
12795
|
+
{
|
|
12796
|
+
associates: {
|
|
12797
|
+
$elemMatch: {
|
|
12798
|
+
resourceId: normalizedResourceId,
|
|
12799
|
+
resourceType
|
|
12801
12800
|
}
|
|
12802
|
-
}
|
|
12803
|
-
|
|
12804
|
-
|
|
12805
|
-
|
|
12806
|
-
|
|
12807
|
-
|
|
12808
|
-
|
|
12809
|
-
|
|
12810
|
-
|
|
12811
|
-
|
|
12812
|
-
|
|
12813
|
-
)
|
|
12801
|
+
}
|
|
12802
|
+
},
|
|
12803
|
+
{
|
|
12804
|
+
associates: 1
|
|
12805
|
+
}
|
|
12806
|
+
).lean();
|
|
12807
|
+
return [
|
|
12808
|
+
...new Set(
|
|
12809
|
+
usersWithAssociates.flatMap(
|
|
12810
|
+
(user) => (user.associates ?? []).filter(
|
|
12811
|
+
(associate) => associate.resourceId === normalizedResourceId && associate.resourceType === resourceType
|
|
12812
|
+
).map((associate) => associate.email)
|
|
12814
12813
|
)
|
|
12815
|
-
|
|
12816
|
-
|
|
12817
|
-
|
|
12818
|
-
|
|
12819
|
-
|
|
12820
|
-
|
|
12814
|
+
)
|
|
12815
|
+
];
|
|
12816
|
+
}
|
|
12817
|
+
async function pullAssociatesFromUsers({
|
|
12818
|
+
normalizedResourceId,
|
|
12819
|
+
resourceType
|
|
12820
|
+
}) {
|
|
12821
|
+
await UserModel.updateMany(
|
|
12822
|
+
{
|
|
12823
|
+
associates: {
|
|
12824
|
+
$elemMatch: {
|
|
12825
|
+
resourceId: normalizedResourceId,
|
|
12826
|
+
resourceType
|
|
12827
|
+
}
|
|
12828
|
+
}
|
|
12829
|
+
},
|
|
12830
|
+
{
|
|
12831
|
+
$pull: {
|
|
12821
12832
|
associates: {
|
|
12822
|
-
|
|
12823
|
-
|
|
12824
|
-
resourceType
|
|
12825
|
-
}
|
|
12833
|
+
resourceId: normalizedResourceId,
|
|
12834
|
+
resourceType
|
|
12826
12835
|
}
|
|
12827
|
-
}
|
|
12828
|
-
|
|
12829
|
-
|
|
12830
|
-
|
|
12831
|
-
|
|
12832
|
-
|
|
12833
|
-
|
|
12836
|
+
}
|
|
12837
|
+
}
|
|
12838
|
+
);
|
|
12839
|
+
}
|
|
12840
|
+
async function pullAssociateParticipantsFromChats(resourceOwnerId, associateEmails) {
|
|
12841
|
+
await ChatModel.updateMany(
|
|
12842
|
+
{
|
|
12843
|
+
active: true,
|
|
12844
|
+
chatType: EnumChatType.RELATION,
|
|
12845
|
+
deletedAt: null,
|
|
12846
|
+
participants: {
|
|
12847
|
+
$elemMatch: {
|
|
12848
|
+
userId: resourceOwnerId
|
|
12834
12849
|
}
|
|
12835
12850
|
}
|
|
12836
|
-
|
|
12837
|
-
|
|
12838
|
-
{
|
|
12839
|
-
active: true,
|
|
12840
|
-
chatType: EnumChatType.RELATION,
|
|
12841
|
-
deletedAt: null,
|
|
12851
|
+
},
|
|
12852
|
+
{
|
|
12853
|
+
$pull: {
|
|
12842
12854
|
participants: {
|
|
12843
|
-
|
|
12844
|
-
|
|
12855
|
+
isAssociate: true,
|
|
12856
|
+
userEmail: {
|
|
12857
|
+
$in: associateEmails
|
|
12845
12858
|
}
|
|
12846
12859
|
}
|
|
12847
|
-
},
|
|
12848
|
-
{
|
|
12849
|
-
$set: {
|
|
12850
|
-
"participants.$[associate].active": false
|
|
12851
|
-
}
|
|
12852
|
-
},
|
|
12853
|
-
{
|
|
12854
|
-
arrayFilters: [
|
|
12855
|
-
{
|
|
12856
|
-
"associate.isAssociate": true,
|
|
12857
|
-
"associate.userEmail": {
|
|
12858
|
-
$in: associateEmails
|
|
12859
|
-
}
|
|
12860
|
-
}
|
|
12861
|
-
]
|
|
12862
12860
|
}
|
|
12861
|
+
}
|
|
12862
|
+
);
|
|
12863
|
+
}
|
|
12864
|
+
async function removeAssociateFromResource({
|
|
12865
|
+
resourceId,
|
|
12866
|
+
resourceOwnerId,
|
|
12867
|
+
resourceType
|
|
12868
|
+
}) {
|
|
12869
|
+
try {
|
|
12870
|
+
const scope = {
|
|
12871
|
+
normalizedResourceId: resourceId.toString(),
|
|
12872
|
+
resourceType
|
|
12873
|
+
};
|
|
12874
|
+
const associateEmails = await getAssociateEmailsForResource(scope);
|
|
12875
|
+
if (associateEmails.length === 0) {
|
|
12876
|
+
return;
|
|
12877
|
+
}
|
|
12878
|
+
await pullAssociatesFromUsers(scope);
|
|
12879
|
+
await pullAssociateParticipantsFromChats(
|
|
12880
|
+
normalizeObjectId(resourceOwnerId),
|
|
12881
|
+
associateEmails
|
|
12863
12882
|
);
|
|
12864
12883
|
} catch (error) {
|
|
12865
12884
|
console.error(
|