shuttlepro-shared 1.1.92 → 1.1.94
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/services/userRoleAndPermissions.js +82 -0
- package/constants/index.js +0 -15
- package/index.js +0 -8
- package/models/Role.js +40 -0
- package/models/UserPermission.js +5 -0
- package/models/UserRole.js +10 -3
- package/models.js +3 -50
- package/package.json +2 -13
- package/utils/index.js +23 -0
- package/common/repositories/descriptionTemplates.repository.js +0 -186
- package/common/repositories/index.js +0 -12
- package/common/repositories/integration.repository.js +0 -197
- package/common/repositories/label.repository.js +0 -85
- package/common/repositories/shipper.repository.js +0 -77
- package/common/repositories/workspace.repository.js +0 -95
- package/config/bull.js +0 -78
- package/config/config.js +0 -14
- package/config/database.js +0 -7
- package/config/index.js +0 -13
- package/config/redis.js +0 -160
- package/config/socket.js +0 -172
- package/models/AgentActivity.js +0 -189
- 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/Chatbot.js +0 -16
- package/models/Checkpoint.js +0 -50
- package/models/City.js +0 -17
- package/models/Column.js +0 -28
- package/models/Conversation.js +0 -84
- package/models/Customer.js +0 -35
- package/models/DescriptionTemplate.js +0 -22
- package/models/Integration.js +0 -53
- package/models/Label.js +0 -42
- package/models/Message.js +0 -47
- package/models/Order.js +0 -131
- package/models/OrderProduct.js +0 -37
- package/models/Profile.js +0 -127
- package/models/Report.js +0 -27
- package/models/Shipper.js +0 -52
- 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/Workspace.js +0 -190
- package/utils/decorator-factory.js +0 -264
- package/utils/logger.js +0 -41
|
@@ -1,197 +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;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Update cached integrations for all workspaces.
|
|
20
|
-
*/
|
|
21
|
-
const updateCachedAllIntegrations = async () => {
|
|
22
|
-
const integrations = await Integration.find({}).lean().exec();
|
|
23
|
-
await setRedisData(CACHE_KEY_ALL, integrations);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Get cached integrations for a specific workspace.
|
|
28
|
-
* Now uses the all integrations cache and filters by workspaceId.
|
|
29
|
-
*/
|
|
30
|
-
const getCachedIntegrations = async (workspaceId) => {
|
|
31
|
-
const allIntegrations = await getCachedAllIntegrations();
|
|
32
|
-
return allIntegrations.filter((intg) => intg.workspaceId === workspaceId);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Create a new integration and update cache.
|
|
37
|
-
*/
|
|
38
|
-
const createIntegration = async (data) => {
|
|
39
|
-
const newIntegration = new Integration(data);
|
|
40
|
-
const savedIntegration = await newIntegration.save();
|
|
41
|
-
|
|
42
|
-
// Update only the main cache
|
|
43
|
-
await updateCachedAllIntegrations();
|
|
44
|
-
|
|
45
|
-
return savedIntegration;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Find an integration by ID.
|
|
50
|
-
*/
|
|
51
|
-
const findIntegrationsByWorkspaceId = async (workspaceId) => {
|
|
52
|
-
return await getCachedIntegrations(workspaceId);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Find integrations by workspace.
|
|
57
|
-
*/
|
|
58
|
-
const findIntegrationsByWorkspace = async (workspaceId, filter = {}) => {
|
|
59
|
-
const allIntegrations = await getCachedIntegrations(workspaceId);
|
|
60
|
-
|
|
61
|
-
return allIntegrations.filter(
|
|
62
|
-
(intg) =>
|
|
63
|
-
intg.workspaceId === workspaceId &&
|
|
64
|
-
Object.entries(filter).every(([key, value]) => intg[key] === value)
|
|
65
|
-
);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Find integration by filter (supports both workspace & non-workspace).
|
|
70
|
-
*/
|
|
71
|
-
const findIntegrationByFilter = async (filter, workspaceId = null) => {
|
|
72
|
-
const allIntegrations = await getCachedAllIntegrations();
|
|
73
|
-
|
|
74
|
-
let filteredIntegrations = allIntegrations;
|
|
75
|
-
if (workspaceId) {
|
|
76
|
-
filteredIntegrations = allIntegrations.filter(
|
|
77
|
-
(intg) => intg.workspaceId === workspaceId
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
filteredIntegrations.find((item) =>
|
|
83
|
-
Object.entries(filter).every(([key, value]) => item.body?.[key] === value)
|
|
84
|
-
) || null
|
|
85
|
-
);
|
|
86
|
-
};
|
|
87
|
-
const findAllIntegrationByFilter = async (
|
|
88
|
-
filter = {},
|
|
89
|
-
bodyFilter = {},
|
|
90
|
-
workspaceId = null
|
|
91
|
-
) => {
|
|
92
|
-
const allIntegrations = await getCachedAllIntegrations();
|
|
93
|
-
|
|
94
|
-
let filteredIntegrations = allIntegrations;
|
|
95
|
-
if (workspaceId) {
|
|
96
|
-
filteredIntegrations = allIntegrations.filter(
|
|
97
|
-
(intg) => intg.workspaceId === workspaceId
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
return (
|
|
101
|
-
filteredIntegrations.filter(
|
|
102
|
-
(item) =>
|
|
103
|
-
Object.entries(filter).every(([key, value]) => item[key] === value) &&
|
|
104
|
-
Object.entries(bodyFilter).every(
|
|
105
|
-
([key, value]) => item.body?.[key] === value
|
|
106
|
-
)
|
|
107
|
-
) || []
|
|
108
|
-
);
|
|
109
|
-
};
|
|
110
|
-
const bulkCreateAndUpdateIntegrations = async (operations) => {
|
|
111
|
-
await Integration.bulkWrite(operations);
|
|
112
|
-
await updateCachedAllIntegrations();
|
|
113
|
-
return operations;
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* Find all integrations (without workspace filtering).
|
|
117
|
-
*/
|
|
118
|
-
const findAllIntegrations = async () => {
|
|
119
|
-
return await getCachedAllIntegrations();
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Update an integration by ID.
|
|
124
|
-
*/
|
|
125
|
-
const updateIntegration = async (id, data) => {
|
|
126
|
-
const updatedIntegration = await Integration.findByIdAndUpdate(id, data, {
|
|
127
|
-
new: true,
|
|
128
|
-
}).exec();
|
|
129
|
-
|
|
130
|
-
if (updatedIntegration) {
|
|
131
|
-
// Update only the main cache
|
|
132
|
-
await updateCachedAllIntegrations();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return updatedIntegration;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Update an integration by filter.
|
|
140
|
-
*/
|
|
141
|
-
const updateIntegrationByFilter = async (filter, data, workspaceId = null) => {
|
|
142
|
-
// Add workspace filter if provided
|
|
143
|
-
const queryFilter = workspaceId ? { ...filter, workspaceId } : filter;
|
|
144
|
-
|
|
145
|
-
const updatedIntegration = await Integration.findOneAndUpdate(
|
|
146
|
-
queryFilter,
|
|
147
|
-
data,
|
|
148
|
-
{
|
|
149
|
-
new: true,
|
|
150
|
-
}
|
|
151
|
-
).exec();
|
|
152
|
-
|
|
153
|
-
if (updatedIntegration) {
|
|
154
|
-
// Update only the main cache
|
|
155
|
-
await updateCachedAllIntegrations();
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return updatedIntegration;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Delete an integration by ID.
|
|
163
|
-
*/
|
|
164
|
-
const deleteIntegration = async (id) => {
|
|
165
|
-
const deletedIntegration = await Integration.findByIdAndDelete(id).exec();
|
|
166
|
-
|
|
167
|
-
if (deletedIntegration) {
|
|
168
|
-
// Update only the main cache
|
|
169
|
-
await updateCachedAllIntegrations();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return deletedIntegration;
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Delete all integrations for a specific workspace.
|
|
177
|
-
*/
|
|
178
|
-
const deleteAllIntegrationsByWorkspace = async (workspaceId) => {
|
|
179
|
-
await Integration.deleteMany({ workspaceId }).exec();
|
|
180
|
-
|
|
181
|
-
// Update only the main cache
|
|
182
|
-
await updateCachedAllIntegrations();
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
module.exports = {
|
|
186
|
-
createIntegration,
|
|
187
|
-
findIntegrationsByWorkspaceId,
|
|
188
|
-
findIntegrationsByWorkspace,
|
|
189
|
-
findIntegrationByFilter,
|
|
190
|
-
findAllIntegrations,
|
|
191
|
-
updateIntegration,
|
|
192
|
-
updateIntegrationByFilter,
|
|
193
|
-
deleteIntegration,
|
|
194
|
-
deleteAllIntegrationsByWorkspace,
|
|
195
|
-
findAllIntegrationByFilter,
|
|
196
|
-
bulkCreateAndUpdateIntegrations,
|
|
197
|
-
};
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
const { getRedisData, setRedisData } = require("../../config/redis");
|
|
2
|
-
const Label = require("../../models/Label");
|
|
3
|
-
|
|
4
|
-
const CACHE_KEY_ALL = "labels_all";
|
|
5
|
-
|
|
6
|
-
const getCachedLabels = async () => {
|
|
7
|
-
let labels = await getRedisData(CACHE_KEY_ALL);
|
|
8
|
-
if (!labels) {
|
|
9
|
-
labels = await Label.find().lean().exec();
|
|
10
|
-
await setRedisData(CACHE_KEY_ALL, JSON.stringify(labels));
|
|
11
|
-
} else {
|
|
12
|
-
labels = JSON.parse(labels);
|
|
13
|
-
}
|
|
14
|
-
return labels;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const updateCachedLabels = async () => {
|
|
18
|
-
const labels = await Label.find().lean().exec();
|
|
19
|
-
await setRedisData(CACHE_KEY_ALL, JSON.stringify(labels));
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const createLabel = async (data) => {
|
|
23
|
-
const newLabel = new Label(data);
|
|
24
|
-
const savedLabel = await newLabel.save();
|
|
25
|
-
await updateCachedLabels();
|
|
26
|
-
return savedLabel;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const findLabelById = async (id) => {
|
|
30
|
-
const labels = await getCachedLabels();
|
|
31
|
-
return labels.find((l) => l._id.toString() === id) || null;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const findLabel = async (filter) => {
|
|
35
|
-
const labels = await getCachedLabels();
|
|
36
|
-
return (
|
|
37
|
-
labels.find((l) =>
|
|
38
|
-
Object.entries(filter).every(([key, value]) => l[key] === value)
|
|
39
|
-
) || null
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const findAllLabels = async (filter = {}) => {
|
|
44
|
-
const labels = await getCachedLabels();
|
|
45
|
-
return labels.filter((l) =>
|
|
46
|
-
Object.entries(filter).every(([key, value]) => l[key] === value)
|
|
47
|
-
);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const updateLabelById = async (id, data) => {
|
|
51
|
-
const updatedLabel = await Label.findByIdAndUpdate(id, data, {
|
|
52
|
-
new: true,
|
|
53
|
-
}).exec();
|
|
54
|
-
if (updatedLabel) {
|
|
55
|
-
await updateCachedLabels();
|
|
56
|
-
}
|
|
57
|
-
return updatedLabel;
|
|
58
|
-
};
|
|
59
|
-
const updateLabel = async (filter, data) => {
|
|
60
|
-
const updatedLabel = await Label.findOneAndUpdate(filter, data, {
|
|
61
|
-
new: true,
|
|
62
|
-
}).exec();
|
|
63
|
-
if (updatedLabel) {
|
|
64
|
-
await updateCachedLabels();
|
|
65
|
-
}
|
|
66
|
-
return updatedLabel;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const deleteLabel = async (id) => {
|
|
70
|
-
const deletedLabel = await Label.findByIdAndDelete(id).exec();
|
|
71
|
-
if (deletedLabel) {
|
|
72
|
-
await updateCachedLabels();
|
|
73
|
-
}
|
|
74
|
-
return deletedLabel;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
module.exports = {
|
|
78
|
-
createLabel,
|
|
79
|
-
findLabelById,
|
|
80
|
-
findLabel,
|
|
81
|
-
findAllLabels,
|
|
82
|
-
updateLabel,
|
|
83
|
-
deleteLabel,
|
|
84
|
-
updateLabelById,
|
|
85
|
-
};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
const { getRedisData, setRedisData } = require("../../config/redis");
|
|
2
|
-
const Shipper = require("../../models/Shipper");
|
|
3
|
-
|
|
4
|
-
const CACHE_KEY_ALL = "shippers_all";
|
|
5
|
-
|
|
6
|
-
const getCachedShippers = async () => {
|
|
7
|
-
let shippers = await getRedisData(CACHE_KEY_ALL);
|
|
8
|
-
if (!shippers) {
|
|
9
|
-
shippers = await Shipper.find().lean().exec();
|
|
10
|
-
await setRedisData(CACHE_KEY_ALL, JSON.stringify(shippers));
|
|
11
|
-
} else {
|
|
12
|
-
shippers = JSON.parse(shippers);
|
|
13
|
-
}
|
|
14
|
-
return shippers;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const updateCachedShippers = async () => {
|
|
18
|
-
const shippers = await Shipper.find().lean().exec();
|
|
19
|
-
await setRedisData(CACHE_KEY_ALL, JSON.stringify(shippers));
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const createShipper = async (data) => {
|
|
23
|
-
const newShipper = new Shipper(data);
|
|
24
|
-
const savedShipper = await newShipper.save();
|
|
25
|
-
await updateCachedShippers();
|
|
26
|
-
return savedShipper;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const findShipperById = async (id) => {
|
|
30
|
-
const shippers = await getCachedShippers();
|
|
31
|
-
const shipper = shippers.find((s) => s._id.toString() === id) || null;
|
|
32
|
-
|
|
33
|
-
return shipper;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const findShipper = async (filter) => {
|
|
37
|
-
const shippers = await getCachedShippers();
|
|
38
|
-
return (
|
|
39
|
-
shippers.find((s) =>
|
|
40
|
-
Object.entries(filter).every(([key, value]) => s[key] === value)
|
|
41
|
-
) || null
|
|
42
|
-
);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const findAllShippers = async (filter = {}) => {
|
|
46
|
-
const shippers = await getCachedShippers();
|
|
47
|
-
return shippers.filter((s) =>
|
|
48
|
-
Object.entries(filter).every(([key, value]) => s[key] === value)
|
|
49
|
-
);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const updateShipper = async (id, data) => {
|
|
53
|
-
const updatedShipper = await Shipper.findByIdAndUpdate(id, data, {
|
|
54
|
-
new: true,
|
|
55
|
-
}).exec();
|
|
56
|
-
if (updatedShipper) {
|
|
57
|
-
await updateCachedShippers();
|
|
58
|
-
}
|
|
59
|
-
return updatedShipper;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const deleteShipper = async (id) => {
|
|
63
|
-
const deletedShipper = await Shipper.findByIdAndDelete(id).exec();
|
|
64
|
-
if (deletedShipper) {
|
|
65
|
-
await updateCachedShippers();
|
|
66
|
-
}
|
|
67
|
-
return deletedShipper;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
module.exports = {
|
|
71
|
-
createShipper,
|
|
72
|
-
findShipperById,
|
|
73
|
-
findShipper,
|
|
74
|
-
findAllShippers,
|
|
75
|
-
updateShipper,
|
|
76
|
-
deleteShipper,
|
|
77
|
-
};
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
const { getRedisData, setRedisData } = require("../../config/redis");
|
|
2
|
-
const Workspace = require("../../models/Workspace");
|
|
3
|
-
|
|
4
|
-
const CACHE_KEY_ALL = "workspaces_all";
|
|
5
|
-
|
|
6
|
-
const getCachedWorkspaces = async () => {
|
|
7
|
-
let workspaces = await getRedisData(CACHE_KEY_ALL);
|
|
8
|
-
if (!workspaces) {
|
|
9
|
-
workspaces = await Workspace.find().exec();
|
|
10
|
-
await setRedisData(CACHE_KEY_ALL, JSON.stringify(workspaces));
|
|
11
|
-
} else {
|
|
12
|
-
workspaces = JSON.parse(workspaces);
|
|
13
|
-
}
|
|
14
|
-
return workspaces;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const updateCachedWorkspaces = async () => {
|
|
18
|
-
const workspaces = await Workspace.find().exec();
|
|
19
|
-
await setRedisData(CACHE_KEY_ALL, JSON.stringify(workspaces));
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const createWorkspace = async (data) => {
|
|
23
|
-
const newWorkspace = new Workspace(data);
|
|
24
|
-
const savedWorkspace = await newWorkspace.save();
|
|
25
|
-
await updateCachedWorkspaces();
|
|
26
|
-
return savedWorkspace;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const findWorkspaceById = async (id, select = []) => {
|
|
30
|
-
const workspaces = await getCachedWorkspaces();
|
|
31
|
-
const workspace = workspaces.find((ws) => ws._id.toString() === id) || null;
|
|
32
|
-
|
|
33
|
-
if (workspace && select.length > 0) {
|
|
34
|
-
return select.reduce((result, field) => {
|
|
35
|
-
if (workspace[field] !== undefined) {
|
|
36
|
-
result[field] = workspace[field];
|
|
37
|
-
}
|
|
38
|
-
return result;
|
|
39
|
-
}, {});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return workspace;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const findWorkspace = async (filter) => {
|
|
46
|
-
const workspaces = await getCachedWorkspaces();
|
|
47
|
-
return (
|
|
48
|
-
workspaces.find((ws) =>
|
|
49
|
-
Object.entries(filter).every(([key, value]) => ws[key] === value)
|
|
50
|
-
) || null
|
|
51
|
-
);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const findWorkspaceByIdAndQueueTracking = async (id) => {
|
|
55
|
-
const workspaces = await getCachedWorkspaces();
|
|
56
|
-
return (
|
|
57
|
-
workspaces.find((ws) => ws._id.toString() === id && ws.queueTracking) ||
|
|
58
|
-
null
|
|
59
|
-
);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const findAllWorkspaces = async (filter = {}) => {
|
|
63
|
-
const workspaces = await getCachedWorkspaces();
|
|
64
|
-
return workspaces.filter((ws) =>
|
|
65
|
-
Object.entries(filter).every(([key, value]) => ws[key] === value)
|
|
66
|
-
);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const updateWorkspace = async (id, data) => {
|
|
70
|
-
const updatedWorkspace = await Workspace.findByIdAndUpdate(id, data, {
|
|
71
|
-
new: true,
|
|
72
|
-
}).exec();
|
|
73
|
-
if (updatedWorkspace) {
|
|
74
|
-
await updateCachedWorkspaces();
|
|
75
|
-
}
|
|
76
|
-
return updatedWorkspace;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const deleteWorkspace = async (id) => {
|
|
80
|
-
const deletedWorkspace = await Workspace.findByIdAndDelete(id).exec();
|
|
81
|
-
if (deletedWorkspace) {
|
|
82
|
-
await updateCachedWorkspaces();
|
|
83
|
-
}
|
|
84
|
-
return deletedWorkspace;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
module.exports = {
|
|
88
|
-
createWorkspace,
|
|
89
|
-
findWorkspaceById,
|
|
90
|
-
findWorkspace,
|
|
91
|
-
findWorkspaceByIdAndQueueTracking,
|
|
92
|
-
findAllWorkspaces,
|
|
93
|
-
updateWorkspace,
|
|
94
|
-
deleteWorkspace,
|
|
95
|
-
};
|
package/config/bull.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
const Queue = require("bull");
|
|
2
|
-
const config = require("./config");
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Create a new queue.
|
|
6
|
-
* @param {string} queueName - The name of the queue.
|
|
7
|
-
* @param {Object} [redisConfig=config.redis] - Redis configuration.
|
|
8
|
-
* @returns {Object} - A collection of queue-related functions.
|
|
9
|
-
*/
|
|
10
|
-
const createQueue = (queueName, redisConfig = config.redis) => {
|
|
11
|
-
const queue = new Queue(queueName, { redis: redisConfig });
|
|
12
|
-
|
|
13
|
-
// Attach event listeners for logging
|
|
14
|
-
queue.on("completed", (job) => console.log(`Job ${job.id} completed.`));
|
|
15
|
-
queue.on("failed", (job, err) => console.error(`Job ${job.id} failed:`, err));
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Add a job to the queue.
|
|
19
|
-
* @param {Object} data - Data to be processed by the job.
|
|
20
|
-
* @param {Object} [options] - Bull job options (e.g., delay, attempts).
|
|
21
|
-
* @returns {Promise<Job>} - The created job.
|
|
22
|
-
*/
|
|
23
|
-
const addJob = async (
|
|
24
|
-
data,
|
|
25
|
-
options = {
|
|
26
|
-
attempts: 3,
|
|
27
|
-
removeOnComplete: true,
|
|
28
|
-
}
|
|
29
|
-
) => {
|
|
30
|
-
return await queue.add(data, options);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Process jobs in the queue.
|
|
35
|
-
* @param {Function} processor - The function to process each job.
|
|
36
|
-
*/
|
|
37
|
-
const processJobs = (processor) => {
|
|
38
|
-
queue.process(processor);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Close the queue connection.
|
|
43
|
-
* @returns {Promise<void>}
|
|
44
|
-
*/
|
|
45
|
-
const closeConnection = async () => {
|
|
46
|
-
await queue.close();
|
|
47
|
-
console.log(`Queue "${queue.name}" connection closed.`);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Pause the queue.
|
|
52
|
-
* @returns {Promise<void>}
|
|
53
|
-
*/
|
|
54
|
-
const pauseQueue = async () => {
|
|
55
|
-
await queue.pause();
|
|
56
|
-
console.log(`Queue "${queue.name}" paused.`);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Resume the queue.
|
|
61
|
-
* @returns {Promise<void>}
|
|
62
|
-
*/
|
|
63
|
-
const resumeQueue = async () => {
|
|
64
|
-
await queue.resume();
|
|
65
|
-
console.log(`Queue "${queue.name}" resumed.`);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// Return the functional interface
|
|
69
|
-
return {
|
|
70
|
-
addJob,
|
|
71
|
-
processJobs,
|
|
72
|
-
closeConnection,
|
|
73
|
-
pauseQueue,
|
|
74
|
-
resumeQueue,
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
module.exports = { createQueue };
|
package/config/config.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const ALLOWED_URLS = process.env.ALLOWED_ORIGIN.split(",");
|
|
2
|
-
const WEBHOOK_API_KEY = process.env.API_KEY || process.env.WEBHOOK_API_KEY;
|
|
3
|
-
const mode = process.env.MODE || "production";
|
|
4
|
-
|
|
5
|
-
const redis = {
|
|
6
|
-
url: process.env.REDIS_URI,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
WEBHOOK_API_KEY,
|
|
11
|
-
ALLOWED_URLS,
|
|
12
|
-
mode,
|
|
13
|
-
redis,
|
|
14
|
-
};
|
package/config/database.js
DELETED
package/config/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const bullConfig = require("./bull");
|
|
2
|
-
const redisConfig = require("./redis");
|
|
3
|
-
const config = require("./config");
|
|
4
|
-
const databaseConfig = require("./database");
|
|
5
|
-
const socketConfig = require("./socket");
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
bullConfig,
|
|
9
|
-
redisConfig,
|
|
10
|
-
config,
|
|
11
|
-
databaseConfig,
|
|
12
|
-
socketConfig,
|
|
13
|
-
};
|