tango-app-api-trax 3.2.1 → 3.3.1-airtel-0
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 +136 -16
- package/src/controllers/gallery.controller.js +124 -31
- package/src/controllers/internalTrax.controller.js +335 -8
- package/src/controllers/mobileTrax.controller.js +200 -40
- package/src/controllers/teaxFlag.controller.js +161 -142
- package/src/controllers/trax.controller.js +1834 -319
- package/src/controllers/traxDashboard.controllers.js +350 -105
- package/src/dtos/dashboardValidation.dtos.js +2 -0
- package/src/dtos/downloadValidation.dtos.js +3 -1
- package/src/dtos/validation.dtos.js +17 -5
- package/src/hbs/login-otp.hbs +943 -943
- package/src/routes/download.router.js +2 -0
- package/src/routes/gallery.routes.js +5 -1
- package/src/routes/internalTraxApi.router.js +4 -1
- package/src/routes/mobileTrax.routes.js +3 -1
- package/src/routes/trax.routes.js +14 -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/processedchecklistconfig.services.js +1 -1
- 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' ].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
|
-
if ( allQuestion.length ) {
|
|
345
|
+
if ( allQuestion.length && getCLconfig.checkListType == 'custom' ) {
|
|
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,8 +597,19 @@ async function insertData( requestData ) {
|
|
|
442
597
|
// }
|
|
443
598
|
}
|
|
444
599
|
} else {
|
|
445
|
-
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring' ].includes( getCLconfig.checkListType ) ) {
|
|
446
|
-
let
|
|
600
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum' ].includes( getCLconfig.checkListType ) ) {
|
|
601
|
+
let storeNameList = allQuestion.map( ( item ) => item.store_id );
|
|
602
|
+
let storeDetails = await storeService.find( { clientId: getCLconfig.client_id, status: 'active', ...( [ 'storeopenandclose', 'mobileusagedetection', 'cleaning', 'scrum' ].includes( getCLconfig.checkListType ) ) ? { storeId: { $in: storeNameList } } : {} }, { storeId: 1 } );
|
|
603
|
+
let storeList = storeDetails.map( ( store ) => store.storeId );
|
|
604
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'cleaning', 'scrum' ].includes( getCLconfig.checkListType ) ) {
|
|
605
|
+
allQuestion = allQuestion.filter( ( ele ) => storeList.includes( ele?.store_id ) );
|
|
606
|
+
} else {
|
|
607
|
+
allQuestion = storeDetails.map( ( item ) => {
|
|
608
|
+
return {
|
|
609
|
+
store_id: item.storeId,
|
|
610
|
+
};
|
|
611
|
+
} );
|
|
612
|
+
}
|
|
447
613
|
let data = {
|
|
448
614
|
checkListId: updatedchecklist._id,
|
|
449
615
|
checkListName: getCLconfig.checkListName,
|
|
@@ -451,6 +617,7 @@ async function insertData( requestData ) {
|
|
|
451
617
|
date_string: currentdate,
|
|
452
618
|
allowedOverTime: getCLconfig.allowedOverTime,
|
|
453
619
|
allowedStoreLocation: getCLconfig.allowedStoreLocation,
|
|
620
|
+
checkListDescription: getCLconfig.checkListDescription,
|
|
454
621
|
scheduleStartTime: getCLconfig.scheduleStartTime,
|
|
455
622
|
scheduleStartTime_iso: startTimeIso.format(),
|
|
456
623
|
scheduleEndTime: getCLconfig.scheduleEndTime,
|
|
@@ -466,9 +633,19 @@ async function insertData( requestData ) {
|
|
|
466
633
|
scheduleRepeatedType: getCLconfig.scheduleRepeatedType,
|
|
467
634
|
storeCount: storeDetails.length,
|
|
468
635
|
client_id: getCLconfig.client_id,
|
|
469
|
-
aiStoreList:
|
|
636
|
+
aiStoreList: allQuestion.length ? allQuestion.map( ( store ) => store.store_id ) : [],
|
|
470
637
|
};
|
|
471
|
-
|
|
638
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'cleaning', 'scrum' ].includes( getCLconfig.checkListType ) ) {
|
|
639
|
+
let processData = {
|
|
640
|
+
aiStoreList: allQuestion.length ? allQuestion.map( ( store ) => {
|
|
641
|
+
return { storeName: store.storeName, storeId: store.store_id, events: store.events };
|
|
642
|
+
} ) : [],
|
|
643
|
+
aiConfig: getCLconfig?.aiConfig,
|
|
644
|
+
};
|
|
645
|
+
await PCLconfig.updateOne( { _id: updatedchecklist._id }, processData );
|
|
646
|
+
}
|
|
647
|
+
// await processedchecklist.create( data );
|
|
648
|
+
await processedchecklist.updateOne( { date_string: currentdate, checkListId: updatedchecklist._id, sourceCheckList_id: getCLconfig._id, checkListType: getCLconfig.checkListType }, data );
|
|
472
649
|
}
|
|
473
650
|
}
|
|
474
651
|
}
|
|
@@ -1277,6 +1454,37 @@ export async function getPDFCSVChecklistDetails( req, res ) {
|
|
|
1277
1454
|
}
|
|
1278
1455
|
|
|
1279
1456
|
|
|
1457
|
+
export async function AiPushNotificationAlert( req, res ) {
|
|
1458
|
+
try {
|
|
1459
|
+
console.log( req.body );
|
|
1460
|
+
let findAichecklist = await PCLconfig.findOne( { checkListType: req.body.checkListType, client_id: req.body.clientId, date_string: req.body.Date }, { aiConfig: 1 } );
|
|
1461
|
+
if ( findAichecklist.aiConfig&&findAichecklist.aiConfig.alerts&&findAichecklist.aiConfig.alerts.users&&findAichecklist.aiConfig.alerts.users.length>0 ) {
|
|
1462
|
+
console.log( findAichecklist.aiConfig.alerts.users );
|
|
1463
|
+
for ( let user of findAichecklist.aiConfig.alerts.users ) {
|
|
1464
|
+
let findOneUser = await userService.findOne( { email: user }, { fcmToken: 1 } );
|
|
1465
|
+
console.log( findOneUser );
|
|
1466
|
+
if ( findOneUser&&findOneUser.fcmToken&&findOneUser.fcmToken!='' ) {
|
|
1467
|
+
console.log( findOneUser.fcmToken );
|
|
1468
|
+
try {
|
|
1469
|
+
await sendPushNotification( req.body.title, req.body.description, findOneUser.fcmToken );
|
|
1470
|
+
} catch ( e ) {
|
|
1471
|
+
logger.error( {
|
|
1472
|
+
message: 'push notification',
|
|
1473
|
+
error: e,
|
|
1474
|
+
details: data,
|
|
1475
|
+
} );
|
|
1476
|
+
}
|
|
1477
|
+
} ;
|
|
1478
|
+
}
|
|
1479
|
+
return res.sendSuccess( 'Push notification send successfully' );
|
|
1480
|
+
}
|
|
1481
|
+
} catch ( e ) {
|
|
1482
|
+
logger.error( { function: 'AiPushNotificationAlert', error: e } );
|
|
1483
|
+
return res.sendError( e, 500 );
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
|
|
1280
1488
|
export async function taskPushNotification( req, res ) {
|
|
1281
1489
|
try {
|
|
1282
1490
|
let query = [ {
|
|
@@ -1421,3 +1629,122 @@ export async function taskPushNotification( req, res ) {
|
|
|
1421
1629
|
return res.sendError( e, 500 );
|
|
1422
1630
|
}
|
|
1423
1631
|
}
|
|
1632
|
+
|
|
1633
|
+
export async function internalSendPushNotification( req, res ) {
|
|
1634
|
+
try {
|
|
1635
|
+
let requestHeader = req.headers;
|
|
1636
|
+
if ( !( requestHeader.clientid ) ) {
|
|
1637
|
+
return res.sendError( 'clientid is Required', 400 );
|
|
1638
|
+
}
|
|
1639
|
+
if ( !( requestHeader.email || requestHeader.storeid ) ) {
|
|
1640
|
+
return res.sendError( 'Email or Storeid is Required', 400 );
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
let requestData = req.body;
|
|
1644
|
+
if ( !requestData.title ) {
|
|
1645
|
+
return res.sendError( 'Title is Required', 400 );
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
if ( !requestData.description ) {
|
|
1649
|
+
return res.sendError( 'Description is Required', 400 );
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
let fcmToken;
|
|
1653
|
+
// fcmToken = 'dwm2tz9WfUq1jdz1H8hfSf:APA91bF9BhTsG9ZDnutQfseGueXk7FZ4RhB8v3G_xJOZhkiZz8vsw3SUWk5su8ZN37lx3-H50eouBKinbwg4zE_br6f483jUswA_44f1XG8k7Sok995f77M';
|
|
1654
|
+
if ( requestHeader.email && requestHeader.email !='' ) {
|
|
1655
|
+
fcmToken = await getUserToken( requestHeader.clientid, requestHeader.email );
|
|
1656
|
+
} else {
|
|
1657
|
+
let storeData = await storeService.findOne( { clientId: requestHeader.clientid, storeId: requestHeader.storeid }, { spocDetails: 1 } );
|
|
1658
|
+
if ( storeData && storeData.spocDetails.length > 0 && storeData.spocDetails[0].email ) {
|
|
1659
|
+
fcmToken = await getUserToken( storeData.spocDetails[0].email );
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
// console.log( 'fcmToken =>', fcmToken );
|
|
1663
|
+
if ( !fcmToken ) {
|
|
1664
|
+
// return res.sendError( 'Token not found', 400 );
|
|
1665
|
+
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1666
|
+
}
|
|
1667
|
+
let responseData = await sendPushNotification( requestData.title, requestData.description, fcmToken );
|
|
1668
|
+
// console.log( 'responseData =>', responseData );
|
|
1669
|
+
if ( responseData ) {
|
|
1670
|
+
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1671
|
+
} else {
|
|
1672
|
+
// return res.sendError( 'Token not found', 400 );
|
|
1673
|
+
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1674
|
+
}
|
|
1675
|
+
} catch ( e ) {
|
|
1676
|
+
logger.error( { error: e, function: 'internalSendPushNotification' } );
|
|
1677
|
+
if ( e.name === 'ValidationError' ) res.sendBadRequest( e );
|
|
1678
|
+
else res.sendError( e, 500 );
|
|
1679
|
+
}
|
|
1680
|
+
};
|
|
1681
|
+
|
|
1682
|
+
async function getUserToken( clientId, userEmail ) {
|
|
1683
|
+
try {
|
|
1684
|
+
if ( clientId && clientId !='' && userEmail && userEmail !='' ) {
|
|
1685
|
+
let userData = await userService.findOne( { clientId: clientId, email: userEmail }, { fcmToken: 1 } );
|
|
1686
|
+
if ( userData && userData.fcmToken && userData.fcmToken !='' ) {
|
|
1687
|
+
return userData.fcmToken;
|
|
1688
|
+
} else {
|
|
1689
|
+
return false;
|
|
1690
|
+
}
|
|
1691
|
+
} else {
|
|
1692
|
+
return false;
|
|
1693
|
+
}
|
|
1694
|
+
} catch ( e ) {
|
|
1695
|
+
logger.error( { error: e, function: 'getUserToken' } );
|
|
1696
|
+
return false;
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
export async function internalAISendPushNotification( req, res ) {
|
|
1701
|
+
try {
|
|
1702
|
+
let requestData = req.body;
|
|
1703
|
+
if ( !requestData.clientId ) {
|
|
1704
|
+
return res.sendError( 'clientId is Required', 400 );
|
|
1705
|
+
}
|
|
1706
|
+
if ( !( requestData?.email || requestData?.storeId ) ) {
|
|
1707
|
+
return res.sendError( 'Email or StoreId is Required', 400 );
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
if ( !requestData.title ) {
|
|
1711
|
+
return res.sendError( 'Title is Required', 400 );
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
if ( !requestData.description ) {
|
|
1715
|
+
return res.sendError( 'Description is Required', 400 );
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
let userData;
|
|
1719
|
+
if ( requestData.email && requestData.email !='' ) {
|
|
1720
|
+
// fcmToken = await getUserToken( requestData.clientId, requestData.email );
|
|
1721
|
+
userData = await userService.findOne( { clientId: requestData.clientId, email: requestData.email }, { fcmToken: 1, loginFrom: 1 } );
|
|
1722
|
+
} else {
|
|
1723
|
+
let storeData = await storeService.findOne( { clientId: requestData.clientId, storeId: requestData.storeId }, { spocDetails: 1 } );
|
|
1724
|
+
if ( storeData && storeData.spocDetails.length > 0 && storeData.spocDetails[0].email ) {
|
|
1725
|
+
// fcmToken = await getUserToken( storeData.spocDetails[0].email );
|
|
1726
|
+
userData = await userService.findOne( { clientId: requestData.clientId, email: requestData.email }, { fcmToken: 1, loginFrom: 1 } );
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
if ( !userData ) {
|
|
1730
|
+
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1731
|
+
}
|
|
1732
|
+
let custom = {
|
|
1733
|
+
title: requestData.title,
|
|
1734
|
+
body: requestData.description,
|
|
1735
|
+
type: req.body?.type,
|
|
1736
|
+
storeId: req.body?.storeId,
|
|
1737
|
+
date: req.body?.date,
|
|
1738
|
+
};
|
|
1739
|
+
let responseData = await sendAiPushNotification( userData.fcmToken, custom, userData.loginFrom );
|
|
1740
|
+
if ( responseData ) {
|
|
1741
|
+
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1742
|
+
} else {
|
|
1743
|
+
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1744
|
+
}
|
|
1745
|
+
} catch ( e ) {
|
|
1746
|
+
logger.error( { error: e, function: 'internalAISendPushNotification' } );
|
|
1747
|
+
if ( e.name === 'ValidationError' ) res.sendBadRequest( e );
|
|
1748
|
+
else res.sendError( e, 500 );
|
|
1749
|
+
}
|
|
1750
|
+
};
|