@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/mongoose/index.mjs
CHANGED
package/dist/service/index.cjs
CHANGED
|
@@ -12451,7 +12451,8 @@ var schema11 = new MongooseSchema15(
|
|
|
12451
12451
|
required: false,
|
|
12452
12452
|
type: [resourceRelationsSchema]
|
|
12453
12453
|
},
|
|
12454
|
-
tags: { required: true, type: [String] }
|
|
12454
|
+
tags: { required: true, type: [String] },
|
|
12455
|
+
unregisteredVendorIds: { default: [], required: false, type: [String] }
|
|
12455
12456
|
},
|
|
12456
12457
|
{ timestamps: true }
|
|
12457
12458
|
);
|
|
@@ -12805,83 +12806,101 @@ async function updateAdStatuses() {
|
|
|
12805
12806
|
|
|
12806
12807
|
// src/service/associate.ts
|
|
12807
12808
|
var import_mongoose26 = __toESM(require("mongoose"));
|
|
12808
|
-
|
|
12809
|
-
|
|
12810
|
-
|
|
12809
|
+
function normalizeObjectId(id) {
|
|
12810
|
+
return typeof id === "string" ? new import_mongoose26.default.Types.ObjectId(id) : id;
|
|
12811
|
+
}
|
|
12812
|
+
async function getAssociateEmailsForResource({
|
|
12813
|
+
normalizedResourceId,
|
|
12811
12814
|
resourceType
|
|
12812
12815
|
}) {
|
|
12813
|
-
|
|
12814
|
-
|
|
12815
|
-
|
|
12816
|
-
|
|
12817
|
-
|
|
12818
|
-
|
|
12819
|
-
$elemMatch: {
|
|
12820
|
-
resourceId: normalizedResourceId,
|
|
12821
|
-
resourceType
|
|
12822
|
-
}
|
|
12816
|
+
const usersWithAssociates = await UserModel.find(
|
|
12817
|
+
{
|
|
12818
|
+
associates: {
|
|
12819
|
+
$elemMatch: {
|
|
12820
|
+
resourceId: normalizedResourceId,
|
|
12821
|
+
resourceType
|
|
12823
12822
|
}
|
|
12824
|
-
}
|
|
12825
|
-
|
|
12826
|
-
|
|
12827
|
-
|
|
12828
|
-
|
|
12829
|
-
|
|
12830
|
-
|
|
12831
|
-
|
|
12832
|
-
|
|
12833
|
-
|
|
12834
|
-
|
|
12835
|
-
)
|
|
12823
|
+
}
|
|
12824
|
+
},
|
|
12825
|
+
{
|
|
12826
|
+
associates: 1
|
|
12827
|
+
}
|
|
12828
|
+
).lean();
|
|
12829
|
+
return [
|
|
12830
|
+
...new Set(
|
|
12831
|
+
usersWithAssociates.flatMap(
|
|
12832
|
+
(user) => (user.associates ?? []).filter(
|
|
12833
|
+
(associate) => associate.resourceId === normalizedResourceId && associate.resourceType === resourceType
|
|
12834
|
+
).map((associate) => associate.email)
|
|
12836
12835
|
)
|
|
12837
|
-
|
|
12838
|
-
|
|
12839
|
-
|
|
12840
|
-
|
|
12841
|
-
|
|
12842
|
-
|
|
12836
|
+
)
|
|
12837
|
+
];
|
|
12838
|
+
}
|
|
12839
|
+
async function pullAssociatesFromUsers({
|
|
12840
|
+
normalizedResourceId,
|
|
12841
|
+
resourceType
|
|
12842
|
+
}) {
|
|
12843
|
+
await UserModel.updateMany(
|
|
12844
|
+
{
|
|
12845
|
+
associates: {
|
|
12846
|
+
$elemMatch: {
|
|
12847
|
+
resourceId: normalizedResourceId,
|
|
12848
|
+
resourceType
|
|
12849
|
+
}
|
|
12850
|
+
}
|
|
12851
|
+
},
|
|
12852
|
+
{
|
|
12853
|
+
$pull: {
|
|
12843
12854
|
associates: {
|
|
12844
|
-
|
|
12845
|
-
|
|
12846
|
-
resourceType
|
|
12847
|
-
}
|
|
12855
|
+
resourceId: normalizedResourceId,
|
|
12856
|
+
resourceType
|
|
12848
12857
|
}
|
|
12849
|
-
}
|
|
12850
|
-
|
|
12851
|
-
|
|
12852
|
-
|
|
12853
|
-
|
|
12854
|
-
|
|
12855
|
-
|
|
12858
|
+
}
|
|
12859
|
+
}
|
|
12860
|
+
);
|
|
12861
|
+
}
|
|
12862
|
+
async function pullAssociateParticipantsFromChats(resourceOwnerId, associateEmails) {
|
|
12863
|
+
await ChatModel.updateMany(
|
|
12864
|
+
{
|
|
12865
|
+
active: true,
|
|
12866
|
+
chatType: EnumChatType.RELATION,
|
|
12867
|
+
deletedAt: null,
|
|
12868
|
+
participants: {
|
|
12869
|
+
$elemMatch: {
|
|
12870
|
+
userId: resourceOwnerId
|
|
12856
12871
|
}
|
|
12857
12872
|
}
|
|
12858
|
-
|
|
12859
|
-
|
|
12860
|
-
{
|
|
12861
|
-
active: true,
|
|
12862
|
-
chatType: EnumChatType.RELATION,
|
|
12863
|
-
deletedAt: null,
|
|
12873
|
+
},
|
|
12874
|
+
{
|
|
12875
|
+
$pull: {
|
|
12864
12876
|
participants: {
|
|
12865
|
-
|
|
12866
|
-
|
|
12877
|
+
isAssociate: true,
|
|
12878
|
+
userEmail: {
|
|
12879
|
+
$in: associateEmails
|
|
12867
12880
|
}
|
|
12868
12881
|
}
|
|
12869
|
-
},
|
|
12870
|
-
{
|
|
12871
|
-
$set: {
|
|
12872
|
-
"participants.$[associate].active": false
|
|
12873
|
-
}
|
|
12874
|
-
},
|
|
12875
|
-
{
|
|
12876
|
-
arrayFilters: [
|
|
12877
|
-
{
|
|
12878
|
-
"associate.isAssociate": true,
|
|
12879
|
-
"associate.userEmail": {
|
|
12880
|
-
$in: associateEmails
|
|
12881
|
-
}
|
|
12882
|
-
}
|
|
12883
|
-
]
|
|
12884
12882
|
}
|
|
12883
|
+
}
|
|
12884
|
+
);
|
|
12885
|
+
}
|
|
12886
|
+
async function removeAssociateFromResource({
|
|
12887
|
+
resourceId,
|
|
12888
|
+
resourceOwnerId,
|
|
12889
|
+
resourceType
|
|
12890
|
+
}) {
|
|
12891
|
+
try {
|
|
12892
|
+
const scope = {
|
|
12893
|
+
normalizedResourceId: resourceId.toString(),
|
|
12894
|
+
resourceType
|
|
12895
|
+
};
|
|
12896
|
+
const associateEmails = await getAssociateEmailsForResource(scope);
|
|
12897
|
+
if (associateEmails.length === 0) {
|
|
12898
|
+
return;
|
|
12899
|
+
}
|
|
12900
|
+
await pullAssociatesFromUsers(scope);
|
|
12901
|
+
await pullAssociateParticipantsFromChats(
|
|
12902
|
+
normalizeObjectId(resourceOwnerId),
|
|
12903
|
+
associateEmails
|
|
12885
12904
|
);
|
|
12886
12905
|
} catch (error) {
|
|
12887
12906
|
console.error(
|