tango-app-api-trax 3.2.1 → 3.3.1-airtel-1
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 +3 -3
- package/src/controllers/download.controller.js +154 -17
- package/src/controllers/gallery.controller.js +124 -31
- package/src/controllers/internalTrax.controller.js +284 -5
- package/src/controllers/mobileTrax.controller.js +200 -40
- package/src/controllers/teaxFlag.controller.js +161 -142
- package/src/controllers/trax.controller.js +1477 -153
- package/src/controllers/traxDashboard.controllers.js +350 -105
- package/src/dtos/dashboardValidation.dtos.js +2 -0
- package/src/dtos/downloadValidation.dtos.js +3 -0
- package/src/dtos/validation.dtos.js +17 -5
- package/src/routes/download.router.js +4 -0
- package/src/routes/gallery.routes.js +5 -1
- package/src/routes/internalTraxApi.router.js +3 -1
- package/src/routes/mobileTrax.routes.js +3 -1
- package/src/routes/trax.routes.js +12 -2
- package/src/routes/traxDashboard.routes.js +3 -1
- package/src/services/checklistAssign.service.js +8 -0
- package/src/services/planogram.service.js +5 -0
- package/src/services/teams.service.js +30 -0
|
@@ -18,7 +18,10 @@ import timeZone from 'dayjs/plugin/timezone.js';
|
|
|
18
18
|
import utc from 'dayjs/plugin/utc.js';
|
|
19
19
|
import { logger } from 'tango-app-api-middleware';
|
|
20
20
|
import mongoose from 'mongoose';
|
|
21
|
-
import { sendPushNotification } from 'tango-app-api-middleware';
|
|
21
|
+
import { sendPushNotification, sendAiPushNotification } from 'tango-app-api-middleware';
|
|
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';
|
|
22
25
|
|
|
23
26
|
|
|
24
27
|
const ObjectId = mongoose.Types.ObjectId;
|
|
@@ -291,6 +294,7 @@ async function insertData( requestData ) {
|
|
|
291
294
|
insertdata.locationCount = getCLconfig.locationCount;
|
|
292
295
|
insertdata.scheduleRepeatedType = getCLconfig.scheduleRepeatedType;
|
|
293
296
|
insertdata.allowedMultiSubmit = getCLconfig.allowedMultiSubmit;
|
|
297
|
+
insertdata.rawImageUpload = getCLconfig.rawImageUpload || false;
|
|
294
298
|
let collectSections = [];
|
|
295
299
|
let sectionQuery = [];
|
|
296
300
|
sectionQuery.push( {
|
|
@@ -300,7 +304,7 @@ async function insertData( requestData ) {
|
|
|
300
304
|
},
|
|
301
305
|
} );
|
|
302
306
|
let getSections = await CLquestions.aggregate( sectionQuery );
|
|
303
|
-
if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring' ].includes( getCLconfig.checkListType ) ) {
|
|
307
|
+
if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall' ].includes( getCLconfig.checkListType ) ) {
|
|
304
308
|
if ( getSections.length ) {
|
|
305
309
|
for ( let element3 of getSections ) {
|
|
306
310
|
let collectQuestions = {};
|
|
@@ -334,12 +338,157 @@ async function insertData( requestData ) {
|
|
|
334
338
|
getquestionQuery.push( {
|
|
335
339
|
$match: {
|
|
336
340
|
checkListId: element2,
|
|
337
|
-
checkFlag: true,
|
|
338
341
|
isdeleted: false,
|
|
339
342
|
},
|
|
340
343
|
} );
|
|
341
344
|
let allQuestion = await CLassign.aggregate( getquestionQuery );
|
|
342
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 ) ), ...teamDetails.flatMap( ( item ) => item.Teamlead.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 ];
|
|
343
492
|
let userIdList = [];
|
|
344
493
|
for ( let element4 of allQuestion ) {
|
|
345
494
|
if ( getCLconfig.allowOnce && ![ 'onetime', 'daily' ].includes( getCLconfig.schedule ) ) {
|
|
@@ -416,6 +565,12 @@ async function insertData( requestData ) {
|
|
|
416
565
|
element4.scheduleRepeatedType = getCLconfig.scheduleRepeatedType;
|
|
417
566
|
element4.approvalEnable = getCLconfig.approver.length ? true : false;
|
|
418
567
|
element4.remainder = getCLconfig?.remainder || [];
|
|
568
|
+
// if ( getCLconfig?.isPlano ) {
|
|
569
|
+
// let planoDetails = await planoService.findOne( { storeId: element4.store_id, clientId: getCLconfig.client_id }, { _id: 1 } );
|
|
570
|
+
// element4.planoId = planoDetails?._id;
|
|
571
|
+
// element4.isPlano = getCLconfig?.isPlano;
|
|
572
|
+
// }
|
|
573
|
+
element4.rawImageUpload = getCLconfig?.rawImageUpload || false;
|
|
419
574
|
}
|
|
420
575
|
if ( userIdList.length ) {
|
|
421
576
|
allQuestion = allQuestion.filter( ( item ) => typeof item._id == 'undefined' );
|
|
@@ -442,7 +597,7 @@ async function insertData( requestData ) {
|
|
|
442
597
|
// }
|
|
443
598
|
}
|
|
444
599
|
} else {
|
|
445
|
-
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring' ].includes( getCLconfig.checkListType ) ) {
|
|
600
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall' ].includes( getCLconfig.checkListType ) ) {
|
|
446
601
|
let storeDetails = await storeService.find( { clientId: getCLconfig.client_id, status: 'active' }, { storeId: 1 } );
|
|
447
602
|
let data = {
|
|
448
603
|
checkListId: updatedchecklist._id,
|
|
@@ -468,7 +623,8 @@ async function insertData( requestData ) {
|
|
|
468
623
|
client_id: getCLconfig.client_id,
|
|
469
624
|
aiStoreList: storeDetails ? storeDetails.map( ( store ) => store.storeId ) : [],
|
|
470
625
|
};
|
|
471
|
-
await processedchecklist.create( data );
|
|
626
|
+
// await processedchecklist.create( data );
|
|
627
|
+
await processedchecklist.updateOne( { date_string: currentdate, checkListId: updatedchecklist._id, sourceCheckList_id: getCLconfig._id, checkListType: getCLconfig.checkListType }, data );
|
|
472
628
|
}
|
|
473
629
|
}
|
|
474
630
|
}
|
|
@@ -1421,3 +1577,126 @@ export async function taskPushNotification( req, res ) {
|
|
|
1421
1577
|
return res.sendError( e, 500 );
|
|
1422
1578
|
}
|
|
1423
1579
|
}
|
|
1580
|
+
|
|
1581
|
+
export async function internalSendPushNotification( req, res ) {
|
|
1582
|
+
try {
|
|
1583
|
+
let requestHeader = req.headers;
|
|
1584
|
+
if ( !( requestHeader.clientid ) ) {
|
|
1585
|
+
return res.sendError( 'clientid is Required', 400 );
|
|
1586
|
+
}
|
|
1587
|
+
if ( !( requestHeader.email || requestHeader.storeid ) ) {
|
|
1588
|
+
return res.sendError( 'Email or Storeid is Required', 400 );
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
let requestData = req.body;
|
|
1592
|
+
if ( !requestData.title ) {
|
|
1593
|
+
return res.sendError( 'Title is Required', 400 );
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
if ( !requestData.description ) {
|
|
1597
|
+
return res.sendError( 'Description is Required', 400 );
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
let fcmToken;
|
|
1601
|
+
// fcmToken = 'dwm2tz9WfUq1jdz1H8hfSf:APA91bF9BhTsG9ZDnutQfseGueXk7FZ4RhB8v3G_xJOZhkiZz8vsw3SUWk5su8ZN37lx3-H50eouBKinbwg4zE_br6f483jUswA_44f1XG8k7Sok995f77M';
|
|
1602
|
+
if ( requestHeader.email && requestHeader.email !='' ) {
|
|
1603
|
+
fcmToken = await getUserToken( requestHeader.clientid, requestHeader.email );
|
|
1604
|
+
} else {
|
|
1605
|
+
let storeData = await storeService.findOne( { clientId: requestHeader.clientid, storeId: requestHeader.storeid }, { spocDetails: 1 } );
|
|
1606
|
+
if ( storeData && storeData.spocDetails.length > 0 && storeData.spocDetails[0].email ) {
|
|
1607
|
+
fcmToken = await getUserToken( storeData.spocDetails[0].email );
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
// console.log( 'fcmToken =>', fcmToken );
|
|
1611
|
+
if ( !fcmToken ) {
|
|
1612
|
+
// return res.sendError( 'Token not found', 400 );
|
|
1613
|
+
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1614
|
+
}
|
|
1615
|
+
let responseData = await sendPushNotification( requestData.title, requestData.description, fcmToken );
|
|
1616
|
+
// console.log( 'responseData =>', responseData );
|
|
1617
|
+
if ( responseData ) {
|
|
1618
|
+
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1619
|
+
} else {
|
|
1620
|
+
// return res.sendError( 'Token not found', 400 );
|
|
1621
|
+
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1622
|
+
}
|
|
1623
|
+
} catch ( e ) {
|
|
1624
|
+
logger.error( { error: e, function: 'internalSendPushNotification' } );
|
|
1625
|
+
if ( e.name === 'ValidationError' ) res.sendBadRequest( e );
|
|
1626
|
+
else res.sendError( e, 500 );
|
|
1627
|
+
}
|
|
1628
|
+
};
|
|
1629
|
+
|
|
1630
|
+
async function getUserToken( clientId, userEmail ) {
|
|
1631
|
+
try {
|
|
1632
|
+
if ( clientId && clientId !='' && userEmail && userEmail !='' ) {
|
|
1633
|
+
let userData = await userService.findOne( { clientId: clientId, email: userEmail }, { fcmToken: 1 } );
|
|
1634
|
+
if ( userData && userData.fcmToken && userData.fcmToken !='' ) {
|
|
1635
|
+
return userData.fcmToken;
|
|
1636
|
+
} else {
|
|
1637
|
+
return false;
|
|
1638
|
+
}
|
|
1639
|
+
} else {
|
|
1640
|
+
return false;
|
|
1641
|
+
}
|
|
1642
|
+
} catch ( e ) {
|
|
1643
|
+
logger.error( { error: e, function: 'getUserToken' } );
|
|
1644
|
+
return false;
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
export async function internalAISendPushNotification( req, res ) {
|
|
1649
|
+
try {
|
|
1650
|
+
let requestData = req.body;
|
|
1651
|
+
// if ( !requestData.clientId ) {
|
|
1652
|
+
// return res.sendError( 'clientId is Required', 400 );
|
|
1653
|
+
// }
|
|
1654
|
+
if ( !( requestData?.email || requestData?.storeId ) ) {
|
|
1655
|
+
return res.sendError( 'Email or StoreId is Required', 400 );
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
if ( !requestData.title ) {
|
|
1659
|
+
return res.sendError( 'Title is Required', 400 );
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
if ( !requestData.description ) {
|
|
1663
|
+
return res.sendError( 'Description is Required', 400 );
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
let userData;
|
|
1667
|
+
if ( requestData.email && requestData.email !='' ) {
|
|
1668
|
+
// fcmToken = await getUserToken( requestData.clientId, requestData.email );
|
|
1669
|
+
// userData = await userService.findOne( { clientId: requestData.clientId, email: requestData.email }, { fcmToken: 1, loginFrom: 1 } );
|
|
1670
|
+
userData = await userService.findOne( { email: requestData.email }, { fcmToken: 1, loginFrom: 1 } );
|
|
1671
|
+
} else {
|
|
1672
|
+
// let storeData = await storeService.findOne( { clientId: requestData.clientId, storeId: requestData.storeId }, { spocDetails: 1 } );
|
|
1673
|
+
let storeData = await storeService.findOne( { storeId: requestData.storeId }, { spocDetails: 1 } );
|
|
1674
|
+
if ( storeData && storeData.spocDetails.length > 0 && storeData.spocDetails[0].email ) {
|
|
1675
|
+
// fcmToken = await getUserToken( storeData.spocDetails[0].email );
|
|
1676
|
+
// userData = await userService.findOne( { clientId: requestData.clientId, email: requestData.email }, { fcmToken: 1, loginFrom: 1 } );
|
|
1677
|
+
userData = await userService.findOne( { email: requestData.email }, { fcmToken: 1, loginFrom: 1 } );
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
if ( !userData ) {
|
|
1681
|
+
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1682
|
+
}
|
|
1683
|
+
let custom = {
|
|
1684
|
+
title: requestData.title,
|
|
1685
|
+
body: requestData.description,
|
|
1686
|
+
type: req.body?.type,
|
|
1687
|
+
storeId: req.body?.storeId,
|
|
1688
|
+
date: req.body?.date,
|
|
1689
|
+
clientId: req.body?.clientId,
|
|
1690
|
+
};
|
|
1691
|
+
let responseData = await sendAiPushNotification( userData.fcmToken, custom, userData.loginFrom );
|
|
1692
|
+
if ( responseData ) {
|
|
1693
|
+
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1694
|
+
} else {
|
|
1695
|
+
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1696
|
+
}
|
|
1697
|
+
} catch ( e ) {
|
|
1698
|
+
logger.error( { error: e, function: 'internalAISendPushNotification' } );
|
|
1699
|
+
if ( e.name === 'ValidationError' ) res.sendBadRequest( e );
|
|
1700
|
+
else res.sendError( e, 500 );
|
|
1701
|
+
}
|
|
1702
|
+
};
|