tango-app-api-trax 3.3.1-hotfix-22 → 3.3.1-hotfix-24
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 +2 -2
- package/src/controllers/download.controller.js +30 -13
- package/src/controllers/internalTrax.controller.js +15 -63
- package/src/controllers/mobileTrax.controller.js +2 -2
- package/src/controllers/trax.controller.js +15 -194
- package/src/dtos/downloadValidation.dtos.js +1 -0
- package/src/hbs/login-otp.hbs +943 -943
- package/src/routes/download.router.js +2 -0
- package/src/routes/internalTraxApi.router.js +0 -1
- package/src/routes/trax.routes.js +1 -3
- package/src/services/processedchecklistconfig.services.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-trax",
|
|
3
|
-
"version": "3.3.1-hotfix-
|
|
3
|
+
"version": "3.3.1-hotfix-24",
|
|
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.
|
|
29
|
+
"tango-api-schema": "^2.2.93",
|
|
30
30
|
"tango-app-api-middleware": "^3.1.70",
|
|
31
31
|
"url": "^0.11.4",
|
|
32
32
|
"winston": "^3.13.1",
|
|
@@ -5,6 +5,7 @@ import * as processedchecklistService from '../services/processedchecklist.servi
|
|
|
5
5
|
import * as processedTaskService from '../services/processedTaskList.service.js';
|
|
6
6
|
import * as taskConfigService from '../services/taskConfig.service.js';
|
|
7
7
|
import * as checklistService from '../services/checklist.service.js';
|
|
8
|
+
// import * as processedTaskconfigService from '../services/processedTaskConfig.service.js';
|
|
8
9
|
import * as processedcheklistconfigService from '../services/processedchecklistconfig.services.js';
|
|
9
10
|
import * as clientService from '../services/clients.services.js';
|
|
10
11
|
import * as storeService from '../services/store.service.js';
|
|
@@ -145,7 +146,6 @@ export const downloadInsert = async ( req, res ) => {
|
|
|
145
146
|
'filtertype': requestData.filtertype || 'Clusters',
|
|
146
147
|
'checkListType': requestData.checkListType,
|
|
147
148
|
};
|
|
148
|
-
console.log( insertData );
|
|
149
149
|
let resultData = await downloadService.insert( insertData );
|
|
150
150
|
if ( resultData ) {
|
|
151
151
|
let sqsMessageRequestData = {
|
|
@@ -177,8 +177,6 @@ export const downloadInsertAI = async ( req, res ) => {
|
|
|
177
177
|
let requestData = req.body;
|
|
178
178
|
let name;
|
|
179
179
|
let fileType = requestData?.fileType || 'pdfzip';
|
|
180
|
-
|
|
181
|
-
|
|
182
180
|
if ( requestData.fileType == 'pdf' ) {
|
|
183
181
|
if ( requestData?.sourceCheckList_id && requestData?.sourceCheckList_id != '' ) {
|
|
184
182
|
fileType = 'pdfzip';
|
|
@@ -187,7 +185,6 @@ export const downloadInsertAI = async ( req, res ) => {
|
|
|
187
185
|
fileType = 'pdfzip';
|
|
188
186
|
}
|
|
189
187
|
}
|
|
190
|
-
|
|
191
188
|
if ( requestData.checklistName != '' ) {
|
|
192
189
|
name = requestData.checklistName + '_' + dayjs( requestData.fromDate ).format( 'DD/MM/YYYY' );
|
|
193
190
|
if ( requestData?.toDate ) {
|
|
@@ -202,10 +199,7 @@ export const downloadInsertAI = async ( req, res ) => {
|
|
|
202
199
|
} else {
|
|
203
200
|
name = requestData?.checklistName;
|
|
204
201
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
202
|
let findchecklist = await processedcheklistconfigService.findOne( { 'checkListType': requestData.checkListType, 'client_id': requestData.clientId } ).sort( { _id: -1 } );
|
|
208
|
-
|
|
209
203
|
console.log( findchecklist );
|
|
210
204
|
name = name + '-' + requestData.fileType;
|
|
211
205
|
let insertData = {
|
|
@@ -236,28 +230,26 @@ export const downloadInsertAI = async ( req, res ) => {
|
|
|
236
230
|
'checkListType': requestData.checkListType,
|
|
237
231
|
'checkListName': findchecklist.checkListName,
|
|
238
232
|
'checkListDescription': findchecklist.checkListDescription,
|
|
239
|
-
|
|
240
233
|
};
|
|
241
234
|
console.log( requestData );
|
|
242
235
|
console.log( insertData );
|
|
243
|
-
|
|
244
236
|
let resultData = await downloadService.insert( insertData );
|
|
237
|
+
console.log( resultData );
|
|
245
238
|
if ( resultData ) {
|
|
246
239
|
let sqsMessageRequestData = {
|
|
247
240
|
'zipId': resultData._id,
|
|
248
241
|
'fileType': fileType || 'zip',
|
|
249
242
|
'storeId': requestData.storeIds || [],
|
|
250
243
|
};
|
|
244
|
+
console.log( sqsMessageRequestData );
|
|
251
245
|
if ( fileType === 'csv' || fileType === 'pdf' || fileType === 'csvzip' || fileType === 'pdfzip' || fileType === 'zipfiles' ) {
|
|
252
246
|
const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).AIchecklistExport}`, JSON.stringify( sqsMessageRequestData ) );
|
|
253
247
|
console.log( 'Send SQS Message CSV/PDF=>', msg );
|
|
254
248
|
}
|
|
255
|
-
|
|
256
249
|
if ( fileType === 'ppt' || fileType === 'pptzip' ) {
|
|
257
250
|
const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).AIchecklistExport}`, JSON.stringify( sqsMessageRequestData ) );
|
|
258
251
|
console.log( 'Send SQS Message PPT=>', msg );
|
|
259
252
|
}
|
|
260
|
-
|
|
261
253
|
res.sendSuccess( 'Success' );
|
|
262
254
|
} else {
|
|
263
255
|
return res.sendError( 'something went wrong, please try again', 500 );
|
|
@@ -267,7 +259,6 @@ export const downloadInsertAI = async ( req, res ) => {
|
|
|
267
259
|
return res.sendError( e, 500 );
|
|
268
260
|
}
|
|
269
261
|
};
|
|
270
|
-
|
|
271
262
|
export const downloadInsertOld = async ( req, res ) => {
|
|
272
263
|
try {
|
|
273
264
|
let requestData = req.body;
|
|
@@ -578,7 +569,33 @@ export const getChecklistFromZipId = async ( req, res ) => {
|
|
|
578
569
|
return res.sendError( error, 500 );
|
|
579
570
|
}
|
|
580
571
|
};
|
|
581
|
-
|
|
572
|
+
export const getAiChecklistDataFromZipId = async ( req, res ) => {
|
|
573
|
+
try {
|
|
574
|
+
let reqquery = req.query;
|
|
575
|
+
let getzipdata = await downloadService.findOne( { _id: new mongoose.Types.ObjectId( reqquery.zipId ) } );
|
|
576
|
+
let brandInfo = {
|
|
577
|
+
clientName: '',
|
|
578
|
+
brandLogo: '',
|
|
579
|
+
checkListDescription: '',
|
|
580
|
+
};
|
|
581
|
+
if ( getzipdata ) {
|
|
582
|
+
let getClientData = await clientService.findOne( { clientId: getzipdata.client_id } );
|
|
583
|
+
if ( getClientData ) {
|
|
584
|
+
brandInfo.clientName = getClientData.clientName;
|
|
585
|
+
brandInfo.brandLogo = getzipdata.client_id + '/logo/' + getClientData.profileDetails.logo;
|
|
586
|
+
}
|
|
587
|
+
getzipdata.brandInfo = brandInfo;
|
|
588
|
+
console.log( getzipdata );
|
|
589
|
+
return res.sendSuccess( getzipdata );
|
|
590
|
+
} else {
|
|
591
|
+
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
592
|
+
}
|
|
593
|
+
} catch ( error ) {
|
|
594
|
+
console.log( 'error =>', error );
|
|
595
|
+
logger.error( { error: error, function: 'getChecklistFromZipId' } );
|
|
596
|
+
return res.sendError( error, 500 );
|
|
597
|
+
}
|
|
598
|
+
};
|
|
582
599
|
export const getPDFCSVChecklistDetails = async ( req, res ) => {
|
|
583
600
|
try {
|
|
584
601
|
let requestData = req.body;
|
|
@@ -304,7 +304,7 @@ async function insertData( requestData ) {
|
|
|
304
304
|
},
|
|
305
305
|
} );
|
|
306
306
|
let getSections = await CLquestions.aggregate( sectionQuery );
|
|
307
|
-
if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum' ].includes( getCLconfig.checkListType ) ) {
|
|
307
|
+
if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall' ].includes( getCLconfig.checkListType ) ) {
|
|
308
308
|
if ( getSections.length ) {
|
|
309
309
|
for ( let element3 of getSections ) {
|
|
310
310
|
let collectQuestions = {};
|
|
@@ -342,7 +342,7 @@ async function insertData( requestData ) {
|
|
|
342
342
|
},
|
|
343
343
|
} );
|
|
344
344
|
let allQuestion = await CLassign.aggregate( getquestionQuery );
|
|
345
|
-
if ( allQuestion.length
|
|
345
|
+
if ( allQuestion.length ) {
|
|
346
346
|
let assignList = [];
|
|
347
347
|
if ( getCLconfig.coverage == 'store' ) {
|
|
348
348
|
let clusterList = allQuestion.filter( ( ele ) => ele?.clusterName ).map( ( item ) => item.assignId );
|
|
@@ -597,19 +597,8 @@ async function insertData( requestData ) {
|
|
|
597
597
|
// }
|
|
598
598
|
}
|
|
599
599
|
} else {
|
|
600
|
-
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum' ].includes( getCLconfig.checkListType ) ) {
|
|
601
|
-
let
|
|
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
|
-
}
|
|
600
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall' ].includes( getCLconfig.checkListType ) ) {
|
|
601
|
+
let storeDetails = await storeService.find( { clientId: getCLconfig.client_id, status: 'active' }, { storeId: 1 } );
|
|
613
602
|
let data = {
|
|
614
603
|
checkListId: updatedchecklist._id,
|
|
615
604
|
checkListName: getCLconfig.checkListName,
|
|
@@ -617,7 +606,6 @@ async function insertData( requestData ) {
|
|
|
617
606
|
date_string: currentdate,
|
|
618
607
|
allowedOverTime: getCLconfig.allowedOverTime,
|
|
619
608
|
allowedStoreLocation: getCLconfig.allowedStoreLocation,
|
|
620
|
-
checkListDescription: getCLconfig.checkListDescription,
|
|
621
609
|
scheduleStartTime: getCLconfig.scheduleStartTime,
|
|
622
610
|
scheduleStartTime_iso: startTimeIso.format(),
|
|
623
611
|
scheduleEndTime: getCLconfig.scheduleEndTime,
|
|
@@ -633,17 +621,8 @@ async function insertData( requestData ) {
|
|
|
633
621
|
scheduleRepeatedType: getCLconfig.scheduleRepeatedType,
|
|
634
622
|
storeCount: storeDetails.length,
|
|
635
623
|
client_id: getCLconfig.client_id,
|
|
636
|
-
aiStoreList:
|
|
624
|
+
aiStoreList: storeDetails ? storeDetails.map( ( store ) => store.storeId ) : [],
|
|
637
625
|
};
|
|
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
626
|
// await processedchecklist.create( data );
|
|
648
627
|
await processedchecklist.updateOne( { date_string: currentdate, checkListId: updatedchecklist._id, sourceCheckList_id: getCLconfig._id, checkListType: getCLconfig.checkListType }, data );
|
|
649
628
|
}
|
|
@@ -1454,37 +1433,6 @@ export async function getPDFCSVChecklistDetails( req, res ) {
|
|
|
1454
1433
|
}
|
|
1455
1434
|
|
|
1456
1435
|
|
|
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
|
-
|
|
1488
1436
|
export async function taskPushNotification( req, res ) {
|
|
1489
1437
|
try {
|
|
1490
1438
|
let query = [ {
|
|
@@ -1700,9 +1648,9 @@ async function getUserToken( clientId, userEmail ) {
|
|
|
1700
1648
|
export async function internalAISendPushNotification( req, res ) {
|
|
1701
1649
|
try {
|
|
1702
1650
|
let requestData = req.body;
|
|
1703
|
-
if ( !requestData.clientId ) {
|
|
1704
|
-
|
|
1705
|
-
}
|
|
1651
|
+
// if ( !requestData.clientId ) {
|
|
1652
|
+
// return res.sendError( 'clientId is Required', 400 );
|
|
1653
|
+
// }
|
|
1706
1654
|
if ( !( requestData?.email || requestData?.storeId ) ) {
|
|
1707
1655
|
return res.sendError( 'Email or StoreId is Required', 400 );
|
|
1708
1656
|
}
|
|
@@ -1718,12 +1666,15 @@ export async function internalAISendPushNotification( req, res ) {
|
|
|
1718
1666
|
let userData;
|
|
1719
1667
|
if ( requestData.email && requestData.email !='' ) {
|
|
1720
1668
|
// fcmToken = await getUserToken( requestData.clientId, requestData.email );
|
|
1721
|
-
userData = await userService.findOne( { clientId: requestData.clientId, email: requestData.email }, { fcmToken: 1, loginFrom: 1 } );
|
|
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 } );
|
|
1722
1671
|
} else {
|
|
1723
|
-
let storeData = await storeService.findOne( { clientId: requestData.clientId, storeId: requestData.storeId }, { spocDetails: 1 } );
|
|
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 } );
|
|
1724
1674
|
if ( storeData && storeData.spocDetails.length > 0 && storeData.spocDetails[0].email ) {
|
|
1725
1675
|
// fcmToken = await getUserToken( storeData.spocDetails[0].email );
|
|
1726
|
-
userData = await userService.findOne( { clientId: requestData.clientId, email: requestData.email }, { fcmToken: 1, loginFrom: 1 } );
|
|
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 } );
|
|
1727
1678
|
}
|
|
1728
1679
|
}
|
|
1729
1680
|
if ( !userData ) {
|
|
@@ -1735,6 +1686,7 @@ export async function internalAISendPushNotification( req, res ) {
|
|
|
1735
1686
|
type: req.body?.type,
|
|
1736
1687
|
storeId: req.body?.storeId,
|
|
1737
1688
|
date: req.body?.date,
|
|
1689
|
+
clientId: req.body?.clientId,
|
|
1738
1690
|
};
|
|
1739
1691
|
let responseData = await sendAiPushNotification( userData.fcmToken, custom, userData.loginFrom );
|
|
1740
1692
|
if ( responseData ) {
|
|
@@ -3397,8 +3397,8 @@ export async function clientConfig( req, res ) {
|
|
|
3397
3397
|
try {
|
|
3398
3398
|
let requestData = req.body;
|
|
3399
3399
|
if ( requestData.clientId && requestData.clientId !='' ) {
|
|
3400
|
-
let getClientData = await clientService.findOne( { clientId: requestData.clientId }, { traxRAWImageUpload: 1, clientId: 1, clientName: 1 } );
|
|
3401
|
-
console.log( ' getClientData=>', getClientData );
|
|
3400
|
+
let getClientData = await clientService.findOne( { clientId: requestData.clientId }, { traxRAWImageUpload: 1, clientId: 1, clientName: 1, traxBlockMobileTimeUpdate: 1 } );
|
|
3401
|
+
// console.log( ' getClientData=>', getClientData );
|
|
3402
3402
|
if ( getClientData ) {
|
|
3403
3403
|
return res.sendSuccess( getClientData );
|
|
3404
3404
|
} else {
|
|
@@ -2041,7 +2041,7 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2041
2041
|
{
|
|
2042
2042
|
$project: {
|
|
2043
2043
|
newEmail: { $toLower: '$email' },
|
|
2044
|
-
isActive: 1,
|
|
2044
|
+
// isActive: 1,
|
|
2045
2045
|
clientId: 1,
|
|
2046
2046
|
email: 1,
|
|
2047
2047
|
},
|
|
@@ -2049,7 +2049,7 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2049
2049
|
{
|
|
2050
2050
|
$match: {
|
|
2051
2051
|
newEmail: { $in: userEmailList },
|
|
2052
|
-
isActive: true,
|
|
2052
|
+
// isActive: true,
|
|
2053
2053
|
clientId: { $ne: req.body.clientId },
|
|
2054
2054
|
},
|
|
2055
2055
|
},
|
|
@@ -2091,7 +2091,7 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2091
2091
|
let newStoreList = storeList.filter( ( ele ) => ele != null && !existsStore.includes( ele.toLowerCase() ) );
|
|
2092
2092
|
if ( req.body.coverage == 'store' ) {
|
|
2093
2093
|
assignDetails.forEach( ( item ) => {
|
|
2094
|
-
let getStoreDetails = storeDetails.find( ( store ) => store.storeName.toLowerCase() == item.storeName.trim().toLowerCase() );
|
|
2094
|
+
let getStoreDetails = storeDetails.find( ( store ) => store.storeName.trim().toLowerCase() == item.storeName.trim().toLowerCase() );
|
|
2095
2095
|
if ( getStoreDetails ) {
|
|
2096
2096
|
let storeUserDetails = userDetails.find( ( ele ) => ele.newEmail.toLowerCase() == item.userEmail.toLowerCase() );
|
|
2097
2097
|
item._id = getStoreDetails._id;
|
|
@@ -2113,6 +2113,10 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2113
2113
|
}
|
|
2114
2114
|
|
|
2115
2115
|
if ( ( newUserList.length || newStoreList.length || existEmail.length || inActiveStores.length ) && !req.body?.addUser ) {
|
|
2116
|
+
newStoreList = [ ...new Set( newStoreList.map( ( item ) => item ) ) ];
|
|
2117
|
+
newUserList = [ ...new Set( newUserList.map( ( item ) => item ) ) ];
|
|
2118
|
+
existEmail = [ ...new Set( existEmail.map( ( item ) => item ) ) ];
|
|
2119
|
+
inActiveStores = [ ...new Set( inActiveStores.map( ( item ) => item ) ) ];
|
|
2116
2120
|
return res.sendError( { validate: false, user: newUserList, store: newStoreList, existEmail, inActiveStores, data: assignDetails }, 400 );
|
|
2117
2121
|
}
|
|
2118
2122
|
await Promise.all( newUserList.map( async ( ele ) => {
|
|
@@ -3426,11 +3430,11 @@ async function updateOpenSearch( user, data ) {
|
|
|
3426
3430
|
export const aiChecklist = async ( req, res ) => {
|
|
3427
3431
|
try {
|
|
3428
3432
|
let storeDetails = await storeService.count( { clientId: req.query.clientId, status: 'active' } );
|
|
3429
|
-
let aiList = [ 'mobileusagedetection', 'storeopenandclose', 'uniformdetection', 'staffleftinthemiddle', 'customerunattended', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum' ];
|
|
3433
|
+
let aiList = [ 'mobileusagedetection', 'storeopenandclose', 'uniformdetection', 'staffleftinthemiddle', 'customerunattended', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall' ];
|
|
3430
3434
|
let checklistDetails = [];
|
|
3431
3435
|
let publishList = [];
|
|
3432
3436
|
let unpublishList = [];
|
|
3433
|
-
publishList = await checklistService.find( { client_id: req.query.clientId, checkListType: { $in: aiList } }, { publish: 1, checkListName: 1, checkListType: 1, client_id: 1, checkListDescription: 1
|
|
3437
|
+
publishList = await checklistService.find( { client_id: req.query.clientId, checkListType: { $in: aiList } }, { publish: 1, checkListName: 1, checkListType: 1, client_id: 1, checkListDescription: 1 } );
|
|
3434
3438
|
if ( publishList.length ) {
|
|
3435
3439
|
let existList = publishList.map( ( item ) => item.checkListType );
|
|
3436
3440
|
aiList = aiList.filter( ( item ) => !existList.includes( item ) );
|
|
@@ -3439,9 +3443,7 @@ export const aiChecklist = async ( req, res ) => {
|
|
|
3439
3443
|
checklistDetails = [ ...publishList, ...unpublishList ];
|
|
3440
3444
|
|
|
3441
3445
|
checklistDetails.forEach( ( item ) => {
|
|
3442
|
-
|
|
3443
|
-
item.storeCount = storeDetails;
|
|
3444
|
-
}
|
|
3446
|
+
item.storeCount = storeDetails;
|
|
3445
3447
|
} );
|
|
3446
3448
|
|
|
3447
3449
|
return res.sendSuccess( checklistDetails );
|
|
@@ -3635,8 +3637,6 @@ export const selectAssign = async ( req, res ) => {
|
|
|
3635
3637
|
userEmail: { $arrayElemAt: [ '$spocDetails.email', 0 ] },
|
|
3636
3638
|
contact: { $arrayElemAt: [ '$spocDetails.contact', 0 ] },
|
|
3637
3639
|
city: '$storeProfile.city',
|
|
3638
|
-
openTime: '$storeProfile.open',
|
|
3639
|
-
closeTime: '$storeProfile.close',
|
|
3640
3640
|
},
|
|
3641
3641
|
},
|
|
3642
3642
|
|
|
@@ -3810,7 +3810,8 @@ export async function updateAssign( req, res ) {
|
|
|
3810
3810
|
},
|
|
3811
3811
|
];
|
|
3812
3812
|
let assignUserDetails = await userService.aggregate( query );
|
|
3813
|
-
|
|
3813
|
+
for ( let assign of req.body.assignedList ) {
|
|
3814
|
+
// await Promise.all( req.body.assignedList.map( async ( assign ) => {
|
|
3814
3815
|
let userDetails = assignUserDetails.find( ( ele ) => ele.email.toLowerCase() == assign.userEmail.toLowerCase() );
|
|
3815
3816
|
if ( !userDetails ) {
|
|
3816
3817
|
let userData = {
|
|
@@ -3824,6 +3825,7 @@ export async function updateAssign( req, res ) {
|
|
|
3824
3825
|
}
|
|
3825
3826
|
let data = {
|
|
3826
3827
|
...assign,
|
|
3828
|
+
userEmail: userDetails?.email,
|
|
3827
3829
|
store_id: assign?.storeId,
|
|
3828
3830
|
client_id: req.body.clientId,
|
|
3829
3831
|
checkListId: req.body.checkListId,
|
|
@@ -3834,7 +3836,8 @@ export async function updateAssign( req, res ) {
|
|
|
3834
3836
|
};
|
|
3835
3837
|
delete data._id;
|
|
3836
3838
|
assignedUserList.push( data );
|
|
3837
|
-
} ) );
|
|
3839
|
+
// } ) );
|
|
3840
|
+
}
|
|
3838
3841
|
let assignGroupDetails = [];
|
|
3839
3842
|
if ( req.body.coverage == 'store' ) {
|
|
3840
3843
|
assignGroupDetails = await clusterServices.findcluster( { _id: { $in: req.body.assignedGroup } } );
|
|
@@ -3862,185 +3865,3 @@ export async function updateAssign( req, res ) {
|
|
|
3862
3865
|
return res.sendError( e, 500 );
|
|
3863
3866
|
}
|
|
3864
3867
|
}
|
|
3865
|
-
|
|
3866
|
-
export async function updateAiConfigure( req, res ) {
|
|
3867
|
-
try {
|
|
3868
|
-
if ( !req.body.storeList.length && req.body.publish ) {
|
|
3869
|
-
return res.sendError( 'Please assign a store', 400 );
|
|
3870
|
-
}
|
|
3871
|
-
let query;
|
|
3872
|
-
query = req.body.type ? { checkListType: req.body.type, client_id: { $exists: false } } : { _id: req.body.id, client_id: req.body.clientId };
|
|
3873
|
-
let aiChecklistDetails = await checklistService.findOne( query );
|
|
3874
|
-
if ( aiChecklistDetails ) {
|
|
3875
|
-
let details = {
|
|
3876
|
-
checkListName: aiChecklistDetails.checkListName,
|
|
3877
|
-
checkListDescription: aiChecklistDetails.checkListDescription,
|
|
3878
|
-
client_id: req.body.clientId,
|
|
3879
|
-
publish: req.body.publish,
|
|
3880
|
-
aiConfig: req.body.aiConfig,
|
|
3881
|
-
createdBy: req.user._id,
|
|
3882
|
-
createdByName: req.user.userName,
|
|
3883
|
-
questionCount: 0,
|
|
3884
|
-
storeCount: req.body.storeList.length,
|
|
3885
|
-
type: 'checklist',
|
|
3886
|
-
checkListType: aiChecklistDetails.checkListType,
|
|
3887
|
-
schedule: 'daily',
|
|
3888
|
-
...( req.body.publish ) ? { publishDate: new Date() } :{},
|
|
3889
|
-
approver: req.body?.approver || [],
|
|
3890
|
-
scheduleRepeatedDay: [ '01' ],
|
|
3891
|
-
scheduleStartTime: '06:00 AM',
|
|
3892
|
-
scheduleEndTime: '11:59 PM',
|
|
3893
|
-
};
|
|
3894
|
-
let aiResponse = await checklistService.updateOne( { checkListType: aiChecklistDetails.checkListType, client_id: req.body.clientId }, details );
|
|
3895
|
-
let checklistId = req.body?.id || aiResponse?.upsertedId;
|
|
3896
|
-
if ( req.body.storeList ) {
|
|
3897
|
-
let storeData = [];
|
|
3898
|
-
req.body.storeList.forEach( ( ele ) => {
|
|
3899
|
-
let eventTime = [];
|
|
3900
|
-
Object.keys( ele ).forEach( ( key ) => {
|
|
3901
|
-
let keyValue ={};
|
|
3902
|
-
if ( req.body.aiConfig?.assignConfig && req.body.aiConfig?.assignConfig == 'store' && key.includes( 'startTime' ) ) {
|
|
3903
|
-
let num = key.slice( -1 );
|
|
3904
|
-
keyValue['time'] = ele[key];
|
|
3905
|
-
keyValue['duration'] = ele[`configTime${num}`];
|
|
3906
|
-
eventTime.push( keyValue );
|
|
3907
|
-
}
|
|
3908
|
-
} );
|
|
3909
|
-
if ( req.body.aiConfig?.assignConfig && req.body.aiConfig?.assignConfig == 'global' ) {
|
|
3910
|
-
req.body.aiConfig.events.forEach( ( event ) => {
|
|
3911
|
-
let keyValue ={};
|
|
3912
|
-
keyValue['time'] = event.time;
|
|
3913
|
-
keyValue['duration'] = event.duration;
|
|
3914
|
-
eventTime.push( keyValue );
|
|
3915
|
-
} );
|
|
3916
|
-
}
|
|
3917
|
-
storeData.push( {
|
|
3918
|
-
storeName: ele.storeName,
|
|
3919
|
-
...( req.body.aiConfig?.assignConfig ) ? { events: eventTime } : { events: [] },
|
|
3920
|
-
checkListId: checklistId,
|
|
3921
|
-
client_id: req.body.clientId,
|
|
3922
|
-
checkListName: aiChecklistDetails.checkListName,
|
|
3923
|
-
store_id: ele.storeId,
|
|
3924
|
-
assignId: ele._id,
|
|
3925
|
-
} );
|
|
3926
|
-
} );
|
|
3927
|
-
await assignedService.deleteMany( { checkListId: checklistId } );
|
|
3928
|
-
await assignedService.insertMany( storeData );
|
|
3929
|
-
if ( req.body.publish ) {
|
|
3930
|
-
let processedData = {
|
|
3931
|
-
client_id: req.body.clientId,
|
|
3932
|
-
date_iso: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
|
|
3933
|
-
date_string: dayjs().format( 'YYYY-MM-DD' ),
|
|
3934
|
-
sourceCheckList_id: checklistId,
|
|
3935
|
-
checkListName: aiChecklistDetails.checkListName,
|
|
3936
|
-
checkListDescription: aiChecklistDetails.checkListDescription,
|
|
3937
|
-
scheduleStartTime: '06:00 AM',
|
|
3938
|
-
scheduleEndTime: '11:59 PM',
|
|
3939
|
-
scheduleStartTime_iso: dayjs.utc( '06:00 AM', 'hh:mm A' ).format(),
|
|
3940
|
-
scheduleEndTime_iso: dayjs.utc( '11:59 PM', 'hh:mm A' ).format(),
|
|
3941
|
-
allowedOverTime: false,
|
|
3942
|
-
allowedStoreLocation: false,
|
|
3943
|
-
createdBy: req.user._id,
|
|
3944
|
-
createdByName: req.user.userName,
|
|
3945
|
-
questionAnswers: [],
|
|
3946
|
-
isdeleted: false,
|
|
3947
|
-
questionCount: 0,
|
|
3948
|
-
storeCount: req.body.storeList.length,
|
|
3949
|
-
publishDate: details?.publishDate,
|
|
3950
|
-
locationCount: 1,
|
|
3951
|
-
checkListType: aiChecklistDetails.checkListType,
|
|
3952
|
-
scheduleRepeatedType: 'daily',
|
|
3953
|
-
aiStoreList: storeData.length? storeData.map( ( store ) => {
|
|
3954
|
-
return { storeName: store.storeName, events: store.events, storeId: store.store_id };
|
|
3955
|
-
} ) : [],
|
|
3956
|
-
aiConfig: req.body.aiConfig,
|
|
3957
|
-
approver: req.body?.approver || [],
|
|
3958
|
-
};
|
|
3959
|
-
let configResponse = await processedchecklistConfig.updateOne( { date_string: dayjs().format( 'YYYY-MM-DD' ), sourceCheckList_id: checklistId, checkListType: aiChecklistDetails.checkListType }, processedData );
|
|
3960
|
-
let data = {
|
|
3961
|
-
...( configResponse?.upsertedId ) ? { checkListId: configResponse?.upsertedId } : {},
|
|
3962
|
-
checkListName: aiChecklistDetails.checkListName,
|
|
3963
|
-
checkListDescription: aiChecklistDetails.checkListDescription,
|
|
3964
|
-
date_iso: new Date( dayjs().format( 'YYYY-MM-DD' ) ),
|
|
3965
|
-
date_string: dayjs().format( 'YYYY-MM-DD' ),
|
|
3966
|
-
allowedOverTime: false,
|
|
3967
|
-
allowedStoreLocation: false,
|
|
3968
|
-
scheduleStartTime: '06:00 AM',
|
|
3969
|
-
scheduleStartTime_iso: dayjs.utc( '06:00 AM', 'hh:mm A' ).format(),
|
|
3970
|
-
scheduleEndTime: '11:59 PM',
|
|
3971
|
-
scheduleEndTime_iso: dayjs.utc( '11:59 PM', 'hh:mm A' ).format(),
|
|
3972
|
-
createdBy: req.user._id,
|
|
3973
|
-
createdByName: req.user.userName,
|
|
3974
|
-
sourceCheckList_id: checklistId,
|
|
3975
|
-
checkListType: aiChecklistDetails.checkListType,
|
|
3976
|
-
storeCount: req.body.storeList.length,
|
|
3977
|
-
questionCount: 0,
|
|
3978
|
-
publishDate: new Date(),
|
|
3979
|
-
locationCount: 0,
|
|
3980
|
-
scheduleRepeatedType: 'daily',
|
|
3981
|
-
client_id: req.body.clientId,
|
|
3982
|
-
aiStoreList: req.body.storeList ? req.body.storeList.map( ( store ) => store.storeId ) : [],
|
|
3983
|
-
};
|
|
3984
|
-
await processedchecklist.updateOne( { date_string: dayjs().format( 'YYYY-MM-DD' ), sourceCheckList_id: checklistId, checkListType: aiChecklistDetails.checkListType }, data );
|
|
3985
|
-
}
|
|
3986
|
-
}
|
|
3987
|
-
return res.sendSuccess( 'Checklist updated successfully' );
|
|
3988
|
-
} else {
|
|
3989
|
-
return res.sendError( 'No data found', 204 );
|
|
3990
|
-
}
|
|
3991
|
-
} catch ( e ) {
|
|
3992
|
-
logger.error( { functionName: 'updateAiConfigure', error: e } );
|
|
3993
|
-
return res.sendError( e, 500 );
|
|
3994
|
-
}
|
|
3995
|
-
}
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
export async function getAiDetails( req, res ) {
|
|
3999
|
-
try {
|
|
4000
|
-
let storeList = [];
|
|
4001
|
-
if ( !req.query.id && !req.query.type ) {
|
|
4002
|
-
return res.sendError( 'Type/Id is required', 400 );
|
|
4003
|
-
}
|
|
4004
|
-
let query = req.query.type ? { checkListType: req.query.type, client_id: { $exists: false } } : { _id: req.query.id, client_id: req.query.clientId };
|
|
4005
|
-
let checklistDetails = await checklistService.findOne( query );
|
|
4006
|
-
if ( !checklistDetails ) {
|
|
4007
|
-
return res.sendError( 'No data found', 204 );
|
|
4008
|
-
}
|
|
4009
|
-
if ( req.query?.id ) {
|
|
4010
|
-
storeList = await assignedService.find( { checkListId: req.query?.id } );
|
|
4011
|
-
let data = [];
|
|
4012
|
-
await Promise.all( ( storeList.map( async ( ele ) => {
|
|
4013
|
-
let element = {};
|
|
4014
|
-
element['storeName'] = ele.storeName,
|
|
4015
|
-
element['store_id'] = ele.store_id;
|
|
4016
|
-
element['_id'] = ele.assignId;
|
|
4017
|
-
let getStoreDetails = await storeService.findOne( { storeId: ele.store_id, status: 'active', clientId: req.query.clientId } );
|
|
4018
|
-
if ( getStoreDetails ) {
|
|
4019
|
-
element['openTime'] = getStoreDetails?.storeProfile?.open;
|
|
4020
|
-
element['closeTime'] = getStoreDetails?.storeProfile?.close;
|
|
4021
|
-
}
|
|
4022
|
-
if ( [ 'cleaning', 'scrum' ].includes( checklistDetails.checkListType ) && checklistDetails?.aiConfig?.assignConfig == 'store' ) {
|
|
4023
|
-
ele.events.forEach( ( event, index ) => {
|
|
4024
|
-
element[`startTime${index+1}`] = event.time;
|
|
4025
|
-
element[`configTime${index+1}`] = event.duration;
|
|
4026
|
-
} );
|
|
4027
|
-
}
|
|
4028
|
-
data.push( element );
|
|
4029
|
-
} ) ) );
|
|
4030
|
-
storeList = data;
|
|
4031
|
-
}
|
|
4032
|
-
|
|
4033
|
-
let response = {
|
|
4034
|
-
checkListName: checklistDetails?.checkListName,
|
|
4035
|
-
checkListDescription: checklistDetails?.checkListDescription,
|
|
4036
|
-
publish: checklistDetails?.publish,
|
|
4037
|
-
aiConfig: checklistDetails?.aiConfig,
|
|
4038
|
-
storeList: storeList,
|
|
4039
|
-
approver: checklistDetails?.approver,
|
|
4040
|
-
};
|
|
4041
|
-
return res.sendSuccess( response );
|
|
4042
|
-
} catch ( e ) {
|
|
4043
|
-
logger.error( { functionName: getAiDetails, error: e } );
|
|
4044
|
-
return res.sendError( e, 500 );
|
|
4045
|
-
}
|
|
4046
|
-
}
|
|
@@ -26,6 +26,7 @@ export const validateDownloadInsertSchema = joi.object( {
|
|
|
26
26
|
filter: joi.string().optional().allow( '' ),
|
|
27
27
|
filtertype: joi.string().optional().allow( '' ),
|
|
28
28
|
checkListType: joi.string().required(),
|
|
29
|
+
|
|
29
30
|
} );
|
|
30
31
|
|
|
31
32
|
export const validateDownloadInsertParams = {
|