shuttlepro-shared 1.3.18 → 1.3.19
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/middlewares/checkPermission/index.js +36 -23
- package/models/UserRole.js +119 -1
- 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 -195
- 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 -37
- 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 -244
- 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 -318
- package/utils/decorator-factory.js +0 -264
- package/utils/logger.js +0 -41
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
const { getRedisData, setRedisData } = require("../../config/redis");
|
|
2
|
-
// const DescriptionTemplate = require("../../../models/DescriptionTemplate");
|
|
3
|
-
const DescriptionTemplate = require("../../models/DescriptionTemplate");
|
|
4
|
-
|
|
5
|
-
const CACHE_KEY_ALL = "description_templates_all";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Get cached descriptionTemplates for all workspaces.
|
|
9
|
-
*/
|
|
10
|
-
const getCachedAllDescriptionTemplates = async () => {
|
|
11
|
-
let descriptionTemplates = await getRedisData(CACHE_KEY_ALL);
|
|
12
|
-
if (!descriptionTemplates) {
|
|
13
|
-
descriptionTemplates = await DescriptionTemplate.find({}).lean().exec();
|
|
14
|
-
await setRedisData(CACHE_KEY_ALL, descriptionTemplates);
|
|
15
|
-
}
|
|
16
|
-
return descriptionTemplates;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Update cached descriptionTemplates for all workspaces.
|
|
21
|
-
*/
|
|
22
|
-
const updateCachedAllDescriptionTemplates = async () => {
|
|
23
|
-
const descriptionTemplates = await DescriptionTemplate.find({}).lean().exec();
|
|
24
|
-
await setRedisData(CACHE_KEY_ALL, descriptionTemplates);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Get cached descriptionTemplates for a specific workspace.
|
|
29
|
-
* Now uses the all descriptionTemplates cache and filters by workspaceId.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Create a new DescriptionTemplate and update cache.
|
|
34
|
-
*/
|
|
35
|
-
const createTemplate = async (data) => {
|
|
36
|
-
const newTemplate = new DescriptionTemplate(data);
|
|
37
|
-
const saveDescriptionTemplate = await newTemplate.save();
|
|
38
|
-
|
|
39
|
-
// Update only the main cache
|
|
40
|
-
await updateCachedAllDescriptionTemplates();
|
|
41
|
-
|
|
42
|
-
return saveDescriptionTemplate;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Find an DescriptionTemplate by ID.
|
|
47
|
-
*/
|
|
48
|
-
const findTemplatesByWorkspaceId = async (workspaceId) => {
|
|
49
|
-
const allDescriptionTemplates = await getCachedAllDescriptionTemplates();
|
|
50
|
-
return allDescriptionTemplates.filter(
|
|
51
|
-
(desc) => desc.workspaceId === workspaceId
|
|
52
|
-
);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Find DescriptionTemplate by filter (supports both workspace & non-workspace).
|
|
57
|
-
*/
|
|
58
|
-
const findTemplateByFilter = async (
|
|
59
|
-
filter,
|
|
60
|
-
bodyFilter = {},
|
|
61
|
-
workspaceId = null
|
|
62
|
-
) => {
|
|
63
|
-
const allTemplates = await getCachedAllDescriptionTemplates();
|
|
64
|
-
|
|
65
|
-
// Filter by workspaceId if provided
|
|
66
|
-
let filteredTemplates = workspaceId
|
|
67
|
-
? allTemplates.filter((desc) => desc.workspaceId === workspaceId)
|
|
68
|
-
: allTemplates;
|
|
69
|
-
|
|
70
|
-
return (
|
|
71
|
-
filteredTemplates.find(
|
|
72
|
-
(item) =>
|
|
73
|
-
// Check direct properties of item
|
|
74
|
-
Object.entries(filter).every(([key, value]) => item[key] === value) &&
|
|
75
|
-
// If bodyFilter is provided, check inside item.body
|
|
76
|
-
Object.entries(bodyFilter).every(
|
|
77
|
-
([key, value]) => item.body?.[key] === value
|
|
78
|
-
)
|
|
79
|
-
) || null
|
|
80
|
-
);
|
|
81
|
-
};
|
|
82
|
-
const findAllTemplateByFilter = async (
|
|
83
|
-
filter,
|
|
84
|
-
bodyFilter = {},
|
|
85
|
-
workspaceId = null
|
|
86
|
-
) => {
|
|
87
|
-
const allTemplates = await getCachedAllDescriptionTemplates();
|
|
88
|
-
|
|
89
|
-
// Filter by workspaceId if provided
|
|
90
|
-
let filteredTemplates = workspaceId
|
|
91
|
-
? allTemplates.filter((desc) => desc.workspaceId === workspaceId)
|
|
92
|
-
: allTemplates;
|
|
93
|
-
|
|
94
|
-
return (
|
|
95
|
-
filteredTemplates.filter(
|
|
96
|
-
(item) =>
|
|
97
|
-
// Check direct properties of item
|
|
98
|
-
Object.entries(filter).every(([key, value]) => item[key] === value) &&
|
|
99
|
-
// If bodyFilter is provided, check inside item.body
|
|
100
|
-
Object.entries(bodyFilter).every(
|
|
101
|
-
([key, value]) => item.body?.[key] === value
|
|
102
|
-
)
|
|
103
|
-
) || null
|
|
104
|
-
);
|
|
105
|
-
};
|
|
106
|
-
const createOrUpdateTemplate = async (filter, data) => {
|
|
107
|
-
const template = await DescriptionTemplate.findOneAndUpdate(filter, data, {
|
|
108
|
-
upsert: true,
|
|
109
|
-
new: true,
|
|
110
|
-
});
|
|
111
|
-
if (template) {
|
|
112
|
-
// Update only the main cache
|
|
113
|
-
await updateCachedAllDescriptionTemplates();
|
|
114
|
-
}
|
|
115
|
-
return template;
|
|
116
|
-
};
|
|
117
|
-
const updateTemplateById = async (id, data) => {
|
|
118
|
-
const updatedTemplate = await DescriptionTemplate.findByIdAndUpdate(
|
|
119
|
-
id,
|
|
120
|
-
data,
|
|
121
|
-
{
|
|
122
|
-
new: true,
|
|
123
|
-
}
|
|
124
|
-
).exec();
|
|
125
|
-
|
|
126
|
-
if (updatedTemplate) {
|
|
127
|
-
// Update only the main cache
|
|
128
|
-
await updateCachedAllDescriptionTemplates();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return updatedTemplate;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Update an DescriptionTemplate by filter.
|
|
136
|
-
*/
|
|
137
|
-
const updateTemplateByFilter = async (filter, data, workspaceId = null) => {
|
|
138
|
-
// Add workspace filter if provided
|
|
139
|
-
const queryFilter = workspaceId ? { ...filter, workspaceId } : filter;
|
|
140
|
-
|
|
141
|
-
const updatedTemplate = await DescriptionTemplate.findOneAndUpdate(
|
|
142
|
-
queryFilter,
|
|
143
|
-
data,
|
|
144
|
-
{
|
|
145
|
-
new: true,
|
|
146
|
-
}
|
|
147
|
-
).exec();
|
|
148
|
-
|
|
149
|
-
if (updatedTemplate) {
|
|
150
|
-
// Update only the main cache
|
|
151
|
-
await updateCachedAllDescriptionTemplates();
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return updatedTemplate;
|
|
155
|
-
};
|
|
156
|
-
const updateManyTemplates = async (filter, data) => {
|
|
157
|
-
const queryFilter = workspaceId ? { ...filter, workspaceId } : filter;
|
|
158
|
-
|
|
159
|
-
const updatedTemplate = await DescriptionTemplate.updateMany(
|
|
160
|
-
queryFilter,
|
|
161
|
-
{ $set: { ...data } },
|
|
162
|
-
{
|
|
163
|
-
new: true,
|
|
164
|
-
}
|
|
165
|
-
).exec();
|
|
166
|
-
|
|
167
|
-
if (updatedTemplate) {
|
|
168
|
-
// Update only the main cache
|
|
169
|
-
await updateCachedAllDescriptionTemplates();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return updatedTemplate;
|
|
173
|
-
};
|
|
174
|
-
/**
|
|
175
|
-
* Delete an DescriptionTemplate by ID.
|
|
176
|
-
*/
|
|
177
|
-
const deleteTemplate = async (id) => {
|
|
178
|
-
const deletedTemplate = await DescriptionTemplate.findByIdAndDelete(
|
|
179
|
-
id
|
|
180
|
-
).exec();
|
|
181
|
-
|
|
182
|
-
if (deletedTemplate) {
|
|
183
|
-
await updateCachedAllDescriptionTemplates();
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return deletedTemplate;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
const deleteAllTemplatesByWorkspace = async (workspaceId) => {
|
|
190
|
-
await DescriptionTemplate.deleteMany({ workspaceId }).exec();
|
|
191
|
-
|
|
192
|
-
await updateCachedAllDescriptionTemplates();
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
const findTemplateById = async (id) => {
|
|
196
|
-
return await DescriptionTemplate.findById(id).lean().exec();
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const deleteTemplatesByFilter = async (filter) => {
|
|
200
|
-
await DescriptionTemplate.deleteMany(filter).exec();
|
|
201
|
-
|
|
202
|
-
await updateCachedAllDescriptionTemplates();
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
const insertManyTemplates = async (templates) => {
|
|
206
|
-
const insertedTemplates = await DescriptionTemplate.insertMany(templates);
|
|
207
|
-
|
|
208
|
-
if (insertedTemplates?.length > 0) {
|
|
209
|
-
await updateCachedAllDescriptionTemplates();
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return insertedTemplates;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
module.exports = {
|
|
216
|
-
createTemplate,
|
|
217
|
-
createOrUpdateTemplate,
|
|
218
|
-
findTemplateByFilter,
|
|
219
|
-
findTemplatesByWorkspaceId,
|
|
220
|
-
updateTemplateById,
|
|
221
|
-
updateTemplateByFilter,
|
|
222
|
-
updateManyTemplates,
|
|
223
|
-
deleteTemplate,
|
|
224
|
-
deleteAllTemplatesByWorkspace,
|
|
225
|
-
findTemplateById,
|
|
226
|
-
deleteTemplatesByFilter,
|
|
227
|
-
insertManyTemplates,
|
|
228
|
-
findAllTemplateByFilter,
|
|
229
|
-
};
|
|
@@ -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
|
-
};
|