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