shuttlepro-shared 1.1.66 → 1.1.68
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/common/repositories/integration.repository.js +13 -4
- package/models/Profile.js +120 -0
- package/models.js +2 -0
- package/package.json +1 -1
|
@@ -69,9 +69,7 @@ const findIntegrationsByWorkspace = async (workspaceId, filter = {}) => {
|
|
|
69
69
|
* Find integration by filter (supports both workspace & non-workspace).
|
|
70
70
|
*/
|
|
71
71
|
const findIntegrationByFilter = async (filter, workspaceId = null) => {
|
|
72
|
-
console.log(filter, "filter");
|
|
73
72
|
const allIntegrations = await getCachedAllIntegrations();
|
|
74
|
-
console.log(allIntegrations, "allIntegrations");
|
|
75
73
|
|
|
76
74
|
let filteredIntegrations = allIntegrations;
|
|
77
75
|
if (workspaceId) {
|
|
@@ -80,9 +78,20 @@ const findIntegrationByFilter = async (filter, workspaceId = null) => {
|
|
|
80
78
|
);
|
|
81
79
|
}
|
|
82
80
|
|
|
81
|
+
console.log(filteredIntegrations, "filteredIntegrations");
|
|
82
|
+
console.log(filter, "filter");
|
|
83
|
+
|
|
84
|
+
console.log(
|
|
85
|
+
filteredIntegrations.find((item) =>
|
|
86
|
+
Object.entries(filter).every(
|
|
87
|
+
([key, value]) => item?.body?.[key] === value
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
|
|
83
92
|
return (
|
|
84
|
-
filteredIntegrations.find((
|
|
85
|
-
Object.entries(filter).every(([key, value]) =>
|
|
93
|
+
filteredIntegrations.find((item) =>
|
|
94
|
+
Object.entries(filter).every(([key, value]) => item.body?.[key] === value)
|
|
86
95
|
) || null
|
|
87
96
|
);
|
|
88
97
|
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
const { Schema } = mongoose;
|
|
3
|
+
const { setRedisData, getRedisData } = require("../utils");
|
|
4
|
+
|
|
5
|
+
const ProfileSchema = new Schema(
|
|
6
|
+
{
|
|
7
|
+
name: { type: String, default: "" },
|
|
8
|
+
userName: { type: String, default: "" },
|
|
9
|
+
profilePicture: { type: String, default: "" },
|
|
10
|
+
profileId: { type: String, default: "" },
|
|
11
|
+
isSpam: { type: Boolean, default: false },
|
|
12
|
+
workspaceId: { type: String, default: "" },
|
|
13
|
+
email: { type: String, default: "" },
|
|
14
|
+
phoneNo: { type: String, default: "" },
|
|
15
|
+
},
|
|
16
|
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
17
|
+
);
|
|
18
|
+
const Profile = mongoose.model("Profile", ProfileSchema);
|
|
19
|
+
|
|
20
|
+
const addOrUpdateProfilesInRedis = async (profile) => {
|
|
21
|
+
try {
|
|
22
|
+
const docId = profile?._id.toString();
|
|
23
|
+
let profiles = await fetchProfiles(profile?.workspaceId);
|
|
24
|
+
const profilesMap = profiles.reduce((map, p) => {
|
|
25
|
+
map[p._id.toString()] = p;
|
|
26
|
+
return map;
|
|
27
|
+
}, {});
|
|
28
|
+
profilesMap[docId] = profile.toObject();
|
|
29
|
+
profiles = Object.values(profilesMap);
|
|
30
|
+
setRedisData(`${profile?.workspaceId}-profiles`, profiles);
|
|
31
|
+
return { code: 200 };
|
|
32
|
+
} catch (err) {
|
|
33
|
+
return { code: 400 };
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const fetchProfiles = async (workspaceId) => {
|
|
38
|
+
try {
|
|
39
|
+
let profiles = await getRedisData(`${workspaceId}-profiles`);
|
|
40
|
+
if (!profiles || profiles.length === 0) {
|
|
41
|
+
profiles = await Profile.find({ workspaceId }).lean().exec();
|
|
42
|
+
setRedisData(`${workspaceId}-profiles`, profiles);
|
|
43
|
+
}
|
|
44
|
+
return profiles;
|
|
45
|
+
} catch (err) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const fetchByProfileIdAndWorkspaceId = async (id, workspaceId) => {
|
|
51
|
+
try {
|
|
52
|
+
let profiles = await fetchProfiles(workspaceId);
|
|
53
|
+
let profile = profiles.find(
|
|
54
|
+
(p) =>
|
|
55
|
+
(p?.profileId === id || p._id.toString() === id.toString()) &&
|
|
56
|
+
p?.workspaceId.toString() === workspaceId.toString()
|
|
57
|
+
);
|
|
58
|
+
return profile || null;
|
|
59
|
+
} catch (err) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const fetchProfileByEmailAndWorkspaceId = async (
|
|
65
|
+
workspaceId,
|
|
66
|
+
userName = ""
|
|
67
|
+
) => {
|
|
68
|
+
try {
|
|
69
|
+
let profiles = await fetchProfiles(workspaceId);
|
|
70
|
+
let profile = profiles.find(
|
|
71
|
+
(p) => p?.userName === userName && p?.workspaceId === workspaceId
|
|
72
|
+
);
|
|
73
|
+
return profile || null;
|
|
74
|
+
} catch (err) {
|
|
75
|
+
console.log(err, "err");
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const createProfile = async (obj) => {
|
|
81
|
+
try {
|
|
82
|
+
let profile = await Profile.create(obj);
|
|
83
|
+
await addOrUpdateProfilesInRedis(profile);
|
|
84
|
+
return profile;
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.log(err, "err");
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const createUpdateProfileModified = async (filter, obj) => {
|
|
91
|
+
try {
|
|
92
|
+
let profile = await Profile.findOneAndUpdate(filter, obj, { new: true });
|
|
93
|
+
await addOrUpdateProfilesInRedis(profile);
|
|
94
|
+
return profile;
|
|
95
|
+
} catch (err) {
|
|
96
|
+
console.log(err, "err");
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const updateProfile = async (query, payload) => {
|
|
101
|
+
try {
|
|
102
|
+
const profile = await Profile.findOneAndUpdate(query, payload, {
|
|
103
|
+
new: true,
|
|
104
|
+
});
|
|
105
|
+
await addOrUpdateProfilesInRedis(profile);
|
|
106
|
+
return profile;
|
|
107
|
+
} catch (err) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
module.exports = {
|
|
113
|
+
fetchByProfileIdAndWorkspaceId,
|
|
114
|
+
fetchProfileByEmailAndWorkspaceId,
|
|
115
|
+
createProfile,
|
|
116
|
+
updateProfile,
|
|
117
|
+
fetchProfiles,
|
|
118
|
+
Profile,
|
|
119
|
+
createUpdateProfileModified,
|
|
120
|
+
};
|
package/models.js
CHANGED
|
@@ -34,6 +34,7 @@ const StatusType = require("./models/StatusType");
|
|
|
34
34
|
const Type = require("./models/Type");
|
|
35
35
|
const Workspace = require("./models/Workspace");
|
|
36
36
|
const Card = require("./models/Card");
|
|
37
|
+
const Profile = require("./models/Profile");
|
|
37
38
|
|
|
38
39
|
module.exports = {
|
|
39
40
|
Website,
|
|
@@ -72,4 +73,5 @@ module.exports = {
|
|
|
72
73
|
StatusType,
|
|
73
74
|
Card,
|
|
74
75
|
DescriptionTemplate,
|
|
76
|
+
Profile,
|
|
75
77
|
};
|