@xuda.io/notification_module 1.1.105 → 1.1.107
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.
- package/index.mjs +22 -21
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -14,7 +14,8 @@ const _common = await import(path.join(process.env.XUDA_HOME, 'common', 'xuda_no
|
|
|
14
14
|
const module_path = path.join(process.env.XUDA_HOME, 'cpi') + (!_conf.is_debug ? '/node_modules/@xuda.io' : '');
|
|
15
15
|
const db_module = await import(`${module_path}/db_module/index.mjs`);
|
|
16
16
|
const email_ms = await import(`${module_path}/email_module/index_ms.mjs`);
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
const ws_dashboard_msa = await import(`${module_path}/ws_dashboard_module/index_msa.mjs`);
|
|
18
19
|
|
|
19
20
|
//////////////////// FCM /////////////////////
|
|
20
21
|
const serviceAccount = _conf.firebase_serviceAccount;
|
|
@@ -26,7 +27,7 @@ const messaging = admin.messaging();
|
|
|
26
27
|
//////////////////////////////////////////////
|
|
27
28
|
|
|
28
29
|
export const get_new_notification_count = async (req) => {
|
|
29
|
-
return await
|
|
30
|
+
return await db_module.get_couch_view('xuda_notification', 'new_notifications_count', {
|
|
30
31
|
key: [req.uid],
|
|
31
32
|
reduce: true,
|
|
32
33
|
group_level: 1,
|
|
@@ -34,7 +35,7 @@ export const get_new_notification_count = async (req) => {
|
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
export const set_notification_read = async (req, job_id, header) => {
|
|
37
|
-
const ret = await
|
|
38
|
+
const ret = await db_module.get_couch_doc('xuda_notification', req.notification_id);
|
|
38
39
|
let notification_doc = ret.data;
|
|
39
40
|
|
|
40
41
|
if (notification_doc.system) {
|
|
@@ -44,21 +45,21 @@ export const set_notification_read = async (req, job_id, header) => {
|
|
|
44
45
|
notification_doc.read_date = Date.now();
|
|
45
46
|
notification_doc.read = true;
|
|
46
47
|
notification_doc.read_header = header;
|
|
47
|
-
return await
|
|
48
|
+
return await db_module.save_couch_doc('xuda_notification', notification_doc);
|
|
48
49
|
};
|
|
49
50
|
|
|
50
51
|
export const update_notification_status = async (req) => {
|
|
51
52
|
const { notification_id, stat, uid } = req;
|
|
52
|
-
const ret = await
|
|
53
|
+
const ret = await db_module.get_couch_doc('xuda_notification', notification_id);
|
|
53
54
|
let notification_doc = ret.data;
|
|
54
55
|
notification_doc.stat_ts = Date.now();
|
|
55
56
|
notification_doc.stat = stat;
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
ws_dashboard_msa.notification({
|
|
58
59
|
to: notification_doc.system ? uid : notification_doc.uid,
|
|
59
60
|
data: notification_doc,
|
|
60
61
|
});
|
|
61
|
-
return await
|
|
62
|
+
return await db_module.save_couch_doc('xuda_notification', notification_doc);
|
|
62
63
|
};
|
|
63
64
|
|
|
64
65
|
export const submit_notification = async (req, _ch = global[`_notification_module_ch`]) => {
|
|
@@ -69,7 +70,7 @@ export const submit_notification = async (req, _ch = global[`_notification_modul
|
|
|
69
70
|
let icon = 'https://dev.xuda.io/dist/images/xuda_ico.png';
|
|
70
71
|
if (app_id) {
|
|
71
72
|
const app_id_reference = await _common.get_project_app_id(app_id, true);
|
|
72
|
-
const app_ret = await
|
|
73
|
+
const app_ret = await db_module.get_couch_doc('xuda_master', app_id_reference);
|
|
73
74
|
if (app_ret.code > -1) {
|
|
74
75
|
icon = app_ret.data.app_pic;
|
|
75
76
|
}
|
|
@@ -105,7 +106,7 @@ export const submit_notification = async (req, _ch = global[`_notification_modul
|
|
|
105
106
|
for await (let delivery_method_item of delivery_method) {
|
|
106
107
|
let account_ret;
|
|
107
108
|
if (!system) {
|
|
108
|
-
account_ret = await
|
|
109
|
+
account_ret = await db_module.get_couch_doc('xuda_accounts', uid);
|
|
109
110
|
if (account_ret.code < 0) {
|
|
110
111
|
throw new Error(`user ${uid} not found`);
|
|
111
112
|
}
|
|
@@ -154,7 +155,7 @@ export const submit_notification = async (req, _ch = global[`_notification_modul
|
|
|
154
155
|
case 'banner':
|
|
155
156
|
case 'consent':
|
|
156
157
|
case 'alert':
|
|
157
|
-
|
|
158
|
+
ws_dashboard_msa.notification({
|
|
158
159
|
to: uid,
|
|
159
160
|
data: obj,
|
|
160
161
|
});
|
|
@@ -162,7 +163,7 @@ export const submit_notification = async (req, _ch = global[`_notification_modul
|
|
|
162
163
|
break;
|
|
163
164
|
case 'push':
|
|
164
165
|
try {
|
|
165
|
-
const ret = await
|
|
166
|
+
const ret = await db_module.find_couch_query('xuda_sessions', {
|
|
166
167
|
selector: {
|
|
167
168
|
docType: 'gtp_session',
|
|
168
169
|
stat: { $lt: 3 },
|
|
@@ -232,7 +233,7 @@ export const submit_notification = async (req, _ch = global[`_notification_modul
|
|
|
232
233
|
break;
|
|
233
234
|
}
|
|
234
235
|
obj.sent = send_result[uid];
|
|
235
|
-
const ret = await
|
|
236
|
+
const ret = await db_module.save_couch_doc('xuda_notification', obj);
|
|
236
237
|
}
|
|
237
238
|
}
|
|
238
239
|
return { code: 1, data: obj };
|
|
@@ -355,7 +356,7 @@ export const get_notifications = async (req) => {
|
|
|
355
356
|
}
|
|
356
357
|
|
|
357
358
|
try {
|
|
358
|
-
let ret = await
|
|
359
|
+
let ret = await db_module.find_couch_query('xuda_notification', opt);
|
|
359
360
|
let data = { docs: [] };
|
|
360
361
|
if (ret.docs) {
|
|
361
362
|
for await (let doc of ret.docs) {
|
|
@@ -390,7 +391,7 @@ export const submit_superuser_notification = async (req) => {
|
|
|
390
391
|
|
|
391
392
|
if (_.isEmpty(to_uid)) {
|
|
392
393
|
if (!system) {
|
|
393
|
-
const all_users = await
|
|
394
|
+
const all_users = await db_module.find_couch_query('xuda_accounts', {
|
|
394
395
|
selector: {
|
|
395
396
|
docType: 'account',
|
|
396
397
|
stat: { $lt: 4 },
|
|
@@ -472,7 +473,7 @@ export const submit_app_notification = async (req) => {
|
|
|
472
473
|
|
|
473
474
|
export const update_system_notification = async (req) => {
|
|
474
475
|
const { display_type, subject, body, delivery_method, uid, type } = req;
|
|
475
|
-
const ret = await
|
|
476
|
+
const ret = await db_module.get_couch_doc('xuda_notification', req._id);
|
|
476
477
|
let notification_doc = ret.data;
|
|
477
478
|
|
|
478
479
|
if (!notification_doc.system) {
|
|
@@ -495,12 +496,12 @@ export const update_system_notification = async (req) => {
|
|
|
495
496
|
notification_doc.type = type;
|
|
496
497
|
}
|
|
497
498
|
|
|
498
|
-
|
|
499
|
+
ws_dashboard_msa.notification({
|
|
499
500
|
to: notification_doc.system ? uid : notification_doc.uid,
|
|
500
501
|
data: notification_doc,
|
|
501
502
|
});
|
|
502
503
|
|
|
503
|
-
return await
|
|
504
|
+
return await db_module.save_couch_doc('xuda_notification', notification_doc);
|
|
504
505
|
};
|
|
505
506
|
|
|
506
507
|
export const submit_topic_app_notification = async (req, _ch) => {
|
|
@@ -554,16 +555,16 @@ export const get_system_notifications = async (req) => {
|
|
|
554
555
|
};
|
|
555
556
|
|
|
556
557
|
export const notifications_validation_fx = async (notification_id) => {
|
|
557
|
-
let { code, data: doc } = await
|
|
558
|
+
let { code, data: doc } = await db_module.get_couch_doc('xuda_notification', notification_id);
|
|
558
559
|
const delete_notification = async () => {
|
|
559
560
|
doc.stat = 4;
|
|
560
|
-
await
|
|
561
|
+
await db_module.save_couch_doc('xuda_notification', doc);
|
|
561
562
|
};
|
|
562
563
|
const read_notification = async () => {
|
|
563
564
|
doc.read = true;
|
|
564
565
|
doc.read_ts = Date.now();
|
|
565
566
|
doc.read_note = 'read by notifications_validation_fx';
|
|
566
|
-
await
|
|
567
|
+
await db_module.save_couch_doc('xuda_notification', doc);
|
|
567
568
|
};
|
|
568
569
|
|
|
569
570
|
if (code < 0) return false;
|
|
@@ -574,7 +575,7 @@ export const notifications_validation_fx = async (notification_id) => {
|
|
|
574
575
|
}
|
|
575
576
|
const fx = {
|
|
576
577
|
new_version_available: async () => {
|
|
577
|
-
const { code, data: app_doc } = await
|
|
578
|
+
const { code, data: app_doc } = await db_module.get_app_obj(doc.app_id);
|
|
578
579
|
if (app_doc.app_build_id >= doc.params.build) {
|
|
579
580
|
await read_notification();
|
|
580
581
|
return false;
|