shuttlepro-shared 1.1.60 → 1.1.62

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,3 @@
1
+ const workspaceRepository = require("./workspace.repository");
2
+
3
+ exports.module = { workspaceRepository };
@@ -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
+ };
@@ -23,3 +23,18 @@ exports.GenericMessages = {
23
23
  URL_FETCH_SUCCESS: "Url Fetched successfully!",
24
24
  WORKSPACE_NOT_FOUND: "Workspace not found!",
25
25
  };
26
+
27
+ exports.DYNAMIC_FIELD_TYPES = [
28
+ "text",
29
+ "autocomplete",
30
+ "radio",
31
+ "text area",
32
+ "number",
33
+ "date",
34
+ "time",
35
+ "email",
36
+ "range",
37
+ "url",
38
+ "colour",
39
+ "file",
40
+ ];
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
  };
package/models.js CHANGED
@@ -15,7 +15,6 @@ const OrderQueue = require("./models/OrderQueue");
15
15
  const AgentActivity = require("./models/AgentActivity");
16
16
  const Assignment = require("./models/Assignment");
17
17
  const BusinessDistribution = require("./models/BusinessDistribution");
18
- const Card = require("./models/Card");
19
18
  const CardComments = require("./models/CardComments");
20
19
  const Checkpoint = require("./models/Checkpoint");
21
20
  const City = require("./models/City");
@@ -33,6 +32,7 @@ const Status = require("./models/Status");
33
32
  const StatusType = require("./models/StatusType");
34
33
  const Type = require("./models/Type");
35
34
  const Workspace = require("./models/Workspace");
35
+ const Card = require("./models/Card");
36
36
 
37
37
  module.exports = {
38
38
  Website,
@@ -52,7 +52,6 @@ module.exports = {
52
52
  AgentActivity,
53
53
  Assignment,
54
54
  BusinessDistribution,
55
- Card,
56
55
  CardComments,
57
56
  Checkpoint,
58
57
  Column,
@@ -70,4 +69,5 @@ module.exports = {
70
69
  Type,
71
70
  Workspace,
72
71
  StatusType,
72
+ Card,
73
73
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shuttlepro-shared",
3
- "version": "1.1.60",
3
+ "version": "1.1.62",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {