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

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.3",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -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 } );
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
  }
@@ -1184,7 +1201,7 @@ export async function createChecklistTask( req, res ) {
1184
1201
  let description = '';
1185
1202
 
1186
1203
  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}.`;
1204
+ description = `A new task has been generated from the response for ${inputBody.storeName}.`;
1188
1205
  } else if ( inputBody.checkListType === 'CCTV' ) {
1189
1206
  description = `A new task has been generated from the Live view for ${inputBody.storeName}.`;
1190
1207
  }
@@ -972,6 +972,20 @@ 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.checklistId && req.body.checklistId != '' ) || req.body.coverage.includes( 'checklist' ) ) {
977
+ let taskQuery;
978
+ if ( req.body.checklistId ) {
979
+ taskQuery = { referenceCheckListId: { $eq: req.body.checklistId } };
980
+ }
981
+ if ( req.body.coverage.includes( 'checklist' ) ) {
982
+ taskQuery = { referenceCheckListId: { $exists: true } };
983
+ }
984
+ let getChecklistDetails = await taskService.find( taskQuery, { _id: 1 } );
985
+ if ( getChecklistDetails ) {
986
+ idList = getChecklistDetails.map( ( item ) => item._id );
987
+ }
988
+ }
975
989
 
976
990
  let query = [
977
991
  {
@@ -979,6 +993,7 @@ export async function taskDetails( req, res ) {
979
993
  date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
980
994
  client_id: req.body.clientId,
981
995
  ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } : {},
996
+ ...( idList.length ) ? { sourceCheckList_id: { $in: idList } } : {},
982
997
  },
983
998
  },
984
999
  { $sort: { date_iso: -1 } },