shuttlepro-shared 1.1.62 → 1.1.64
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.
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const { getRedisData, setRedisData } = require("../../config/redis");
|
|
2
|
+
const Integration = require("../../models/Integration");
|
|
3
|
+
|
|
4
|
+
const CACHE_KEY_PREFIX = "integrations";
|
|
5
|
+
|
|
6
|
+
const getCachedIntegrations = async (workspaceId) => {
|
|
7
|
+
let integrations = await getRedisData(workspaceId, CACHE_KEY_PREFIX);
|
|
8
|
+
if (!integrations) {
|
|
9
|
+
integrations = await Integration.find({ workspaceId }).exec();
|
|
10
|
+
await setRedisData(workspaceId, integrations, CACHE_KEY_PREFIX);
|
|
11
|
+
}
|
|
12
|
+
return integrations;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const updateCachedIntegrations = async (workspaceId) => {
|
|
16
|
+
const integrations = await Integration.find({ workspaceId }).exec();
|
|
17
|
+
await setRedisData(workspaceId, integrations, CACHE_KEY_PREFIX);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const createIntegration = async (data) => {
|
|
21
|
+
const newIntegration = new Integration(data);
|
|
22
|
+
const savedIntegration = await newIntegration.save();
|
|
23
|
+
await updateCachedIntegrations(savedIntegration.workspaceId);
|
|
24
|
+
return savedIntegration;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const findIntegrationById = async (id, workspaceId) => {
|
|
28
|
+
const integrations = await getCachedIntegrations(workspaceId);
|
|
29
|
+
return integrations.find((intg) => intg._id.toString() === id) || null;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const findIntegrationsByWorkspace = async (workspaceId, filter = {}) => {
|
|
33
|
+
const integrations = await getCachedIntegrations(workspaceId);
|
|
34
|
+
return integrations.filter((intg) =>
|
|
35
|
+
Object.entries(filter).every(([key, value]) => intg[key] === value)
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const findIntegrationByFilter = async (workspaceId, filter) => {
|
|
40
|
+
const integrations = await getCachedIntegrations(workspaceId);
|
|
41
|
+
return (
|
|
42
|
+
integrations.find((intg) =>
|
|
43
|
+
Object.entries(filter).every(([key, value]) => intg[key] === value)
|
|
44
|
+
) || null
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const updateIntegration = async (id, data, workspaceId) => {
|
|
49
|
+
const updatedIntegration = await Integration.findByIdAndUpdate(id, data, {
|
|
50
|
+
new: true,
|
|
51
|
+
}).exec();
|
|
52
|
+
if (updatedIntegration) {
|
|
53
|
+
await updateCachedIntegrations(workspaceId);
|
|
54
|
+
}
|
|
55
|
+
return updatedIntegration;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const updateIntegrationByFilter = async (workspaceId, filter, data) => {
|
|
59
|
+
const updatedIntegration = await Integration.findOneAndUpdate(filter, data, {
|
|
60
|
+
new: true,
|
|
61
|
+
}).exec();
|
|
62
|
+
if (updatedIntegration) {
|
|
63
|
+
await updateCachedIntegrations(workspaceId);
|
|
64
|
+
}
|
|
65
|
+
return updatedIntegration;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const deleteIntegration = async (id, workspaceId) => {
|
|
69
|
+
const deletedIntegration = await Integration.findByIdAndDelete(id).exec();
|
|
70
|
+
if (deletedIntegration) {
|
|
71
|
+
await updateCachedIntegrations(workspaceId);
|
|
72
|
+
}
|
|
73
|
+
return deletedIntegration;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const deleteAllIntegrationsByWorkspace = async (workspaceId) => {
|
|
77
|
+
await Integration.deleteMany({ workspaceId }).exec();
|
|
78
|
+
await updateCachedIntegrations(workspaceId);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
module.exports = {
|
|
82
|
+
createIntegration,
|
|
83
|
+
findIntegrationById,
|
|
84
|
+
findIntegrationsByWorkspace,
|
|
85
|
+
findIntegrationByFilter,
|
|
86
|
+
updateIntegration,
|
|
87
|
+
updateIntegrationByFilter,
|
|
88
|
+
deleteIntegration,
|
|
89
|
+
deleteAllIntegrationsByWorkspace,
|
|
90
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
const { Schema } = mongoose;
|
|
3
|
+
const DescriptionTemplateSchema = new Schema(
|
|
4
|
+
{
|
|
5
|
+
name: { type: String, default: "" },
|
|
6
|
+
subject: { type: String, default: "" },
|
|
7
|
+
format: { type: String, default: "" },
|
|
8
|
+
workspaceId: { type: String, default: "" },
|
|
9
|
+
businessId: { type: String, default: "" },
|
|
10
|
+
integrationId: { type: String, default: "" },
|
|
11
|
+
type: { type: String, default: "" },
|
|
12
|
+
body: {},
|
|
13
|
+
arbitraryValues: {},
|
|
14
|
+
moduleType: { type: String, default: "" },
|
|
15
|
+
},
|
|
16
|
+
{ timestamps: true, toJSON: { virtuals: true }, toObject: { virtuals: true } }
|
|
17
|
+
);
|
|
18
|
+
const DescriptionTemplate =
|
|
19
|
+
mongoose.models.DescriptionTemplate ||
|
|
20
|
+
mongoose.model("DescriptionTemplate", DescriptionTemplateSchema);
|
|
21
|
+
|
|
22
|
+
module.exports = DescriptionTemplate;
|
package/models.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const Website = require("./models/Website");
|
|
2
|
+
const DescriptionTemplate = require("./models/DescriptionTemplate");
|
|
2
3
|
const ProductQueue = require("./models/ProductQueue");
|
|
3
4
|
const ColumnPreference = require("./models/ColumnPreference");
|
|
4
5
|
const UserPermission = require("./models/UserPermission");
|
|
@@ -70,4 +71,5 @@ module.exports = {
|
|
|
70
71
|
Workspace,
|
|
71
72
|
StatusType,
|
|
72
73
|
Card,
|
|
74
|
+
DescriptionTemplate,
|
|
73
75
|
};
|