shuttlepro-shared 1.3.53 → 1.3.54
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.
|
@@ -1,22 +1,62 @@
|
|
|
1
1
|
const { getRedisData, setRedisData } = require("../../config/redis");
|
|
2
2
|
const Workspace = require("../../models/Workspace");
|
|
3
|
+
const FormTemplate = require("../../models/FormTemplate");
|
|
3
4
|
|
|
4
5
|
const CACHE_KEY_ALL = "workspaces_all";
|
|
5
6
|
|
|
6
7
|
const getCachedWorkspaces = async () => {
|
|
7
8
|
let workspaces = await getRedisData(CACHE_KEY_ALL);
|
|
9
|
+
|
|
8
10
|
if (!workspaces) {
|
|
9
11
|
workspaces = await Workspace.find().lean().exec();
|
|
12
|
+
|
|
13
|
+
const templates = await FormTemplate.find({
|
|
14
|
+
type: "ticket",
|
|
15
|
+
subType: "complaint",
|
|
16
|
+
})
|
|
17
|
+
.lean()
|
|
18
|
+
.exec();
|
|
19
|
+
|
|
20
|
+
const templateMap = {};
|
|
21
|
+
templates.forEach((template) => {
|
|
22
|
+
templateMap[template.workspaceId.toString()] = template;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
workspaces = workspaces.map((workspace) => {
|
|
26
|
+
return {
|
|
27
|
+
...workspace,
|
|
28
|
+
formTemplate: templateMap[workspace._id.toString()] || null,
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
|
|
10
32
|
await setRedisData(CACHE_KEY_ALL, workspaces);
|
|
11
|
-
} else {
|
|
12
|
-
workspaces = workspaces;
|
|
13
33
|
}
|
|
34
|
+
|
|
14
35
|
return workspaces;
|
|
15
36
|
};
|
|
16
37
|
|
|
17
38
|
const updateCachedWorkspaces = async () => {
|
|
18
39
|
const workspaces = await Workspace.find().lean().exec();
|
|
19
|
-
await
|
|
40
|
+
const templates = await FormTemplate.find({
|
|
41
|
+
type: "ticket",
|
|
42
|
+
subType: "complaint",
|
|
43
|
+
})
|
|
44
|
+
.lean()
|
|
45
|
+
.exec();
|
|
46
|
+
|
|
47
|
+
const templateMap = {};
|
|
48
|
+
templates.forEach((template) => {
|
|
49
|
+
templateMap[template.workspaceId.toString()] = template;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const enrichedWorkspaces = workspaces.map((workspace) => {
|
|
53
|
+
return {
|
|
54
|
+
...workspace,
|
|
55
|
+
formTemplate: templateMap[workspace._id.toString()] || null,
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
await setRedisData(CACHE_KEY_ALL, enrichedWorkspaces);
|
|
20
60
|
};
|
|
21
61
|
|
|
22
62
|
const createWorkspace = async (data) => {
|