tango-app-api-trax 3.2.1 → 3.3.1-beta-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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-trax",
3
- "version": "3.2.1",
3
+ "version": "3.3.1-beta-1",
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.16",
29
+ "tango-api-schema": "^2.2.24",
30
30
  "tango-app-api-middleware": "^3.1.50",
31
31
  "url": "^0.11.4",
32
32
  "winston": "^3.13.1",
@@ -1421,3 +1421,70 @@ export async function taskPushNotification( req, res ) {
1421
1421
  return res.sendError( e, 500 );
1422
1422
  }
1423
1423
  }
1424
+
1425
+ export async function internalSendPushNotification( req, res ) {
1426
+ try {
1427
+ let requestHeader = req.headers;
1428
+ if ( !( requestHeader.clientid ) ) {
1429
+ return res.sendError( 'clientid is Required', 400 );
1430
+ }
1431
+ if ( !( requestHeader.email || requestHeader.storeid ) ) {
1432
+ return res.sendError( 'Email or Storeid is Required', 400 );
1433
+ }
1434
+
1435
+ let requestData = req.body;
1436
+ if ( !requestData.title ) {
1437
+ return res.sendError( 'Title is Required', 400 );
1438
+ }
1439
+
1440
+ if ( !requestData.description ) {
1441
+ return res.sendError( 'Description is Required', 400 );
1442
+ }
1443
+
1444
+ let fcmToken;
1445
+ // fcmToken = 'dwm2tz9WfUq1jdz1H8hfSf:APA91bF9BhTsG9ZDnutQfseGueXk7FZ4RhB8v3G_xJOZhkiZz8vsw3SUWk5su8ZN37lx3-H50eouBKinbwg4zE_br6f483jUswA_44f1XG8k7Sok995f77M';
1446
+ if ( requestHeader.email && requestHeader.email !='' ) {
1447
+ fcmToken = await getUserToken( requestHeader.clientid, requestHeader.email );
1448
+ } else {
1449
+ let storeData = await storeService.findOne( { clientId: requestHeader.clientid, storeId: requestHeader.storeid }, { spocDetails: 1 } );
1450
+ if ( storeData && storeData.spocDetails.length > 0 && storeData.spocDetails[0].email ) {
1451
+ fcmToken = await getUserToken( storeData.spocDetails[0].email );
1452
+ }
1453
+ }
1454
+ // console.log( 'fcmToken =>', fcmToken );
1455
+ if ( !fcmToken ) {
1456
+ // return res.sendError( 'Token not found', 400 );
1457
+ return res.sendSuccess( 'Notification Send Successfully' );
1458
+ }
1459
+ let responseData = await sendPushNotification( requestData.title, requestData.description, fcmToken );
1460
+ // console.log( 'responseData =>', responseData );
1461
+ if ( responseData ) {
1462
+ return res.sendSuccess( 'Notification Send Successfully' );
1463
+ } else {
1464
+ // return res.sendError( 'Token not found', 400 );
1465
+ return res.sendSuccess( 'Notification Send Successfully' );
1466
+ }
1467
+ } catch ( e ) {
1468
+ logger.error( { error: e, function: 'internalSendPushNotification' } );
1469
+ if ( e.name === 'ValidationError' ) res.sendBadRequest( e );
1470
+ else res.sendError( e, 500 );
1471
+ }
1472
+ };
1473
+
1474
+ async function getUserToken( clientId, userEmail ) {
1475
+ try {
1476
+ if ( clientId && clientId !='' && userEmail && userEmail !='' ) {
1477
+ let userData = await userService.findOne( { clientId: clientId, email: userEmail }, { fcmToken: 1 } );
1478
+ if ( userData && userData.fcmToken && userData.fcmToken !='' ) {
1479
+ return userData.fcmToken;
1480
+ } else {
1481
+ return false;
1482
+ }
1483
+ } else {
1484
+ return false;
1485
+ }
1486
+ } catch ( e ) {
1487
+ logger.error( { error: e, function: 'getUserToken' } );
1488
+ return false;
1489
+ }
1490
+ }
@@ -1792,7 +1792,9 @@ export async function submitChecklist( req, res ) {
1792
1792
  // createdAt: createdAtDate,
1793
1793
  // };
1794
1794
  // await detectionService.create( detectionData );
1795
- updateOpenSearch( req.user, requestData );
1795
+ if ( requestData.submittype == 'submit' ) {
1796
+ updateOpenSearch( req.user, requestData );
1797
+ }
1796
1798
 
1797
1799
  return res.sendSuccess( 'Checklist Updated Successfully' );
1798
1800
  } else {
@@ -1956,7 +1958,9 @@ export async function submitTask( req, res ) {
1956
1958
  };
1957
1959
  await checklistLogs.create( logInsertData );
1958
1960
 
1959
- updateOpenSearchTask( user, requestData );
1961
+ if ( submittype == 'submit' ) {
1962
+ updateOpenSearchTask( user, requestData );
1963
+ }
1960
1964
 
1961
1965
  return res.sendSuccess( 'Task Updated Successfully' );
1962
1966
  } else {
@@ -3282,3 +3286,24 @@ export async function checkVersion( req, res ) {
3282
3286
  return res.sendError( e, 500 );
3283
3287
  }
3284
3288
  }
3289
+
3290
+ export async function clientConfig( req, res ) {
3291
+ try {
3292
+ let requestData = req.body;
3293
+ if ( requestData.clientId && requestData.clientId !='' ) {
3294
+ let getClientData = await clientService.findOne( { clientId: requestData.clientId }, { traxRAWImageUpload: 1, clientId: 1, clientName: 1 } );
3295
+ console.log( ' getClientData=>', getClientData );
3296
+ if ( getClientData ) {
3297
+ return res.sendSuccess( getClientData );
3298
+ } else {
3299
+ return res.sendError( 'Invalid clientId', 400 );
3300
+ }
3301
+ } else {
3302
+ return res.sendError( 'clientId is Required', 400 );
3303
+ }
3304
+ } catch ( e ) {
3305
+ console.log( 'e =>', e );
3306
+ logger.error( { error: e, function: 'clientConfig' } );
3307
+ return res.sendError( e, 500 );
3308
+ }
3309
+ }
@@ -21,6 +21,8 @@ import utc from 'dayjs/plugin/utc.js';
21
21
  import isEqual from 'lodash/isEqual.js';
22
22
  dayjs.extend( utc );
23
23
  dayjs.extend( customParseFormat );
24
+ import * as clusterServices from '../services/cluster.service.js';
25
+ import * as teamsServices from '../services/teams.service.js';
24
26
 
25
27
 
26
28
  export const checklist = async ( req, res ) => {
@@ -2177,18 +2179,17 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
2177
2179
  getsubmitDetails[0].date_iso = new Date( date );
2178
2180
  getsubmitDetails[0].redoStatus = false;
2179
2181
  getsubmitDetails[0].approvalStatus = false;
2180
- } else {
2181
- if ( editSubmit && getsubmitDetails[0].checklistStatus == 'submit' ) {
2182
- console.log( editSubmit );
2183
- let user = {
2184
- _id: getsubmitDetails[0].userId,
2185
- clientId: getsubmitDetails[0].client_id,
2186
- };
2187
- updateOpenSearch( user, { processedcheckListId: getsubmitDetails[0]._id, date: getsubmitDetails[0].date_string } );
2188
- }
2189
2182
  }
2190
2183
  let data = { ...getsubmitDetails[0]._doc };
2191
2184
  await processedchecklist.updateOne( { _id: getsubmitDetails[0]._id }, data );
2185
+ if ( editSubmit && getsubmitDetails[0].checklistStatus == 'submit' ) {
2186
+ console.log( editSubmit );
2187
+ let user = {
2188
+ _id: getsubmitDetails[0].userId,
2189
+ clientId: getsubmitDetails[0].client_id,
2190
+ };
2191
+ updateOpenSearch( user, { processedcheckListId: getsubmitDetails[0]._id, date: getsubmitDetails[0].date_string } );
2192
+ }
2192
2193
  }
2193
2194
  if ( getsubmitDetails[0]?.checklistStatus == 'submit' ) {
2194
2195
  userIdList.push( element4._id );
@@ -2237,15 +2238,29 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
2237
2238
  await processedchecklist.insertMany( submitUser );
2238
2239
  }
2239
2240
  } else {
2240
- let deleteQuery = {
2241
+ let deleteInprogressQuery = {
2241
2242
  date_string: insertdata.date_string,
2242
2243
  date_iso: insertdata.date_iso,
2243
2244
  client_id: insertdata.client_id,
2244
2245
  checkListId: updatedchecklist._id,
2245
- checklistStatus: { $nin: [ 'submit' ] },
2246
+ checklistStatus: { $nin: [ 'submit', 'inprogress' ] },
2247
+ redoStatus: false,
2246
2248
  };
2247
- await processedchecklist.deleteMany( deleteQuery );
2248
- await processedchecklist.insertMany( allQuestion );
2249
+ await processedchecklist.deleteMany( deleteInprogressQuery );
2250
+ deleteInprogressQuery.checklistStatus = 'inprogress';
2251
+ deleteInprogressQuery.redoStatus = false;
2252
+ let getInprogressData = await processedchecklist.find( deleteInprogressQuery, { userId: 1, store_id: 1 } );
2253
+ if ( getInprogressData ) {
2254
+ allQuestion = allQuestion.filter( ( item ) => {
2255
+ let inprogressData = getInprogressData.find( ( ele ) => ele.userId.toString() == item.userId.toString() && ele.store_id == item.store_id );
2256
+ if ( !inprogressData ) {
2257
+ return item;
2258
+ }
2259
+ } );
2260
+ }
2261
+ if ( allQuestion.length ) {
2262
+ await processedchecklist.insertMany( allQuestion );
2263
+ }
2249
2264
  }
2250
2265
  } else {
2251
2266
  let unAssignedList = allQuestion.reduce( ( acc, item ) => {
@@ -2534,3 +2549,55 @@ export const preDefinedChecklist = async ( req, res ) => {
2534
2549
  }
2535
2550
  };
2536
2551
 
2552
+ export const selectAssign = async ( req, res ) => {
2553
+ try {
2554
+ let requestData = req.body;
2555
+ let resuldData;
2556
+ if ( requestData.coverage == 'store' ) {
2557
+ // //Select Store and cluster
2558
+ let storeQuery = [
2559
+ { $match: { clientId: requestData.clientId } },
2560
+ { $project: { 'storeName': 1, 'storeId': 1, 'type': 'store' } },
2561
+ ];
2562
+ let clusterQuery = [
2563
+ { $match: { clientId: requestData.clientId } },
2564
+ { $project: { 'clusterName': 1, 'type': 'cluster' } },
2565
+ ];
2566
+
2567
+ const [ getStores, getClusters ] = await Promise.all( [
2568
+ storeService.aggregate( storeQuery ),
2569
+ clusterServices.aggregateCluster( clusterQuery ),
2570
+ ] );
2571
+ // console.log( 'getStores =>', getStores );
2572
+ // console.log( 'getClusters =>', getClusters );
2573
+ resuldData = [ ...getStores, ...getClusters ];
2574
+ console.log( 'resuldData =>', resuldData );
2575
+ } else if ( requestData.coverage == 'user' ) {
2576
+ // //Select User and Teams
2577
+ let userQuery = [
2578
+ { $match: { clientId: requestData.clientId } },
2579
+ { $project: { 'userEmail': 1, 'userName': 1, 'type': 'user' } },
2580
+ ];
2581
+ // let getUsers = await userService.aggregate( userQuery );
2582
+ // console.log( 'getUsers =>', getUsers );
2583
+ let teamQuery = [
2584
+ { $match: { clientId: requestData.clientId } },
2585
+ { $project: { 'teamName': 1, 'type': 'team' } },
2586
+ ];
2587
+ // let getTeams = await teamsServices.aggregateTeams( teamQuery );
2588
+ // console.log( 'getTeams =>', getTeams );
2589
+ const [ getUsers, getTeams ] = await Promise.all( [
2590
+ userService.aggregate( userQuery ),
2591
+ teamsServices.aggregateTeams( teamQuery ),
2592
+ ] );
2593
+ resuldData = [ ...getUsers, ...getTeams ];
2594
+ console.log( 'resuldData =>', resuldData );
2595
+ }
2596
+ return res.sendSuccess( { 'totalCount': resuldData.length, 'data': resuldData } );
2597
+ } catch ( e ) {
2598
+ console.log( 'e =>', e );
2599
+ logger.error( 'selectAssign =>', e );
2600
+ return res.sendError( e, 500 );
2601
+ }
2602
+ };
2603
+
@@ -144,4 +144,13 @@ export const startValidation = {
144
144
  body: startSchema,
145
145
  };
146
146
 
147
+ export const selectAssignSchema = joi.object( {
148
+ clientId: joi.string().required(),
149
+ coverage: joi.string().required(),
150
+ } );
151
+
152
+ export const selectAssign = {
153
+ body: selectAssignSchema,
154
+ };
155
+
147
156
 
@@ -19,6 +19,7 @@ internalTraxRouter
19
19
  .get( '/checklist', isAllowedInternalAPIHandler, internalController.internalAPIChecklist )
20
20
  .post( '/getPDFCSVChecklistDetails', isAllowedInternalAPIHandler, internalController.getPDFCSVChecklistDetails )
21
21
  .get( '/getOTP', isAllowedInternalAPIHandler, internalController.getOTP )
22
- .get( '/getDownloads', isAllowedInternalAPIHandler, internalController.getDownloads );
22
+ .get( '/getDownloads', isAllowedInternalAPIHandler, internalController.getDownloads )
23
+ .post( '/sendPushNotification', isAllowedInternalAPIHandler, internalController.internalSendPushNotification );
23
24
 
24
25
 
@@ -24,5 +24,6 @@ mobileRouter
24
24
  .post( '/appVersion', mobileController.updateappVersion )
25
25
  .post( '/verifylocation', isAllowedSessionHandler, mobileController.getStoreLocation, mobileController.location )
26
26
  .post( '/login', mobileController.login )
27
- .post( '/checkUpdateVersion', mobileController.checkVersion );
27
+ .post( '/checkUpdateVersion', mobileController.checkVersion )
28
+ .post( '/checkClientConfig', isAllowedSessionHandler, mobileController.clientConfig );
28
29
 
@@ -1,6 +1,6 @@
1
1
  import express from 'express';
2
2
  import { isAllowedSessionHandler, validate, accessVerification, isAllowedClient } from 'tango-app-api-middleware';
3
- import { checklistValidation, checklistDetailsValidation, runaiValidation, checklistPageSchema, duplicateValidation, updateChecklistValidation, uploadUserValidation, aichecklistValidation, publishValidation } from '../dtos/validation.dtos.js';
3
+ import { checklistValidation, checklistDetailsValidation, runaiValidation, checklistPageSchema, duplicateValidation, updateChecklistValidation, uploadUserValidation, aichecklistValidation, publishValidation, selectAssign } from '../dtos/validation.dtos.js';
4
4
  import * as traxController from '../controllers/trax.controller.js';
5
5
 
6
6
  export const traxRouter = express.Router();
@@ -21,4 +21,7 @@ traxRouter
21
21
  .get( '/userList', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ), traxController.userlist )
22
22
  .get( '/zoneList', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ), traxController.zoneList )
23
23
  .get( '/aichecklist', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ), validate( aichecklistValidation ), traxController.aiChecklist )
24
- .get( '/predefinedChecklist', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ), validate( aichecklistValidation ), traxController.preDefinedChecklist );
24
+ .get( '/predefinedChecklist', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ), validate( aichecklistValidation ), traxController.preDefinedChecklist )
25
+ .post( '/selectAssign', validate( selectAssign ), traxController.selectAssign );
26
+
27
+ // isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ),
@@ -0,0 +1,30 @@
1
+ import teamsModel from 'tango-api-schema/schema/teams.model.js';
2
+
3
+
4
+ export async function createTeamsModel( data ) {
5
+ return await teamsModel.create( data );
6
+ };
7
+ export async function updateOneTeams( query, record ) {
8
+ return await teamsModel.updateOne( query, { $set: record }, { upsert: true } );
9
+ };
10
+
11
+ export async function aggregateTeams( query ) {
12
+ return await teamsModel.aggregate( query );
13
+ };
14
+ export async function deleteTeams( query ={} ) {
15
+ return await teamsModel.deleteOne( query );
16
+ };
17
+
18
+ export async function findOneTeams( query ={}, field={} ) {
19
+ return await teamsModel.findOne( query, field );
20
+ };
21
+ export async function findteams( query ={}, field={} ) {
22
+ return await teamsModel.find( query, field );
23
+ };
24
+
25
+ export async function updateOneTeamModel( query, record ) {
26
+ return await teamsModel.updateOne( query, record );
27
+ }
28
+ export function countDocumentsTeams( query ) {
29
+ return teamsModel.countDocuments( query );
30
+ }