shuttlepro-shared 1.2.49 → 1.2.50
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.
|
@@ -7,10 +7,10 @@ const userRepository = require("./user.repository");
|
|
|
7
7
|
const userRoleRepository = require("./userRole.repository");
|
|
8
8
|
const settingRepository = require("./settings.repository");
|
|
9
9
|
const socialMediaSettingRepository = require("./socialMediaSetting.repository");
|
|
10
|
-
const notificationSettingRepository = require("./notificationSetting.repository");
|
|
11
10
|
const chatMemberRepository = require("./chatMember.repository");
|
|
12
11
|
const roleRepository = require("./role.repository");
|
|
13
12
|
const userPermissionRepository = require("./userPermission.repository");
|
|
13
|
+
const notificationSettingsRepository = require("./notificationSettings.repository");
|
|
14
14
|
exports.module = {
|
|
15
15
|
workspaceRepository,
|
|
16
16
|
integrationRepository,
|
|
@@ -21,7 +21,7 @@ exports.module = {
|
|
|
21
21
|
userRoleRepository,
|
|
22
22
|
settingRepository,
|
|
23
23
|
socialMediaSettingRepository,
|
|
24
|
-
|
|
24
|
+
notificationSettingsRepository,
|
|
25
25
|
chatMemberRepository,
|
|
26
26
|
roleRepository,
|
|
27
27
|
userPermissionRepository,
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const { getRedisData, setRedisData } = require("../../config/redis");
|
|
2
|
+
|
|
3
|
+
const NotificationSettings = require("../../models/NotificationSettings");
|
|
4
|
+
|
|
5
|
+
const getNotificationFromCache = async (workspaceId, userId) => {
|
|
6
|
+
let notificationSettings = await getRedisData(
|
|
7
|
+
`notificationSettings-${userId}`
|
|
8
|
+
);
|
|
9
|
+
if (!notificationSettings) {
|
|
10
|
+
notificationSettings = await NotificationSettings.findOne({
|
|
11
|
+
workspaceId,
|
|
12
|
+
createdBy: userId,
|
|
13
|
+
});
|
|
14
|
+
await setRedisData(`notificationSettings-${userId}`, notificationSettings);
|
|
15
|
+
}
|
|
16
|
+
return notificationSettings;
|
|
17
|
+
};
|
|
18
|
+
const getUserNotificationSettings = async (workspaceId, userId) => {
|
|
19
|
+
return await getNotificationFromCache(workspaceId, userId);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const defaultNotifications = async (workspaceId, userId = null) => {
|
|
23
|
+
try {
|
|
24
|
+
const obj = {
|
|
25
|
+
workspaceId: workspaceId,
|
|
26
|
+
products: true,
|
|
27
|
+
orders: {
|
|
28
|
+
createOrder: true,
|
|
29
|
+
orderAssign: true,
|
|
30
|
+
orderComment: true,
|
|
31
|
+
},
|
|
32
|
+
default: true,
|
|
33
|
+
conversation: {
|
|
34
|
+
instaMessage: true,
|
|
35
|
+
fbMessage: true,
|
|
36
|
+
instaComment: true,
|
|
37
|
+
fbComment: true,
|
|
38
|
+
email: true,
|
|
39
|
+
whatsapp: true,
|
|
40
|
+
},
|
|
41
|
+
socialProfiles: {
|
|
42
|
+
socialProfileComment: true,
|
|
43
|
+
story: true,
|
|
44
|
+
},
|
|
45
|
+
taskManager: {
|
|
46
|
+
cardAssign: true,
|
|
47
|
+
cardMove: true,
|
|
48
|
+
},
|
|
49
|
+
sound: {
|
|
50
|
+
play: true,
|
|
51
|
+
},
|
|
52
|
+
createdBy: userId,
|
|
53
|
+
};
|
|
54
|
+
return await NotificationSettings.create(obj);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
console.log(err, "err");
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const updateUserNotificationSettings = async (body, userId) => {
|
|
61
|
+
try {
|
|
62
|
+
const { type } = body;
|
|
63
|
+
let { value } = body;
|
|
64
|
+
|
|
65
|
+
if (type === "default" || type === "products") {
|
|
66
|
+
value = value?.all || false;
|
|
67
|
+
} else {
|
|
68
|
+
delete value?.all;
|
|
69
|
+
}
|
|
70
|
+
let notificationSettings = await NotificationSettings.findOne({
|
|
71
|
+
workspaceId: body.workspaceId,
|
|
72
|
+
createdBy: userId,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (notificationSettings) {
|
|
76
|
+
notificationSettings[type] = value;
|
|
77
|
+
const updatedSettings = await notificationSettings.save();
|
|
78
|
+
await setRedisData(`notificationSettings-${userId}`, updatedSettings);
|
|
79
|
+
} else {
|
|
80
|
+
const newSettings = await defaultNotifications(body.workspaceId, userId);
|
|
81
|
+
|
|
82
|
+
await setRedisData(`notificationSettings-${userId}`, newSettings);
|
|
83
|
+
return newSettings;
|
|
84
|
+
}
|
|
85
|
+
} catch (error) {
|
|
86
|
+
console.log(error, "err");
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
module.exports = {
|
|
91
|
+
getUserNotificationSettings,
|
|
92
|
+
updateUserNotificationSettings,
|
|
93
|
+
};
|
package/models.js
CHANGED
|
@@ -39,6 +39,7 @@ const Chatbot = require("./models/Chatbot");
|
|
|
39
39
|
const Step = require("./models/Step");
|
|
40
40
|
const Role = require("./models/Role");
|
|
41
41
|
const NewProduct = require("./models/NewProduct");
|
|
42
|
+
const NotificationSettings = require("./models/NotificationSettings");
|
|
42
43
|
module.exports = {
|
|
43
44
|
Website,
|
|
44
45
|
ProductQueue,
|
|
@@ -81,4 +82,5 @@ module.exports = {
|
|
|
81
82
|
Step,
|
|
82
83
|
Role,
|
|
83
84
|
NewProduct,
|
|
85
|
+
NotificationSettings,
|
|
84
86
|
};
|
package/package.json
CHANGED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
const NotificationSettings = require("../../models/NotificationSettings");
|
|
2
|
-
|
|
3
|
-
const createNotificationSetting = async (data) => {
|
|
4
|
-
const newSetting = new NotificationSettings(data);
|
|
5
|
-
const savedSetting = await newSetting.save();
|
|
6
|
-
return savedSetting;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const findNotificationSetting = async (filter) => {
|
|
10
|
-
return await NotificationSettings.findOne(filter).exec();
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const updateNotificationSetting = async (id, data) => {
|
|
14
|
-
const updatedSetting = await NotificationSettings.findByIdAndUpdate(
|
|
15
|
-
id,
|
|
16
|
-
data,
|
|
17
|
-
{
|
|
18
|
-
new: true,
|
|
19
|
-
}
|
|
20
|
-
).exec();
|
|
21
|
-
|
|
22
|
-
return updatedSetting;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const deleteNotificationSetting = async (id) => {
|
|
26
|
-
const deletedSetting = await NotificationSettings.findByIdAndDelete(
|
|
27
|
-
id
|
|
28
|
-
).exec();
|
|
29
|
-
|
|
30
|
-
return deletedSetting;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
module.exports = {
|
|
34
|
-
createNotificationSetting,
|
|
35
|
-
findNotificationSetting,
|
|
36
|
-
updateNotificationSetting,
|
|
37
|
-
deleteNotificationSetting,
|
|
38
|
-
};
|