@xuda.io/account_module 1.2.2060 → 1.2.2062
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 +127 -124
- package/package.json +1 -1
- package/get_active_account_profile_info.mjs +0 -21
- package/get_user_info.mjs +0 -126
package/index.mjs
CHANGED
|
@@ -41,7 +41,8 @@ const _utils = await import(path.join(process.env.XUDA_HOME, 'common', 'xuda-cpi
|
|
|
41
41
|
|
|
42
42
|
// Module Paths
|
|
43
43
|
const module_path = path.join(process.env.XUDA_HOME, 'cpi') + (!_conf.is_debug ? '/node_modules/@xuda.io' : '');
|
|
44
|
-
|
|
44
|
+
|
|
45
|
+
const db_ms = await import(`${module_path}/db_module/index_ms.mjs`);
|
|
45
46
|
const ai_ms = await import(`${module_path}/ai_module/index_ms.mjs`);
|
|
46
47
|
const drive_ms = await import(`${module_path}/drive_module/index_ms.mjs`);
|
|
47
48
|
|
|
@@ -52,6 +53,8 @@ const stripe_ms = await import(`${module_path}/stripe_module/index_ms.mjs`);
|
|
|
52
53
|
const logs_ms = await import(`${module_path}/logs_module/index_ms.mjs`);
|
|
53
54
|
const ws_dashboard_ms = await import(`${module_path}/ws_dashboard_module/index_ms.mjs`);
|
|
54
55
|
|
|
56
|
+
// const {get_active_account_profile_info} = await import(`${module_path}/ws_dashboard_module/get_active_account_profile_info.mjs`);
|
|
57
|
+
|
|
55
58
|
export const update_account_info = async function (req, job_id, headers) {
|
|
56
59
|
const { uid } = req;
|
|
57
60
|
const data = req;
|
|
@@ -74,7 +77,7 @@ export const update_account_info = async function (req, job_id, headers) {
|
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
const ret = await
|
|
80
|
+
const ret = await db_ms.get_couch_doc('xuda_accounts', uid);
|
|
78
81
|
var account_obj = ret.data;
|
|
79
82
|
account_obj.ts = Date.now();
|
|
80
83
|
var change = '';
|
|
@@ -167,7 +170,7 @@ export const update_account_info = async function (req, job_id, headers) {
|
|
|
167
170
|
delete account_obj.account_info.job_id;
|
|
168
171
|
delete account_obj.account_info.app_id;
|
|
169
172
|
|
|
170
|
-
const save_ret = await
|
|
173
|
+
const save_ret = await db_ms.save_couch_doc('xuda_accounts', account_obj);
|
|
171
174
|
|
|
172
175
|
if (account_obj.account_info?.profile_picture) {
|
|
173
176
|
if (!account_obj.account_info?.profile_avatar && account_obj.account_info.profile_avatar_stat !== 2) {
|
|
@@ -184,12 +187,12 @@ export const update_account_info = async function (req, job_id, headers) {
|
|
|
184
187
|
export const update_account_preferences = async function (req) {
|
|
185
188
|
const { uid, hide_create_button, default_dashboard, sidebar_style } = req;
|
|
186
189
|
try {
|
|
187
|
-
let account_doc = await
|
|
190
|
+
let account_doc = await db_ms.get_couch_doc_native('xuda_accounts', uid);
|
|
188
191
|
account_doc.ts = Date.now();
|
|
189
192
|
|
|
190
193
|
account_doc.preferences = { hide_create_button, default_dashboard, sidebar_style };
|
|
191
194
|
|
|
192
|
-
const save_ret = await
|
|
195
|
+
const save_ret = await db_ms.save_couch_doc('xuda_accounts', account_doc);
|
|
193
196
|
if (save_ret.code < 0) {
|
|
194
197
|
throw new Error(save_ret.data);
|
|
195
198
|
}
|
|
@@ -200,7 +203,7 @@ export const update_account_preferences = async function (req) {
|
|
|
200
203
|
};
|
|
201
204
|
|
|
202
205
|
export const save_admin_presets = async function (req) {
|
|
203
|
-
const ret = await
|
|
206
|
+
const ret = await db_ms.get_couch_doc('xuda_master', req.app_id);
|
|
204
207
|
if (ret.code < 0) {
|
|
205
208
|
return ret;
|
|
206
209
|
}
|
|
@@ -208,7 +211,7 @@ export const save_admin_presets = async function (req) {
|
|
|
208
211
|
app_obj.deploy_data.admin_presets = req.admin_presets;
|
|
209
212
|
app_obj.deploy_data.preset_id = req.preset_id;
|
|
210
213
|
|
|
211
|
-
const ret3 = await
|
|
214
|
+
const ret3 = await db_ms.save_app_obj(app_obj, null, req.app_id);
|
|
212
215
|
var obj = {};
|
|
213
216
|
if (ret3.code > -1) {
|
|
214
217
|
obj = {
|
|
@@ -230,7 +233,7 @@ export const increment_account_usage = async function (req) {
|
|
|
230
233
|
if (uid) {
|
|
231
234
|
opt.key = uid;
|
|
232
235
|
}
|
|
233
|
-
const accounts_ret = await
|
|
236
|
+
const accounts_ret = await db_ms.get_couch_view_raw('xuda_accounts', 'all_accounts', opt);
|
|
234
237
|
|
|
235
238
|
function bytesToGB(bytes) {
|
|
236
239
|
return bytes / 1073741824; // or bytes / (1024 ** 3)
|
|
@@ -243,7 +246,7 @@ export const increment_account_usage = async function (req) {
|
|
|
243
246
|
try {
|
|
244
247
|
const usage_id = await _common.xuda_get_uuid('usage');
|
|
245
248
|
|
|
246
|
-
const usage_ret = await
|
|
249
|
+
const usage_ret = await db_ms.get_couch_view_raw('xuda_usage', 'open_drive_usage', {
|
|
247
250
|
key: account_data._id,
|
|
248
251
|
});
|
|
249
252
|
|
|
@@ -277,7 +280,7 @@ export const increment_account_usage = async function (req) {
|
|
|
277
280
|
doc.price += price_per_hour;
|
|
278
281
|
|
|
279
282
|
doc.ts = Date.now();
|
|
280
|
-
await
|
|
283
|
+
await db_ms.save_couch_doc('xuda_usage', doc);
|
|
281
284
|
}
|
|
282
285
|
}
|
|
283
286
|
} catch (err) {
|
|
@@ -286,7 +289,7 @@ export const increment_account_usage = async function (req) {
|
|
|
286
289
|
};
|
|
287
290
|
|
|
288
291
|
const run_account_apps = async function (account_data) {
|
|
289
|
-
const apps_ret = await
|
|
292
|
+
const apps_ret = await db_ms.get_couch_view('xuda_master', 'user_apps', {
|
|
290
293
|
startkey: [account_data._id, ''],
|
|
291
294
|
endkey: [account_data._id, 'ZZZZZ'],
|
|
292
295
|
include_docs: true,
|
|
@@ -320,13 +323,13 @@ export const increment_account_usage = async function (req) {
|
|
|
320
323
|
if (size_ret.code > -1) account_data.plugins_drive_size += size_ret.data;
|
|
321
324
|
|
|
322
325
|
// db data
|
|
323
|
-
const couch_info_ret = await
|
|
326
|
+
const couch_info_ret = await db_ms.get_couch_app_info(app.id);
|
|
324
327
|
account_data.project_data_size += couch_info_ret?.data?.sizes?.active || 0;
|
|
325
328
|
}
|
|
326
329
|
|
|
327
330
|
const usage_id = await _common.xuda_get_uuid('usage');
|
|
328
331
|
|
|
329
|
-
const usage_ret = await
|
|
332
|
+
const usage_ret = await db_ms.get_couch_view_raw('xuda_usage', 'open_app_usage', {
|
|
330
333
|
key: [app.id, app.doc?.app_hosting?.app_server_type || app.doc.app_type],
|
|
331
334
|
});
|
|
332
335
|
|
|
@@ -379,7 +382,7 @@ export const increment_account_usage = async function (req) {
|
|
|
379
382
|
} else {
|
|
380
383
|
// backup of project
|
|
381
384
|
|
|
382
|
-
const info_ret = await
|
|
385
|
+
const info_ret = await db_ms.get_couch_app_info(doc.app_id);
|
|
383
386
|
if (info_ret.code > 0) {
|
|
384
387
|
const size = info_ret.data.sizes.active / 1000 / 1000 / 1000; //gb
|
|
385
388
|
price_per_hour = (size * _conf.PRICE_OBJ.price_per_gb_backup) / _conf.PRICE_OBJ.avg_hours_in_month;
|
|
@@ -388,7 +391,7 @@ export const increment_account_usage = async function (req) {
|
|
|
388
391
|
break;
|
|
389
392
|
|
|
390
393
|
case 'user_group': {
|
|
391
|
-
const team_ret = await
|
|
394
|
+
const team_ret = await db_ms.get_couch_view('xuda_team', 'user_group_shares_count', {
|
|
392
395
|
key: app.id,
|
|
393
396
|
reduce: true,
|
|
394
397
|
group_level: 1,
|
|
@@ -418,7 +421,7 @@ export const increment_account_usage = async function (req) {
|
|
|
418
421
|
}
|
|
419
422
|
|
|
420
423
|
doc.ts = Date.now();
|
|
421
|
-
await
|
|
424
|
+
await db_ms.save_couch_doc('xuda_usage', doc);
|
|
422
425
|
}
|
|
423
426
|
}
|
|
424
427
|
} catch (err) {
|
|
@@ -446,7 +449,7 @@ export const increment_account_usage = async function (req) {
|
|
|
446
449
|
await run_account_drive(account_data);
|
|
447
450
|
|
|
448
451
|
account_data.total_drive_size = account_data.user_drive_size + account_data.studio_drive_size + account_data.workspace_drive_size + account_data.plugins_drive_size + account_data.builds_drive_size + account_data.project_data_size;
|
|
449
|
-
await
|
|
452
|
+
await db_ms.save_couch_doc('xuda_accounts', account_data);
|
|
450
453
|
}
|
|
451
454
|
};
|
|
452
455
|
|
|
@@ -454,11 +457,11 @@ export const get_account_data = async function (req) {
|
|
|
454
457
|
var { uid, enforce_usage } = req;
|
|
455
458
|
|
|
456
459
|
try {
|
|
457
|
-
const { data: acc_obj } = await
|
|
460
|
+
const { data: acc_obj } = await db_ms.get_couch_doc('xuda_accounts', uid);
|
|
458
461
|
|
|
459
462
|
// let _design;
|
|
460
463
|
// if (acc_obj.account_project_id) {
|
|
461
|
-
// _design = await
|
|
464
|
+
// _design = await db_ms.get_app_couch_doc_native(acc_obj.account_project_id, '_design/xuda');
|
|
462
465
|
// }
|
|
463
466
|
|
|
464
467
|
var ret = { code: 1 };
|
|
@@ -523,23 +526,23 @@ export const get_account_projects = async function (req) {
|
|
|
523
526
|
opt = {};
|
|
524
527
|
}
|
|
525
528
|
|
|
526
|
-
var ret = await
|
|
529
|
+
var ret = await db_ms.get_couch_view('xuda_master', 'user_projects', opt);
|
|
527
530
|
|
|
528
531
|
return ret;
|
|
529
532
|
};
|
|
530
533
|
|
|
531
534
|
export const get_account_datacenters = async function (req) {
|
|
532
|
-
return await
|
|
535
|
+
return await db_ms.get_couch_view('xuda_master', 'user_datacenters', {
|
|
533
536
|
key: req.uid,
|
|
534
537
|
});
|
|
535
538
|
};
|
|
536
539
|
export const get_account_deployments = async function (req) {
|
|
537
|
-
return await
|
|
540
|
+
return await db_ms.get_couch_view('xuda_master', 'user_deployments', {
|
|
538
541
|
key: req.uid,
|
|
539
542
|
});
|
|
540
543
|
};
|
|
541
544
|
export const get_account_instances = async function (req) {
|
|
542
|
-
return await
|
|
545
|
+
return await db_ms.get_couch_view('xuda_master', 'user_all_instances', {
|
|
543
546
|
key: req.uid,
|
|
544
547
|
});
|
|
545
548
|
};
|
|
@@ -553,11 +556,11 @@ export const get_account_info = async function (req) {
|
|
|
553
556
|
|
|
554
557
|
export const get_active_account_profile_info = async function (uid, profile_id) {
|
|
555
558
|
try {
|
|
556
|
-
const acc_obj = await
|
|
559
|
+
const acc_obj = await db_ms.get_couch_doc_native('xuda_accounts', uid);
|
|
557
560
|
|
|
558
561
|
let active_account_profile_id = profile_id || acc_obj.account_info.active_account_profile_id;
|
|
559
562
|
|
|
560
|
-
const account_profile_obj = await
|
|
563
|
+
const account_profile_obj = await db_ms.get_app_couch_doc_native(acc_obj.account_project_id, active_account_profile_id);
|
|
561
564
|
if (account_profile_obj.share_item_id) {
|
|
562
565
|
// set the original profile id if shared
|
|
563
566
|
active_account_profile_id = account_profile_obj.share_item_id;
|
|
@@ -572,7 +575,7 @@ export const get_active_account_profile_info = async function (uid, profile_id)
|
|
|
572
575
|
};
|
|
573
576
|
|
|
574
577
|
export const get_account_name = async function (req) {
|
|
575
|
-
const data = await
|
|
578
|
+
const data = await db_ms.get_couch_doc('xuda_accounts', req.uid_query || req.uid);
|
|
576
579
|
if (data.code < 0) {
|
|
577
580
|
return data;
|
|
578
581
|
}
|
|
@@ -635,7 +638,7 @@ export const account_validate_username = async function (req) {
|
|
|
635
638
|
limit: 1,
|
|
636
639
|
};
|
|
637
640
|
|
|
638
|
-
var ret = await
|
|
641
|
+
var ret = await db_ms.find_couch_query('xuda_accounts', opt);
|
|
639
642
|
|
|
640
643
|
if (ret.docs.length) {
|
|
641
644
|
return { code: -400, data: 'User exist' };
|
|
@@ -645,7 +648,7 @@ export const account_validate_username = async function (req) {
|
|
|
645
648
|
};
|
|
646
649
|
|
|
647
650
|
// export const get_account_activity = async function (req) {
|
|
648
|
-
// return await
|
|
651
|
+
// return await db_ms.get_couch_view(
|
|
649
652
|
// "xuda_activity",
|
|
650
653
|
// "activity_per_account",
|
|
651
654
|
// {
|
|
@@ -660,14 +663,14 @@ export const verify_account = async function (req) {
|
|
|
660
663
|
return { code: -10, data: 'Missing id' };
|
|
661
664
|
}
|
|
662
665
|
|
|
663
|
-
const ret = await
|
|
666
|
+
const ret = await db_ms.get_couch_doc('xuda_accounts', account_id);
|
|
664
667
|
|
|
665
668
|
if (ret.code < 0) {
|
|
666
669
|
return { code: -1, data: 'account not found' };
|
|
667
670
|
}
|
|
668
671
|
var obj = ret.data;
|
|
669
672
|
obj.stat = 3;
|
|
670
|
-
const ret_acc = await
|
|
673
|
+
const ret_acc = await db_ms.save_couch_doc('xuda_accounts', obj);
|
|
671
674
|
if (ret.code < 0) {
|
|
672
675
|
return ret_acc;
|
|
673
676
|
}
|
|
@@ -677,7 +680,7 @@ export const verify_account = async function (req) {
|
|
|
677
680
|
export const validate_user_plan = async function (req) {
|
|
678
681
|
const { account_id, app_obj } = req;
|
|
679
682
|
|
|
680
|
-
const apps_ret = await
|
|
683
|
+
const apps_ret = await db_ms.get_couch_view('xuda_master', 'user_apps_count', {
|
|
681
684
|
startkey: [account_id, ''],
|
|
682
685
|
endkey: [account_id, 'ZZZZZ'],
|
|
683
686
|
reduce: true,
|
|
@@ -693,7 +696,7 @@ export const validate_user_plan = async function (req) {
|
|
|
693
696
|
{},
|
|
694
697
|
);
|
|
695
698
|
|
|
696
|
-
const ret = await
|
|
699
|
+
const ret = await db_ms.get_couch_doc('xuda_accounts', account_id);
|
|
697
700
|
if (ret.code < 0) {
|
|
698
701
|
return ret;
|
|
699
702
|
}
|
|
@@ -714,7 +717,7 @@ export const validate_user_plan = async function (req) {
|
|
|
714
717
|
|
|
715
718
|
// validate number of team members
|
|
716
719
|
|
|
717
|
-
const user_active_app_requests_count_ret = await
|
|
720
|
+
const user_active_app_requests_count_ret = await db_ms.get_couch_view('xuda_team', 'user_active_app_requests_count', {
|
|
718
721
|
key: account_id,
|
|
719
722
|
reduce: true,
|
|
720
723
|
// group_level: 2,
|
|
@@ -813,7 +816,7 @@ export const save_ssh_key = async function (req) {
|
|
|
813
816
|
};
|
|
814
817
|
|
|
815
818
|
if (_id) {
|
|
816
|
-
const ret = await
|
|
819
|
+
const ret = await db_ms.get_couch_doc('xuda_ssh_keys', _id);
|
|
817
820
|
if (ret.code < 0) {
|
|
818
821
|
return ret;
|
|
819
822
|
}
|
|
@@ -826,14 +829,14 @@ export const save_ssh_key = async function (req) {
|
|
|
826
829
|
doc.ssh_key_name = ssh_key_name;
|
|
827
830
|
doc.ssh_key_content = ssh_key_content;
|
|
828
831
|
|
|
829
|
-
const save_ret = await
|
|
832
|
+
const save_ret = await db_ms.save_couch_doc('xuda_ssh_keys', doc);
|
|
830
833
|
|
|
831
834
|
return save_ret;
|
|
832
835
|
};
|
|
833
836
|
export const delete_ssh_key = async function (req) {
|
|
834
837
|
const { ssh_key_id } = req;
|
|
835
838
|
|
|
836
|
-
const ret = await
|
|
839
|
+
const ret = await db_ms.get_couch_doc('xuda_ssh_keys', ssh_key_id);
|
|
837
840
|
if (ret.code < 0) {
|
|
838
841
|
return ret;
|
|
839
842
|
}
|
|
@@ -841,7 +844,7 @@ export const delete_ssh_key = async function (req) {
|
|
|
841
844
|
doc.date_updated_ts = Date.now();
|
|
842
845
|
doc.stat = 4;
|
|
843
846
|
|
|
844
|
-
const save_ret = await
|
|
847
|
+
const save_ret = await db_ms.save_couch_doc('xuda_ssh_keys', doc);
|
|
845
848
|
|
|
846
849
|
return save_ret;
|
|
847
850
|
};
|
|
@@ -857,7 +860,7 @@ export const get_ssh_keys = async function (req) {
|
|
|
857
860
|
opt.selector._id = _id;
|
|
858
861
|
}
|
|
859
862
|
|
|
860
|
-
var ret = await
|
|
863
|
+
var ret = await db_ms.find_couch_query('xuda_ssh_keys', opt);
|
|
861
864
|
return ret;
|
|
862
865
|
};
|
|
863
866
|
|
|
@@ -940,7 +943,7 @@ export const search_users = async function (req) {
|
|
|
940
943
|
}
|
|
941
944
|
|
|
942
945
|
try {
|
|
943
|
-
var ret = await
|
|
946
|
+
var ret = await db_ms.find_couch_query('xuda_accounts', opt);
|
|
944
947
|
|
|
945
948
|
let docs = [];
|
|
946
949
|
for await (let e of ret.docs) {
|
|
@@ -1270,7 +1273,7 @@ export const get_contact_info = async function (uid, contact_doc, _id) {
|
|
|
1270
1273
|
const chat_conversation_count = async function () {
|
|
1271
1274
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
1272
1275
|
|
|
1273
|
-
const counts_ret = await
|
|
1276
|
+
const counts_ret = await db_ms.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
|
|
1274
1277
|
reduce: true,
|
|
1275
1278
|
group_level: 1,
|
|
1276
1279
|
|
|
@@ -1283,7 +1286,7 @@ export const get_contact_info = async function (uid, contact_doc, _id) {
|
|
|
1283
1286
|
const chat_conversation_read = async function () {
|
|
1284
1287
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
1285
1288
|
|
|
1286
|
-
const counts_ret = await
|
|
1289
|
+
const counts_ret = await db_ms.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_read', {
|
|
1287
1290
|
reduce: true,
|
|
1288
1291
|
group_level: 2,
|
|
1289
1292
|
|
|
@@ -1318,7 +1321,7 @@ export const get_contact_info = async function (uid, contact_doc, _id) {
|
|
|
1318
1321
|
|
|
1319
1322
|
if (doc.team_req_id) {
|
|
1320
1323
|
try {
|
|
1321
|
-
const req_doc = await
|
|
1324
|
+
const req_doc = await db_ms.get_couch_doc_native('xuda_team', doc.team_req_id);
|
|
1322
1325
|
doc.connection_stat = req_doc.team_req_stat;
|
|
1323
1326
|
doc.connection_type = req_doc.access_type;
|
|
1324
1327
|
doc.connection_uid = req_doc.team_req_from_uid === uid ? req_doc.team_req_to_uid : req_doc.team_req_from_uid;
|
|
@@ -1329,7 +1332,7 @@ export const get_contact_info = async function (uid, contact_doc, _id) {
|
|
|
1329
1332
|
if (doc.connection_type === 'account_profile') {
|
|
1330
1333
|
try {
|
|
1331
1334
|
const app_id = await get_account_default_project_id(uid);
|
|
1332
|
-
const account_profile_doc = await
|
|
1335
|
+
const account_profile_doc = await db_ms.get_app_couch_doc_native(app_id, req_doc.share_item_id);
|
|
1333
1336
|
doc.account_profile = account_profile_doc;
|
|
1334
1337
|
} catch (error) {}
|
|
1335
1338
|
}
|
|
@@ -1393,7 +1396,7 @@ export const get_pending_contact_out = async function (uid, _id) {
|
|
|
1393
1396
|
if (_id) {
|
|
1394
1397
|
to_opt.selector._id = _id;
|
|
1395
1398
|
}
|
|
1396
|
-
const requests_to_res = await
|
|
1399
|
+
const requests_to_res = await db_ms.find_couch_query('xuda_team', to_opt);
|
|
1397
1400
|
|
|
1398
1401
|
for await (let e of requests_to_res.docs) {
|
|
1399
1402
|
let doc = { docType: 'contact', date_created: e.team_req_date, email: [e.team_req_to_email], name: '', pending: true, contact_uid: e.team_req_to_uid, team_req_id: e._id, team_req_from_uid: uid };
|
|
@@ -1424,7 +1427,7 @@ export const get_pending_contact_in = async function (uid, _id) {
|
|
|
1424
1427
|
to_opt.selector._id = _id;
|
|
1425
1428
|
}
|
|
1426
1429
|
|
|
1427
|
-
const requests_from_res = await
|
|
1430
|
+
const requests_from_res = await db_ms.find_couch_query('xuda_team', from_opt);
|
|
1428
1431
|
|
|
1429
1432
|
for await (let e of requests_from_res.docs) {
|
|
1430
1433
|
let doc = { docType: 'contact', date_created: e.team_req_date, email: [e.sender_account_info.email], name: '', pending: true, contact_uid: e.team_req_from_uid, team_req_id: e._id };
|
|
@@ -1453,7 +1456,7 @@ export const get_pending_share_contact_in = async function (uid, _id) {
|
|
|
1453
1456
|
to_opt.selector._id = _id;
|
|
1454
1457
|
}
|
|
1455
1458
|
|
|
1456
|
-
const requests_from_res = await
|
|
1459
|
+
const requests_from_res = await db_ms.find_couch_query('xuda_team', from_opt);
|
|
1457
1460
|
|
|
1458
1461
|
for await (let e of requests_from_res.docs) {
|
|
1459
1462
|
let doc = await get_contact(uid, e.share_item_id);
|
|
@@ -1521,7 +1524,7 @@ export const update_contact = async function (req) {
|
|
|
1521
1524
|
}
|
|
1522
1525
|
|
|
1523
1526
|
if (contact_uid) {
|
|
1524
|
-
const ret = await
|
|
1527
|
+
const ret = await db_ms.get_couch_doc('xuda_accounts', contact_uid);
|
|
1525
1528
|
const account_obj = ret.data;
|
|
1526
1529
|
doc.profile_picture = account_obj.account_info.profile_picture;
|
|
1527
1530
|
doc.profile_avatar = account_obj.account_info.profile_avatar;
|
|
@@ -1533,7 +1536,7 @@ export const update_contact = async function (req) {
|
|
|
1533
1536
|
};
|
|
1534
1537
|
|
|
1535
1538
|
export const get_account_rt_info = async function (uid) {
|
|
1536
|
-
const doc_ret = await
|
|
1539
|
+
const doc_ret = await db_ms.get_couch_doc('xuda_accounts', uid);
|
|
1537
1540
|
if (doc_ret.code < 0) {
|
|
1538
1541
|
console.error('get_account_rt_info', doc_ret);
|
|
1539
1542
|
return {};
|
|
@@ -1684,7 +1687,7 @@ export const create_account_oauth_link = async function (req, job_id) {
|
|
|
1684
1687
|
};
|
|
1685
1688
|
|
|
1686
1689
|
export const get_default_project_account_doc = async function (uid) {
|
|
1687
|
-
const ret = await
|
|
1690
|
+
const ret = await db_ms.get_couch_doc('xuda_accounts', uid);
|
|
1688
1691
|
return ret.data;
|
|
1689
1692
|
};
|
|
1690
1693
|
export const get_account_default_project_id = async function (uid) {
|
|
@@ -1740,7 +1743,7 @@ export const onboarding_completed = async function (req, job_id, headers) {
|
|
|
1740
1743
|
try {
|
|
1741
1744
|
await update_account_info(req, job_id, headers);
|
|
1742
1745
|
|
|
1743
|
-
let account_doc = await
|
|
1746
|
+
let account_doc = await db_ms.get_couch_doc_native('xuda_accounts', uid);
|
|
1744
1747
|
|
|
1745
1748
|
if (!account_doc.account_info?.profile_picture) {
|
|
1746
1749
|
throw new Error(`missing profile_picture`);
|
|
@@ -1754,7 +1757,7 @@ export const onboarding_completed = async function (req, job_id, headers) {
|
|
|
1754
1757
|
|
|
1755
1758
|
account_doc.boarded_info = { headers, date_ts: Date.now() };
|
|
1756
1759
|
account_doc.isBoarded = true;
|
|
1757
|
-
const save_ret = await
|
|
1760
|
+
const save_ret = await db_ms.save_couch_doc('xuda_accounts', account_doc);
|
|
1758
1761
|
|
|
1759
1762
|
return save_ret;
|
|
1760
1763
|
} catch (err) {
|
|
@@ -1777,13 +1780,13 @@ export const get_account_ai_usage = async function (req, job_id, headers) {
|
|
|
1777
1780
|
const { uid, year, month, day, usage_scope = 'account' } = req;
|
|
1778
1781
|
try {
|
|
1779
1782
|
// const app_id = await get_account_default_project_id(uid);
|
|
1780
|
-
// const { data: acc_obj } = await
|
|
1783
|
+
// const { data: acc_obj } = await db_ms.get_couch_doc('xuda_accounts', uid);
|
|
1781
1784
|
|
|
1782
1785
|
const d = new Date();
|
|
1783
1786
|
const curr_month = Number(String(d.getMonth() + 1).padStart(2, '0')); // months are 0-based
|
|
1784
1787
|
const curr_year = d.getFullYear();
|
|
1785
1788
|
|
|
1786
|
-
const ai_usage = await
|
|
1789
|
+
const ai_usage = await db_ms.get_couch_view('xuda_usage', 'ai_usage', {
|
|
1787
1790
|
startkey: [uid, year || curr_year, month || curr_month, day || 0],
|
|
1788
1791
|
endkey: [uid, year || curr_year, month || curr_month, day || 99],
|
|
1789
1792
|
reduce: true,
|
|
@@ -1822,7 +1825,7 @@ export const get_account_ai_usage = async function (req, job_id, headers) {
|
|
|
1822
1825
|
// let contact_connection = 0;
|
|
1823
1826
|
// let total_credits = membership_plan + ai_workspace_plan + contact_connection;
|
|
1824
1827
|
|
|
1825
|
-
const ai_credits = await
|
|
1828
|
+
const ai_credits = await db_ms.get_couch_view('xuda_billing', 'ai_credits', {
|
|
1826
1829
|
startkey: [uid, ''],
|
|
1827
1830
|
endkey: [uid, 'zzz'],
|
|
1828
1831
|
reduce: true,
|
|
@@ -1858,7 +1861,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
|
|
|
1858
1861
|
try {
|
|
1859
1862
|
let profile_picture;
|
|
1860
1863
|
|
|
1861
|
-
let { code: account_code, data: account_obj } = await
|
|
1864
|
+
let { code: account_code, data: account_obj } = await db_ms.get_couch_doc('xuda_accounts', account_uid);
|
|
1862
1865
|
let account_info = account_obj.account_info;
|
|
1863
1866
|
|
|
1864
1867
|
if (account_code < 0) {
|
|
@@ -1871,7 +1874,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
|
|
|
1871
1874
|
if (!account_info.profile_picture) {
|
|
1872
1875
|
const file_ret = await ai_ms.get_profile_picture(uid, account_info.account_type, name, { email: account_info.email, metadata, account_info }, account_profile_info, job_id, headers);
|
|
1873
1876
|
|
|
1874
|
-
let { code: account_code, data: account_obj2 } = await
|
|
1877
|
+
let { code: account_code, data: account_obj2 } = await db_ms.get_couch_doc('xuda_accounts', account_uid);
|
|
1875
1878
|
account_obj = account_obj2;
|
|
1876
1879
|
account_info = account_obj.account_info;
|
|
1877
1880
|
|
|
@@ -1880,7 +1883,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
|
|
|
1880
1883
|
|
|
1881
1884
|
account_info.profile_picture = account_info.profile_picture_obj.file_url;
|
|
1882
1885
|
account_info.profile_picture_source = file_ret.profile_picture_source;
|
|
1883
|
-
const account_save_ret = await
|
|
1886
|
+
const account_save_ret = await db_ms.save_couch_doc('xuda_accounts', account_obj);
|
|
1884
1887
|
profile_picture = account_info.profile_picture;
|
|
1885
1888
|
}
|
|
1886
1889
|
|
|
@@ -1925,7 +1928,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
|
|
|
1925
1928
|
if (file_ret.code < 0) {
|
|
1926
1929
|
throw new Error(file_ret.data);
|
|
1927
1930
|
}
|
|
1928
|
-
let { code: account_code, data: account_obj3 } = await
|
|
1931
|
+
let { code: account_code, data: account_obj3 } = await db_ms.get_couch_doc('xuda_accounts', account_uid);
|
|
1929
1932
|
account_obj = account_obj3;
|
|
1930
1933
|
account_info = account_obj.account_info;
|
|
1931
1934
|
|
|
@@ -1933,7 +1936,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
|
|
|
1933
1936
|
account_info.profile_avatar_obj = file_ret.data;
|
|
1934
1937
|
account_info.profile_avatar = account_info.profile_avatar_obj.file_url;
|
|
1935
1938
|
|
|
1936
|
-
const account_save_ret = await
|
|
1939
|
+
const account_save_ret = await db_ms.save_couch_doc('xuda_accounts', account_obj);
|
|
1937
1940
|
await update_account_profile_picture_status(account_uid, 3);
|
|
1938
1941
|
}
|
|
1939
1942
|
} catch (err) {
|
|
@@ -1954,7 +1957,7 @@ setTimeout(async () => {
|
|
|
1954
1957
|
// ret = await create_account_profile({ uid });
|
|
1955
1958
|
// ret = await get_account_profiles({ uid });
|
|
1956
1959
|
|
|
1957
|
-
// let _design = await
|
|
1960
|
+
// let _design = await db_ms.get_app_couch_doc_native(app_id, '_design/xuda');
|
|
1958
1961
|
// ret = _design.views.ai_chat_usage;
|
|
1959
1962
|
// console.log(_design.views.ai_chat_usage);
|
|
1960
1963
|
// ret = await set_contact_profile_picture(uid, 'cnt_2d21d55f8f0cdaf65a7a69f69617f532', {}, null, {});
|
|
@@ -2023,7 +2026,7 @@ export const add_contact = async function (req, job_id, headers) {
|
|
|
2023
2026
|
let cached_contact;
|
|
2024
2027
|
let business_has_person;
|
|
2025
2028
|
if (contact_uid) {
|
|
2026
|
-
let { code: account_code, data: account_obj } = await
|
|
2029
|
+
let { code: account_code, data: account_obj } = await db_ms.get_couch_doc('xuda_accounts', contact_uid);
|
|
2027
2030
|
// account_info = account_obj.account_info;
|
|
2028
2031
|
// account_info_ret = await get_account_name({ uid_query: contact_uid });
|
|
2029
2032
|
if (account_code < 0) {
|
|
@@ -2123,7 +2126,7 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2123
2126
|
try {
|
|
2124
2127
|
// let profile_picture;
|
|
2125
2128
|
|
|
2126
|
-
const contact_ret = await
|
|
2129
|
+
const contact_ret = await db_ms.get_app_couch_doc(account_profile_info.app_id, contact_id);
|
|
2127
2130
|
|
|
2128
2131
|
if (contact_ret.code < 0) {
|
|
2129
2132
|
throw new Error(`contact ${contact_id} not found`);
|
|
@@ -2163,13 +2166,13 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2163
2166
|
}
|
|
2164
2167
|
}
|
|
2165
2168
|
if (file_ret?.data?.file_url) {
|
|
2166
|
-
let { code: contact_code, data: contact_obj2 } = await
|
|
2169
|
+
let { code: contact_code, data: contact_obj2 } = await db_ms.get_app_couch_doc(account_profile_info.app_id, contact_id);
|
|
2167
2170
|
contact_obj = contact_obj2;
|
|
2168
2171
|
contact_obj.profile_picture_obj = file_ret.data;
|
|
2169
2172
|
contact_obj.profile_picture = contact_obj.profile_picture_obj.file_url;
|
|
2170
2173
|
contact_obj.profile_picture_source = file_ret.profile_picture_source;
|
|
2171
2174
|
|
|
2172
|
-
const contact_save_ret = await
|
|
2175
|
+
const contact_save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, contact_obj);
|
|
2173
2176
|
// profile_picture = contact_obj.profile_picture;
|
|
2174
2177
|
}
|
|
2175
2178
|
}
|
|
@@ -2219,7 +2222,7 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2219
2222
|
if (file_ret.data === 'Input file contains unsupported image format') {
|
|
2220
2223
|
contact_obj.profile_picture = null;
|
|
2221
2224
|
contact_obj.profile_picture_obj = null;
|
|
2222
|
-
const contact_save_ret = await
|
|
2225
|
+
const contact_save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, contact_obj);
|
|
2223
2226
|
}
|
|
2224
2227
|
throw new Error(file_ret.data);
|
|
2225
2228
|
}
|
|
@@ -2248,12 +2251,12 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2248
2251
|
// save_xuda_cache(uid, 'profile_avatar', contact_obj.email, file_ret.data, { account_type: contact_obj.account_type, type: 'contact' });
|
|
2249
2252
|
}
|
|
2250
2253
|
|
|
2251
|
-
let { code: contact_code, data: contact_obj3 } = await
|
|
2254
|
+
let { code: contact_code, data: contact_obj3 } = await db_ms.get_app_couch_doc(account_profile_info.app_id, contact_id);
|
|
2252
2255
|
contact_obj = contact_obj3;
|
|
2253
2256
|
contact_obj.profile_avatar_obj = file_ret.data;
|
|
2254
2257
|
contact_obj.profile_avatar = contact_obj?.profile_avatar_obj?.file_url;
|
|
2255
2258
|
contact_obj.avatar_source = file_ret?.data?.avatar_source;
|
|
2256
|
-
const contact_save_ret = await
|
|
2259
|
+
const contact_save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, contact_obj);
|
|
2257
2260
|
}
|
|
2258
2261
|
await update_contact_profile_picture_status(uid, contact_id, 3);
|
|
2259
2262
|
} catch (err) {
|
|
@@ -2264,11 +2267,11 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2264
2267
|
|
|
2265
2268
|
const update_account_profile_picture_status = async function (uid, stat, error) {
|
|
2266
2269
|
try {
|
|
2267
|
-
let doc = await
|
|
2270
|
+
let doc = await db_ms.get_couch_doc_native('xuda_accounts', uid);
|
|
2268
2271
|
doc.account_info.profile_avatar_stat = stat;
|
|
2269
2272
|
doc.account_info.profile_avatar_error = error;
|
|
2270
2273
|
doc.account_info.profile_avatar_stat_ts = Date.now();
|
|
2271
|
-
const save_ret = await
|
|
2274
|
+
const save_ret = await db_ms.save_couch_doc_native('xuda_accounts', doc);
|
|
2272
2275
|
} catch (err) {
|
|
2273
2276
|
console.error(err);
|
|
2274
2277
|
}
|
|
@@ -2277,12 +2280,12 @@ const update_account_profile_picture_status = async function (uid, stat, error)
|
|
|
2277
2280
|
const update_contact_profile_picture_status = async function (uid, contact_id, stat, error) {
|
|
2278
2281
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
2279
2282
|
try {
|
|
2280
|
-
let doc = await
|
|
2283
|
+
let doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, contact_id);
|
|
2281
2284
|
doc.profile_avatar_stat = stat;
|
|
2282
2285
|
doc.profile_avatar_error = error;
|
|
2283
2286
|
doc.profile_avatar_stat_ts = Date.now();
|
|
2284
2287
|
|
|
2285
|
-
const save_ret = await
|
|
2288
|
+
const save_ret = await db_ms.save_app_couch_doc_native(account_profile_info.app_id, doc);
|
|
2286
2289
|
} catch (err) {
|
|
2287
2290
|
console.error(err);
|
|
2288
2291
|
}
|
|
@@ -2533,15 +2536,15 @@ export const unfriend_contact = async function (req) {
|
|
|
2533
2536
|
if (!contact_doc.team_req_id) {
|
|
2534
2537
|
throw new Error('no friend relationship found');
|
|
2535
2538
|
}
|
|
2536
|
-
let req_doc = await
|
|
2539
|
+
let req_doc = await db_ms.get_couch_doc_native('xuda_team', contact_doc.team_req_id);
|
|
2537
2540
|
req_doc.team_req_stat = 4;
|
|
2538
2541
|
req_doc.team_req_stat_desc = 'unfriend by the user';
|
|
2539
|
-
await
|
|
2542
|
+
await db_ms.get_couch_doc_native('xuda_team', contact_doc.team_req_id);
|
|
2540
2543
|
|
|
2541
2544
|
contact_doc.team_req_id = null;
|
|
2542
2545
|
const contact_save_ret = await save_contact(uid, contact_doc);
|
|
2543
2546
|
|
|
2544
|
-
const req_save_ret = await
|
|
2547
|
+
const req_save_ret = await db_ms.save_couch_doc('xuda_team', req_doc);
|
|
2545
2548
|
|
|
2546
2549
|
return req_save_ret;
|
|
2547
2550
|
} catch (err) {
|
|
@@ -2625,7 +2628,7 @@ export const not_spam_contact = async function (req, job_id, headers) {
|
|
|
2625
2628
|
var contact_doc = await get_contact(uid, contact_id);
|
|
2626
2629
|
|
|
2627
2630
|
if (contact_doc.is_spam) {
|
|
2628
|
-
await
|
|
2631
|
+
await db_ms.save_couch_doc_native('xuda_accounts', {
|
|
2629
2632
|
_id: await _common.xuda_get_uuid('spam_whitelist'),
|
|
2630
2633
|
uid,
|
|
2631
2634
|
docType: 'spam_whitelist',
|
|
@@ -2653,7 +2656,7 @@ export const not_spam_contact = async function (req, job_id, headers) {
|
|
|
2653
2656
|
await delete_xuda_cache(contact_doc);
|
|
2654
2657
|
set_contact_profile_picture(uid, contact_doc._id, {}, job_id, headers, account_profile_info, false);
|
|
2655
2658
|
|
|
2656
|
-
const emails = await
|
|
2659
|
+
const emails = await db_ms.find_app_couch_query(account_profile_info.app_id, {
|
|
2657
2660
|
selector: {
|
|
2658
2661
|
docType: 'email',
|
|
2659
2662
|
contact_id,
|
|
@@ -2665,14 +2668,14 @@ export const not_spam_contact = async function (req, job_id, headers) {
|
|
|
2665
2668
|
for await (let email of emails.docs) {
|
|
2666
2669
|
const app_id = await get_account_default_project_id(uid);
|
|
2667
2670
|
if (email.conversation_id) {
|
|
2668
|
-
|
|
2671
|
+
db_ms.delete_app_couch_doc(app_id, email.conversation_id);
|
|
2669
2672
|
email.conversation_id = null;
|
|
2670
2673
|
}
|
|
2671
2674
|
if (email.conversation_item_id) {
|
|
2672
|
-
|
|
2675
|
+
db_ms.delete_app_couch_doc(app_id, email.conversation_item_id);
|
|
2673
2676
|
email.conversation_item_id = null;
|
|
2674
2677
|
}
|
|
2675
|
-
const save_ret = await
|
|
2678
|
+
const save_ret = await db_ms.save_app_couch_doc_native(app_id, email);
|
|
2676
2679
|
|
|
2677
2680
|
// save attachments
|
|
2678
2681
|
// summarized_body
|
|
@@ -2740,7 +2743,7 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
2740
2743
|
const contact_save_ret = await save_contact(uid, contact_doc);
|
|
2741
2744
|
await delete_xuda_cache(contact_doc);
|
|
2742
2745
|
|
|
2743
|
-
const conversation_items = await
|
|
2746
|
+
const conversation_items = await db_ms.find_app_couch_query(account_profile_info.app_id, {
|
|
2744
2747
|
selector: {
|
|
2745
2748
|
docType: 'chat_conversation_item',
|
|
2746
2749
|
reference_id: contact_id,
|
|
@@ -2752,7 +2755,7 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
2752
2755
|
for await (let conversation_item of conversation_items.docs) {
|
|
2753
2756
|
try {
|
|
2754
2757
|
const account_profile_info = await get_active_account_profile_info(conversation_item.uid);
|
|
2755
|
-
let conversation_doc = await
|
|
2758
|
+
let conversation_doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, conversation_item.conversation_id);
|
|
2756
2759
|
|
|
2757
2760
|
const transcript = await ai_ms.get_transcript(conversation_item.uid, conversation_item.app_id, conversation_item.conversation_id, account_profile_info, conversation_item.file.filename);
|
|
2758
2761
|
let items;
|
|
@@ -2762,7 +2765,7 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
2762
2765
|
|
|
2763
2766
|
conversation_item.text = transcript?.data || transcript || '';
|
|
2764
2767
|
conversation_item.process_stat = 'full';
|
|
2765
|
-
const conversation_item_save_ret = await
|
|
2768
|
+
const conversation_item_save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, conversation_item);
|
|
2766
2769
|
}
|
|
2767
2770
|
} catch (err) {
|
|
2768
2771
|
throw err;
|
|
@@ -2806,10 +2809,10 @@ export const get_pending_share_profile_in = async function (uid, _id) {
|
|
|
2806
2809
|
to_opt.selector._id = _id;
|
|
2807
2810
|
}
|
|
2808
2811
|
|
|
2809
|
-
const requests_from_res = await
|
|
2812
|
+
const requests_from_res = await db_ms.find_couch_query('xuda_team', from_opt);
|
|
2810
2813
|
|
|
2811
2814
|
for await (let e of requests_from_res.docs) {
|
|
2812
|
-
let doc = await
|
|
2815
|
+
let doc = await db_ms.get_couch_doc_native('xuda_accounts', e.share_item_id);
|
|
2813
2816
|
|
|
2814
2817
|
doc.shared_from_uid = e.team_req_from_uid;
|
|
2815
2818
|
doc.pending = true;
|
|
@@ -2825,7 +2828,7 @@ export const get_account_profile_info = async function (uid, contact_profile_doc
|
|
|
2825
2828
|
const app_id = await get_account_default_project_id(uid);
|
|
2826
2829
|
let doc = contact_profile_doc;
|
|
2827
2830
|
if (_id) {
|
|
2828
|
-
doc = await
|
|
2831
|
+
doc = await db_ms.get_couch_doc_native('xuda_accounts', _id);
|
|
2829
2832
|
}
|
|
2830
2833
|
doc.notifications = 0;
|
|
2831
2834
|
|
|
@@ -2850,7 +2853,7 @@ export const get_account_profile_info = async function (uid, contact_profile_doc
|
|
|
2850
2853
|
let ret = `default-pattern.png`;
|
|
2851
2854
|
|
|
2852
2855
|
if (doc.shared_from_uid) {
|
|
2853
|
-
// const account_profile_doc = await
|
|
2856
|
+
// const account_profile_doc = await db_ms.get_couch_doc_native('xuda_accounts', doc.share_item_id);
|
|
2854
2857
|
const shared_from_uid_ret = await get_account_name({ uid_query: doc.shared_from_uid });
|
|
2855
2858
|
ret = shared_from_uid_ret.data.profile_avatar;
|
|
2856
2859
|
} else if (doc.is_spam) {
|
|
@@ -2883,7 +2886,7 @@ export const get_account_profile_info = async function (uid, contact_profile_doc
|
|
|
2883
2886
|
const get_online = async () => {
|
|
2884
2887
|
let online = false;
|
|
2885
2888
|
let selector = { docType: 'team_request', team_req_stat: 3, share_item_id: doc._id, access_type: 'account_profile', team_req_from_uid: uid };
|
|
2886
|
-
let ret = await
|
|
2889
|
+
let ret = await db_ms.find_couch_query('xuda_team', { selector });
|
|
2887
2890
|
for (const req_obj of ret.docs) {
|
|
2888
2891
|
const account_info_ret = await get_account_name({ uid_query: req_obj.team_req_to_uid });
|
|
2889
2892
|
online = account_info_ret.data.online;
|
|
@@ -2909,7 +2912,7 @@ export const get_account_profile_info = async function (uid, contact_profile_doc
|
|
|
2909
2912
|
const get_members = async () => {
|
|
2910
2913
|
let members = [];
|
|
2911
2914
|
let selector = { docType: 'team_request', team_req_stat: 3, share_item_id: doc._id, access_type: 'account_profile', team_req_from_uid: uid };
|
|
2912
|
-
let ret = await
|
|
2915
|
+
let ret = await db_ms.find_couch_query('xuda_team', { selector });
|
|
2913
2916
|
for (const req_obj of ret.docs) {
|
|
2914
2917
|
const account_info_ret = await get_account_name({ uid_query: req_obj.team_req_to_uid });
|
|
2915
2918
|
const info = await await get_contact_info(uid, account_info_ret.data);
|
|
@@ -2922,7 +2925,7 @@ export const get_account_profile_info = async function (uid, contact_profile_doc
|
|
|
2922
2925
|
// const account_profile_info = await get_active_account_profile_info(uid);
|
|
2923
2926
|
|
|
2924
2927
|
let selector = { docType: 'account_profile', stat: 3 };
|
|
2925
|
-
let ret = await
|
|
2928
|
+
let ret = await db_ms.find_app_couch_query(app_id, { selector });
|
|
2926
2929
|
|
|
2927
2930
|
return ret.docs;
|
|
2928
2931
|
};
|
|
@@ -2964,7 +2967,7 @@ export const get_account_profiles = async function (req) {
|
|
|
2964
2967
|
const { _id, uid, profile_name, limit, skip, bookmark, search, filter_type = 'all', profile_id, active_tab } = req;
|
|
2965
2968
|
const app_id = await get_account_default_project_id(uid);
|
|
2966
2969
|
if (_id) {
|
|
2967
|
-
let data = await
|
|
2970
|
+
let data = await db_ms.get_app_couch_doc(app_id, _id);
|
|
2968
2971
|
return data;
|
|
2969
2972
|
}
|
|
2970
2973
|
|
|
@@ -3032,7 +3035,7 @@ export const get_account_profiles = async function (req) {
|
|
|
3032
3035
|
let profiles = { docs: [], total_docs: 0 };
|
|
3033
3036
|
|
|
3034
3037
|
if (filter_type !== 'pending') {
|
|
3035
|
-
profiles = await
|
|
3038
|
+
profiles = await db_ms.find_app_couch_query(app_id, opt);
|
|
3036
3039
|
if (!limit || profile_id) {
|
|
3037
3040
|
profiles.total_docs = profiles.docs.length;
|
|
3038
3041
|
} else {
|
|
@@ -3041,7 +3044,7 @@ export const get_account_profiles = async function (req) {
|
|
|
3041
3044
|
opt.limit = 9999;
|
|
3042
3045
|
opt.fields = ['_id'];
|
|
3043
3046
|
|
|
3044
|
-
const counter = await
|
|
3047
|
+
const counter = await db_ms.find_app_couch_query(app_id, opt);
|
|
3045
3048
|
profiles.total_docs = counter.docs.length;
|
|
3046
3049
|
}
|
|
3047
3050
|
}
|
|
@@ -3093,7 +3096,7 @@ export const archive_account_profile = async function (req) {
|
|
|
3093
3096
|
|
|
3094
3097
|
await team_ms.validate_share_exist(uid, 'account_profile', profile_id);
|
|
3095
3098
|
|
|
3096
|
-
var account_profile_doc = await
|
|
3099
|
+
var account_profile_doc = await db_ms.get_app_couch_doc_native(app_id, profile_id);
|
|
3097
3100
|
|
|
3098
3101
|
if (account_profile_doc.main) {
|
|
3099
3102
|
throw new Error('reserve');
|
|
@@ -3103,7 +3106,7 @@ export const archive_account_profile = async function (req) {
|
|
|
3103
3106
|
account_profile_doc.stat_ts = Date.now();
|
|
3104
3107
|
account_profile_doc.stat_reason = 'archived by the user';
|
|
3105
3108
|
|
|
3106
|
-
const account_profile_save_ret = await
|
|
3109
|
+
const account_profile_save_ret = await db_ms.save_app_couch_doc(app_id, account_profile_doc);
|
|
3107
3110
|
|
|
3108
3111
|
return account_profile_save_ret;
|
|
3109
3112
|
} catch (err) {
|
|
@@ -3118,7 +3121,7 @@ export const delete_account_profile = async function (req, job_id, headers) {
|
|
|
3118
3121
|
const { profile_id, uid } = req;
|
|
3119
3122
|
try {
|
|
3120
3123
|
const app_id = await get_account_default_project_id(uid);
|
|
3121
|
-
var account_profile_doc = await
|
|
3124
|
+
var account_profile_doc = await db_ms.get_app_couch_doc_native(app_id, profile_id);
|
|
3122
3125
|
if (account_profile_doc.stat !== 5) {
|
|
3123
3126
|
throw new Error('A document can only be deleted after it has been archived');
|
|
3124
3127
|
}
|
|
@@ -3126,7 +3129,7 @@ export const delete_account_profile = async function (req, job_id, headers) {
|
|
|
3126
3129
|
account_profile_doc.stat_ts = Date.now();
|
|
3127
3130
|
account_profile_doc.stat_reason = 'deleted by the user';
|
|
3128
3131
|
|
|
3129
|
-
const account_profile_save_ret = await
|
|
3132
|
+
const account_profile_save_ret = await db_ms.save_app_couch_doc(app_id, account_profile_doc);
|
|
3130
3133
|
|
|
3131
3134
|
ai_ms.delete_depended_chats(uid, profile_id);
|
|
3132
3135
|
return account_profile_save_ret;
|
|
@@ -3143,7 +3146,7 @@ export const unarchive_account_profile = async function (req) {
|
|
|
3143
3146
|
try {
|
|
3144
3147
|
const app_id = await get_account_default_project_id(uid);
|
|
3145
3148
|
|
|
3146
|
-
var account_profile_doc = await
|
|
3149
|
+
var account_profile_doc = await db_ms.get_app_couch_doc_native(app_id, profile_id);
|
|
3147
3150
|
|
|
3148
3151
|
if (account_profile_doc.stat !== 5) {
|
|
3149
3152
|
throw new Error('account profile is not archived');
|
|
@@ -3153,7 +3156,7 @@ export const unarchive_account_profile = async function (req) {
|
|
|
3153
3156
|
account_profile_doc.stat_ts = Date.now();
|
|
3154
3157
|
account_profile_doc.stat_reason = 'archived by the user';
|
|
3155
3158
|
|
|
3156
|
-
const account_profile_save_ret = await
|
|
3159
|
+
const account_profile_save_ret = await db_ms.save_app_couch_doc(app_id, account_profile_doc);
|
|
3157
3160
|
|
|
3158
3161
|
return account_profile_save_ret;
|
|
3159
3162
|
}
|
|
@@ -3169,7 +3172,7 @@ export const create_account_profile = async function (req, job_id, headers) {
|
|
|
3169
3172
|
const { uid, profile_name, profile_signature, email_account_id, profile_picture, profile_avatar, profile_picture_obj, profile_avatar_obj, main, account_type } = req;
|
|
3170
3173
|
try {
|
|
3171
3174
|
const app_id = await get_account_default_project_id(uid);
|
|
3172
|
-
// const { data: acc_obj } = await
|
|
3175
|
+
// const { data: acc_obj } = await db_ms.get_couch_doc('xuda_accounts', uid);
|
|
3173
3176
|
|
|
3174
3177
|
const d = Date.now();
|
|
3175
3178
|
const doc = {
|
|
@@ -3189,7 +3192,7 @@ export const create_account_profile = async function (req, job_id, headers) {
|
|
|
3189
3192
|
profile_avatar_obj,
|
|
3190
3193
|
main,
|
|
3191
3194
|
};
|
|
3192
|
-
const save_ret = await
|
|
3195
|
+
const save_ret = await db_ms.save_app_couch_doc(app_id, doc);
|
|
3193
3196
|
// acc_obj.active_profile_id = save_ret.data.id;
|
|
3194
3197
|
|
|
3195
3198
|
// return { code: 55, data: save_ret };
|
|
@@ -3204,7 +3207,7 @@ export const update_account_profile = async function (req, job_id, headers) {
|
|
|
3204
3207
|
const app_id = await get_account_default_project_id(uid);
|
|
3205
3208
|
const account_profile_properties = ['profile_name', 'profile_signature', 'email_account_id', 'profile_picture', 'profile_avatar', 'profile_picture_obj', 'profile_avatar_obj', 'auto_respond', 'auto_respond_mode', 'auto_respond_agents', 'account_type', 'active_ai_model'];
|
|
3206
3209
|
try {
|
|
3207
|
-
let { data: account_profile_doc } = await
|
|
3210
|
+
let { data: account_profile_doc } = await db_ms.get_app_couch_doc(app_id, _id);
|
|
3208
3211
|
|
|
3209
3212
|
if (account_profile_doc.docType !== 'account_profile') {
|
|
3210
3213
|
throw new Error('not account profile doc');
|
|
@@ -3228,7 +3231,7 @@ export const update_account_profile = async function (req, job_id, headers) {
|
|
|
3228
3231
|
|
|
3229
3232
|
account_profile_doc.ts = Date.now();
|
|
3230
3233
|
|
|
3231
|
-
const save_ret = await
|
|
3234
|
+
const save_ret = await db_ms.save_app_couch_doc(app_id, account_profile_doc);
|
|
3232
3235
|
|
|
3233
3236
|
return { code: 56, data: save_ret };
|
|
3234
3237
|
} catch (err) {
|
|
@@ -3245,7 +3248,7 @@ export const update_entity_account_profiles = async function (req, job_id, heade
|
|
|
3245
3248
|
throw new Error('account_profiles cannot be empty');
|
|
3246
3249
|
}
|
|
3247
3250
|
|
|
3248
|
-
let doc = await
|
|
3251
|
+
let doc = await db_ms.get_app_couch_doc_native(app_id, _id);
|
|
3249
3252
|
|
|
3250
3253
|
switch (doc.docType) {
|
|
3251
3254
|
case 'chat_conversation':
|
|
@@ -3265,7 +3268,7 @@ export const update_entity_account_profiles = async function (req, job_id, heade
|
|
|
3265
3268
|
break;
|
|
3266
3269
|
}
|
|
3267
3270
|
|
|
3268
|
-
const save_ret = await
|
|
3271
|
+
const save_ret = await db_ms.save_app_couch_doc(app_id, doc);
|
|
3269
3272
|
|
|
3270
3273
|
return { code: 57, data: save_ret };
|
|
3271
3274
|
} catch (err) {
|
|
@@ -3275,24 +3278,24 @@ export const update_entity_account_profiles = async function (req, job_id, heade
|
|
|
3275
3278
|
|
|
3276
3279
|
export const get_contact = async function (uid, contact_id) {
|
|
3277
3280
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
3278
|
-
const contact_ret = await
|
|
3281
|
+
const contact_ret = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, contact_id);
|
|
3279
3282
|
return contact_ret;
|
|
3280
3283
|
};
|
|
3281
3284
|
|
|
3282
3285
|
export const save_contact = async function (uid, contact_doc) {
|
|
3283
3286
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
3284
|
-
const contact_ret = await
|
|
3287
|
+
const contact_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, contact_doc);
|
|
3285
3288
|
return contact_ret;
|
|
3286
3289
|
};
|
|
3287
3290
|
|
|
3288
3291
|
export const find_contact_query = async function (uid, opt) {
|
|
3289
3292
|
const app_id = await get_account_default_project_id(uid);
|
|
3290
|
-
const ret = await
|
|
3293
|
+
const ret = await db_ms.find_app_couch_query(app_id, opt);
|
|
3291
3294
|
return ret;
|
|
3292
3295
|
};
|
|
3293
3296
|
|
|
3294
3297
|
export const delete_xuda_cache = async function (contact_obj) {
|
|
3295
|
-
const ret = await
|
|
3298
|
+
const ret = await db_ms.find_couch_query('xuda_cache', {
|
|
3296
3299
|
selector: {
|
|
3297
3300
|
$or: [
|
|
3298
3301
|
{
|
|
@@ -3307,7 +3310,7 @@ export const delete_xuda_cache = async function (contact_obj) {
|
|
|
3307
3310
|
|
|
3308
3311
|
for (let doc of ret.docs) {
|
|
3309
3312
|
doc._deleted = true;
|
|
3310
|
-
const save_ret = await
|
|
3313
|
+
const save_ret = await db_ms.save_couch_doc('xuda_cache', doc);
|
|
3311
3314
|
}
|
|
3312
3315
|
};
|
|
3313
3316
|
|
|
@@ -3327,12 +3330,12 @@ export const save_xuda_cache = async function (uid, docType, key, file, metadata
|
|
|
3327
3330
|
metadata,
|
|
3328
3331
|
hits: 0,
|
|
3329
3332
|
};
|
|
3330
|
-
const save_ret = await
|
|
3333
|
+
const save_ret = await db_ms.save_couch_doc('xuda_cache', doc);
|
|
3331
3334
|
return save_ret;
|
|
3332
3335
|
};
|
|
3333
3336
|
|
|
3334
3337
|
export const get_xuda_cache = async function (uid, docType, key, return_property) {
|
|
3335
|
-
let ret = await
|
|
3338
|
+
let ret = await db_ms.find_couch_query('xuda_cache', {
|
|
3336
3339
|
selector: { docType, key: key.toLowerCase().trim() },
|
|
3337
3340
|
limit: 1,
|
|
3338
3341
|
});
|
|
@@ -3343,7 +3346,7 @@ export const get_xuda_cache = async function (uid, docType, key, return_property
|
|
|
3343
3346
|
|
|
3344
3347
|
return null;
|
|
3345
3348
|
|
|
3346
|
-
// ret = await
|
|
3349
|
+
// ret = await db_ms.find_couch_query('xuda_cache', {
|
|
3347
3350
|
// selector: { docType, name: name.trim() },
|
|
3348
3351
|
// limit: 1,
|
|
3349
3352
|
// });
|
|
@@ -3354,10 +3357,10 @@ export const get_xuda_cache = async function (uid, docType, key, return_property
|
|
|
3354
3357
|
};
|
|
3355
3358
|
|
|
3356
3359
|
export const save_cache_hit = async function (_id) {
|
|
3357
|
-
let doc_ret = await
|
|
3360
|
+
let doc_ret = await db_ms.get_couch_doc('xuda_cache', _id);
|
|
3358
3361
|
if (doc_ret.code > -1) {
|
|
3359
3362
|
doc_ret.data.hits++;
|
|
3360
|
-
await
|
|
3363
|
+
await db_ms.save_couch_doc('xuda_cache', doc_ret.data);
|
|
3361
3364
|
}
|
|
3362
3365
|
};
|
|
3363
3366
|
|
|
@@ -3387,7 +3390,7 @@ export const record_ai_usage = async function (uid, input_tokens, output_tokens,
|
|
|
3387
3390
|
account_profile_info,
|
|
3388
3391
|
tools,
|
|
3389
3392
|
};
|
|
3390
|
-
const save_ret = await
|
|
3393
|
+
const save_ret = await db_ms.save_couch_doc('xuda_usage', usage_doc);
|
|
3391
3394
|
// console.log(save_ret);
|
|
3392
3395
|
} catch (err) {
|
|
3393
3396
|
console.error(err);
|
|
@@ -3396,7 +3399,7 @@ export const record_ai_usage = async function (uid, input_tokens, output_tokens,
|
|
|
3396
3399
|
|
|
3397
3400
|
export const record_ai_credit = async function (uid, credits = 0, source, details, credited_uid) {
|
|
3398
3401
|
try {
|
|
3399
|
-
var dup = await
|
|
3402
|
+
var dup = await db_ms.find_couch_query('xuda_billing', {
|
|
3400
3403
|
selector: {
|
|
3401
3404
|
docType: 'ai_credit',
|
|
3402
3405
|
credited_uid,
|
|
@@ -3422,7 +3425,7 @@ export const record_ai_credit = async function (uid, credits = 0, source, detail
|
|
|
3422
3425
|
credited_uid,
|
|
3423
3426
|
details,
|
|
3424
3427
|
};
|
|
3425
|
-
const save_ret = await
|
|
3428
|
+
const save_ret = await db_ms.save_couch_doc('xuda_billing', credit_doc);
|
|
3426
3429
|
// console.log(save_ret);
|
|
3427
3430
|
return save_ret;
|
|
3428
3431
|
} catch (err) {
|
|
@@ -3441,13 +3444,13 @@ export const add_ai_credits_to_active_accounts = async function () {
|
|
|
3441
3444
|
});
|
|
3442
3445
|
|
|
3443
3446
|
const _24_hr_ms = 1000 * 60 * 60 * 24;
|
|
3444
|
-
const active_accounts = await
|
|
3447
|
+
const active_accounts = await db_ms.find_couch_query('xuda_accounts', { selector: { stat: 3, docType: 'account', last_free_daily_ai_credit_ts: { $lt: Date.now() - _24_hr_ms }, ai_workspace_plan: 'free_ai_workspace' }, limit: 99999 });
|
|
3445
3448
|
for await (let account_doc of active_accounts.docs) {
|
|
3446
3449
|
const ret = await record_ai_credit('system', 1, 'daily credit', 'free daily credit ' + date_str, account_doc._id);
|
|
3447
3450
|
if (ret.code > -1) {
|
|
3448
3451
|
account_doc.last_free_daily_ai_credit_ts = Date.now();
|
|
3449
3452
|
account_doc.last_free_daily_ai_credit_id = ret.data.id;
|
|
3450
|
-
const save_ret = await
|
|
3453
|
+
const save_ret = await db_ms.save_couch_doc('xuda_accounts', account_doc);
|
|
3451
3454
|
}
|
|
3452
3455
|
}
|
|
3453
3456
|
};
|
|
@@ -3456,17 +3459,17 @@ export const archive_expire_ai_credits = async function () {
|
|
|
3456
3459
|
const _24_hr_ms = 1000 * 60 * 60 * 24;
|
|
3457
3460
|
const _mo_ms = _24_hr_ms * 30;
|
|
3458
3461
|
|
|
3459
|
-
const active_ai_credits = await
|
|
3462
|
+
const active_ai_credits = await db_ms.find_couch_query('xuda_billing', { selector: { stat: 3, docType: 'ai_credit', date_created_ts: { $lt: Date.now() - _mo_ms } }, limit: 99999 });
|
|
3460
3463
|
for await (let ai_credit_doc of active_ai_credits.docs) {
|
|
3461
3464
|
ai_credit_doc.stat = 5;
|
|
3462
3465
|
ai_credit_doc.stat_ts = Date.now();
|
|
3463
3466
|
ai_credit_doc.stat_reason = 'expired';
|
|
3464
|
-
const save_ret = await
|
|
3467
|
+
const save_ret = await db_ms.save_couch_doc('xuda_billing', ai_credit_doc);
|
|
3465
3468
|
}
|
|
3466
3469
|
};
|
|
3467
3470
|
|
|
3468
3471
|
export const read_accounts_emails = async function () {
|
|
3469
|
-
const active_accounts = await
|
|
3472
|
+
const active_accounts = await db_ms.find_couch_query('xuda_accounts', { selector: { stat: 3, docType: 'account' }, limit: 99999 });
|
|
3470
3473
|
for await (let account_doc of active_accounts.docs) {
|
|
3471
3474
|
if (!account_doc?.account_info?.active_account_profile_id) continue;
|
|
3472
3475
|
email_ms.refresh_mailboxes({ uid: account_doc._id });
|
|
@@ -3474,7 +3477,7 @@ export const read_accounts_emails = async function () {
|
|
|
3474
3477
|
};
|
|
3475
3478
|
|
|
3476
3479
|
export const process_accounts_emails = async function () {
|
|
3477
|
-
const active_accounts = await
|
|
3480
|
+
const active_accounts = await db_ms.find_couch_query('xuda_accounts', { selector: { stat: 3, docType: 'account' }, limit: 99999 });
|
|
3478
3481
|
for await (let account_doc of active_accounts.docs) {
|
|
3479
3482
|
if (!account_doc?.account_info?.active_account_profile_id) continue;
|
|
3480
3483
|
email_ms.process_emails({ uid: account_doc._id });
|
|
@@ -3482,7 +3485,7 @@ export const process_accounts_emails = async function () {
|
|
|
3482
3485
|
};
|
|
3483
3486
|
|
|
3484
3487
|
const isLikelySpamEmail = async function (email) {
|
|
3485
|
-
const spam_whitelists = await
|
|
3488
|
+
const spam_whitelists = await db_ms.find_couch_query('xuda_accounts', {
|
|
3486
3489
|
selector: {
|
|
3487
3490
|
docType: 'spam_whitelist',
|
|
3488
3491
|
email,
|
package/package.json
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const db_module = await import(`${module_path}/db_module/index.mjs`);
|
|
2
|
-
|
|
3
|
-
export const get_active_account_profile_info = async function (uid, profile_id) {
|
|
4
|
-
try {
|
|
5
|
-
const acc_obj = await db_module.get_couch_doc_native('xuda_accounts', uid);
|
|
6
|
-
|
|
7
|
-
let active_account_profile_id = profile_id || acc_obj.account_info.active_account_profile_id;
|
|
8
|
-
|
|
9
|
-
const account_profile_obj = await db_module.get_app_couch_doc_native(acc_obj.account_project_id, active_account_profile_id);
|
|
10
|
-
if (account_profile_obj.share_item_id) {
|
|
11
|
-
// set the original profile id if shared
|
|
12
|
-
active_account_profile_id = account_profile_obj.share_item_id;
|
|
13
|
-
}
|
|
14
|
-
const app_id = await get_account_default_project_id(account_profile_obj.shared_from_uid || account_profile_obj.uid);
|
|
15
|
-
|
|
16
|
-
return { uid: account_profile_obj.shared_from_uid || uid, account_profile_id: active_account_profile_id, app_id, is_main: active_account_profile_id === acc_obj.account_profile_id, account_profile_obj };
|
|
17
|
-
} catch (err) {
|
|
18
|
-
console.error('**** get_active_account_profile_info', err);
|
|
19
|
-
debugger;
|
|
20
|
-
}
|
|
21
|
-
};
|
package/get_user_info.mjs
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
export const get_contact_info = async function (uid, contact_doc, _id) {
|
|
2
|
-
let doc = contact_doc;
|
|
3
|
-
if (_id) {
|
|
4
|
-
doc = await get_contact(uid, _id);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
delete doc.metadata;
|
|
8
|
-
delete doc.profile_avatar_obj;
|
|
9
|
-
delete doc.profile_picture_obj;
|
|
10
|
-
delete doc.bio;
|
|
11
|
-
|
|
12
|
-
const chat_conversation_count = async function () {
|
|
13
|
-
const account_profile_info = await get_active_account_profile_info(uid);
|
|
14
|
-
|
|
15
|
-
const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
|
|
16
|
-
reduce: true,
|
|
17
|
-
group_level: 1,
|
|
18
|
-
|
|
19
|
-
startkey: [doc._id, ''],
|
|
20
|
-
endkey: [doc._id, 'zzzzzz'],
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
return counts_ret?.rows?.[0]?.value || 0;
|
|
24
|
-
};
|
|
25
|
-
const chat_conversation_read = async function () {
|
|
26
|
-
const account_profile_info = await get_active_account_profile_info(uid);
|
|
27
|
-
|
|
28
|
-
const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_read', {
|
|
29
|
-
reduce: true,
|
|
30
|
-
group_level: 2,
|
|
31
|
-
|
|
32
|
-
startkey: [uid, doc._id, ''],
|
|
33
|
-
endkey: [uid, doc._id, 'zzzzzz'],
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
return counts_ret?.rows?.[0]?.value || 0;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
doc.notifications = 0;
|
|
40
|
-
if (doc.contact_uid) {
|
|
41
|
-
const account_info_ret = await get_account_name({ uid_query: doc.contact_uid });
|
|
42
|
-
if (account_info_ret.code < 0) {
|
|
43
|
-
return; // throw new Error(`account ${contact_uid} not found`);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
doc.profile_avatar = account_info_ret.data.profile_avatar;
|
|
47
|
-
|
|
48
|
-
//membership_plan
|
|
49
|
-
// doc.name = `${account_info_ret.data.first_name} ${account_info_ret.data.last_name}`;
|
|
50
|
-
doc.name = account_info_ret.data?.account_type === 'business' ? account_info_ret.data.business_name : `${account_info_ret.data.first_name} ${account_info_ret.data.last_name}`;
|
|
51
|
-
|
|
52
|
-
if (account_info_ret.data.phone_number) {
|
|
53
|
-
try {
|
|
54
|
-
doc.phone_number = formatPhoneWithFlag(account_info_ret.data.phone_number, account_info_ret.data.country);
|
|
55
|
-
} catch (err) {
|
|
56
|
-
// console.error(err);
|
|
57
|
-
doc.phone_number = account_info_ret.data.phone_number;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (doc.team_req_id) {
|
|
62
|
-
try {
|
|
63
|
-
const req_doc = await db_module.get_couch_doc_native('xuda_team', doc.team_req_id);
|
|
64
|
-
doc.connection_stat = req_doc.team_req_stat;
|
|
65
|
-
doc.connection_type = req_doc.access_type;
|
|
66
|
-
doc.connection_uid = req_doc.team_req_from_uid === uid ? req_doc.team_req_to_uid : req_doc.team_req_from_uid;
|
|
67
|
-
doc.connection_contact_id = req_doc.team_req_from_contact_id === doc._id ? req_doc.team_req_to_contact_id : req_doc.team_req_from_contact_id;
|
|
68
|
-
if (doc.connection_type === 'contact_connection') {
|
|
69
|
-
doc.friend_since = req_doc.team_req_date;
|
|
70
|
-
}
|
|
71
|
-
if (doc.connection_type === 'account_profile') {
|
|
72
|
-
try {
|
|
73
|
-
const app_id = await get_account_default_project_id(uid);
|
|
74
|
-
const account_profile_doc = await db_module.get_app_couch_doc_native(app_id, req_doc.share_item_id);
|
|
75
|
-
doc.account_profile = account_profile_doc;
|
|
76
|
-
} catch (error) {}
|
|
77
|
-
}
|
|
78
|
-
} catch (err) {
|
|
79
|
-
if (err.message === 'deleted') {
|
|
80
|
-
try {
|
|
81
|
-
let contact_doc = await get_contact(uid, doc._id);
|
|
82
|
-
contact_doc.team_req_id = '';
|
|
83
|
-
await save_contact(uid, contact_doc);
|
|
84
|
-
} catch (error) {}
|
|
85
|
-
}
|
|
86
|
-
doc.connection_stat = 0;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
doc.avatar_source = account_info_ret.data.avatar_source;
|
|
91
|
-
// doc.icon_pattern = await get_contact_pattern(doc);
|
|
92
|
-
doc.username = account_info_ret.data.username;
|
|
93
|
-
doc.business_name = account_info_ret.data.business_name;
|
|
94
|
-
doc.address = account_info_ret.data.address;
|
|
95
|
-
doc.city = account_info_ret.data.city;
|
|
96
|
-
doc.state = account_info_ret.data.state;
|
|
97
|
-
doc.zip = account_info_ret.data.zip;
|
|
98
|
-
doc.account_type = account_info_ret.data.account_type;
|
|
99
|
-
doc.email = doc.email;
|
|
100
|
-
if (doc.connection_stat === 3) {
|
|
101
|
-
doc.online = account_info_ret.data.online;
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
doc.email = doc.email;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
doc.business_has_person = doc?.business_has_person && doc?.person_info?.person_full_name !== 'Not available';
|
|
108
|
-
doc.icon_pattern = await get_contact_pattern(doc);
|
|
109
|
-
|
|
110
|
-
delete doc.account_type_info;
|
|
111
|
-
delete doc.person_info;
|
|
112
|
-
delete doc.business_info;
|
|
113
|
-
|
|
114
|
-
const contact_chat_conversation_count_ret = await chat_conversation_count();
|
|
115
|
-
const contact_chat_conversation_read_ret = await chat_conversation_read();
|
|
116
|
-
|
|
117
|
-
doc.interactions = contact_chat_conversation_count_ret;
|
|
118
|
-
doc.notifications = contact_chat_conversation_count_ret - contact_chat_conversation_read_ret;
|
|
119
|
-
doc.chats = doc.interactions;
|
|
120
|
-
|
|
121
|
-
doc.card_background = get_contact_background(doc);
|
|
122
|
-
|
|
123
|
-
doc.border = get_contact_border(doc);
|
|
124
|
-
|
|
125
|
-
return doc;
|
|
126
|
-
};
|