@xuda.io/account_module 1.2.1263 → 1.2.1265

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 +117 -114
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1436,7 +1436,7 @@ export const get_contact_info = async function (uid, contact_doc, _id) {
1436
1436
  } catch (err) {
1437
1437
  if (err.message === 'deleted') {
1438
1438
  try {
1439
- let contact_doc = await db_module.get_couch_doc_native('xuda_contacts', doc._id);
1439
+ let contact_doc = await get_contact(uid, doc._id);
1440
1440
  contact_doc.team_req_id = '';
1441
1441
  await db_module.save_couch_doc('xuda_contacts', contact_doc);
1442
1442
  } catch (error) {}
@@ -1554,7 +1554,7 @@ export const get_pending_share_contact_in = async function (uid, _id) {
1554
1554
  const requests_from_res = await db_module.find_couch_query('xuda_team', from_opt);
1555
1555
 
1556
1556
  for await (let e of requests_from_res.docs) {
1557
- let doc = await db_module.get_couch_doc_native('xuda_contacts', e.share_item_id);
1557
+ let doc = await get_contact(uid, e.share_item_id);
1558
1558
  delete doc.contact_mood_level;
1559
1559
  doc.shared_from_uid = e.team_req_from_uid;
1560
1560
  doc.pending = true;
@@ -2019,7 +2019,7 @@ export const onboarding_completed = async function (req, job_id, headers) {
2019
2019
 
2020
2020
  export const ts_contact = async function (contact_id) {
2021
2021
  try {
2022
- const contact_doc = await db_module.get_couch_doc_native('xuda_contacts', contact_id);
2022
+ const contact_doc = await get_contact(uid, contact_id);
2023
2023
  contact_doc.ts = Date.now();
2024
2024
  const save_ret = await db_module.save_couch_doc('xuda_contacts', contact_doc);
2025
2025
  return save_ret;
@@ -2188,144 +2188,147 @@ export const add_contact = async function (req, job_id, headers) {
2188
2188
 
2189
2189
  export const get_contacts = async function (req) {
2190
2190
  const { _id, uid, name, limit, skip, bookmark, search, filter_type = 'all', contact_id } = req;
2191
+ try {
2192
+ const account_profile_info = await get_active_account_profile_info(uid);
2193
+ if (_id) {
2194
+ let data = await db_module.get_couch_doc('xuda_contacts', _id);
2195
+ return data;
2196
+ }
2191
2197
 
2192
- const account_profile_info = await get_active_account_profile_info(uid);
2193
- if (_id) {
2194
- let data = await db_module.get_couch_doc('xuda_contacts', _id);
2195
- return data;
2196
- }
2198
+ let { with_requests } = req;
2199
+ var opt = {
2200
+ selector: {
2201
+ docType: 'contact',
2202
+ uid: account_profile_info.uid,
2203
+ stat: { $lt: 4 },
2204
+ },
2205
+ limit: limit || 9999,
2206
+ skip: skip || 0,
2207
+ sort: [{ ts: 'desc' }],
2208
+ };
2197
2209
 
2198
- let { with_requests } = req;
2199
- var opt = {
2200
- selector: {
2201
- docType: 'contact',
2202
- uid: account_profile_info.uid,
2203
- stat: { $lt: 4 },
2204
- },
2205
- limit: limit || 9999,
2206
- skip: skip || 0,
2207
- sort: [{ ts: 'desc' }],
2208
- };
2210
+ switch (filter_type) {
2211
+ case 'archived': {
2212
+ opt.selector.stat = 5;
2213
+ break;
2214
+ }
2215
+ case 'shared': {
2216
+ opt.selector.shared_from_uid = { $gt: null };
2217
+ break;
2218
+ }
2209
2219
 
2210
- switch (filter_type) {
2211
- case 'archived': {
2212
- opt.selector.stat = 5;
2213
- break;
2214
- }
2215
- case 'shared': {
2216
- opt.selector.shared_from_uid = { $gt: null };
2217
- break;
2218
- }
2220
+ case 'pinned': {
2221
+ opt.selector.pinned = true;
2222
+ break;
2223
+ }
2219
2224
 
2220
- case 'pinned': {
2221
- opt.selector.pinned = true;
2222
- break;
2223
- }
2225
+ case 'online': {
2226
+ opt.limit = 9999;
2227
+ break;
2228
+ }
2224
2229
 
2225
- case 'online': {
2226
- opt.limit = 9999;
2227
- break;
2230
+ default:
2231
+ with_requests = true;
2232
+ break;
2228
2233
  }
2229
2234
 
2230
- default:
2231
- with_requests = true;
2232
- break;
2233
- }
2234
-
2235
- if (_id) {
2236
- opt.selector._id = _id;
2237
- }
2235
+ if (_id) {
2236
+ opt.selector._id = _id;
2237
+ }
2238
2238
 
2239
- if (contact_id) {
2240
- opt.selector._id = contact_id;
2241
- }
2239
+ if (contact_id) {
2240
+ opt.selector._id = contact_id;
2241
+ }
2242
2242
 
2243
- if (typeof name !== 'undefined') {
2244
- opt.selector.name = { $regex: `(?i)${name}` };
2245
- }
2243
+ if (typeof name !== 'undefined') {
2244
+ opt.selector.name = { $regex: `(?i)${name}` };
2245
+ }
2246
2246
 
2247
- if (typeof search !== 'undefined') {
2248
- opt.selector['$or'] = [
2249
- {
2250
- name: {
2251
- $regex: `(?i)${search}`,
2247
+ if (typeof search !== 'undefined') {
2248
+ opt.selector['$or'] = [
2249
+ {
2250
+ name: {
2251
+ $regex: `(?i)${search}`,
2252
+ },
2252
2253
  },
2253
- },
2254
- {
2255
- email: {
2256
- $regex: `(?i)${search}`,
2254
+ {
2255
+ email: {
2256
+ $regex: `(?i)${search}`,
2257
+ },
2257
2258
  },
2258
- },
2259
- ];
2260
- }
2259
+ ];
2260
+ }
2261
2261
 
2262
- if (bookmark && bookmark !== 'nil') {
2263
- opt.bookmark = bookmark;
2264
- }
2262
+ if (bookmark && bookmark !== 'nil') {
2263
+ opt.bookmark = bookmark;
2264
+ }
2265
2265
 
2266
- let contacts = { docs: [], total_docs: 0 };
2266
+ let contacts = { docs: [], total_docs: 0 };
2267
2267
 
2268
- if (filter_type !== 'pending') {
2269
- contacts = await db_module.find_couch_query('xuda_contacts', opt);
2270
- if (!limit || contact_id) {
2271
- contacts.total_docs = contacts.docs.length;
2272
- } else {
2273
- delete opt.sort;
2274
- delete opt.skip;
2275
- opt.limit = 9999;
2276
- opt.fields = ['_id'];
2268
+ if (filter_type !== 'pending') {
2269
+ contacts = await db_module.find_couch_query('xuda_contacts', opt);
2270
+ if (!limit || contact_id) {
2271
+ contacts.total_docs = contacts.docs.length;
2272
+ } else {
2273
+ delete opt.sort;
2274
+ delete opt.skip;
2275
+ opt.limit = 9999;
2276
+ opt.fields = ['_id'];
2277
2277
 
2278
- const counter = await db_module.find_couch_query('xuda_contacts', opt);
2279
- contacts.total_docs = counter.docs.length;
2278
+ const counter = await db_module.find_couch_query('xuda_contacts', opt);
2279
+ contacts.total_docs = counter.docs.length;
2280
+ }
2280
2281
  }
2281
- }
2282
2282
 
2283
- let requests_to = { docs: [], total_docs: 0 };
2284
- let requests_from = { docs: [], total_docs: 0 };
2285
- let shared_from = { docs: [], total_docs: 0 };
2283
+ let requests_to = { docs: [], total_docs: 0 };
2284
+ let requests_from = { docs: [], total_docs: 0 };
2285
+ let shared_from = { docs: [], total_docs: 0 };
2286
2286
 
2287
- let contact_docs = { docs: [], total_docs: contacts.total_docs };
2288
- for await (let doc of contacts.docs) {
2289
- const ret_to = requests_to.docs.find((e) => {
2290
- return e.contact_uid === doc.contact_uid;
2291
- });
2292
- if (ret_to) continue;
2287
+ let contact_docs = { docs: [], total_docs: contacts.total_docs };
2288
+ for await (let doc of contacts.docs) {
2289
+ const ret_to = requests_to.docs.find((e) => {
2290
+ return e.contact_uid === doc.contact_uid;
2291
+ });
2292
+ if (ret_to) continue;
2293
2293
 
2294
- const ret_from = requests_from.docs.find((e) => {
2295
- return e.contact_uid === doc.contact_uid;
2296
- });
2297
- if (ret_from) continue;
2294
+ const ret_from = requests_from.docs.find((e) => {
2295
+ return e.contact_uid === doc.contact_uid;
2296
+ });
2297
+ if (ret_from) continue;
2298
2298
 
2299
- doc = await get_contact_info(uid, doc);
2299
+ doc = await get_contact_info(uid, doc);
2300
2300
 
2301
- if (filter_type === 'online') {
2302
- if (!doc.online) continue;
2303
- }
2301
+ if (filter_type === 'online') {
2302
+ if (!doc.online) continue;
2303
+ }
2304
2304
 
2305
- contact_docs.docs.push(doc);
2306
- }
2305
+ contact_docs.docs.push(doc);
2306
+ }
2307
2307
 
2308
- if (!contact_id && with_requests) {
2309
- if (filter_type === 'pending') {
2310
- ////// TO - OUT
2311
- requests_to.docs = await get_pending_contact_out(uid);
2312
- requests_to.total_docs = requests_to.docs.length;
2308
+ if (!contact_id && with_requests) {
2309
+ if (filter_type === 'pending') {
2310
+ ////// TO - OUT
2311
+ requests_to.docs = await get_pending_contact_out(uid);
2312
+ requests_to.total_docs = requests_to.docs.length;
2313
2313
 
2314
- ////// FROM - IN
2315
- requests_from.docs = await get_pending_contact_in(uid);
2316
- requests_from.total_docs = requests_from.docs.length;
2317
- shared_from.docs = await get_pending_share_contact_in(uid);
2318
- shared_from.total_docs = shared_from.docs.length;
2314
+ ////// FROM - IN
2315
+ requests_from.docs = await get_pending_contact_in(uid);
2316
+ requests_from.total_docs = requests_from.docs.length;
2317
+ shared_from.docs = await get_pending_share_contact_in(uid);
2318
+ shared_from.total_docs = shared_from.docs.length;
2319
+ }
2319
2320
  }
2320
- }
2321
2321
 
2322
- return {
2323
- code: 1,
2324
- data: {
2325
- docs: [...shared_from.docs, ...requests_from.docs, ...requests_to.docs, ...contact_docs.docs],
2326
- total_docs: shared_from.total_docs + requests_from.total_docs + requests_to.total_docs + contact_docs.total_docs,
2327
- },
2328
- };
2322
+ return {
2323
+ code: 1,
2324
+ data: {
2325
+ docs: [...shared_from.docs, ...requests_from.docs, ...requests_to.docs, ...contact_docs.docs],
2326
+ total_docs: shared_from.total_docs + requests_from.total_docs + requests_to.total_docs + contact_docs.total_docs,
2327
+ },
2328
+ };
2329
+ } catch (err) {
2330
+ return { code: -34, data: err.message };
2331
+ }
2329
2332
  };
2330
2333
 
2331
2334
  export const archive_contact = async function (req) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.1263",
3
+ "version": "1.2.1265",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {