@xuda.io/account_module 1.2.2061 → 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 +125 -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
|
|
|
@@ -76,7 +77,7 @@ export const update_account_info = async function (req, job_id, headers) {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
const ret = await
|
|
80
|
+
const ret = await db_ms.get_couch_doc('xuda_accounts', uid);
|
|
80
81
|
var account_obj = ret.data;
|
|
81
82
|
account_obj.ts = Date.now();
|
|
82
83
|
var change = '';
|
|
@@ -169,7 +170,7 @@ export const update_account_info = async function (req, job_id, headers) {
|
|
|
169
170
|
delete account_obj.account_info.job_id;
|
|
170
171
|
delete account_obj.account_info.app_id;
|
|
171
172
|
|
|
172
|
-
const save_ret = await
|
|
173
|
+
const save_ret = await db_ms.save_couch_doc('xuda_accounts', account_obj);
|
|
173
174
|
|
|
174
175
|
if (account_obj.account_info?.profile_picture) {
|
|
175
176
|
if (!account_obj.account_info?.profile_avatar && account_obj.account_info.profile_avatar_stat !== 2) {
|
|
@@ -186,12 +187,12 @@ export const update_account_info = async function (req, job_id, headers) {
|
|
|
186
187
|
export const update_account_preferences = async function (req) {
|
|
187
188
|
const { uid, hide_create_button, default_dashboard, sidebar_style } = req;
|
|
188
189
|
try {
|
|
189
|
-
let account_doc = await
|
|
190
|
+
let account_doc = await db_ms.get_couch_doc_native('xuda_accounts', uid);
|
|
190
191
|
account_doc.ts = Date.now();
|
|
191
192
|
|
|
192
193
|
account_doc.preferences = { hide_create_button, default_dashboard, sidebar_style };
|
|
193
194
|
|
|
194
|
-
const save_ret = await
|
|
195
|
+
const save_ret = await db_ms.save_couch_doc('xuda_accounts', account_doc);
|
|
195
196
|
if (save_ret.code < 0) {
|
|
196
197
|
throw new Error(save_ret.data);
|
|
197
198
|
}
|
|
@@ -202,7 +203,7 @@ export const update_account_preferences = async function (req) {
|
|
|
202
203
|
};
|
|
203
204
|
|
|
204
205
|
export const save_admin_presets = async function (req) {
|
|
205
|
-
const ret = await
|
|
206
|
+
const ret = await db_ms.get_couch_doc('xuda_master', req.app_id);
|
|
206
207
|
if (ret.code < 0) {
|
|
207
208
|
return ret;
|
|
208
209
|
}
|
|
@@ -210,7 +211,7 @@ export const save_admin_presets = async function (req) {
|
|
|
210
211
|
app_obj.deploy_data.admin_presets = req.admin_presets;
|
|
211
212
|
app_obj.deploy_data.preset_id = req.preset_id;
|
|
212
213
|
|
|
213
|
-
const ret3 = await
|
|
214
|
+
const ret3 = await db_ms.save_app_obj(app_obj, null, req.app_id);
|
|
214
215
|
var obj = {};
|
|
215
216
|
if (ret3.code > -1) {
|
|
216
217
|
obj = {
|
|
@@ -232,7 +233,7 @@ export const increment_account_usage = async function (req) {
|
|
|
232
233
|
if (uid) {
|
|
233
234
|
opt.key = uid;
|
|
234
235
|
}
|
|
235
|
-
const accounts_ret = await
|
|
236
|
+
const accounts_ret = await db_ms.get_couch_view_raw('xuda_accounts', 'all_accounts', opt);
|
|
236
237
|
|
|
237
238
|
function bytesToGB(bytes) {
|
|
238
239
|
return bytes / 1073741824; // or bytes / (1024 ** 3)
|
|
@@ -245,7 +246,7 @@ export const increment_account_usage = async function (req) {
|
|
|
245
246
|
try {
|
|
246
247
|
const usage_id = await _common.xuda_get_uuid('usage');
|
|
247
248
|
|
|
248
|
-
const usage_ret = await
|
|
249
|
+
const usage_ret = await db_ms.get_couch_view_raw('xuda_usage', 'open_drive_usage', {
|
|
249
250
|
key: account_data._id,
|
|
250
251
|
});
|
|
251
252
|
|
|
@@ -279,7 +280,7 @@ export const increment_account_usage = async function (req) {
|
|
|
279
280
|
doc.price += price_per_hour;
|
|
280
281
|
|
|
281
282
|
doc.ts = Date.now();
|
|
282
|
-
await
|
|
283
|
+
await db_ms.save_couch_doc('xuda_usage', doc);
|
|
283
284
|
}
|
|
284
285
|
}
|
|
285
286
|
} catch (err) {
|
|
@@ -288,7 +289,7 @@ export const increment_account_usage = async function (req) {
|
|
|
288
289
|
};
|
|
289
290
|
|
|
290
291
|
const run_account_apps = async function (account_data) {
|
|
291
|
-
const apps_ret = await
|
|
292
|
+
const apps_ret = await db_ms.get_couch_view('xuda_master', 'user_apps', {
|
|
292
293
|
startkey: [account_data._id, ''],
|
|
293
294
|
endkey: [account_data._id, 'ZZZZZ'],
|
|
294
295
|
include_docs: true,
|
|
@@ -322,13 +323,13 @@ export const increment_account_usage = async function (req) {
|
|
|
322
323
|
if (size_ret.code > -1) account_data.plugins_drive_size += size_ret.data;
|
|
323
324
|
|
|
324
325
|
// db data
|
|
325
|
-
const couch_info_ret = await
|
|
326
|
+
const couch_info_ret = await db_ms.get_couch_app_info(app.id);
|
|
326
327
|
account_data.project_data_size += couch_info_ret?.data?.sizes?.active || 0;
|
|
327
328
|
}
|
|
328
329
|
|
|
329
330
|
const usage_id = await _common.xuda_get_uuid('usage');
|
|
330
331
|
|
|
331
|
-
const usage_ret = await
|
|
332
|
+
const usage_ret = await db_ms.get_couch_view_raw('xuda_usage', 'open_app_usage', {
|
|
332
333
|
key: [app.id, app.doc?.app_hosting?.app_server_type || app.doc.app_type],
|
|
333
334
|
});
|
|
334
335
|
|
|
@@ -381,7 +382,7 @@ export const increment_account_usage = async function (req) {
|
|
|
381
382
|
} else {
|
|
382
383
|
// backup of project
|
|
383
384
|
|
|
384
|
-
const info_ret = await
|
|
385
|
+
const info_ret = await db_ms.get_couch_app_info(doc.app_id);
|
|
385
386
|
if (info_ret.code > 0) {
|
|
386
387
|
const size = info_ret.data.sizes.active / 1000 / 1000 / 1000; //gb
|
|
387
388
|
price_per_hour = (size * _conf.PRICE_OBJ.price_per_gb_backup) / _conf.PRICE_OBJ.avg_hours_in_month;
|
|
@@ -390,7 +391,7 @@ export const increment_account_usage = async function (req) {
|
|
|
390
391
|
break;
|
|
391
392
|
|
|
392
393
|
case 'user_group': {
|
|
393
|
-
const team_ret = await
|
|
394
|
+
const team_ret = await db_ms.get_couch_view('xuda_team', 'user_group_shares_count', {
|
|
394
395
|
key: app.id,
|
|
395
396
|
reduce: true,
|
|
396
397
|
group_level: 1,
|
|
@@ -420,7 +421,7 @@ export const increment_account_usage = async function (req) {
|
|
|
420
421
|
}
|
|
421
422
|
|
|
422
423
|
doc.ts = Date.now();
|
|
423
|
-
await
|
|
424
|
+
await db_ms.save_couch_doc('xuda_usage', doc);
|
|
424
425
|
}
|
|
425
426
|
}
|
|
426
427
|
} catch (err) {
|
|
@@ -448,7 +449,7 @@ export const increment_account_usage = async function (req) {
|
|
|
448
449
|
await run_account_drive(account_data);
|
|
449
450
|
|
|
450
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;
|
|
451
|
-
await
|
|
452
|
+
await db_ms.save_couch_doc('xuda_accounts', account_data);
|
|
452
453
|
}
|
|
453
454
|
};
|
|
454
455
|
|
|
@@ -456,11 +457,11 @@ export const get_account_data = async function (req) {
|
|
|
456
457
|
var { uid, enforce_usage } = req;
|
|
457
458
|
|
|
458
459
|
try {
|
|
459
|
-
const { data: acc_obj } = await
|
|
460
|
+
const { data: acc_obj } = await db_ms.get_couch_doc('xuda_accounts', uid);
|
|
460
461
|
|
|
461
462
|
// let _design;
|
|
462
463
|
// if (acc_obj.account_project_id) {
|
|
463
|
-
// _design = await
|
|
464
|
+
// _design = await db_ms.get_app_couch_doc_native(acc_obj.account_project_id, '_design/xuda');
|
|
464
465
|
// }
|
|
465
466
|
|
|
466
467
|
var ret = { code: 1 };
|
|
@@ -525,23 +526,23 @@ export const get_account_projects = async function (req) {
|
|
|
525
526
|
opt = {};
|
|
526
527
|
}
|
|
527
528
|
|
|
528
|
-
var ret = await
|
|
529
|
+
var ret = await db_ms.get_couch_view('xuda_master', 'user_projects', opt);
|
|
529
530
|
|
|
530
531
|
return ret;
|
|
531
532
|
};
|
|
532
533
|
|
|
533
534
|
export const get_account_datacenters = async function (req) {
|
|
534
|
-
return await
|
|
535
|
+
return await db_ms.get_couch_view('xuda_master', 'user_datacenters', {
|
|
535
536
|
key: req.uid,
|
|
536
537
|
});
|
|
537
538
|
};
|
|
538
539
|
export const get_account_deployments = async function (req) {
|
|
539
|
-
return await
|
|
540
|
+
return await db_ms.get_couch_view('xuda_master', 'user_deployments', {
|
|
540
541
|
key: req.uid,
|
|
541
542
|
});
|
|
542
543
|
};
|
|
543
544
|
export const get_account_instances = async function (req) {
|
|
544
|
-
return await
|
|
545
|
+
return await db_ms.get_couch_view('xuda_master', 'user_all_instances', {
|
|
545
546
|
key: req.uid,
|
|
546
547
|
});
|
|
547
548
|
};
|
|
@@ -555,11 +556,11 @@ export const get_account_info = async function (req) {
|
|
|
555
556
|
|
|
556
557
|
export const get_active_account_profile_info = async function (uid, profile_id) {
|
|
557
558
|
try {
|
|
558
|
-
const acc_obj = await
|
|
559
|
+
const acc_obj = await db_ms.get_couch_doc_native('xuda_accounts', uid);
|
|
559
560
|
|
|
560
561
|
let active_account_profile_id = profile_id || acc_obj.account_info.active_account_profile_id;
|
|
561
562
|
|
|
562
|
-
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);
|
|
563
564
|
if (account_profile_obj.share_item_id) {
|
|
564
565
|
// set the original profile id if shared
|
|
565
566
|
active_account_profile_id = account_profile_obj.share_item_id;
|
|
@@ -574,7 +575,7 @@ export const get_active_account_profile_info = async function (uid, profile_id)
|
|
|
574
575
|
};
|
|
575
576
|
|
|
576
577
|
export const get_account_name = async function (req) {
|
|
577
|
-
const data = await
|
|
578
|
+
const data = await db_ms.get_couch_doc('xuda_accounts', req.uid_query || req.uid);
|
|
578
579
|
if (data.code < 0) {
|
|
579
580
|
return data;
|
|
580
581
|
}
|
|
@@ -637,7 +638,7 @@ export const account_validate_username = async function (req) {
|
|
|
637
638
|
limit: 1,
|
|
638
639
|
};
|
|
639
640
|
|
|
640
|
-
var ret = await
|
|
641
|
+
var ret = await db_ms.find_couch_query('xuda_accounts', opt);
|
|
641
642
|
|
|
642
643
|
if (ret.docs.length) {
|
|
643
644
|
return { code: -400, data: 'User exist' };
|
|
@@ -647,7 +648,7 @@ export const account_validate_username = async function (req) {
|
|
|
647
648
|
};
|
|
648
649
|
|
|
649
650
|
// export const get_account_activity = async function (req) {
|
|
650
|
-
// return await
|
|
651
|
+
// return await db_ms.get_couch_view(
|
|
651
652
|
// "xuda_activity",
|
|
652
653
|
// "activity_per_account",
|
|
653
654
|
// {
|
|
@@ -662,14 +663,14 @@ export const verify_account = async function (req) {
|
|
|
662
663
|
return { code: -10, data: 'Missing id' };
|
|
663
664
|
}
|
|
664
665
|
|
|
665
|
-
const ret = await
|
|
666
|
+
const ret = await db_ms.get_couch_doc('xuda_accounts', account_id);
|
|
666
667
|
|
|
667
668
|
if (ret.code < 0) {
|
|
668
669
|
return { code: -1, data: 'account not found' };
|
|
669
670
|
}
|
|
670
671
|
var obj = ret.data;
|
|
671
672
|
obj.stat = 3;
|
|
672
|
-
const ret_acc = await
|
|
673
|
+
const ret_acc = await db_ms.save_couch_doc('xuda_accounts', obj);
|
|
673
674
|
if (ret.code < 0) {
|
|
674
675
|
return ret_acc;
|
|
675
676
|
}
|
|
@@ -679,7 +680,7 @@ export const verify_account = async function (req) {
|
|
|
679
680
|
export const validate_user_plan = async function (req) {
|
|
680
681
|
const { account_id, app_obj } = req;
|
|
681
682
|
|
|
682
|
-
const apps_ret = await
|
|
683
|
+
const apps_ret = await db_ms.get_couch_view('xuda_master', 'user_apps_count', {
|
|
683
684
|
startkey: [account_id, ''],
|
|
684
685
|
endkey: [account_id, 'ZZZZZ'],
|
|
685
686
|
reduce: true,
|
|
@@ -695,7 +696,7 @@ export const validate_user_plan = async function (req) {
|
|
|
695
696
|
{},
|
|
696
697
|
);
|
|
697
698
|
|
|
698
|
-
const ret = await
|
|
699
|
+
const ret = await db_ms.get_couch_doc('xuda_accounts', account_id);
|
|
699
700
|
if (ret.code < 0) {
|
|
700
701
|
return ret;
|
|
701
702
|
}
|
|
@@ -716,7 +717,7 @@ export const validate_user_plan = async function (req) {
|
|
|
716
717
|
|
|
717
718
|
// validate number of team members
|
|
718
719
|
|
|
719
|
-
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', {
|
|
720
721
|
key: account_id,
|
|
721
722
|
reduce: true,
|
|
722
723
|
// group_level: 2,
|
|
@@ -815,7 +816,7 @@ export const save_ssh_key = async function (req) {
|
|
|
815
816
|
};
|
|
816
817
|
|
|
817
818
|
if (_id) {
|
|
818
|
-
const ret = await
|
|
819
|
+
const ret = await db_ms.get_couch_doc('xuda_ssh_keys', _id);
|
|
819
820
|
if (ret.code < 0) {
|
|
820
821
|
return ret;
|
|
821
822
|
}
|
|
@@ -828,14 +829,14 @@ export const save_ssh_key = async function (req) {
|
|
|
828
829
|
doc.ssh_key_name = ssh_key_name;
|
|
829
830
|
doc.ssh_key_content = ssh_key_content;
|
|
830
831
|
|
|
831
|
-
const save_ret = await
|
|
832
|
+
const save_ret = await db_ms.save_couch_doc('xuda_ssh_keys', doc);
|
|
832
833
|
|
|
833
834
|
return save_ret;
|
|
834
835
|
};
|
|
835
836
|
export const delete_ssh_key = async function (req) {
|
|
836
837
|
const { ssh_key_id } = req;
|
|
837
838
|
|
|
838
|
-
const ret = await
|
|
839
|
+
const ret = await db_ms.get_couch_doc('xuda_ssh_keys', ssh_key_id);
|
|
839
840
|
if (ret.code < 0) {
|
|
840
841
|
return ret;
|
|
841
842
|
}
|
|
@@ -843,7 +844,7 @@ export const delete_ssh_key = async function (req) {
|
|
|
843
844
|
doc.date_updated_ts = Date.now();
|
|
844
845
|
doc.stat = 4;
|
|
845
846
|
|
|
846
|
-
const save_ret = await
|
|
847
|
+
const save_ret = await db_ms.save_couch_doc('xuda_ssh_keys', doc);
|
|
847
848
|
|
|
848
849
|
return save_ret;
|
|
849
850
|
};
|
|
@@ -859,7 +860,7 @@ export const get_ssh_keys = async function (req) {
|
|
|
859
860
|
opt.selector._id = _id;
|
|
860
861
|
}
|
|
861
862
|
|
|
862
|
-
var ret = await
|
|
863
|
+
var ret = await db_ms.find_couch_query('xuda_ssh_keys', opt);
|
|
863
864
|
return ret;
|
|
864
865
|
};
|
|
865
866
|
|
|
@@ -942,7 +943,7 @@ export const search_users = async function (req) {
|
|
|
942
943
|
}
|
|
943
944
|
|
|
944
945
|
try {
|
|
945
|
-
var ret = await
|
|
946
|
+
var ret = await db_ms.find_couch_query('xuda_accounts', opt);
|
|
946
947
|
|
|
947
948
|
let docs = [];
|
|
948
949
|
for await (let e of ret.docs) {
|
|
@@ -1272,7 +1273,7 @@ export const get_contact_info = async function (uid, contact_doc, _id) {
|
|
|
1272
1273
|
const chat_conversation_count = async function () {
|
|
1273
1274
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
1274
1275
|
|
|
1275
|
-
const counts_ret = await
|
|
1276
|
+
const counts_ret = await db_ms.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
|
|
1276
1277
|
reduce: true,
|
|
1277
1278
|
group_level: 1,
|
|
1278
1279
|
|
|
@@ -1285,7 +1286,7 @@ export const get_contact_info = async function (uid, contact_doc, _id) {
|
|
|
1285
1286
|
const chat_conversation_read = async function () {
|
|
1286
1287
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
1287
1288
|
|
|
1288
|
-
const counts_ret = await
|
|
1289
|
+
const counts_ret = await db_ms.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_read', {
|
|
1289
1290
|
reduce: true,
|
|
1290
1291
|
group_level: 2,
|
|
1291
1292
|
|
|
@@ -1320,7 +1321,7 @@ export const get_contact_info = async function (uid, contact_doc, _id) {
|
|
|
1320
1321
|
|
|
1321
1322
|
if (doc.team_req_id) {
|
|
1322
1323
|
try {
|
|
1323
|
-
const req_doc = await
|
|
1324
|
+
const req_doc = await db_ms.get_couch_doc_native('xuda_team', doc.team_req_id);
|
|
1324
1325
|
doc.connection_stat = req_doc.team_req_stat;
|
|
1325
1326
|
doc.connection_type = req_doc.access_type;
|
|
1326
1327
|
doc.connection_uid = req_doc.team_req_from_uid === uid ? req_doc.team_req_to_uid : req_doc.team_req_from_uid;
|
|
@@ -1331,7 +1332,7 @@ export const get_contact_info = async function (uid, contact_doc, _id) {
|
|
|
1331
1332
|
if (doc.connection_type === 'account_profile') {
|
|
1332
1333
|
try {
|
|
1333
1334
|
const app_id = await get_account_default_project_id(uid);
|
|
1334
|
-
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);
|
|
1335
1336
|
doc.account_profile = account_profile_doc;
|
|
1336
1337
|
} catch (error) {}
|
|
1337
1338
|
}
|
|
@@ -1395,7 +1396,7 @@ export const get_pending_contact_out = async function (uid, _id) {
|
|
|
1395
1396
|
if (_id) {
|
|
1396
1397
|
to_opt.selector._id = _id;
|
|
1397
1398
|
}
|
|
1398
|
-
const requests_to_res = await
|
|
1399
|
+
const requests_to_res = await db_ms.find_couch_query('xuda_team', to_opt);
|
|
1399
1400
|
|
|
1400
1401
|
for await (let e of requests_to_res.docs) {
|
|
1401
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 };
|
|
@@ -1426,7 +1427,7 @@ export const get_pending_contact_in = async function (uid, _id) {
|
|
|
1426
1427
|
to_opt.selector._id = _id;
|
|
1427
1428
|
}
|
|
1428
1429
|
|
|
1429
|
-
const requests_from_res = await
|
|
1430
|
+
const requests_from_res = await db_ms.find_couch_query('xuda_team', from_opt);
|
|
1430
1431
|
|
|
1431
1432
|
for await (let e of requests_from_res.docs) {
|
|
1432
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 };
|
|
@@ -1455,7 +1456,7 @@ export const get_pending_share_contact_in = async function (uid, _id) {
|
|
|
1455
1456
|
to_opt.selector._id = _id;
|
|
1456
1457
|
}
|
|
1457
1458
|
|
|
1458
|
-
const requests_from_res = await
|
|
1459
|
+
const requests_from_res = await db_ms.find_couch_query('xuda_team', from_opt);
|
|
1459
1460
|
|
|
1460
1461
|
for await (let e of requests_from_res.docs) {
|
|
1461
1462
|
let doc = await get_contact(uid, e.share_item_id);
|
|
@@ -1523,7 +1524,7 @@ export const update_contact = async function (req) {
|
|
|
1523
1524
|
}
|
|
1524
1525
|
|
|
1525
1526
|
if (contact_uid) {
|
|
1526
|
-
const ret = await
|
|
1527
|
+
const ret = await db_ms.get_couch_doc('xuda_accounts', contact_uid);
|
|
1527
1528
|
const account_obj = ret.data;
|
|
1528
1529
|
doc.profile_picture = account_obj.account_info.profile_picture;
|
|
1529
1530
|
doc.profile_avatar = account_obj.account_info.profile_avatar;
|
|
@@ -1535,7 +1536,7 @@ export const update_contact = async function (req) {
|
|
|
1535
1536
|
};
|
|
1536
1537
|
|
|
1537
1538
|
export const get_account_rt_info = async function (uid) {
|
|
1538
|
-
const doc_ret = await
|
|
1539
|
+
const doc_ret = await db_ms.get_couch_doc('xuda_accounts', uid);
|
|
1539
1540
|
if (doc_ret.code < 0) {
|
|
1540
1541
|
console.error('get_account_rt_info', doc_ret);
|
|
1541
1542
|
return {};
|
|
@@ -1686,7 +1687,7 @@ export const create_account_oauth_link = async function (req, job_id) {
|
|
|
1686
1687
|
};
|
|
1687
1688
|
|
|
1688
1689
|
export const get_default_project_account_doc = async function (uid) {
|
|
1689
|
-
const ret = await
|
|
1690
|
+
const ret = await db_ms.get_couch_doc('xuda_accounts', uid);
|
|
1690
1691
|
return ret.data;
|
|
1691
1692
|
};
|
|
1692
1693
|
export const get_account_default_project_id = async function (uid) {
|
|
@@ -1742,7 +1743,7 @@ export const onboarding_completed = async function (req, job_id, headers) {
|
|
|
1742
1743
|
try {
|
|
1743
1744
|
await update_account_info(req, job_id, headers);
|
|
1744
1745
|
|
|
1745
|
-
let account_doc = await
|
|
1746
|
+
let account_doc = await db_ms.get_couch_doc_native('xuda_accounts', uid);
|
|
1746
1747
|
|
|
1747
1748
|
if (!account_doc.account_info?.profile_picture) {
|
|
1748
1749
|
throw new Error(`missing profile_picture`);
|
|
@@ -1756,7 +1757,7 @@ export const onboarding_completed = async function (req, job_id, headers) {
|
|
|
1756
1757
|
|
|
1757
1758
|
account_doc.boarded_info = { headers, date_ts: Date.now() };
|
|
1758
1759
|
account_doc.isBoarded = true;
|
|
1759
|
-
const save_ret = await
|
|
1760
|
+
const save_ret = await db_ms.save_couch_doc('xuda_accounts', account_doc);
|
|
1760
1761
|
|
|
1761
1762
|
return save_ret;
|
|
1762
1763
|
} catch (err) {
|
|
@@ -1779,13 +1780,13 @@ export const get_account_ai_usage = async function (req, job_id, headers) {
|
|
|
1779
1780
|
const { uid, year, month, day, usage_scope = 'account' } = req;
|
|
1780
1781
|
try {
|
|
1781
1782
|
// const app_id = await get_account_default_project_id(uid);
|
|
1782
|
-
// const { data: acc_obj } = await
|
|
1783
|
+
// const { data: acc_obj } = await db_ms.get_couch_doc('xuda_accounts', uid);
|
|
1783
1784
|
|
|
1784
1785
|
const d = new Date();
|
|
1785
1786
|
const curr_month = Number(String(d.getMonth() + 1).padStart(2, '0')); // months are 0-based
|
|
1786
1787
|
const curr_year = d.getFullYear();
|
|
1787
1788
|
|
|
1788
|
-
const ai_usage = await
|
|
1789
|
+
const ai_usage = await db_ms.get_couch_view('xuda_usage', 'ai_usage', {
|
|
1789
1790
|
startkey: [uid, year || curr_year, month || curr_month, day || 0],
|
|
1790
1791
|
endkey: [uid, year || curr_year, month || curr_month, day || 99],
|
|
1791
1792
|
reduce: true,
|
|
@@ -1824,7 +1825,7 @@ export const get_account_ai_usage = async function (req, job_id, headers) {
|
|
|
1824
1825
|
// let contact_connection = 0;
|
|
1825
1826
|
// let total_credits = membership_plan + ai_workspace_plan + contact_connection;
|
|
1826
1827
|
|
|
1827
|
-
const ai_credits = await
|
|
1828
|
+
const ai_credits = await db_ms.get_couch_view('xuda_billing', 'ai_credits', {
|
|
1828
1829
|
startkey: [uid, ''],
|
|
1829
1830
|
endkey: [uid, 'zzz'],
|
|
1830
1831
|
reduce: true,
|
|
@@ -1860,7 +1861,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
|
|
|
1860
1861
|
try {
|
|
1861
1862
|
let profile_picture;
|
|
1862
1863
|
|
|
1863
|
-
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);
|
|
1864
1865
|
let account_info = account_obj.account_info;
|
|
1865
1866
|
|
|
1866
1867
|
if (account_code < 0) {
|
|
@@ -1873,7 +1874,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
|
|
|
1873
1874
|
if (!account_info.profile_picture) {
|
|
1874
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);
|
|
1875
1876
|
|
|
1876
|
-
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);
|
|
1877
1878
|
account_obj = account_obj2;
|
|
1878
1879
|
account_info = account_obj.account_info;
|
|
1879
1880
|
|
|
@@ -1882,7 +1883,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
|
|
|
1882
1883
|
|
|
1883
1884
|
account_info.profile_picture = account_info.profile_picture_obj.file_url;
|
|
1884
1885
|
account_info.profile_picture_source = file_ret.profile_picture_source;
|
|
1885
|
-
const account_save_ret = await
|
|
1886
|
+
const account_save_ret = await db_ms.save_couch_doc('xuda_accounts', account_obj);
|
|
1886
1887
|
profile_picture = account_info.profile_picture;
|
|
1887
1888
|
}
|
|
1888
1889
|
|
|
@@ -1927,7 +1928,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
|
|
|
1927
1928
|
if (file_ret.code < 0) {
|
|
1928
1929
|
throw new Error(file_ret.data);
|
|
1929
1930
|
}
|
|
1930
|
-
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);
|
|
1931
1932
|
account_obj = account_obj3;
|
|
1932
1933
|
account_info = account_obj.account_info;
|
|
1933
1934
|
|
|
@@ -1935,7 +1936,7 @@ const set_account_profile_picture = async function (uid, account_uid, metadata,
|
|
|
1935
1936
|
account_info.profile_avatar_obj = file_ret.data;
|
|
1936
1937
|
account_info.profile_avatar = account_info.profile_avatar_obj.file_url;
|
|
1937
1938
|
|
|
1938
|
-
const account_save_ret = await
|
|
1939
|
+
const account_save_ret = await db_ms.save_couch_doc('xuda_accounts', account_obj);
|
|
1939
1940
|
await update_account_profile_picture_status(account_uid, 3);
|
|
1940
1941
|
}
|
|
1941
1942
|
} catch (err) {
|
|
@@ -1956,7 +1957,7 @@ setTimeout(async () => {
|
|
|
1956
1957
|
// ret = await create_account_profile({ uid });
|
|
1957
1958
|
// ret = await get_account_profiles({ uid });
|
|
1958
1959
|
|
|
1959
|
-
// let _design = await
|
|
1960
|
+
// let _design = await db_ms.get_app_couch_doc_native(app_id, '_design/xuda');
|
|
1960
1961
|
// ret = _design.views.ai_chat_usage;
|
|
1961
1962
|
// console.log(_design.views.ai_chat_usage);
|
|
1962
1963
|
// ret = await set_contact_profile_picture(uid, 'cnt_2d21d55f8f0cdaf65a7a69f69617f532', {}, null, {});
|
|
@@ -2025,7 +2026,7 @@ export const add_contact = async function (req, job_id, headers) {
|
|
|
2025
2026
|
let cached_contact;
|
|
2026
2027
|
let business_has_person;
|
|
2027
2028
|
if (contact_uid) {
|
|
2028
|
-
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);
|
|
2029
2030
|
// account_info = account_obj.account_info;
|
|
2030
2031
|
// account_info_ret = await get_account_name({ uid_query: contact_uid });
|
|
2031
2032
|
if (account_code < 0) {
|
|
@@ -2125,7 +2126,7 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2125
2126
|
try {
|
|
2126
2127
|
// let profile_picture;
|
|
2127
2128
|
|
|
2128
|
-
const contact_ret = await
|
|
2129
|
+
const contact_ret = await db_ms.get_app_couch_doc(account_profile_info.app_id, contact_id);
|
|
2129
2130
|
|
|
2130
2131
|
if (contact_ret.code < 0) {
|
|
2131
2132
|
throw new Error(`contact ${contact_id} not found`);
|
|
@@ -2165,13 +2166,13 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2165
2166
|
}
|
|
2166
2167
|
}
|
|
2167
2168
|
if (file_ret?.data?.file_url) {
|
|
2168
|
-
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);
|
|
2169
2170
|
contact_obj = contact_obj2;
|
|
2170
2171
|
contact_obj.profile_picture_obj = file_ret.data;
|
|
2171
2172
|
contact_obj.profile_picture = contact_obj.profile_picture_obj.file_url;
|
|
2172
2173
|
contact_obj.profile_picture_source = file_ret.profile_picture_source;
|
|
2173
2174
|
|
|
2174
|
-
const contact_save_ret = await
|
|
2175
|
+
const contact_save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, contact_obj);
|
|
2175
2176
|
// profile_picture = contact_obj.profile_picture;
|
|
2176
2177
|
}
|
|
2177
2178
|
}
|
|
@@ -2221,7 +2222,7 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2221
2222
|
if (file_ret.data === 'Input file contains unsupported image format') {
|
|
2222
2223
|
contact_obj.profile_picture = null;
|
|
2223
2224
|
contact_obj.profile_picture_obj = null;
|
|
2224
|
-
const contact_save_ret = await
|
|
2225
|
+
const contact_save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, contact_obj);
|
|
2225
2226
|
}
|
|
2226
2227
|
throw new Error(file_ret.data);
|
|
2227
2228
|
}
|
|
@@ -2250,12 +2251,12 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2250
2251
|
// save_xuda_cache(uid, 'profile_avatar', contact_obj.email, file_ret.data, { account_type: contact_obj.account_type, type: 'contact' });
|
|
2251
2252
|
}
|
|
2252
2253
|
|
|
2253
|
-
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);
|
|
2254
2255
|
contact_obj = contact_obj3;
|
|
2255
2256
|
contact_obj.profile_avatar_obj = file_ret.data;
|
|
2256
2257
|
contact_obj.profile_avatar = contact_obj?.profile_avatar_obj?.file_url;
|
|
2257
2258
|
contact_obj.avatar_source = file_ret?.data?.avatar_source;
|
|
2258
|
-
const contact_save_ret = await
|
|
2259
|
+
const contact_save_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, contact_obj);
|
|
2259
2260
|
}
|
|
2260
2261
|
await update_contact_profile_picture_status(uid, contact_id, 3);
|
|
2261
2262
|
} catch (err) {
|
|
@@ -2266,11 +2267,11 @@ const set_contact_profile_picture = async function (uid, contact_id, metadata, j
|
|
|
2266
2267
|
|
|
2267
2268
|
const update_account_profile_picture_status = async function (uid, stat, error) {
|
|
2268
2269
|
try {
|
|
2269
|
-
let doc = await
|
|
2270
|
+
let doc = await db_ms.get_couch_doc_native('xuda_accounts', uid);
|
|
2270
2271
|
doc.account_info.profile_avatar_stat = stat;
|
|
2271
2272
|
doc.account_info.profile_avatar_error = error;
|
|
2272
2273
|
doc.account_info.profile_avatar_stat_ts = Date.now();
|
|
2273
|
-
const save_ret = await
|
|
2274
|
+
const save_ret = await db_ms.save_couch_doc_native('xuda_accounts', doc);
|
|
2274
2275
|
} catch (err) {
|
|
2275
2276
|
console.error(err);
|
|
2276
2277
|
}
|
|
@@ -2279,12 +2280,12 @@ const update_account_profile_picture_status = async function (uid, stat, error)
|
|
|
2279
2280
|
const update_contact_profile_picture_status = async function (uid, contact_id, stat, error) {
|
|
2280
2281
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
2281
2282
|
try {
|
|
2282
|
-
let doc = await
|
|
2283
|
+
let doc = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, contact_id);
|
|
2283
2284
|
doc.profile_avatar_stat = stat;
|
|
2284
2285
|
doc.profile_avatar_error = error;
|
|
2285
2286
|
doc.profile_avatar_stat_ts = Date.now();
|
|
2286
2287
|
|
|
2287
|
-
const save_ret = await
|
|
2288
|
+
const save_ret = await db_ms.save_app_couch_doc_native(account_profile_info.app_id, doc);
|
|
2288
2289
|
} catch (err) {
|
|
2289
2290
|
console.error(err);
|
|
2290
2291
|
}
|
|
@@ -2535,15 +2536,15 @@ export const unfriend_contact = async function (req) {
|
|
|
2535
2536
|
if (!contact_doc.team_req_id) {
|
|
2536
2537
|
throw new Error('no friend relationship found');
|
|
2537
2538
|
}
|
|
2538
|
-
let req_doc = await
|
|
2539
|
+
let req_doc = await db_ms.get_couch_doc_native('xuda_team', contact_doc.team_req_id);
|
|
2539
2540
|
req_doc.team_req_stat = 4;
|
|
2540
2541
|
req_doc.team_req_stat_desc = 'unfriend by the user';
|
|
2541
|
-
await
|
|
2542
|
+
await db_ms.get_couch_doc_native('xuda_team', contact_doc.team_req_id);
|
|
2542
2543
|
|
|
2543
2544
|
contact_doc.team_req_id = null;
|
|
2544
2545
|
const contact_save_ret = await save_contact(uid, contact_doc);
|
|
2545
2546
|
|
|
2546
|
-
const req_save_ret = await
|
|
2547
|
+
const req_save_ret = await db_ms.save_couch_doc('xuda_team', req_doc);
|
|
2547
2548
|
|
|
2548
2549
|
return req_save_ret;
|
|
2549
2550
|
} catch (err) {
|
|
@@ -2627,7 +2628,7 @@ export const not_spam_contact = async function (req, job_id, headers) {
|
|
|
2627
2628
|
var contact_doc = await get_contact(uid, contact_id);
|
|
2628
2629
|
|
|
2629
2630
|
if (contact_doc.is_spam) {
|
|
2630
|
-
await
|
|
2631
|
+
await db_ms.save_couch_doc_native('xuda_accounts', {
|
|
2631
2632
|
_id: await _common.xuda_get_uuid('spam_whitelist'),
|
|
2632
2633
|
uid,
|
|
2633
2634
|
docType: 'spam_whitelist',
|
|
@@ -2655,7 +2656,7 @@ export const not_spam_contact = async function (req, job_id, headers) {
|
|
|
2655
2656
|
await delete_xuda_cache(contact_doc);
|
|
2656
2657
|
set_contact_profile_picture(uid, contact_doc._id, {}, job_id, headers, account_profile_info, false);
|
|
2657
2658
|
|
|
2658
|
-
const emails = await
|
|
2659
|
+
const emails = await db_ms.find_app_couch_query(account_profile_info.app_id, {
|
|
2659
2660
|
selector: {
|
|
2660
2661
|
docType: 'email',
|
|
2661
2662
|
contact_id,
|
|
@@ -2667,14 +2668,14 @@ export const not_spam_contact = async function (req, job_id, headers) {
|
|
|
2667
2668
|
for await (let email of emails.docs) {
|
|
2668
2669
|
const app_id = await get_account_default_project_id(uid);
|
|
2669
2670
|
if (email.conversation_id) {
|
|
2670
|
-
|
|
2671
|
+
db_ms.delete_app_couch_doc(app_id, email.conversation_id);
|
|
2671
2672
|
email.conversation_id = null;
|
|
2672
2673
|
}
|
|
2673
2674
|
if (email.conversation_item_id) {
|
|
2674
|
-
|
|
2675
|
+
db_ms.delete_app_couch_doc(app_id, email.conversation_item_id);
|
|
2675
2676
|
email.conversation_item_id = null;
|
|
2676
2677
|
}
|
|
2677
|
-
const save_ret = await
|
|
2678
|
+
const save_ret = await db_ms.save_app_couch_doc_native(app_id, email);
|
|
2678
2679
|
|
|
2679
2680
|
// save attachments
|
|
2680
2681
|
// summarized_body
|
|
@@ -2742,7 +2743,7 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
2742
2743
|
const contact_save_ret = await save_contact(uid, contact_doc);
|
|
2743
2744
|
await delete_xuda_cache(contact_doc);
|
|
2744
2745
|
|
|
2745
|
-
const conversation_items = await
|
|
2746
|
+
const conversation_items = await db_ms.find_app_couch_query(account_profile_info.app_id, {
|
|
2746
2747
|
selector: {
|
|
2747
2748
|
docType: 'chat_conversation_item',
|
|
2748
2749
|
reference_id: contact_id,
|
|
@@ -2754,7 +2755,7 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
2754
2755
|
for await (let conversation_item of conversation_items.docs) {
|
|
2755
2756
|
try {
|
|
2756
2757
|
const account_profile_info = await get_active_account_profile_info(conversation_item.uid);
|
|
2757
|
-
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);
|
|
2758
2759
|
|
|
2759
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);
|
|
2760
2761
|
let items;
|
|
@@ -2764,7 +2765,7 @@ export const set_deep_research_contact = async function (req, job_id, headers) {
|
|
|
2764
2765
|
|
|
2765
2766
|
conversation_item.text = transcript?.data || transcript || '';
|
|
2766
2767
|
conversation_item.process_stat = 'full';
|
|
2767
|
-
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);
|
|
2768
2769
|
}
|
|
2769
2770
|
} catch (err) {
|
|
2770
2771
|
throw err;
|
|
@@ -2808,10 +2809,10 @@ export const get_pending_share_profile_in = async function (uid, _id) {
|
|
|
2808
2809
|
to_opt.selector._id = _id;
|
|
2809
2810
|
}
|
|
2810
2811
|
|
|
2811
|
-
const requests_from_res = await
|
|
2812
|
+
const requests_from_res = await db_ms.find_couch_query('xuda_team', from_opt);
|
|
2812
2813
|
|
|
2813
2814
|
for await (let e of requests_from_res.docs) {
|
|
2814
|
-
let doc = await
|
|
2815
|
+
let doc = await db_ms.get_couch_doc_native('xuda_accounts', e.share_item_id);
|
|
2815
2816
|
|
|
2816
2817
|
doc.shared_from_uid = e.team_req_from_uid;
|
|
2817
2818
|
doc.pending = true;
|
|
@@ -2827,7 +2828,7 @@ export const get_account_profile_info = async function (uid, contact_profile_doc
|
|
|
2827
2828
|
const app_id = await get_account_default_project_id(uid);
|
|
2828
2829
|
let doc = contact_profile_doc;
|
|
2829
2830
|
if (_id) {
|
|
2830
|
-
doc = await
|
|
2831
|
+
doc = await db_ms.get_couch_doc_native('xuda_accounts', _id);
|
|
2831
2832
|
}
|
|
2832
2833
|
doc.notifications = 0;
|
|
2833
2834
|
|
|
@@ -2852,7 +2853,7 @@ export const get_account_profile_info = async function (uid, contact_profile_doc
|
|
|
2852
2853
|
let ret = `default-pattern.png`;
|
|
2853
2854
|
|
|
2854
2855
|
if (doc.shared_from_uid) {
|
|
2855
|
-
// const account_profile_doc = await
|
|
2856
|
+
// const account_profile_doc = await db_ms.get_couch_doc_native('xuda_accounts', doc.share_item_id);
|
|
2856
2857
|
const shared_from_uid_ret = await get_account_name({ uid_query: doc.shared_from_uid });
|
|
2857
2858
|
ret = shared_from_uid_ret.data.profile_avatar;
|
|
2858
2859
|
} else if (doc.is_spam) {
|
|
@@ -2885,7 +2886,7 @@ export const get_account_profile_info = async function (uid, contact_profile_doc
|
|
|
2885
2886
|
const get_online = async () => {
|
|
2886
2887
|
let online = false;
|
|
2887
2888
|
let selector = { docType: 'team_request', team_req_stat: 3, share_item_id: doc._id, access_type: 'account_profile', team_req_from_uid: uid };
|
|
2888
|
-
let ret = await
|
|
2889
|
+
let ret = await db_ms.find_couch_query('xuda_team', { selector });
|
|
2889
2890
|
for (const req_obj of ret.docs) {
|
|
2890
2891
|
const account_info_ret = await get_account_name({ uid_query: req_obj.team_req_to_uid });
|
|
2891
2892
|
online = account_info_ret.data.online;
|
|
@@ -2911,7 +2912,7 @@ export const get_account_profile_info = async function (uid, contact_profile_doc
|
|
|
2911
2912
|
const get_members = async () => {
|
|
2912
2913
|
let members = [];
|
|
2913
2914
|
let selector = { docType: 'team_request', team_req_stat: 3, share_item_id: doc._id, access_type: 'account_profile', team_req_from_uid: uid };
|
|
2914
|
-
let ret = await
|
|
2915
|
+
let ret = await db_ms.find_couch_query('xuda_team', { selector });
|
|
2915
2916
|
for (const req_obj of ret.docs) {
|
|
2916
2917
|
const account_info_ret = await get_account_name({ uid_query: req_obj.team_req_to_uid });
|
|
2917
2918
|
const info = await await get_contact_info(uid, account_info_ret.data);
|
|
@@ -2924,7 +2925,7 @@ export const get_account_profile_info = async function (uid, contact_profile_doc
|
|
|
2924
2925
|
// const account_profile_info = await get_active_account_profile_info(uid);
|
|
2925
2926
|
|
|
2926
2927
|
let selector = { docType: 'account_profile', stat: 3 };
|
|
2927
|
-
let ret = await
|
|
2928
|
+
let ret = await db_ms.find_app_couch_query(app_id, { selector });
|
|
2928
2929
|
|
|
2929
2930
|
return ret.docs;
|
|
2930
2931
|
};
|
|
@@ -2966,7 +2967,7 @@ export const get_account_profiles = async function (req) {
|
|
|
2966
2967
|
const { _id, uid, profile_name, limit, skip, bookmark, search, filter_type = 'all', profile_id, active_tab } = req;
|
|
2967
2968
|
const app_id = await get_account_default_project_id(uid);
|
|
2968
2969
|
if (_id) {
|
|
2969
|
-
let data = await
|
|
2970
|
+
let data = await db_ms.get_app_couch_doc(app_id, _id);
|
|
2970
2971
|
return data;
|
|
2971
2972
|
}
|
|
2972
2973
|
|
|
@@ -3034,7 +3035,7 @@ export const get_account_profiles = async function (req) {
|
|
|
3034
3035
|
let profiles = { docs: [], total_docs: 0 };
|
|
3035
3036
|
|
|
3036
3037
|
if (filter_type !== 'pending') {
|
|
3037
|
-
profiles = await
|
|
3038
|
+
profiles = await db_ms.find_app_couch_query(app_id, opt);
|
|
3038
3039
|
if (!limit || profile_id) {
|
|
3039
3040
|
profiles.total_docs = profiles.docs.length;
|
|
3040
3041
|
} else {
|
|
@@ -3043,7 +3044,7 @@ export const get_account_profiles = async function (req) {
|
|
|
3043
3044
|
opt.limit = 9999;
|
|
3044
3045
|
opt.fields = ['_id'];
|
|
3045
3046
|
|
|
3046
|
-
const counter = await
|
|
3047
|
+
const counter = await db_ms.find_app_couch_query(app_id, opt);
|
|
3047
3048
|
profiles.total_docs = counter.docs.length;
|
|
3048
3049
|
}
|
|
3049
3050
|
}
|
|
@@ -3095,7 +3096,7 @@ export const archive_account_profile = async function (req) {
|
|
|
3095
3096
|
|
|
3096
3097
|
await team_ms.validate_share_exist(uid, 'account_profile', profile_id);
|
|
3097
3098
|
|
|
3098
|
-
var account_profile_doc = await
|
|
3099
|
+
var account_profile_doc = await db_ms.get_app_couch_doc_native(app_id, profile_id);
|
|
3099
3100
|
|
|
3100
3101
|
if (account_profile_doc.main) {
|
|
3101
3102
|
throw new Error('reserve');
|
|
@@ -3105,7 +3106,7 @@ export const archive_account_profile = async function (req) {
|
|
|
3105
3106
|
account_profile_doc.stat_ts = Date.now();
|
|
3106
3107
|
account_profile_doc.stat_reason = 'archived by the user';
|
|
3107
3108
|
|
|
3108
|
-
const account_profile_save_ret = await
|
|
3109
|
+
const account_profile_save_ret = await db_ms.save_app_couch_doc(app_id, account_profile_doc);
|
|
3109
3110
|
|
|
3110
3111
|
return account_profile_save_ret;
|
|
3111
3112
|
} catch (err) {
|
|
@@ -3120,7 +3121,7 @@ export const delete_account_profile = async function (req, job_id, headers) {
|
|
|
3120
3121
|
const { profile_id, uid } = req;
|
|
3121
3122
|
try {
|
|
3122
3123
|
const app_id = await get_account_default_project_id(uid);
|
|
3123
|
-
var account_profile_doc = await
|
|
3124
|
+
var account_profile_doc = await db_ms.get_app_couch_doc_native(app_id, profile_id);
|
|
3124
3125
|
if (account_profile_doc.stat !== 5) {
|
|
3125
3126
|
throw new Error('A document can only be deleted after it has been archived');
|
|
3126
3127
|
}
|
|
@@ -3128,7 +3129,7 @@ export const delete_account_profile = async function (req, job_id, headers) {
|
|
|
3128
3129
|
account_profile_doc.stat_ts = Date.now();
|
|
3129
3130
|
account_profile_doc.stat_reason = 'deleted by the user';
|
|
3130
3131
|
|
|
3131
|
-
const account_profile_save_ret = await
|
|
3132
|
+
const account_profile_save_ret = await db_ms.save_app_couch_doc(app_id, account_profile_doc);
|
|
3132
3133
|
|
|
3133
3134
|
ai_ms.delete_depended_chats(uid, profile_id);
|
|
3134
3135
|
return account_profile_save_ret;
|
|
@@ -3145,7 +3146,7 @@ export const unarchive_account_profile = async function (req) {
|
|
|
3145
3146
|
try {
|
|
3146
3147
|
const app_id = await get_account_default_project_id(uid);
|
|
3147
3148
|
|
|
3148
|
-
var account_profile_doc = await
|
|
3149
|
+
var account_profile_doc = await db_ms.get_app_couch_doc_native(app_id, profile_id);
|
|
3149
3150
|
|
|
3150
3151
|
if (account_profile_doc.stat !== 5) {
|
|
3151
3152
|
throw new Error('account profile is not archived');
|
|
@@ -3155,7 +3156,7 @@ export const unarchive_account_profile = async function (req) {
|
|
|
3155
3156
|
account_profile_doc.stat_ts = Date.now();
|
|
3156
3157
|
account_profile_doc.stat_reason = 'archived by the user';
|
|
3157
3158
|
|
|
3158
|
-
const account_profile_save_ret = await
|
|
3159
|
+
const account_profile_save_ret = await db_ms.save_app_couch_doc(app_id, account_profile_doc);
|
|
3159
3160
|
|
|
3160
3161
|
return account_profile_save_ret;
|
|
3161
3162
|
}
|
|
@@ -3171,7 +3172,7 @@ export const create_account_profile = async function (req, job_id, headers) {
|
|
|
3171
3172
|
const { uid, profile_name, profile_signature, email_account_id, profile_picture, profile_avatar, profile_picture_obj, profile_avatar_obj, main, account_type } = req;
|
|
3172
3173
|
try {
|
|
3173
3174
|
const app_id = await get_account_default_project_id(uid);
|
|
3174
|
-
// const { data: acc_obj } = await
|
|
3175
|
+
// const { data: acc_obj } = await db_ms.get_couch_doc('xuda_accounts', uid);
|
|
3175
3176
|
|
|
3176
3177
|
const d = Date.now();
|
|
3177
3178
|
const doc = {
|
|
@@ -3191,7 +3192,7 @@ export const create_account_profile = async function (req, job_id, headers) {
|
|
|
3191
3192
|
profile_avatar_obj,
|
|
3192
3193
|
main,
|
|
3193
3194
|
};
|
|
3194
|
-
const save_ret = await
|
|
3195
|
+
const save_ret = await db_ms.save_app_couch_doc(app_id, doc);
|
|
3195
3196
|
// acc_obj.active_profile_id = save_ret.data.id;
|
|
3196
3197
|
|
|
3197
3198
|
// return { code: 55, data: save_ret };
|
|
@@ -3206,7 +3207,7 @@ export const update_account_profile = async function (req, job_id, headers) {
|
|
|
3206
3207
|
const app_id = await get_account_default_project_id(uid);
|
|
3207
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'];
|
|
3208
3209
|
try {
|
|
3209
|
-
let { data: account_profile_doc } = await
|
|
3210
|
+
let { data: account_profile_doc } = await db_ms.get_app_couch_doc(app_id, _id);
|
|
3210
3211
|
|
|
3211
3212
|
if (account_profile_doc.docType !== 'account_profile') {
|
|
3212
3213
|
throw new Error('not account profile doc');
|
|
@@ -3230,7 +3231,7 @@ export const update_account_profile = async function (req, job_id, headers) {
|
|
|
3230
3231
|
|
|
3231
3232
|
account_profile_doc.ts = Date.now();
|
|
3232
3233
|
|
|
3233
|
-
const save_ret = await
|
|
3234
|
+
const save_ret = await db_ms.save_app_couch_doc(app_id, account_profile_doc);
|
|
3234
3235
|
|
|
3235
3236
|
return { code: 56, data: save_ret };
|
|
3236
3237
|
} catch (err) {
|
|
@@ -3247,7 +3248,7 @@ export const update_entity_account_profiles = async function (req, job_id, heade
|
|
|
3247
3248
|
throw new Error('account_profiles cannot be empty');
|
|
3248
3249
|
}
|
|
3249
3250
|
|
|
3250
|
-
let doc = await
|
|
3251
|
+
let doc = await db_ms.get_app_couch_doc_native(app_id, _id);
|
|
3251
3252
|
|
|
3252
3253
|
switch (doc.docType) {
|
|
3253
3254
|
case 'chat_conversation':
|
|
@@ -3267,7 +3268,7 @@ export const update_entity_account_profiles = async function (req, job_id, heade
|
|
|
3267
3268
|
break;
|
|
3268
3269
|
}
|
|
3269
3270
|
|
|
3270
|
-
const save_ret = await
|
|
3271
|
+
const save_ret = await db_ms.save_app_couch_doc(app_id, doc);
|
|
3271
3272
|
|
|
3272
3273
|
return { code: 57, data: save_ret };
|
|
3273
3274
|
} catch (err) {
|
|
@@ -3277,24 +3278,24 @@ export const update_entity_account_profiles = async function (req, job_id, heade
|
|
|
3277
3278
|
|
|
3278
3279
|
export const get_contact = async function (uid, contact_id) {
|
|
3279
3280
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
3280
|
-
const contact_ret = await
|
|
3281
|
+
const contact_ret = await db_ms.get_app_couch_doc_native(account_profile_info.app_id, contact_id);
|
|
3281
3282
|
return contact_ret;
|
|
3282
3283
|
};
|
|
3283
3284
|
|
|
3284
3285
|
export const save_contact = async function (uid, contact_doc) {
|
|
3285
3286
|
const account_profile_info = await get_active_account_profile_info(uid);
|
|
3286
|
-
const contact_ret = await
|
|
3287
|
+
const contact_ret = await db_ms.save_app_couch_doc(account_profile_info.app_id, contact_doc);
|
|
3287
3288
|
return contact_ret;
|
|
3288
3289
|
};
|
|
3289
3290
|
|
|
3290
3291
|
export const find_contact_query = async function (uid, opt) {
|
|
3291
3292
|
const app_id = await get_account_default_project_id(uid);
|
|
3292
|
-
const ret = await
|
|
3293
|
+
const ret = await db_ms.find_app_couch_query(app_id, opt);
|
|
3293
3294
|
return ret;
|
|
3294
3295
|
};
|
|
3295
3296
|
|
|
3296
3297
|
export const delete_xuda_cache = async function (contact_obj) {
|
|
3297
|
-
const ret = await
|
|
3298
|
+
const ret = await db_ms.find_couch_query('xuda_cache', {
|
|
3298
3299
|
selector: {
|
|
3299
3300
|
$or: [
|
|
3300
3301
|
{
|
|
@@ -3309,7 +3310,7 @@ export const delete_xuda_cache = async function (contact_obj) {
|
|
|
3309
3310
|
|
|
3310
3311
|
for (let doc of ret.docs) {
|
|
3311
3312
|
doc._deleted = true;
|
|
3312
|
-
const save_ret = await
|
|
3313
|
+
const save_ret = await db_ms.save_couch_doc('xuda_cache', doc);
|
|
3313
3314
|
}
|
|
3314
3315
|
};
|
|
3315
3316
|
|
|
@@ -3329,12 +3330,12 @@ export const save_xuda_cache = async function (uid, docType, key, file, metadata
|
|
|
3329
3330
|
metadata,
|
|
3330
3331
|
hits: 0,
|
|
3331
3332
|
};
|
|
3332
|
-
const save_ret = await
|
|
3333
|
+
const save_ret = await db_ms.save_couch_doc('xuda_cache', doc);
|
|
3333
3334
|
return save_ret;
|
|
3334
3335
|
};
|
|
3335
3336
|
|
|
3336
3337
|
export const get_xuda_cache = async function (uid, docType, key, return_property) {
|
|
3337
|
-
let ret = await
|
|
3338
|
+
let ret = await db_ms.find_couch_query('xuda_cache', {
|
|
3338
3339
|
selector: { docType, key: key.toLowerCase().trim() },
|
|
3339
3340
|
limit: 1,
|
|
3340
3341
|
});
|
|
@@ -3345,7 +3346,7 @@ export const get_xuda_cache = async function (uid, docType, key, return_property
|
|
|
3345
3346
|
|
|
3346
3347
|
return null;
|
|
3347
3348
|
|
|
3348
|
-
// ret = await
|
|
3349
|
+
// ret = await db_ms.find_couch_query('xuda_cache', {
|
|
3349
3350
|
// selector: { docType, name: name.trim() },
|
|
3350
3351
|
// limit: 1,
|
|
3351
3352
|
// });
|
|
@@ -3356,10 +3357,10 @@ export const get_xuda_cache = async function (uid, docType, key, return_property
|
|
|
3356
3357
|
};
|
|
3357
3358
|
|
|
3358
3359
|
export const save_cache_hit = async function (_id) {
|
|
3359
|
-
let doc_ret = await
|
|
3360
|
+
let doc_ret = await db_ms.get_couch_doc('xuda_cache', _id);
|
|
3360
3361
|
if (doc_ret.code > -1) {
|
|
3361
3362
|
doc_ret.data.hits++;
|
|
3362
|
-
await
|
|
3363
|
+
await db_ms.save_couch_doc('xuda_cache', doc_ret.data);
|
|
3363
3364
|
}
|
|
3364
3365
|
};
|
|
3365
3366
|
|
|
@@ -3389,7 +3390,7 @@ export const record_ai_usage = async function (uid, input_tokens, output_tokens,
|
|
|
3389
3390
|
account_profile_info,
|
|
3390
3391
|
tools,
|
|
3391
3392
|
};
|
|
3392
|
-
const save_ret = await
|
|
3393
|
+
const save_ret = await db_ms.save_couch_doc('xuda_usage', usage_doc);
|
|
3393
3394
|
// console.log(save_ret);
|
|
3394
3395
|
} catch (err) {
|
|
3395
3396
|
console.error(err);
|
|
@@ -3398,7 +3399,7 @@ export const record_ai_usage = async function (uid, input_tokens, output_tokens,
|
|
|
3398
3399
|
|
|
3399
3400
|
export const record_ai_credit = async function (uid, credits = 0, source, details, credited_uid) {
|
|
3400
3401
|
try {
|
|
3401
|
-
var dup = await
|
|
3402
|
+
var dup = await db_ms.find_couch_query('xuda_billing', {
|
|
3402
3403
|
selector: {
|
|
3403
3404
|
docType: 'ai_credit',
|
|
3404
3405
|
credited_uid,
|
|
@@ -3424,7 +3425,7 @@ export const record_ai_credit = async function (uid, credits = 0, source, detail
|
|
|
3424
3425
|
credited_uid,
|
|
3425
3426
|
details,
|
|
3426
3427
|
};
|
|
3427
|
-
const save_ret = await
|
|
3428
|
+
const save_ret = await db_ms.save_couch_doc('xuda_billing', credit_doc);
|
|
3428
3429
|
// console.log(save_ret);
|
|
3429
3430
|
return save_ret;
|
|
3430
3431
|
} catch (err) {
|
|
@@ -3443,13 +3444,13 @@ export const add_ai_credits_to_active_accounts = async function () {
|
|
|
3443
3444
|
});
|
|
3444
3445
|
|
|
3445
3446
|
const _24_hr_ms = 1000 * 60 * 60 * 24;
|
|
3446
|
-
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 });
|
|
3447
3448
|
for await (let account_doc of active_accounts.docs) {
|
|
3448
3449
|
const ret = await record_ai_credit('system', 1, 'daily credit', 'free daily credit ' + date_str, account_doc._id);
|
|
3449
3450
|
if (ret.code > -1) {
|
|
3450
3451
|
account_doc.last_free_daily_ai_credit_ts = Date.now();
|
|
3451
3452
|
account_doc.last_free_daily_ai_credit_id = ret.data.id;
|
|
3452
|
-
const save_ret = await
|
|
3453
|
+
const save_ret = await db_ms.save_couch_doc('xuda_accounts', account_doc);
|
|
3453
3454
|
}
|
|
3454
3455
|
}
|
|
3455
3456
|
};
|
|
@@ -3458,17 +3459,17 @@ export const archive_expire_ai_credits = async function () {
|
|
|
3458
3459
|
const _24_hr_ms = 1000 * 60 * 60 * 24;
|
|
3459
3460
|
const _mo_ms = _24_hr_ms * 30;
|
|
3460
3461
|
|
|
3461
|
-
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 });
|
|
3462
3463
|
for await (let ai_credit_doc of active_ai_credits.docs) {
|
|
3463
3464
|
ai_credit_doc.stat = 5;
|
|
3464
3465
|
ai_credit_doc.stat_ts = Date.now();
|
|
3465
3466
|
ai_credit_doc.stat_reason = 'expired';
|
|
3466
|
-
const save_ret = await
|
|
3467
|
+
const save_ret = await db_ms.save_couch_doc('xuda_billing', ai_credit_doc);
|
|
3467
3468
|
}
|
|
3468
3469
|
};
|
|
3469
3470
|
|
|
3470
3471
|
export const read_accounts_emails = async function () {
|
|
3471
|
-
const active_accounts = await
|
|
3472
|
+
const active_accounts = await db_ms.find_couch_query('xuda_accounts', { selector: { stat: 3, docType: 'account' }, limit: 99999 });
|
|
3472
3473
|
for await (let account_doc of active_accounts.docs) {
|
|
3473
3474
|
if (!account_doc?.account_info?.active_account_profile_id) continue;
|
|
3474
3475
|
email_ms.refresh_mailboxes({ uid: account_doc._id });
|
|
@@ -3476,7 +3477,7 @@ export const read_accounts_emails = async function () {
|
|
|
3476
3477
|
};
|
|
3477
3478
|
|
|
3478
3479
|
export const process_accounts_emails = async function () {
|
|
3479
|
-
const active_accounts = await
|
|
3480
|
+
const active_accounts = await db_ms.find_couch_query('xuda_accounts', { selector: { stat: 3, docType: 'account' }, limit: 99999 });
|
|
3480
3481
|
for await (let account_doc of active_accounts.docs) {
|
|
3481
3482
|
if (!account_doc?.account_info?.active_account_profile_id) continue;
|
|
3482
3483
|
email_ms.process_emails({ uid: account_doc._id });
|
|
@@ -3484,7 +3485,7 @@ export const process_accounts_emails = async function () {
|
|
|
3484
3485
|
};
|
|
3485
3486
|
|
|
3486
3487
|
const isLikelySpamEmail = async function (email) {
|
|
3487
|
-
const spam_whitelists = await
|
|
3488
|
+
const spam_whitelists = await db_ms.find_couch_query('xuda_accounts', {
|
|
3488
3489
|
selector: {
|
|
3489
3490
|
docType: 'spam_whitelist',
|
|
3490
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
|
-
};
|