shuttlepro-shared 1.3.13 → 1.3.14
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/constants/index.js +0 -15
- package/index.js +0 -8
- package/models/UserRole.js +119 -1
- package/models/Website.js +1 -0
- package/models.js +1 -62
- package/package.json +2 -13
- package/common/repositories/chatMember.repository.js +0 -9
- package/common/repositories/customerProfile.repository.js +0 -147
- package/common/repositories/descriptionTemplates.repository.js +0 -229
- package/common/repositories/index.js +0 -32
- package/common/repositories/integration.repository.js +0 -210
- package/common/repositories/label.repository.js +0 -95
- package/common/repositories/notificationSettings.repository.js +0 -95
- package/common/repositories/role.repository.js +0 -333
- package/common/repositories/settings.repository.js +0 -32
- package/common/repositories/shipper.repository.js +0 -77
- package/common/repositories/socialMediaSetting.repository.js +0 -33
- package/common/repositories/user.repository.js +0 -150
- package/common/repositories/userPermission.repository.js +0 -228
- package/common/repositories/userRepository.js +0 -31
- package/common/repositories/userRole.repository.js +0 -235
- package/common/repositories/userRolePermission.repository.js +0 -59
- package/common/repositories/workspace.repository.js +0 -147
- package/config/bull.js +0 -78
- package/config/config.js +0 -14
- package/config/database.js +0 -4
- package/config/index.js +0 -13
- package/config/redis.js +0 -196
- package/config/socket.js +0 -172
- package/models/AgentActivity.js +0 -192
- package/models/Assignment.js +0 -23
- package/models/BusinessDistribution.js +0 -23
- package/models/Card.js +0 -144
- package/models/CardComments.js +0 -33
- package/models/ChatMember.js +0 -17
- package/models/Chatbot.js +0 -20
- package/models/Checkpoint.js +0 -50
- package/models/City.js +0 -17
- package/models/Column.js +0 -28
- package/models/Conversation.js +0 -87
- package/models/Customer.js +0 -36
- package/models/CustomerProfile.js +0 -27
- package/models/DefaultRolePermission.js +0 -34
- package/models/DescriptionTemplate.js +0 -22
- package/models/Integration.js +0 -51
- package/models/Label.js +0 -42
- package/models/Message.js +0 -47
- package/models/NewProduct.js +0 -71
- package/models/NotificationSettings.js +0 -130
- package/models/Order.js +0 -236
- package/models/OrderProduct.js +0 -37
- package/models/Profile.js +0 -127
- package/models/Report.js +0 -27
- package/models/Setting.js +0 -18
- package/models/Shipper.js +0 -62
- package/models/SocialMediaSetting.js +0 -28
- package/models/Status.js +0 -58
- package/models/StatusType.js +0 -10
- package/models/Step.js +0 -50
- package/models/Type.js +0 -25
- package/models/UserWorkflow.js +0 -46
- package/models/Workspace.js +0 -308
- package/utils/decorator-factory.js +0 -264
- package/utils/logger.js +0 -41
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const workspaceRepository = require("./workspace.repository");
|
|
2
|
-
const integrationRepository = require("./integration.repository");
|
|
3
|
-
const descriptionTemplateRepository = require("./descriptionTemplates.repository");
|
|
4
|
-
const shipperRepository = require("./shipper.repository");
|
|
5
|
-
const labelRepository = require("./label.repository");
|
|
6
|
-
const userRepository = require("./user.repository");
|
|
7
|
-
const userRoleRepository = require("./userRole.repository");
|
|
8
|
-
const settingRepository = require("./settings.repository");
|
|
9
|
-
const socialMediaSettingRepository = require("./socialMediaSetting.repository");
|
|
10
|
-
const chatMemberRepository = require("./chatMember.repository");
|
|
11
|
-
const roleRepository = require("./role.repository");
|
|
12
|
-
const userPermissionRepository = require("./userPermission.repository");
|
|
13
|
-
const userRolePermissionRepository = require("./userRolePermission.repository");
|
|
14
|
-
const notificationSettingsRepository = require("./notificationSettings.repository");
|
|
15
|
-
const customerProfileRepository = require("./customerProfile.repository");
|
|
16
|
-
exports.module = {
|
|
17
|
-
workspaceRepository,
|
|
18
|
-
integrationRepository,
|
|
19
|
-
descriptionTemplateRepository,
|
|
20
|
-
shipperRepository,
|
|
21
|
-
labelRepository,
|
|
22
|
-
userRepository,
|
|
23
|
-
userRoleRepository,
|
|
24
|
-
settingRepository,
|
|
25
|
-
socialMediaSettingRepository,
|
|
26
|
-
notificationSettingsRepository,
|
|
27
|
-
chatMemberRepository,
|
|
28
|
-
roleRepository,
|
|
29
|
-
userPermissionRepository,
|
|
30
|
-
userRolePermissionRepository,
|
|
31
|
-
customerProfileRepository,
|
|
32
|
-
};
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
const { getRedisData, setRedisData } = require("../../config/redis");
|
|
2
|
-
const Integration = require("../../models/Integration");
|
|
3
|
-
|
|
4
|
-
const CACHE_KEY_ALL = "integrations_all";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Get cached integrations for all workspaces.
|
|
8
|
-
*/
|
|
9
|
-
const getCachedAllIntegrations = async () => {
|
|
10
|
-
let integrations = await getRedisData(CACHE_KEY_ALL);
|
|
11
|
-
if (!integrations) {
|
|
12
|
-
integrations = await Integration.find({}).lean().exec();
|
|
13
|
-
await setRedisData(CACHE_KEY_ALL, integrations);
|
|
14
|
-
}
|
|
15
|
-
return integrations?.map((x) => {
|
|
16
|
-
return {
|
|
17
|
-
...x,
|
|
18
|
-
_id: x?._id?.toString(),
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Update cached integrations for all workspaces.
|
|
25
|
-
*/
|
|
26
|
-
const updateCachedAllIntegrations = async () => {
|
|
27
|
-
const integrations = await Integration.find({}).lean().exec();
|
|
28
|
-
await setRedisData(CACHE_KEY_ALL, integrations);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Get cached integrations for a specific workspace.
|
|
33
|
-
* Now uses the all integrations cache and filters by workspaceId.
|
|
34
|
-
*/
|
|
35
|
-
const getCachedIntegrations = async (workspaceId) => {
|
|
36
|
-
const allIntegrations = await getCachedAllIntegrations();
|
|
37
|
-
return allIntegrations.filter((intg) => intg.workspaceId === workspaceId);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Create a new integration and update cache.
|
|
42
|
-
*/
|
|
43
|
-
const createIntegration = async (data) => {
|
|
44
|
-
const newIntegration = new Integration(data);
|
|
45
|
-
const savedIntegration = await newIntegration.save();
|
|
46
|
-
|
|
47
|
-
// Update only the main cache
|
|
48
|
-
await updateCachedAllIntegrations();
|
|
49
|
-
|
|
50
|
-
return savedIntegration;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Find an integration by ID.
|
|
55
|
-
*/
|
|
56
|
-
const findIntegrationsByWorkspaceId = async (workspaceId) => {
|
|
57
|
-
return await getCachedIntegrations(workspaceId);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Find integrations by workspace.
|
|
62
|
-
*/
|
|
63
|
-
const findIntegrationsByWorkspace = async (workspaceId, filter = {}) => {
|
|
64
|
-
const allIntegrations = await getCachedIntegrations(workspaceId);
|
|
65
|
-
|
|
66
|
-
return allIntegrations.filter(
|
|
67
|
-
(intg) =>
|
|
68
|
-
intg.workspaceId === workspaceId &&
|
|
69
|
-
Object.entries(filter).every(([key, value]) => intg[key] === value)
|
|
70
|
-
);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Find integration by filter (supports both workspace & non-workspace).
|
|
75
|
-
*/
|
|
76
|
-
const findIntegrationByFilter = async (
|
|
77
|
-
filter,
|
|
78
|
-
bodyFilter = {},
|
|
79
|
-
workspaceId = null
|
|
80
|
-
) => {
|
|
81
|
-
const allIntegrations = await getCachedAllIntegrations();
|
|
82
|
-
|
|
83
|
-
let filteredIntegrations = allIntegrations;
|
|
84
|
-
if (workspaceId) {
|
|
85
|
-
filteredIntegrations = allIntegrations.filter(
|
|
86
|
-
(intg) => intg.workspaceId === workspaceId
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return (
|
|
91
|
-
filteredIntegrations.find(
|
|
92
|
-
(item) =>
|
|
93
|
-
Object.entries(filter).every(([key, value]) => item[key] === value) &&
|
|
94
|
-
Object.entries(bodyFilter).every(
|
|
95
|
-
([key, value]) => item.body?.[key] === value
|
|
96
|
-
)
|
|
97
|
-
) || null
|
|
98
|
-
);
|
|
99
|
-
};
|
|
100
|
-
const findAllIntegrationByFilter = async (
|
|
101
|
-
filter = {},
|
|
102
|
-
bodyFilter = {},
|
|
103
|
-
workspaceId = null
|
|
104
|
-
) => {
|
|
105
|
-
const allIntegrations = await getCachedAllIntegrations();
|
|
106
|
-
|
|
107
|
-
let filteredIntegrations = allIntegrations;
|
|
108
|
-
if (workspaceId) {
|
|
109
|
-
filteredIntegrations = allIntegrations.filter(
|
|
110
|
-
(intg) => intg.workspaceId === workspaceId
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
return (
|
|
114
|
-
filteredIntegrations.filter(
|
|
115
|
-
(item) =>
|
|
116
|
-
Object.entries(filter).every(([key, value]) => item[key] === value) &&
|
|
117
|
-
Object.entries(bodyFilter).every(
|
|
118
|
-
([key, value]) => item.body?.[key] === value
|
|
119
|
-
)
|
|
120
|
-
) || []
|
|
121
|
-
);
|
|
122
|
-
};
|
|
123
|
-
const bulkCreateAndUpdateIntegrations = async (operations) => {
|
|
124
|
-
await Integration.bulkWrite(operations);
|
|
125
|
-
await updateCachedAllIntegrations();
|
|
126
|
-
return operations;
|
|
127
|
-
};
|
|
128
|
-
/**
|
|
129
|
-
* Find all integrations (without workspace filtering).
|
|
130
|
-
*/
|
|
131
|
-
const findAllIntegrations = async () => {
|
|
132
|
-
return await getCachedAllIntegrations();
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Update an integration by ID.
|
|
137
|
-
*/
|
|
138
|
-
const updateIntegration = async (id, data) => {
|
|
139
|
-
const updatedIntegration = await Integration.findByIdAndUpdate(id, data, {
|
|
140
|
-
new: true,
|
|
141
|
-
}).exec();
|
|
142
|
-
|
|
143
|
-
if (updatedIntegration) {
|
|
144
|
-
// Update only the main cache
|
|
145
|
-
await updateCachedAllIntegrations();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return updatedIntegration;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Update an integration by filter.
|
|
153
|
-
*/
|
|
154
|
-
const updateIntegrationByFilter = async (filter, data, workspaceId = null) => {
|
|
155
|
-
// Add workspace filter if provided
|
|
156
|
-
const queryFilter = workspaceId ? { ...filter, workspaceId } : filter;
|
|
157
|
-
|
|
158
|
-
const updatedIntegration = await Integration.findOneAndUpdate(
|
|
159
|
-
queryFilter,
|
|
160
|
-
data,
|
|
161
|
-
{
|
|
162
|
-
new: true,
|
|
163
|
-
}
|
|
164
|
-
).exec();
|
|
165
|
-
|
|
166
|
-
if (updatedIntegration) {
|
|
167
|
-
// Update only the main cache
|
|
168
|
-
await updateCachedAllIntegrations();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return updatedIntegration;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Delete an integration by ID.
|
|
176
|
-
*/
|
|
177
|
-
const deleteIntegration = async (id) => {
|
|
178
|
-
const deletedIntegration = await Integration.findByIdAndDelete(id).exec();
|
|
179
|
-
|
|
180
|
-
if (deletedIntegration) {
|
|
181
|
-
// Update only the main cache
|
|
182
|
-
await updateCachedAllIntegrations();
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return deletedIntegration;
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Delete all integrations for a specific workspace.
|
|
190
|
-
*/
|
|
191
|
-
const deleteAllIntegrationsByWorkspace = async (workspaceId) => {
|
|
192
|
-
await Integration.deleteMany({ workspaceId }).exec();
|
|
193
|
-
|
|
194
|
-
// Update only the main cache
|
|
195
|
-
await updateCachedAllIntegrations();
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
module.exports = {
|
|
199
|
-
createIntegration,
|
|
200
|
-
findIntegrationsByWorkspaceId,
|
|
201
|
-
findIntegrationsByWorkspace,
|
|
202
|
-
findIntegrationByFilter,
|
|
203
|
-
findAllIntegrations,
|
|
204
|
-
updateIntegration,
|
|
205
|
-
updateIntegrationByFilter,
|
|
206
|
-
deleteIntegration,
|
|
207
|
-
deleteAllIntegrationsByWorkspace,
|
|
208
|
-
findAllIntegrationByFilter,
|
|
209
|
-
bulkCreateAndUpdateIntegrations,
|
|
210
|
-
};
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
const Label = require("../../models/Label");
|
|
2
|
-
const {
|
|
3
|
-
setRedisData,
|
|
4
|
-
getRedisData,
|
|
5
|
-
deleteRedisData,
|
|
6
|
-
} = require("../../config/redis");
|
|
7
|
-
|
|
8
|
-
const CACHE_KEYS = {
|
|
9
|
-
ALL_LABELS: "labels:all",
|
|
10
|
-
WORKSPACE_LABELS: (workspaceId) => `labels:workspace:${workspaceId}`,
|
|
11
|
-
LABEL_DETAILS: (labelId) => `labels:details:${labelId}`,
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const CACHE_EXPIRY = 60 * 60; // 1 hour
|
|
15
|
-
|
|
16
|
-
// Utility function for caching
|
|
17
|
-
const withCache = async (cacheKey, fetchFn, forceFresh = false) => {
|
|
18
|
-
if (!forceFresh) {
|
|
19
|
-
const cachedData = await getRedisData(cacheKey);
|
|
20
|
-
if (cachedData) return cachedData;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const data = await fetchFn();
|
|
24
|
-
if (data && data.length) {
|
|
25
|
-
await setRedisData(cacheKey, data, null, CACHE_EXPIRY);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return data;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// Core functions
|
|
32
|
-
const createLabel = async (labelData) => {
|
|
33
|
-
const existingLabels = await Label.find();
|
|
34
|
-
const isDuplicate = existingLabels.some(
|
|
35
|
-
(label) =>
|
|
36
|
-
label.title.toLowerCase() === labelData.title.toLowerCase() &&
|
|
37
|
-
label.workspaceId === labelData.workspaceId
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
if (isDuplicate) throw new Error("Label with this title already exists");
|
|
41
|
-
|
|
42
|
-
const newLabel = new Label(labelData);
|
|
43
|
-
return await newLabel.save();
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const findLabels = async (query = {}, options = {}) => {
|
|
47
|
-
return await withCache(JSON.stringify(query), () =>
|
|
48
|
-
Label.find(query)
|
|
49
|
-
.sort({ createdAt: -1 })
|
|
50
|
-
.limit(options.limit || 100)
|
|
51
|
-
.exec()
|
|
52
|
-
);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const findAllLabels = async (query = {}) => {
|
|
56
|
-
return await withCache(JSON.stringify(query), () => Label.find(query).exec());
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const findLabelById = async (labelId) => {
|
|
60
|
-
return await withCache(CACHE_KEYS.LABEL_DETAILS(labelId), () =>
|
|
61
|
-
Label.findById(labelId).exec()
|
|
62
|
-
);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const findLabel = async (query = {}) => {
|
|
66
|
-
return await Label.findOne(query).exec();
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const updateLabel = async (labelId, updateData) => {
|
|
70
|
-
const updatedLabel = await Label.findByIdAndUpdate(labelId, updateData, {
|
|
71
|
-
new: true,
|
|
72
|
-
});
|
|
73
|
-
await setRedisData(
|
|
74
|
-
CACHE_KEYS.LABEL_DETAILS(labelId),
|
|
75
|
-
updatedLabel.toObject(),
|
|
76
|
-
null,
|
|
77
|
-
CACHE_EXPIRY
|
|
78
|
-
);
|
|
79
|
-
return updatedLabel;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const deleteLabel = async (labelId) => {
|
|
83
|
-
await deleteRedisData(CACHE_KEYS.LABEL_DETAILS(labelId));
|
|
84
|
-
return await Label.findByIdAndDelete(labelId);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
module.exports = {
|
|
88
|
-
createLabel,
|
|
89
|
-
findLabels,
|
|
90
|
-
findAllLabels,
|
|
91
|
-
findLabelById,
|
|
92
|
-
findLabel,
|
|
93
|
-
updateLabel,
|
|
94
|
-
deleteLabel,
|
|
95
|
-
};
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
const { getRedisData, setRedisData } = require("../../config/redis");
|
|
2
|
-
|
|
3
|
-
const NotificationSettings = require("../../models/NotificationSettings");
|
|
4
|
-
|
|
5
|
-
const getNotificationFromCache = async (workspaceId, userId) => {
|
|
6
|
-
let notificationSettings = await getRedisData(
|
|
7
|
-
`notificationSettings-${userId}`
|
|
8
|
-
);
|
|
9
|
-
if (!notificationSettings) {
|
|
10
|
-
notificationSettings = await NotificationSettings.findOne({
|
|
11
|
-
workspaceId,
|
|
12
|
-
createdBy: userId,
|
|
13
|
-
});
|
|
14
|
-
await setRedisData(`notificationSettings-${userId}`, notificationSettings);
|
|
15
|
-
}
|
|
16
|
-
return notificationSettings;
|
|
17
|
-
};
|
|
18
|
-
const getUserNotificationSettings = async (workspaceId, userId) => {
|
|
19
|
-
return await getNotificationFromCache(workspaceId, userId);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const defaultNotifications = async (workspaceId, userId = null) => {
|
|
23
|
-
try {
|
|
24
|
-
const obj = {
|
|
25
|
-
workspaceId: workspaceId,
|
|
26
|
-
products: true,
|
|
27
|
-
orders: {
|
|
28
|
-
createOrder: true,
|
|
29
|
-
orderAssign: true,
|
|
30
|
-
orderComment: true,
|
|
31
|
-
},
|
|
32
|
-
default: true,
|
|
33
|
-
conversation: {
|
|
34
|
-
instaMessage: true,
|
|
35
|
-
fbMessage: true,
|
|
36
|
-
instaComment: true,
|
|
37
|
-
fbComment: true,
|
|
38
|
-
email: true,
|
|
39
|
-
whatsapp: true,
|
|
40
|
-
},
|
|
41
|
-
socialProfiles: {
|
|
42
|
-
socialProfileComment: true,
|
|
43
|
-
story: true,
|
|
44
|
-
},
|
|
45
|
-
taskManager: {
|
|
46
|
-
cardAssign: true,
|
|
47
|
-
cardMove: true,
|
|
48
|
-
},
|
|
49
|
-
sound: {
|
|
50
|
-
play: true,
|
|
51
|
-
},
|
|
52
|
-
createdBy: userId,
|
|
53
|
-
};
|
|
54
|
-
return await NotificationSettings.create(obj);
|
|
55
|
-
} catch (err) {
|
|
56
|
-
console.log(err, "err");
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const updateUserNotificationSettings = async (body, userId) => {
|
|
61
|
-
try {
|
|
62
|
-
const { type } = body;
|
|
63
|
-
let { value } = body;
|
|
64
|
-
|
|
65
|
-
if (type === "default" || type === "products") {
|
|
66
|
-
value = value?.all || false;
|
|
67
|
-
} else {
|
|
68
|
-
delete value?.all;
|
|
69
|
-
}
|
|
70
|
-
let notificationSettings = await NotificationSettings.findOne({
|
|
71
|
-
workspaceId: body.workspaceId,
|
|
72
|
-
createdBy: userId,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
if (notificationSettings) {
|
|
76
|
-
notificationSettings[type] = value;
|
|
77
|
-
const updatedSettings = await notificationSettings.save();
|
|
78
|
-
await setRedisData(`notificationSettings-${userId}`, updatedSettings);
|
|
79
|
-
return updatedSettings;
|
|
80
|
-
} else {
|
|
81
|
-
const newSettings = await defaultNotifications(body.workspaceId, userId);
|
|
82
|
-
|
|
83
|
-
await setRedisData(`notificationSettings-${userId}`, newSettings);
|
|
84
|
-
return newSettings;
|
|
85
|
-
}
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.log(error, "err");
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
module.exports = {
|
|
92
|
-
getUserNotificationSettings,
|
|
93
|
-
updateUserNotificationSettings,
|
|
94
|
-
defaultNotifications,
|
|
95
|
-
};
|