@xuda.io/account_module 1.2.1060 → 1.2.1062

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.
Files changed (2) hide show
  1. package/index.mjs +108 -26
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -2483,6 +2483,88 @@ setTimeout(async () => {
2483
2483
  console.log(ret);
2484
2484
  }, 1000);
2485
2485
 
2486
+ export const get_account_profile_info = async function (uid, contact_profile_doc, _id) {
2487
+ const ai_module = await import(`${module_path}/ai_module/index.mjs`);
2488
+ let doc = contact_profile_doc;
2489
+ if (_id) {
2490
+ doc = await db_module.get_couch_doc_native('xuda_accounts', _id);
2491
+ }
2492
+ doc.notifications = 0;
2493
+
2494
+ const account_info_ret = await get_account_name({ uid_query: uid });
2495
+ if (account_info_ret.code < 0) {
2496
+ return;
2497
+ }
2498
+
2499
+ doc.profile_avatar = account_info_ret.data.profile_avatar;
2500
+
2501
+ //membership_plan
2502
+ // doc.name = `${account_info_ret.data.first_name} ${account_info_ret.data.last_name}`;
2503
+ 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}`;
2504
+
2505
+ if (account_info_ret.data.phone_number) {
2506
+ try {
2507
+ doc.phone_number = formatPhoneWithFlag(account_info_ret.data.phone_number, account_info_ret.data.country);
2508
+ } catch (err) {
2509
+ console.error(err);
2510
+ doc.phone_number = account_info_ret.data.phone_number;
2511
+ }
2512
+ }
2513
+
2514
+ if (doc.team_req_id) {
2515
+ try {
2516
+ const req_doc = await db_module.get_couch_doc_native('xuda_team', doc.team_req_id);
2517
+ doc.connection_stat = req_doc.team_req_stat;
2518
+ doc.connection_type = req_doc.access_type;
2519
+ if (doc.connection_type === 'contact_connection') {
2520
+ doc.friend_since = req_doc.team_req_date;
2521
+ }
2522
+ } catch (err) {
2523
+ if (err.message === 'deleted') {
2524
+ try {
2525
+ let contact_doc = await db_module.get_couch_doc_native('xuda_contacts', doc._id);
2526
+ contact_doc.team_req_id = '';
2527
+ await db_module.save_couch_doc('xuda_contacts', contact_doc);
2528
+ } catch (error) {}
2529
+ }
2530
+ doc.connection_stat = 0;
2531
+ }
2532
+ }
2533
+ doc.avatar_source = account_info_ret.data.avatar_source;
2534
+ doc.icon_pattern = await get_contact_pattern(doc);
2535
+ doc.username = account_info_ret.data.username;
2536
+ doc.business_name = account_info_ret.data.business_name;
2537
+ doc.address = account_info_ret.data.address;
2538
+ doc.city = account_info_ret.data.city;
2539
+ doc.state = account_info_ret.data.state;
2540
+ doc.zip = account_info_ret.data.zip;
2541
+ doc.account_type = account_info_ret.data.account_type;
2542
+ doc.email = doc.email?.[0];
2543
+ if (doc.connection_stat === 3) {
2544
+ doc.online = account_info_ret.data.online;
2545
+ }
2546
+
2547
+ doc.interactions = 0;
2548
+ doc.chats = 0;
2549
+
2550
+ const chats_ret = await ai_module.get_ai_chats({ uid, reference_id: doc._id });
2551
+ for (let chat_doc of chats_ret.data.docs) {
2552
+ doc.notifications += chat_doc.notifications;
2553
+
2554
+ doc.chats++;
2555
+ if (chat_doc.interactions) {
2556
+ doc.interactions += chat_doc.interactions;
2557
+ }
2558
+ doc.contact_mood_level = chat_doc.mood_level || 0;
2559
+ }
2560
+
2561
+ doc.card_background = get_contact_background(doc);
2562
+
2563
+ doc.border = get_contact_border(doc);
2564
+
2565
+ return doc;
2566
+ };
2567
+
2486
2568
  export const get_account_profiles = async function (req) {
2487
2569
  const { _id, uid, profile_name, limit, skip, bookmark, search, filter_type = 'all', profile_id } = req;
2488
2570
 
@@ -2654,33 +2736,33 @@ export const unarchive_account_profile = async function (req) {
2654
2736
  }
2655
2737
  };
2656
2738
 
2657
- export const unfriend_account_profile = async function (req) {
2658
- const { profile_id } = req;
2659
- try {
2660
- const contact_ret = await db_module.get_couch_doc('xuda_accounts', profile_id);
2661
- if (contact_ret.code < 0) {
2662
- throw new Error(contact_ret.data);
2663
- }
2664
- var account_profile_doc = contact_ret.data;
2739
+ // export const unfriend_account_profile = async function (req) {
2740
+ // const { profile_id } = req;
2741
+ // try {
2742
+ // const contact_ret = await db_module.get_couch_doc('xuda_accounts', profile_id);
2743
+ // if (contact_ret.code < 0) {
2744
+ // throw new Error(contact_ret.data);
2745
+ // }
2746
+ // var account_profile_doc = contact_ret.data;
2665
2747
 
2666
- if (!account_profile_doc.team_req_id) {
2667
- throw new Error('no friend relationship found');
2668
- }
2669
- let req_doc = await db_module.get_couch_doc_native('xuda_team', account_profile_doc.team_req_id);
2670
- req_doc.team_req_stat = 4;
2671
- req_doc.team_req_stat_desc = 'unfriend by the user';
2672
- await db_module.get_couch_doc_native('xuda_team', account_profile_doc.team_req_id);
2748
+ // if (!account_profile_doc.team_req_id) {
2749
+ // throw new Error('no friend relationship found');
2750
+ // }
2751
+ // let req_doc = await db_module.get_couch_doc_native('xuda_team', account_profile_doc.team_req_id);
2752
+ // req_doc.team_req_stat = 4;
2753
+ // req_doc.team_req_stat_desc = 'unfriend by the user';
2754
+ // await db_module.get_couch_doc_native('xuda_team', account_profile_doc.team_req_id);
2673
2755
 
2674
- account_profile_doc.team_req_id = null;
2675
- const account_profile_save_ret = await db_module.save_couch_doc('xuda_accounts', account_profile_doc);
2756
+ // account_profile_doc.team_req_id = null;
2757
+ // const account_profile_save_ret = await db_module.save_couch_doc('xuda_accounts', account_profile_doc);
2676
2758
 
2677
- const req_save_ret = await db_module.save_couch_doc('xuda_team', req_doc);
2759
+ // const req_save_ret = await db_module.save_couch_doc('xuda_team', req_doc);
2678
2760
 
2679
- return req_save_ret;
2680
- } catch (err) {
2681
- return {
2682
- code: -21,
2683
- data: err.message,
2684
- };
2685
- }
2686
- };
2761
+ // return req_save_ret;
2762
+ // } catch (err) {
2763
+ // return {
2764
+ // code: -21,
2765
+ // data: err.message,
2766
+ // };
2767
+ // }
2768
+ // };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.1060",
3
+ "version": "1.2.1062",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {