shuttlepro-shared 1.1.61 → 1.1.63
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,95 @@
|
|
|
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/index.js
CHANGED
|
@@ -3,6 +3,7 @@ const sharedFunctions = require("./functions");
|
|
|
3
3
|
const logger = require("./utils/logger");
|
|
4
4
|
const shuttlePro = require("./utils/decorator-factory");
|
|
5
5
|
const configs = require("./config");
|
|
6
|
+
const repositories = require("./common/repositories");
|
|
6
7
|
|
|
7
8
|
module.exports = {
|
|
8
9
|
sharedModels,
|
|
@@ -10,4 +11,5 @@ module.exports = {
|
|
|
10
11
|
logger,
|
|
11
12
|
shuttlePro,
|
|
12
13
|
configs,
|
|
14
|
+
repositories,
|
|
13
15
|
};
|
|
@@ -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
|
};
|