shuttlepro-shared 1.3.46 → 1.3.47

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,103 +1,42 @@
1
- const { getRedisData, setRedisData } = require("../../config/redis");
2
1
  const CustomerProfile = require("../../models/CustomerProfile");
3
2
 
4
- const CACHE_KEY_ALL = "customer_profiles_all";
5
-
6
- const getCachedAllCustomerProfiles = async () => {
7
- let profiles = await getRedisData(CACHE_KEY_ALL);
8
- if (!profiles) {
9
- profiles = await CustomerProfile.find({}).lean().exec();
10
- await setRedisData(CACHE_KEY_ALL, profiles);
11
- }
12
- return profiles;
13
- };
14
-
15
- const updateCachedAllCustomerProfiles = async () => {
16
- const profiles = await CustomerProfile.find({}).lean().exec();
17
- await setRedisData(CACHE_KEY_ALL, profiles);
18
- };
19
-
20
- const getCachedCustomerProfiles = async (workspaceId) => {
21
- const allProfiles = await getCachedAllCustomerProfiles();
22
- return allProfiles.filter((profile) => profile.workspaceId === workspaceId);
23
- };
24
-
25
3
  const createCustomerProfile = async (data) => {
26
4
  const newProfile = new CustomerProfile(data);
27
5
  const savedProfile = await newProfile.save();
28
-
29
- updateCachedAllCustomerProfiles();
30
6
  return savedProfile;
31
7
  };
32
8
 
33
9
  const findCustomerProfilesByWorkspaceId = async (workspaceId) => {
34
- return await getCachedCustomerProfiles(workspaceId);
10
+ return await CustomerProfile.find({ workspaceId }).lean().exec();
35
11
  };
36
12
 
37
13
  const findCustomerProfilesByWorkspace = async (workspaceId, filter = {}) => {
38
- const profiles = await getCachedCustomerProfiles(workspaceId);
39
- return profiles.filter((profile) =>
40
- Object.entries(filter).every(([key, value]) => profile[key] === value)
41
- );
14
+ return await CustomerProfile.find({ workspaceId, ...filter })
15
+ .lean()
16
+ .exec();
42
17
  };
43
18
 
44
19
  const findCustomerProfileByFilter = async (
45
20
  filter = {},
46
- bodyFilter = {},
21
+
47
22
  workspaceId = null
48
23
  ) => {
49
- const allProfiles = await getCachedAllCustomerProfiles();
50
-
51
- const filtered = workspaceId
52
- ? allProfiles.filter((p) => p.workspaceId === workspaceId)
53
- : allProfiles;
54
-
55
- return (
56
- filtered.find(
57
- (profile) =>
58
- Object.entries(filter).every(
59
- ([key, value]) => profile[key] === value
60
- ) &&
61
- Object.entries(bodyFilter).every(
62
- ([key, value]) => profile.body?.[key] === value
63
- )
64
- ) || null
65
- );
24
+ const query = workspaceId ? { ...filter, workspaceId } : filter;
25
+ return await CustomerProfile.findOne(query).lean().exec();
66
26
  };
67
27
 
68
28
  const findAllCustomerProfilesByFilter = async (
69
29
  filter = {},
70
- bodyFilter = {},
71
30
  workspaceId = null
72
31
  ) => {
73
- const allProfiles = await getCachedAllCustomerProfiles();
74
-
75
- const filtered = workspaceId
76
- ? allProfiles.filter((p) => p.workspaceId === workspaceId)
77
- : allProfiles;
78
-
79
- return (
80
- filtered.filter(
81
- (profile) =>
82
- Object.entries(filter).every(
83
- ([key, value]) => profile[key] === value
84
- ) &&
85
- Object.entries(bodyFilter).every(
86
- ([key, value]) => profile.body?.[key] === value
87
- )
88
- ) || []
89
- );
32
+ const query = workspaceId ? { ...filter, workspaceId } : filter;
33
+ return await CustomerProfile.find(query).lean().exec();
90
34
  };
91
35
 
92
36
  const updateCustomerProfile = async (id, data) => {
93
37
  const updated = await CustomerProfile.findByIdAndUpdate(id, data, {
94
38
  new: true,
95
39
  }).exec();
96
-
97
- if (updated) {
98
- updateCachedAllCustomerProfiles();
99
- }
100
-
101
40
  return updated;
102
41
  };
103
42
 
@@ -107,33 +46,24 @@ const updateCustomerProfileByFilter = async (
107
46
  workspaceId = null
108
47
  ) => {
109
48
  const query = workspaceId ? { ...filter, workspaceId } : filter;
110
-
111
49
  const updated = await CustomerProfile.findOneAndUpdate(query, data, {
112
50
  new: true,
113
51
  }).exec();
114
-
115
- if (updated) {
116
- updateCachedAllCustomerProfiles();
117
- }
118
-
119
52
  return updated;
120
53
  };
121
54
 
122
55
  const deleteCustomerProfile = async (id) => {
123
56
  const deleted = await CustomerProfile.findByIdAndDelete(id).exec();
124
-
125
- if (deleted) {
126
- updateCachedAllCustomerProfiles();
127
- }
128
-
129
57
  return deleted;
130
58
  };
131
59
 
132
60
  const deleteAllCustomerProfilesByWorkspace = async (workspaceId) => {
133
61
  await CustomerProfile.deleteMany({ workspaceId }).exec();
134
- await updateCachedAllCustomerProfiles();
135
62
  };
136
-
63
+ const findAllCustomerProfilesByFilterFromDb = async (filter = {}) => {
64
+ const profiles = await CustomerProfile.find(filter).lean().exec();
65
+ return profiles ?? [];
66
+ };
137
67
  module.exports = {
138
68
  createCustomerProfile,
139
69
  findCustomerProfilesByWorkspaceId,
@@ -144,4 +74,5 @@ module.exports = {
144
74
  deleteCustomerProfile,
145
75
  deleteAllCustomerProfilesByWorkspace,
146
76
  findAllCustomerProfilesByFilter,
77
+ findAllCustomerProfilesByFilterFromDb,
147
78
  };
@@ -47,6 +47,8 @@ const activitySchema = new mongoose.Schema({
47
47
  remarks: { type: String, required: false },
48
48
  avgAccuracy: { type: Number, required: false, default: 10 },
49
49
  sender: { type: String, required: "" },
50
+ members: [],
51
+ closedBy: {},
50
52
  });
51
53
 
52
54
  const totalActivitySchema = new mongoose.Schema({
@@ -141,6 +141,7 @@ const AutomationCondition = new Schema({
141
141
  "label",
142
142
  "orderAutomation",
143
143
  "post",
144
+ "shift",
144
145
  ],
145
146
  },
146
147
  keyValue: {
@@ -159,6 +160,8 @@ const AutomationCondition = new Schema({
159
160
  "openTicket",
160
161
  "publishedPosts",
161
162
  "label",
163
+ "withInShift",
164
+ "afterShift",
162
165
  "orderConfirmation",
163
166
  "orderPublish",
164
167
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shuttlepro-shared",
3
- "version": "1.3.46",
3
+ "version": "1.3.47",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {