tango-app-api-task 1.0.0-alpha.10 → 1.0.0-alpha.11

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": "1.0.0-alpha.10",
3
+ "version": "1.0.0-alpha.11",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -668,7 +668,7 @@ async function taskDropdownListData( requestData ) {
668
668
  return res.sendError( error, 500 );
669
669
  }
670
670
  }
671
- export const taskDropdownListV1 = async ( req, res ) => {
671
+ export const taskDropdownListV1OLD = async ( req, res ) => {
672
672
  try {
673
673
  let requestData = req.body;
674
674
  let result = {};
@@ -713,6 +713,110 @@ export const taskDropdownListV1 = async ( req, res ) => {
713
713
  return res.sendError( { error: error }, 500 );
714
714
  }
715
715
  };
716
+ export const taskDropdownListV1 = async ( req, res ) => {
717
+ try {
718
+ let requestData = req.body;
719
+ let fromDate = new Date( requestData.fromDate );
720
+ let toDate = new Date( requestData.toDate );
721
+ let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
722
+ toDate = new Date( toDate.getTime() - userTimezoneOffset );
723
+ toDate.setUTCHours( 23, 59, 59, 59 );
724
+ let result = {};
725
+
726
+ let findQuery = [
727
+ { $match: { $and: [
728
+ { client_id: requestData.clientId },
729
+ { store_id: { $in: requestData.storeId } },
730
+ { date_iso: { $gte: fromDate, $lte: toDate } },
731
+ { checkListType: { $in: [ 'task', 'checklistTask', 'cctv' ] } },
732
+ ] } },
733
+ {
734
+ $project: {
735
+ sourceCheckList_id: 1,
736
+ checkListName: 1,
737
+ },
738
+ },
739
+ {
740
+ $group: {
741
+ _id: '$sourceCheckList_id',
742
+ checkListName: { $last: '$checkListName' },
743
+ },
744
+ },
745
+ {
746
+ $project: {
747
+ _id: 0,
748
+ sourceCheckList_id: '$_id',
749
+ checkListName: 1,
750
+ },
751
+ },
752
+ {
753
+ $lookup: {
754
+ from: 'taskconfigs',
755
+ let: { sourceId: '$sourceCheckList_id' },
756
+ pipeline: [
757
+ {
758
+ $match: {
759
+ $expr: {
760
+ $and: [
761
+ { $eq: [ '$_id', '$$sourceId' ] },
762
+ ],
763
+ },
764
+ },
765
+ },
766
+ {
767
+ $project: {
768
+ _id: 1,
769
+ checkListName: 1,
770
+ checkListNameLowercase: { $toLower: '$checkListName' },
771
+ checkListType: 1,
772
+ createdByName: 1,
773
+ publish: 1,
774
+ scheduleEndTime: 1,
775
+ scheduleRepeatedType: 1,
776
+ scheduleStartTime: 1,
777
+ sourceCheckList_id: '$_id',
778
+ storeCount: 1,
779
+ },
780
+ },
781
+ ], as: 'checklistData',
782
+ },
783
+ },
784
+ { $unwind: { path: '$checklistData', preserveNullAndEmptyArrays: true } },
785
+ {
786
+ $project: {
787
+ _id: '$checklistData._id',
788
+ checkListName: '$checklistData.checkListName',
789
+ checkListNameLowercase: { $toLower: '$checkListName' },
790
+ checkListType: '$checklistData.checkListType',
791
+ createdByName: '$checklistData.createdByName',
792
+ publish: '$checklistData.publish',
793
+ scheduleEndTime: '$checklistData.scheduleEndTime',
794
+ scheduleRepeatedType: '$checklistData.scheduleRepeatedType',
795
+ scheduleStartTime: '$checklistData.scheduleStartTime',
796
+ sourceCheckList_id: '$checklistData._id',
797
+ storeCount: '$checklistData.storeCount',
798
+ },
799
+ },
800
+ ];
801
+ if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
802
+ findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
803
+ } else {
804
+ findQuery.push( { $sort: { ['checkListNameLowercase']: -1 } } );
805
+ }
806
+
807
+ let getChecklistData = await processedTaskService.aggregate( findQuery );
808
+ if ( !getChecklistData.length ) {
809
+ return res.sendError( { error: 'No Data Found' }, 204 );
810
+ }
811
+ result.totalCount = getChecklistData.length;
812
+ result.checklistData = getChecklistData;
813
+ return res.sendSuccess( result );
814
+ } catch ( error ) {
815
+ console.log( 'error =>', error );
816
+ logger.error( { error: error, message: req.query, function: 'checklistDropdownV1' } );
817
+ return res.sendError( { error: error }, 500 );
818
+ }
819
+ };
716
820
  export const taskInfoView = async ( req, res ) => {
717
821
  try {
718
822
  let requestData = req.body;
@@ -785,5 +889,3 @@ export const taskDeleteV1 = async ( req, res ) => {
785
889
  return res.sendError( e, 500 );
786
890
  }
787
891
  };
788
-
789
-