tango-app-api-task 3.2.0-beta.0 → 3.2.0-beta.10

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-task",
3
- "version": "3.2.0-beta.0",
3
+ "version": "3.2.0-beta.10",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -25,7 +25,7 @@
25
25
  "nodemon": "^3.1.7",
26
26
  "npm": "^10.9.2",
27
27
  "tango-api-schema": "^2.2.16",
28
- "tango-app-api-middleware": "^3.1.48",
28
+ "tango-app-api-middleware": "^3.1.50",
29
29
  "winston": "^3.17.0",
30
30
  "winston-daily-rotate-file": "^5.0.0"
31
31
  },
@@ -436,9 +436,9 @@ export async function validateUser( req, res ) {
436
436
  if ( !storeExists.length ) {
437
437
  storeId.push( { store: item.storeName, message: '' } );
438
438
  }
439
- if ( storeExists.length && !storeExists[0]?.storeProfile?.city && !item.city ) {
440
- storeId.push( { store: item.storeName, message: 'city is required' } );
441
- }
439
+ // if ( storeExists.length && !storeExists[0]?.storeProfile?.city && !item.city ) {
440
+ // storeId.push( { store: item.storeName, message: 'city is required' } );
441
+ // }
442
442
  if ( storeExists.length && storeExists[0].status != 'active' ) {
443
443
  storeId.push( { store: item.storeName, message: 'store is inactive' } );
444
444
  }
@@ -722,8 +722,8 @@ export async function taskConfig( req, res ) {
722
722
  if ( inputBody.removedUsers.length ) {
723
723
  await taskAssignService.updateMany( { _id: { $in: inputBody.removedUsers } }, { checkFlag: false } );
724
724
  }
725
- let storeDetails = await taskAssignService.find( { checkListId: inputBody._id, checkFlag: true }, { _id: 0, store_id: 1, userEmail: 1 } );
726
- let storeList = storeDetails.map( ( store ) => store.store_id );
725
+ let storeConfigDetails = await taskAssignService.find( { checkListId: inputBody._id, checkFlag: true }, { _id: 0, store_id: 1, userEmail: 1, storeName: 1 } );
726
+ let storeList = storeConfigDetails.map( ( store ) => store.store_id );
727
727
 
728
728
  storeCount = storeList.length;
729
729
  if ( storeList.length ) {
@@ -752,6 +752,22 @@ export async function taskConfig( req, res ) {
752
752
  }
753
753
  await taskService.updateOne( { _id: inputBody._id }, { storeCount, locationCount } );
754
754
  if ( inputBody.submitType == 'publish' ) {
755
+ let taskName = checklistDetails.checkListName;
756
+ let dueDate = dayjs( configDetails.scheduleEndTimeISO ).format( 'YYYY-MM-DD hh:mm A' );
757
+
758
+ let assignedUsers = storeConfigDetails.map( ( store ) => {
759
+ return { email: store.userEmail, storeName: store.storeName };
760
+ } );
761
+
762
+ for ( let userDetails of assignedUsers ) {
763
+ let title = `New Task Alert ${taskName}`;
764
+ let description = `A new task has been assigned to ${userDetails.storeName}. Please complete it before the due date of ${dueDate}.`;
765
+ let user = await userService.findOne( { email: userDetails.email } );
766
+ if ( user && user.fcmToken ) {
767
+ sendPushNotification( title, description, user.fcmToken );
768
+ }
769
+ }
770
+
755
771
  let tDate = dayjs().format( 'YYYY-MM-DD' ) + ' ' + dayjs().format( 'hh:mm A' );
756
772
  let currentDate = dayjs( tDate, 'YYYY-MM-DD hh:mm A' ).format();
757
773
  if ( configDetails.scheduleEndTimeISO >= currentDate ) {
@@ -776,6 +792,7 @@ export async function taskConfig( req, res ) {
776
792
  return res.sendSuccess( { id: inputBody._id, message: message } );
777
793
  }
778
794
  } catch ( e ) {
795
+ console.log( 'e', e );
779
796
  logger.error( { functionName: 'taskConfig =>', error: e, message: req.body } );
780
797
  return res.sendError( e, 500 );
781
798
  }
@@ -1070,6 +1087,78 @@ async function createUser( data ) {
1070
1087
  role: 'user',
1071
1088
  password: '5dqFKAJj29PsV6P+kL+3Dw==',
1072
1089
  isActive: true,
1090
+ userType: 'client',
1091
+ rolespermission: [
1092
+ {
1093
+ featureName: 'Global',
1094
+ modules: [
1095
+ {
1096
+ name: 'Store',
1097
+ isAdd: false,
1098
+ isEdit: false,
1099
+
1100
+ },
1101
+ {
1102
+ name: 'User',
1103
+ isAdd: false,
1104
+ isEdit: false,
1105
+
1106
+ },
1107
+ {
1108
+ name: 'Camera',
1109
+ isAdd: false,
1110
+ isEdit: false,
1111
+
1112
+ },
1113
+ {
1114
+ name: 'Configuration',
1115
+ isAdd: false,
1116
+ isEdit: false,
1117
+
1118
+ },
1119
+ {
1120
+ name: 'Subscription',
1121
+ isAdd: false,
1122
+ isEdit: false,
1123
+
1124
+ },
1125
+ {
1126
+ name: 'Billing',
1127
+ isAdd: false,
1128
+ isEdit: false,
1129
+
1130
+ },
1131
+ ],
1132
+ },
1133
+ {
1134
+ featurName: 'TangoEye',
1135
+ modules: [
1136
+ {
1137
+ name: 'ZoneTag',
1138
+ isAdd: false,
1139
+ isEdit: false,
1140
+
1141
+ },
1142
+ ],
1143
+ },
1144
+ {
1145
+ featurName: 'TangoTrax',
1146
+ modules: [
1147
+ {
1148
+ name: 'checklist',
1149
+ isAdd: false,
1150
+ isEdit: false,
1151
+
1152
+ },
1153
+ {
1154
+ name: 'Task',
1155
+ isAdd: false,
1156
+ isEdit: false,
1157
+
1158
+ },
1159
+ ],
1160
+ },
1161
+ ],
1073
1162
  };
1074
1163
  let response = await userService.create( params );
1075
1164
  return response._id;
@@ -1184,7 +1273,7 @@ export async function createChecklistTask( req, res ) {
1184
1273
  let description = '';
1185
1274
 
1186
1275
  if ( inputBody.checkListType === 'checklistTask' ) {
1187
- description = `A new task has been assigned to ${inputBody.storeName}. Please complete it before the due date of ${inputBody.scheduleDate}.`;
1276
+ description = `A new task has been generated from the response for ${inputBody.storeName}.`;
1188
1277
  } else if ( inputBody.checkListType === 'CCTV' ) {
1189
1278
  description = `A new task has been generated from the Live view for ${inputBody.storeName}.`;
1190
1279
  }
@@ -1194,7 +1283,6 @@ export async function createChecklistTask( req, res ) {
1194
1283
  await sendPushNotification( title, description, fcmToken );
1195
1284
  }
1196
1285
 
1197
-
1198
1286
  let time = inputBody?.scheduleEndTime || '11:59 PM';
1199
1287
  let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
1200
1288
  let data = {
@@ -1451,6 +1539,13 @@ export async function redoTask( req, res ) {
1451
1539
 
1452
1540
  let response = await taskProcessedService.updateOne( { _id: req.body.payload._id }, updateData );
1453
1541
  if ( response.modifiedCount || response.matchedCount ) {
1542
+ let storeTimeZone = await storeService.findOne( { storeName: taskDetails.storeName }, { 'storeProfile.timeZone': 1 } );
1543
+ let currentDateTime;
1544
+ if ( storeTimeZone?.storeProfile?.timeZone ) {
1545
+ currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
1546
+ } else {
1547
+ currentDateTime = dayjs();
1548
+ }
1454
1549
  data = {
1455
1550
  checklistId: taskDetails.sourceCheckList_id,
1456
1551
  checkListName: taskDetails.checkListName,
@@ -1466,7 +1561,7 @@ export async function redoTask( req, res ) {
1466
1561
  type: taskDetails.checkListType,
1467
1562
  userAnswer: userAnswer,
1468
1563
  initiatedBy: req.user.userName,
1469
- initiatedTime: dayjs().format(),
1564
+ initiatedTime: dayjs.utc( currentDateTime.format( 'hh:mm:ss A, DD MMM YYYY' ), 'hh:mm:ss A, DD MMM YYYY' ).format(),
1470
1565
  answerType: question[sectionIndex].questions[req.body.payload.qno - 1].answerType,
1471
1566
  submitedBy: taskDetails.userName,
1472
1567
  submitTime: taskDetails.submitTime,
@@ -15337,13 +15432,10 @@ export async function teamMigrations( req, res ) {
15337
15432
  },
15338
15433
  ],
15339
15434
  };
15340
- console.log( payload );
15341
15435
  const teams = await createTeamsModel( payload );
15342
- console.log( teams );
15343
15436
  } else {
15344
15437
  let userIn = teamsExist.users.filter( ( data ) => data.email === userexits.userName );
15345
15438
  if ( userIn.length==0 ) {
15346
- console.log( '---------------------------', teamsExist.users.length );
15347
15439
  let update = {
15348
15440
  'userName': userexits.userName,
15349
15441
  'email': userexits.email,
@@ -222,7 +222,6 @@ export const approvalTableV1 = async ( req, res ) => {
222
222
  },
223
223
  ...groupQuery,
224
224
  ];
225
- promises.push( processedChecklist.aggregate( query ) );
226
225
  if ( req.body?.searchValue.trim() && req.body?.searchValue.trim().length ) {
227
226
  query.push( {
228
227
  $match: {
@@ -230,6 +229,7 @@ export const approvalTableV1 = async ( req, res ) => {
230
229
  },
231
230
  } );
232
231
  }
232
+ promises.push( processedChecklist.aggregate( query ) );
233
233
  } else {
234
234
  promises.push( Promise.resolve( null ) );
235
235
  }
@@ -972,6 +972,18 @@ export async function taskDetails( req, res ) {
972
972
  toDate.setUTCHours( 23, 59, 59, 59 );
973
973
  let limit = req.body?.limit || 10;
974
974
  let page = req.body?.offset ? ( req.body.offset * req.body.limit ) : 0;
975
+ let idList = [];
976
+ if ( req.body.coverage.includes( 'checklist' ) ) {
977
+ let taskQuery;
978
+ taskQuery = {
979
+ referenceCheckListId: { $exists: true },
980
+ ...( req.body.checklistId && req.body.checklistId != '' ) ? { referenceCheckListId: { $eq: req.body.checklistId } } : {},
981
+ };
982
+ let getChecklistDetails = await taskService.find( taskQuery, { _id: 1 } );
983
+ if ( getChecklistDetails ) {
984
+ idList = getChecklistDetails.map( ( item ) => item._id );
985
+ }
986
+ }
975
987
 
976
988
  let query = [
977
989
  {
@@ -979,6 +991,7 @@ export async function taskDetails( req, res ) {
979
991
  date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
980
992
  client_id: req.body.clientId,
981
993
  ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } : {},
994
+ ...( idList.length ) ? { sourceCheckList_id: { $in: idList } } : {},
982
995
  },
983
996
  },
984
997
  { $sort: { date_iso: -1 } },