@xuda.io/account_module 1.2.2117 → 1.2.2119

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 +106 -99
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1263,130 +1263,135 @@ function formatPhoneWithFlag(phoneString, country = 'US') {
1263
1263
  }
1264
1264
 
1265
1265
  export const get_contact_info = async function (uid, contact_doc, _id) {
1266
- let doc = contact_doc;
1267
- if (_id) {
1268
- doc = await get_contact(uid, _id);
1269
- }
1266
+ try {
1267
+ let doc = contact_doc;
1268
+ if (_id) {
1269
+ doc = await get_contact(uid, _id);
1270
+ }
1270
1271
 
1271
- delete doc.metadata;
1272
- delete doc.profile_avatar_obj;
1273
- delete doc.profile_picture_obj;
1274
- delete doc.bio;
1272
+ delete doc.metadata;
1273
+ delete doc.profile_avatar_obj;
1274
+ delete doc.profile_picture_obj;
1275
+ delete doc.bio;
1275
1276
 
1276
- const chat_conversation_count = async function () {
1277
- const account_profile_info = await get_active_account_profile_info(uid);
1277
+ const chat_conversation_count = async function () {
1278
+ const account_profile_info = await get_active_account_profile_info(uid);
1278
1279
 
1279
- const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
1280
- reduce: true,
1281
- group_level: 1,
1280
+ const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_counts', {
1281
+ reduce: true,
1282
+ group_level: 1,
1282
1283
 
1283
- startkey: [doc._id, ''],
1284
- endkey: [doc._id, 'zzzzzz'],
1285
- });
1284
+ startkey: [doc._id, ''],
1285
+ endkey: [doc._id, 'zzzzzz'],
1286
+ });
1286
1287
 
1287
- return counts_ret?.rows?.[0]?.value || 0;
1288
- };
1289
- const chat_conversation_read = async function () {
1290
- const account_profile_info = await get_active_account_profile_info(uid);
1288
+ return counts_ret?.rows?.[0]?.value || 0;
1289
+ };
1290
+ const chat_conversation_read = async function () {
1291
+ const account_profile_info = await get_active_account_profile_info(uid);
1291
1292
 
1292
- const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_read', {
1293
- reduce: true,
1294
- group_level: 2,
1293
+ const counts_ret = await db_module.get_app_couch_view(account_profile_info.app_id, 'chat_conversation_item_read', {
1294
+ reduce: true,
1295
+ group_level: 2,
1295
1296
 
1296
- startkey: [uid, doc._id, ''],
1297
- endkey: [uid, doc._id, 'zzzzzz'],
1298
- });
1297
+ startkey: [uid, doc._id, ''],
1298
+ endkey: [uid, doc._id, 'zzzzzz'],
1299
+ });
1299
1300
 
1300
- return counts_ret?.rows?.[0]?.value || 0;
1301
- };
1301
+ return counts_ret?.rows?.[0]?.value || 0;
1302
+ };
1302
1303
 
1303
- doc.notifications = 0;
1304
- if (doc.contact_uid) {
1305
- const account_info_ret = await get_account_name({ uid_query: doc.contact_uid });
1306
- if (account_info_ret.code < 0) {
1307
- return; // throw new Error(`account ${contact_uid} not found`);
1308
- }
1304
+ doc.notifications = 0;
1305
+ if (doc.contact_uid) {
1306
+ const account_info_ret = await get_account_name({ uid_query: doc.contact_uid });
1307
+ if (account_info_ret.code < 0) {
1308
+ return; // throw new Error(`account ${contact_uid} not found`);
1309
+ }
1309
1310
 
1310
- doc.profile_avatar = account_info_ret.data.profile_avatar;
1311
+ doc.profile_avatar = account_info_ret.data.profile_avatar;
1311
1312
 
1312
- //membership_plan
1313
- // doc.name = `${account_info_ret.data.first_name} ${account_info_ret.data.last_name}`;
1314
- 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}`;
1313
+ //membership_plan
1314
+ // doc.name = `${account_info_ret.data.first_name} ${account_info_ret.data.last_name}`;
1315
+ 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}`;
1315
1316
 
1316
- if (account_info_ret.data.phone_number) {
1317
- try {
1318
- doc.phone_number = formatPhoneWithFlag(account_info_ret.data.phone_number, account_info_ret.data.country);
1319
- } catch (err) {
1320
- // console.error(err);
1321
- doc.phone_number = account_info_ret.data.phone_number;
1317
+ if (account_info_ret.data.phone_number) {
1318
+ try {
1319
+ doc.phone_number = formatPhoneWithFlag(account_info_ret.data.phone_number, account_info_ret.data.country);
1320
+ } catch (err) {
1321
+ // console.error(err);
1322
+ doc.phone_number = account_info_ret.data.phone_number;
1323
+ }
1322
1324
  }
1323
- }
1324
1325
 
1325
- if (doc.team_req_id) {
1326
- try {
1327
- const req_doc = await db_module.get_couch_doc_native('xuda_team', doc.team_req_id);
1328
- doc.connection_stat = req_doc.team_req_stat;
1329
- doc.connection_type = req_doc.access_type;
1330
- doc.connection_uid = req_doc.team_req_from_uid === uid ? req_doc.team_req_to_uid : req_doc.team_req_from_uid;
1331
- 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;
1332
- if (doc.connection_type === 'contact_connection') {
1333
- doc.friend_since = req_doc.team_req_date;
1334
- }
1335
- if (doc.connection_type === 'account_profile') {
1336
- try {
1337
- const app_id = await get_account_default_project_id(uid);
1338
- const account_profile_doc = await db_module.get_app_couch_doc_native(app_id, req_doc.share_item_id);
1339
- doc.account_profile = account_profile_doc;
1340
- } catch (error) {}
1341
- }
1342
- } catch (err) {
1343
- if (err.message === 'deleted') {
1344
- try {
1345
- let contact_doc = await get_contact(uid, doc._id);
1346
- contact_doc.team_req_id = '';
1347
- await save_contact(uid, contact_doc);
1348
- } catch (error) {}
1326
+ if (doc.team_req_id) {
1327
+ try {
1328
+ const req_doc = await db_module.get_couch_doc_native('xuda_team', doc.team_req_id);
1329
+ doc.connection_stat = req_doc.team_req_stat;
1330
+ doc.connection_type = req_doc.access_type;
1331
+ doc.connection_uid = req_doc.team_req_from_uid === uid ? req_doc.team_req_to_uid : req_doc.team_req_from_uid;
1332
+ 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;
1333
+ if (doc.connection_type === 'contact_connection') {
1334
+ doc.friend_since = req_doc.team_req_date;
1335
+ }
1336
+ if (doc.connection_type === 'account_profile') {
1337
+ try {
1338
+ const app_id = await get_account_default_project_id(uid);
1339
+ const account_profile_doc = await db_module.get_app_couch_doc_native(app_id, req_doc.share_item_id);
1340
+ doc.account_profile = account_profile_doc;
1341
+ } catch (error) {}
1342
+ }
1343
+ } catch (err) {
1344
+ if (err.message === 'deleted') {
1345
+ try {
1346
+ let contact_doc = await get_contact(uid, doc._id);
1347
+ contact_doc.team_req_id = '';
1348
+ await save_contact(uid, contact_doc);
1349
+ } catch (error) {}
1350
+ }
1351
+ doc.connection_stat = 0;
1349
1352
  }
1350
- doc.connection_stat = 0;
1351
1353
  }
1352
- }
1353
1354
 
1354
- doc.avatar_source = account_info_ret.data.avatar_source;
1355
- // doc.icon_pattern = await get_contact_pattern(doc);
1356
- doc.username = account_info_ret.data.username;
1357
- doc.business_name = account_info_ret.data.business_name;
1358
- doc.address = account_info_ret.data.address;
1359
- doc.city = account_info_ret.data.city;
1360
- doc.state = account_info_ret.data.state;
1361
- doc.zip = account_info_ret.data.zip;
1362
- doc.account_type = account_info_ret.data.account_type;
1363
- doc.email = doc.email;
1364
- if (doc.connection_stat === 3) {
1365
- doc.online = account_info_ret.data.online;
1355
+ doc.avatar_source = account_info_ret.data.avatar_source;
1356
+ // doc.icon_pattern = await get_contact_pattern(doc);
1357
+ doc.username = account_info_ret.data.username;
1358
+ doc.business_name = account_info_ret.data.business_name;
1359
+ doc.address = account_info_ret.data.address;
1360
+ doc.city = account_info_ret.data.city;
1361
+ doc.state = account_info_ret.data.state;
1362
+ doc.zip = account_info_ret.data.zip;
1363
+ doc.account_type = account_info_ret.data.account_type;
1364
+ doc.email = doc.email;
1365
+ if (doc.connection_stat === 3) {
1366
+ doc.online = account_info_ret.data.online;
1367
+ }
1368
+ } else {
1369
+ doc.email = doc.email;
1366
1370
  }
1367
- } else {
1368
- doc.email = doc.email;
1369
- }
1370
1371
 
1371
- doc.business_has_person = doc?.business_has_person && doc?.person_info?.person_full_name !== 'Not available';
1372
- doc.icon_pattern = await get_contact_pattern(doc);
1372
+ doc.business_has_person = doc?.business_has_person && doc?.person_info?.person_full_name !== 'Not available';
1373
+ doc.icon_pattern = await get_contact_pattern(doc);
1373
1374
 
1374
- delete doc.account_type_info;
1375
- delete doc.person_info;
1376
- delete doc.business_info;
1375
+ delete doc.account_type_info;
1376
+ delete doc.person_info;
1377
+ delete doc.business_info;
1377
1378
 
1378
- const contact_chat_conversation_count_ret = await chat_conversation_count();
1379
- const contact_chat_conversation_read_ret = await chat_conversation_read();
1379
+ const contact_chat_conversation_count_ret = await chat_conversation_count();
1380
+ const contact_chat_conversation_read_ret = await chat_conversation_read();
1380
1381
 
1381
- doc.interactions = contact_chat_conversation_count_ret;
1382
- doc.notifications = contact_chat_conversation_count_ret - contact_chat_conversation_read_ret;
1383
- doc.chats = doc.interactions;
1382
+ doc.interactions = contact_chat_conversation_count_ret;
1383
+ doc.notifications = contact_chat_conversation_count_ret - contact_chat_conversation_read_ret;
1384
+ doc.chats = doc.interactions;
1384
1385
 
1385
- doc.card_background = get_contact_background(doc);
1386
+ doc.card_background = get_contact_background(doc);
1386
1387
 
1387
- doc.border = get_contact_border(doc);
1388
+ doc.border = get_contact_border(doc);
1388
1389
 
1389
- return doc;
1390
+ return doc;
1391
+ } catch (err) {
1392
+ console.error(err);
1393
+ return {};
1394
+ }
1390
1395
  };
1391
1396
 
1392
1397
  export const get_pending_contact_out = async function (uid, _id) {
@@ -1717,6 +1722,7 @@ export const get_user_name = async function (uid) {
1717
1722
  };
1718
1723
 
1719
1724
  export const get_user_card = async function (req) {
1725
+ debugger;
1720
1726
  const { uid, uid_query } = req;
1721
1727
  if (uid === uid_query) return await get_user_contact(uid, uid_query);
1722
1728
 
@@ -3307,6 +3313,7 @@ export const update_entity_account_profiles = async function (req, job_id, heade
3307
3313
 
3308
3314
  export const get_contact = async function (uid, contact_id) {
3309
3315
  const account_profile_info = await get_active_account_profile_info(uid);
3316
+
3310
3317
  const contact_ret = await db_module.get_app_couch_doc_native(account_profile_info.app_id, contact_id);
3311
3318
  return contact_ret;
3312
3319
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.2117",
3
+ "version": "1.2.2119",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {