tango-app-api-task 1.0.0-beta.2 → 1.0.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": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.3",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -24,8 +24,8 @@
24
24
  "mongodb": "^6.10.0",
25
25
  "nodemon": "^3.1.7",
26
26
  "npm": "^10.9.2",
27
- "tango-api-schema": "^2.1.99",
28
- "tango-app-api-middleware": "^3.1.43-alpha.10",
27
+ "tango-api-schema": "2.2.2",
28
+ "tango-app-api-middleware": "3.1.43-alpha.10",
29
29
  "winston": "^3.17.0",
30
30
  "winston-daily-rotate-file": "^5.0.0"
31
31
  },
@@ -827,21 +827,54 @@ export async function insertSingleProcessData( checklistId ) {
827
827
  }
828
828
  insertdata.questionAnswers = collectSections;
829
829
  insertdata.updatedAt = new Date();
830
- let insertdataquery = {};
831
- insertdataquery.date_string = insertdata.date_string;
832
- insertdataquery.date_iso = insertdata.date_iso;
833
- insertdataquery.client_id = insertdata.client_id;
834
- insertdataquery.sourceCheckList_id = insertdata.sourceCheckList_id;
835
- let updatedchecklist;
836
- let checklistDetails = await taskProcessedConfigService.findOne( insertdataquery );
837
- if ( !checklistDetails ) {
838
- updatedchecklist = await taskProcessedConfigService.insert( insertdata );
839
- } else {
840
- await taskProcessedConfigService.updateOne( { _id: checklistDetails._id }, insertdata );
841
- updatedchecklist = checklistDetails;
842
- }
843
- if ( updatedchecklist ) {
844
- insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedchecklist, date, startTimeIso, endTimeIso, insertdata );
830
+ function getDaysBeforeEndDate( endDate ) {
831
+ const end = dayjs.utc( endDate );
832
+ const now = dayjs.utc();
833
+
834
+ if ( end.isBefore( now ) ) {
835
+ throw new Error( 'End date must be in the future.' );
836
+ }
837
+
838
+ const daysArray = [];
839
+ let currentDate = now.startOf( 'day' );
840
+
841
+ while ( currentDate.isBefore( end ) ) {
842
+ daysArray.push( currentDate.format( ) );
843
+ currentDate = currentDate.add( 1, 'day' );
844
+ }
845
+
846
+ return daysArray;
847
+ };
848
+
849
+ const dateArray = getDaysBeforeEndDate( endDate );
850
+
851
+ for ( const dateVal of dateArray ) {
852
+ const insertdataquery = {
853
+ date_string: dayjs( dateVal ).format( 'YYYY-MM-DD' ),
854
+ date_iso: dayjs( dateVal ).toDate(),
855
+ client_id: insertdata.client_id,
856
+ sourceCheckList_id: insertdata.sourceCheckList_id,
857
+ };
858
+
859
+ const insertDataPerDay = {
860
+ ...insertdata,
861
+ date_string: dayjs( dateVal ).format( 'YYYY-MM-DD' ),
862
+ date_iso: dayjs( dateVal ).toDate(),
863
+ };
864
+
865
+ let updatedchecklist;
866
+ let checklistDetails = await taskProcessedConfigService.findOne( insertdataquery );
867
+
868
+ if ( !checklistDetails ) {
869
+ updatedchecklist = await taskProcessedConfigService.insert( insertDataPerDay );
870
+ } else {
871
+ await taskProcessedConfigService.updateOne( { _id: checklistDetails._id }, insertDataPerDay );
872
+ updatedchecklist = checklistDetails;
873
+ }
874
+
875
+ if ( updatedchecklist ) {
876
+ await insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, dateVal, startTimeIso, endTimeIso, insertdata );
877
+ }
845
878
  }
846
879
  }
847
880
  }
@@ -852,7 +885,7 @@ export async function insertSingleProcessData( checklistId ) {
852
885
  }
853
886
  };
854
887
 
855
- async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedchecklist, date, startTimeIso, endTimeIso, insertdata ) {
888
+ async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date, startTimeIso, endTimeIso, insertdata ) {
856
889
  let getquestionQuery = [];
857
890
  getquestionQuery.push( {
858
891
  $match: {
@@ -893,7 +926,7 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
893
926
  element4.checkListName = getCLconfig.checkListName;
894
927
  element4.checkListDescription = getCLconfig.checkListDescription;
895
928
  element4.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
896
- element4.date_string = dayjs( currentdate ).format( 'YYYY-MM-DD' );
929
+ element4.date_string = dayjs( date ).format( 'YYYY-MM-DD' );
897
930
  element4.allowedOverTime = false;
898
931
  element4.allowedStoreLocation = getCLconfig.allowedStoreLocation;
899
932
  element4.scheduleStartTime = '12:00 AM';