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

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.2",
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
  }