tango-app-api-trax 3.4.1-alpha-19 → 3.4.1-alpha-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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-trax",
3
- "version": "3.4.1-alpha-19",
3
+ "version": "3.4.1-alpha-0",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "mongodb": "^6.8.0",
27
27
  "nodemon": "^3.1.4",
28
28
  "path": "^0.12.7",
29
- "tango-api-schema": "^2.2.73",
30
- "tango-app-api-middleware": "^3.1.66",
29
+ "tango-api-schema": "^2.2.101",
30
+ "tango-app-api-middleware": "^3.1.72",
31
31
  "url": "^0.11.4",
32
32
  "winston": "^3.13.1",
33
33
  "winston-daily-rotate-file": "^5.0.0"
@@ -6,6 +6,7 @@ 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
8
  // import * as processedTaskconfigService from '../services/processedTaskConfig.service.js';
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';
11
12
 
@@ -143,8 +144,9 @@ export const downloadInsert = async ( req, res ) => {
143
144
  'viewRedo': requestData.viewRedo || false,
144
145
  'userEmailList': requestData.userEmailList || [],
145
146
  'filtertype': requestData.filtertype || 'Clusters',
146
-
147
+ 'checkListType': requestData.checkListType,
147
148
  };
149
+ console.log( insertData );
148
150
  let resultData = await downloadService.insert( insertData );
149
151
  if ( resultData ) {
150
152
  let sqsMessageRequestData = {
@@ -171,7 +173,93 @@ export const downloadInsert = async ( req, res ) => {
171
173
  return res.sendError( e, 500 );
172
174
  }
173
175
  };
174
-
176
+ export const downloadInsertAI = async ( req, res ) => {
177
+ try {
178
+ let requestData = req.body;
179
+ let name;
180
+ let fileType = requestData?.fileType || 'pdfzip';
181
+ if ( requestData.fileType == 'pdf' ) {
182
+ if ( requestData?.sourceCheckList_id && requestData?.sourceCheckList_id != '' ) {
183
+ fileType = 'pdfzip';
184
+ }
185
+ if ( requestData?.checklistId && requestData?.checklistId.length > 1 ) {
186
+ fileType = 'pdfzip';
187
+ }
188
+ }
189
+ if ( requestData.checklistName != '' ) {
190
+ name = requestData.checklistName + '_' + dayjs( requestData.fromDate ).format( 'DD/MM/YYYY' );
191
+ if ( requestData?.toDate ) {
192
+ name = name + '-' + dayjs( requestData?.toDate ).format( 'DD/MM/YYYY' );
193
+ }
194
+ let regexName = new RegExp( `^${name.split( '(' )[0]} \\(.*\\)$`, 'i' );
195
+ let type = requestData.fileType || 'pdfzip';
196
+ let downloadDetails = await downloadService.getCount( { $and: [ { $or: [ { name: { $regex: regexName } }, { name: name } ] }, { fileType: type } ] } );
197
+ if ( downloadDetails ) {
198
+ name = name + ' (' + downloadDetails + ')';
199
+ }
200
+ } else {
201
+ name = requestData?.checklistName;
202
+ }
203
+ let findchecklist = await processedcheklistconfigService.findOne( { 'checkListType': requestData.checkListType, 'client_id': requestData.clientId } ).sort( { _id: -1 } );
204
+ console.log( findchecklist );
205
+ name = name + '-' + requestData.fileType;
206
+ let insertData = {
207
+ 'date_string': requestData.fromDate || '',
208
+ 'sourceCheckList_id': requestData?.sourceCheckList_id || '',
209
+ 'checklistIdList': requestData?.checklistId || [],
210
+ 'status': 'inprogress',
211
+ 'client_id': requestData.clientId || '',
212
+ 'date_iso': new Date( requestData.fromDate ) || '',
213
+ 'createdBy': req.user._id || '',
214
+ 'name': name,
215
+ 'fileType': fileType,
216
+ 'storeIds': requestData.storeIds || [],
217
+ 'questions': requestData.questions || [],
218
+ 'fromDate': requestData.fromDate || '',
219
+ 'toDate': requestData.toDate || '',
220
+ 'previewType': requestData.previewType || '',
221
+ 'viewFlag': requestData.viewFlag || false,
222
+ 'userEmail': req.user.email || '',
223
+ 'createdBy': req.user._id || '',
224
+ 'downloadInsertFrom': requestData.downloadInsertFrom || '',
225
+ 'answerType': requestData.answerType || '',
226
+ 'searchValue': requestData.searchValue || '',
227
+ 'insertType': requestData.insertType || '',
228
+ 'viewRedo': requestData.viewRedo || false,
229
+ 'userEmailList': requestData.userEmailList || [],
230
+ 'filtertype': requestData.filtertype || 'Clusters',
231
+ 'checkListType': requestData.checkListType,
232
+ 'checkListName': findchecklist.checkListName,
233
+ 'checkListDescription': findchecklist.checkListDescription,
234
+ };
235
+ console.log( requestData );
236
+ console.log( insertData );
237
+ let resultData = await downloadService.insert( insertData );
238
+ console.log( resultData );
239
+ if ( resultData ) {
240
+ let sqsMessageRequestData = {
241
+ 'zipId': resultData._id,
242
+ 'fileType': fileType || 'zip',
243
+ 'storeId': requestData.storeIds || [],
244
+ };
245
+ console.log( sqsMessageRequestData );
246
+ if ( fileType === 'csv' || fileType === 'pdf' || fileType === 'csvzip' || fileType === 'pdfzip' || fileType === 'zipfiles' ) {
247
+ const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).AIchecklistExport}`, JSON.stringify( sqsMessageRequestData ) );
248
+ console.log( 'Send SQS Message CSV/PDF=>', msg );
249
+ }
250
+ if ( fileType === 'ppt' || fileType === 'pptzip' ) {
251
+ const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).AIchecklistExport}`, JSON.stringify( sqsMessageRequestData ) );
252
+ console.log( 'Send SQS Message PPT=>', msg );
253
+ }
254
+ res.sendSuccess( 'Success' );
255
+ } else {
256
+ return res.sendError( 'something went wrong, please try again', 500 );
257
+ }
258
+ } catch ( e ) {
259
+ console.log( 'insertdownloadRequest =>', e );
260
+ return res.sendError( e, 500 );
261
+ }
262
+ };
175
263
  export const downloadInsertOld = async ( req, res ) => {
176
264
  try {
177
265
  let requestData = req.body;
@@ -482,7 +570,33 @@ export const getChecklistFromZipId = async ( req, res ) => {
482
570
  return res.sendError( error, 500 );
483
571
  }
484
572
  };
485
-
573
+ export const getAiChecklistDataFromZipId = async ( req, res ) => {
574
+ try {
575
+ let reqquery = req.query;
576
+ let getzipdata = await downloadService.findOne( { _id: new mongoose.Types.ObjectId( reqquery.zipId ) } );
577
+ let brandInfo = {
578
+ clientName: '',
579
+ brandLogo: '',
580
+ checkListDescription: '',
581
+ };
582
+ if ( getzipdata ) {
583
+ let getClientData = await clientService.findOne( { clientId: getzipdata.client_id } );
584
+ if ( getClientData ) {
585
+ brandInfo.clientName = getClientData.clientName;
586
+ brandInfo.brandLogo = getzipdata.client_id + '/logo/' + getClientData.profileDetails.logo;
587
+ }
588
+ getzipdata.brandInfo = brandInfo;
589
+ console.log( getzipdata );
590
+ return res.sendSuccess( getzipdata );
591
+ } else {
592
+ return res.sendError( { error: 'No Data Found' }, 204 );
593
+ }
594
+ } catch ( error ) {
595
+ console.log( 'error =>', error );
596
+ logger.error( { error: error, function: 'getChecklistFromZipId' } );
597
+ return res.sendError( error, 500 );
598
+ }
599
+ };
486
600
  export const getPDFCSVChecklistDetails = async ( req, res ) => {
487
601
  try {
488
602
  let requestData = req.body;
@@ -18,7 +18,7 @@ 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
22
  // import * as planoService from '../services/planogram.service.js';
23
23
  import * as clusterServices from '../services/cluster.service.js';
24
24
  import * as teamsServices from '../services/teams.service.js';
@@ -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', 'drinking', 'bagdetection' ].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 && getCLconfig.checkListType == 'custom' ) {
346
346
  let assignList = [];
347
347
  if ( getCLconfig.coverage == 'store' ) {
348
348
  let clusterList = allQuestion.filter( ( ele ) => ele?.clusterName ).map( ( item ) => item.assignId );
@@ -597,8 +597,19 @@ 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 storeDetails = await storeService.find( { clientId: getCLconfig.client_id, status: 'active' }, { storeId: 1 } );
600
+ if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection' ].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
+ }
602
613
  let data = {
603
614
  checkListId: updatedchecklist._id,
604
615
  checkListName: getCLconfig.checkListName,
@@ -606,6 +617,7 @@ async function insertData( requestData ) {
606
617
  date_string: currentdate,
607
618
  allowedOverTime: getCLconfig.allowedOverTime,
608
619
  allowedStoreLocation: getCLconfig.allowedStoreLocation,
620
+ checkListDescription: getCLconfig.checkListDescription,
609
621
  scheduleStartTime: getCLconfig.scheduleStartTime,
610
622
  scheduleStartTime_iso: startTimeIso.format(),
611
623
  scheduleEndTime: getCLconfig.scheduleEndTime,
@@ -621,8 +633,17 @@ async function insertData( requestData ) {
621
633
  scheduleRepeatedType: getCLconfig.scheduleRepeatedType,
622
634
  storeCount: storeDetails.length,
623
635
  client_id: getCLconfig.client_id,
624
- aiStoreList: storeDetails ? storeDetails.map( ( store ) => store.storeId ) : [],
636
+ aiStoreList: allQuestion.length ? allQuestion.map( ( store ) => store.store_id ) : [],
625
637
  };
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
+ }
626
647
  // await processedchecklist.create( data );
627
648
  await processedchecklist.updateOne( { date_string: currentdate, checkListId: updatedchecklist._id, sourceCheckList_id: getCLconfig._id, checkListType: getCLconfig.checkListType }, data );
628
649
  }
@@ -1433,6 +1454,37 @@ export async function getPDFCSVChecklistDetails( req, res ) {
1433
1454
  }
1434
1455
 
1435
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
+
1436
1488
  export async function taskPushNotification( req, res ) {
1437
1489
  try {
1438
1490
  let query = [ {
@@ -1644,3 +1696,59 @@ async function getUserToken( clientId, userEmail ) {
1644
1696
  return false;
1645
1697
  }
1646
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
+ userData = await userService.findOne( { email: requestData.email }, { fcmToken: 1, loginFrom: 1 } );
1723
+ } else {
1724
+ // let storeData = await storeService.findOne( { clientId: requestData.clientId, storeId: requestData.storeId }, { spocDetails: 1 } );
1725
+ let storeData = await storeService.findOne( { storeId: requestData.storeId }, { spocDetails: 1 } );
1726
+ if ( storeData && storeData.spocDetails.length > 0 && storeData.spocDetails[0].email ) {
1727
+ // fcmToken = await getUserToken( storeData.spocDetails[0].email );
1728
+ // userData = await userService.findOne( { clientId: requestData.clientId, email: requestData.email }, { fcmToken: 1, loginFrom: 1 } );
1729
+ userData = await userService.findOne( { email: requestData.email }, { fcmToken: 1, loginFrom: 1 } );
1730
+ }
1731
+ }
1732
+ if ( !userData ) {
1733
+ return res.sendSuccess( 'Notification Send Successfully' );
1734
+ }
1735
+ let custom = {
1736
+ title: requestData.title,
1737
+ body: requestData.description,
1738
+ type: req.body?.type,
1739
+ storeId: req.body?.storeId,
1740
+ date: req.body?.date,
1741
+ clientId: req.body?.clientId,
1742
+ };
1743
+ let responseData = await sendAiPushNotification( userData.fcmToken, custom, userData.loginFrom );
1744
+ if ( responseData ) {
1745
+ return res.sendSuccess( 'Notification Send Successfully' );
1746
+ } else {
1747
+ return res.sendSuccess( 'Notification Send Successfully' );
1748
+ }
1749
+ } catch ( e ) {
1750
+ logger.error( { error: e, function: 'internalAISendPushNotification' } );
1751
+ if ( e.name === 'ValidationError' ) res.sendBadRequest( e );
1752
+ else res.sendError( e, 500 );
1753
+ }
1754
+ };