tango-app-api-trax 3.3.1-beta-20 → 3.3.1-beta-22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-trax",
3
- "version": "3.3.1-beta-20",
3
+ "version": "3.3.1-beta-22",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,7 +26,7 @@
26
26
  "mongodb": "^6.8.0",
27
27
  "nodemon": "^3.1.4",
28
28
  "path": "^0.12.7",
29
- "tango-api-schema": "^2.2.41",
29
+ "tango-api-schema": "^2.2.49",
30
30
  "tango-app-api-middleware": "^3.1.55",
31
31
  "url": "^0.11.4",
32
32
  "winston": "^3.13.1",
@@ -20,6 +20,8 @@ import { logger } from 'tango-app-api-middleware';
20
20
  import mongoose from 'mongoose';
21
21
  import { sendPushNotification } from 'tango-app-api-middleware';
22
22
  import * as planoService from '../services/planogram.service.js';
23
+ import * as clusterServices from '../services/cluster.service.js';
24
+ import * as teamsServices from '../services/teams.service.js';
23
25
 
24
26
 
25
27
  const ObjectId = mongoose.Types.ObjectId;
@@ -341,6 +343,152 @@ async function insertData( requestData ) {
341
343
  } );
342
344
  let allQuestion = await CLassign.aggregate( getquestionQuery );
343
345
  if ( allQuestion.length ) {
346
+ let assignList = [];
347
+ if ( getCLconfig.coverage == 'store' ) {
348
+ let clusterList = allQuestion.filter( ( ele ) => ele?.clusterName ).map( ( item ) => item.assignId );
349
+ if ( clusterList.length ) {
350
+ let clusterDetails = await clusterServices.findcluster( { _id: { $in: clusterList } } );
351
+ if ( clusterDetails.length ) {
352
+ let idList = clusterDetails.flatMap( ( item ) => item.stores.map( ( ele ) => ele.store ) );
353
+ let getStoreDetails = await storeService.find( { _id: { $in: idList } } );
354
+ if ( getStoreDetails.length ) {
355
+ assignList = await Promise.all( getStoreDetails.map( async ( store ) => {
356
+ let userDetails = await userService.findOne( { email: store?.spocDetails?.[0]?.email, clientId: store.clientId } );
357
+ if ( !userDetails ) {
358
+ let data = {
359
+ clientId: store.clientId,
360
+ userName: store.spocDetails?.[0]?.name,
361
+ mobileNumber: store.spocDetails?.[0]?.phone || '',
362
+ email: store.spocDetails[0].email,
363
+ password: '5dqFKAJj29PsV6P+kL+3Dw==',
364
+ role: 'user',
365
+ userType: 'client',
366
+ rolespermission: [
367
+ {
368
+ featureName: 'Global',
369
+ modules: [
370
+ {
371
+ name: 'Store',
372
+ isAdd: false,
373
+ isEdit: false,
374
+
375
+ },
376
+ {
377
+ name: 'User',
378
+ isAdd: false,
379
+ isEdit: false,
380
+
381
+ },
382
+ {
383
+ name: 'Camera',
384
+ isAdd: false,
385
+ isEdit: false,
386
+
387
+ },
388
+ {
389
+ name: 'Configuration',
390
+ isAdd: false,
391
+ isEdit: false,
392
+
393
+ },
394
+ {
395
+ name: 'Subscription',
396
+ isAdd: false,
397
+ isEdit: false,
398
+
399
+ },
400
+ {
401
+ name: 'Billing',
402
+ isAdd: false,
403
+ isEdit: false,
404
+
405
+ },
406
+ ],
407
+ },
408
+ {
409
+ featurName: 'TangoEye',
410
+ modules: [
411
+ {
412
+ name: 'ZoneTag',
413
+ isAdd: false,
414
+ isEdit: false,
415
+
416
+ },
417
+ ],
418
+ },
419
+ {
420
+ featurName: 'TangoTrax',
421
+ modules: [
422
+ {
423
+ name: 'checklist',
424
+ isAdd: false,
425
+ isEdit: false,
426
+
427
+ },
428
+ {
429
+ name: 'Task',
430
+ isAdd: false,
431
+ isEdit: false,
432
+
433
+ },
434
+ ],
435
+ },
436
+ ],
437
+ };
438
+ userDetails = await userService.create( data );
439
+ }
440
+ let data = {
441
+ store_id: store?.storeId,
442
+ storeName: store?.storeName,
443
+ userId: userDetails._id,
444
+ userName: userDetails.userName,
445
+ userEmail: userDetails.email,
446
+ userPhone: userDetails?.mobileNumber,
447
+ city: store?.storeProfile?.city,
448
+ country: store?.storeProfile?.country,
449
+ checkFlag: true,
450
+ checkListId: getCLconfig._id,
451
+ checkListName: getCLconfig.checkListName,
452
+ client_id: getCLconfig.client_id,
453
+ };
454
+ return data;
455
+ } ) );
456
+ }
457
+ }
458
+ }
459
+ allQuestion = allQuestion.filter( ( ele ) => !clusterList.includes( ele.assignId ) );
460
+ }
461
+ if ( getCLconfig.coverage == 'user' ) {
462
+ let teamsList = allQuestion.filter( ( ele ) => ele?.teamName ).map( ( item ) => item.assignId );
463
+ if ( teamsList.length ) {
464
+ let teamDetails = await teamsServices.findteams( { _id: { $in: teamsList } } );
465
+ if ( teamDetails.length ) {
466
+ let idList = teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) );
467
+ let getUserDetails = await userService.find( { _id: { $in: idList } } );
468
+ if ( getUserDetails.length ) {
469
+ assignList = getUserDetails.map( ( user ) => {
470
+ let data = {
471
+ store_id: '',
472
+ storeName: '',
473
+ userId: user._id,
474
+ userName: user.userName,
475
+ userEmail: user.email,
476
+ userPhone: user?.mobileNumber,
477
+ city: '',
478
+ country: '',
479
+ checkFlag: true,
480
+ checkListId: getCLconfig._id,
481
+ checkListName: getCLconfig.checkListName,
482
+ client_id: getCLconfig.client_id,
483
+ };
484
+ return data;
485
+ } );
486
+ }
487
+ }
488
+ }
489
+ allQuestion = allQuestion.filter( ( ele ) => !teamsList.includes( ele.assignId ) );
490
+ }
491
+ allQuestion = [ ...allQuestion, ...assignList ];
344
492
  let userIdList = [];
345
493
  for ( let element4 of allQuestion ) {
346
494
  if ( getCLconfig.allowOnce && ![ 'onetime', 'daily' ].includes( getCLconfig.schedule ) ) {
@@ -394,9 +394,9 @@ export const getConfigDetails = async ( req, res ) => {
394
394
  result.checkListDetails.scheduleStartTime = result.openTime;
395
395
  result.checkListDetails.scheduleEndTime = result.closeTime;
396
396
  }
397
- let removedUsers = await assignedService.find( { checkFlag: false, checkListId: storechecklistdetails._id }, { _id: 1 } );
398
- removedUsers = removedUsers?.map( ( item ) => item._id );
399
- result.checkListDetails = { ...result.checkListDetails, ...{ sections: sectionList }, ...{ assignedUsers: [] }, ...{ removedUsers: removedUsers } };
397
+ let assignedUsers = await assignedService.find( { checkListId: storechecklistdetails._id }, { _id: 1, assignId: 1 } );
398
+ assignedUsers = assignedUsers?.map( ( item ) => item.assignId );
399
+ result.checkListDetails = { ...result.checkListDetails, ...{ sections: sectionList }, ...{ assignedUsers: assignedUsers }, ...{ removedUsers: [] } };
400
400
  }
401
401
 
402
402
  return res.sendSuccess( result );
@@ -863,7 +863,7 @@ export const assignedUserDetails = async ( req, res ) => {
863
863
  let page = parseInt( req.query.offset ) || 0;
864
864
  let skip = limit * page;
865
865
 
866
- let query = [ { $match: { checkListId: new ObjectId( req.params.checklistId ), isdeleted: false } } ];
866
+ let query = [ { $match: { checkListId: new ObjectId( req.params.checklistId ), ...( req.query.coverage ) ? { coverage: req.query.coverage } : {}, isdeleted: false } } ];
867
867
  if ( req.query.search.trim() && req.query.search.trim() != '' ) {
868
868
  let searchValue = req.query.search;
869
869
  searchValue = searchValue.split( ',' ).map( ( item ) => item.trim().toLowerCase() );
@@ -972,7 +972,7 @@ export const assignedUserDetailsv1 = async ( req, res ) => {
972
972
  // let page = parseInt( req.query.offset ) || 0;
973
973
  // let skip = limit * page;
974
974
 
975
- let query = [ { $match: { checkListId: new ObjectId( req.params.checklistId ), isdeleted: false } } ];
975
+ let query = [ { $match: { checkListId: new ObjectId( req.params.checklistId ), ...( req.query.coverage ) ? { coverage: req.query.coverage } : {}, isdeleted: false } } ];
976
976
  if ( req.query.search.trim() && req.query.search.trim() != '' ) {
977
977
  let searchValue = req.query.search;
978
978
  searchValue = searchValue.split( ',' ).map( ( item ) => item.trim().toLowerCase() );
@@ -3638,7 +3638,7 @@ async function assignUsers( data ) {
3638
3638
  ];
3639
3639
  let storeDetails = await storeService.aggregate( query );
3640
3640
  if ( storeDetails.length ) {
3641
- let email = data?.upload ? data.userEmail : storeDetails?.[0]?.spocDetails?.email;
3641
+ let email = data?.upload ? data.userEmail : storeDetails?.[0]?.spocDetails?.[0]?.email;
3642
3642
  let userDetails = await userService.findOne( { email: email, clientId: data.clientId } );
3643
3643
  if ( !userDetails ) {
3644
3644
  let userData = {
@@ -3764,7 +3764,7 @@ export async function checklistAssign( req, res ) {
3764
3764
  return res.sendError( 'No data found', 204 );
3765
3765
  }
3766
3766
  assignList = await Promise.all( getStoreDetails.map( async ( store ) => {
3767
- let userDetails = await userService.findOne( { email: store?.spocDetails?.email, clientId: store.clientId } );
3767
+ let userDetails = await userService.findOne( { email: store?.spocDetails?.[0]?.email, clientId: store.clientId } );
3768
3768
  if ( !userDetails ) {
3769
3769
  let data = {
3770
3770
  clientId: store.clientId,