tango-app-api-task 3.3.1-hotfix-3 → 3.4.0-alpha-0

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.3.1-hotfix-3",
3
+ "version": "3.4.0-alpha-0",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  "mongodb": "^6.10.0",
25
25
  "nodemon": "^3.1.7",
26
26
  "npm": "^10.9.2",
27
- "tango-api-schema": "^2.2.52",
27
+ "tango-api-schema": "^2.2.73",
28
28
  "tango-app-api-middleware": "^3.1.58",
29
29
  "winston": "^3.17.0",
30
30
  "winston-daily-rotate-file": "^5.0.0"
@@ -1688,6 +1688,7 @@ export async function createChecklistTask( req, res ) {
1688
1688
  section_id: inputBody.sectionId,
1689
1689
  qno: inputBody.qno,
1690
1690
  parentQuestion: inputBody.parentQuestion,
1691
+ uniqueNo: inputBody.uniqueNo,
1691
1692
  },
1692
1693
  'upsert': {
1693
1694
  taskId: String( response?._id ),
@@ -1696,7 +1697,7 @@ export async function createChecklistTask( req, res ) {
1696
1697
  taskDate: dayjs( response.scheduleDate ).format( 'YYYY-MM-DD' ),
1697
1698
  },
1698
1699
  };
1699
-
1700
+ console.log( params );
1700
1701
  const requestOptions = {
1701
1702
  method: 'POST',
1702
1703
  headers: {
@@ -1722,6 +1723,205 @@ export async function createChecklistTask( req, res ) {
1722
1723
  }
1723
1724
  }
1724
1725
 
1726
+ export async function createChecklistMultiTask( req, res ) {
1727
+ try {
1728
+ let inputBody = req.body;
1729
+ console.log( inputBody );
1730
+ let inputData= inputBody.coverage==='user'?inputBody.userEmail:inputBody.storeName;
1731
+ let userDetailList;
1732
+ for ( let user of inputData ) {
1733
+ userDetailList = await userService.findOne( { email: user.userEmail } );
1734
+ if ( !userDetailList ) {
1735
+ let userData = {
1736
+ userName: user.userName,
1737
+ email: user.userEmail,
1738
+ mobileNumber: '',
1739
+ clientId: inputBody.clientId,
1740
+ };
1741
+ userDetailList = await createUser( userData );
1742
+ }
1743
+ }
1744
+
1745
+ // let title = `New Task Alert ${inputBody.checkListName}`;
1746
+ // let description = '';
1747
+
1748
+ // if ( inputBody.checkListType === 'checklistTask' ) {
1749
+ // description = `A new task has been generated from the response for ${inputBody.storeName}.`;
1750
+ // } else if ( inputBody.checkListType === 'CCTV' ) {
1751
+ // description = `A new task has been generated from the Live view for ${inputBody.storeName}.`;
1752
+ // }
1753
+
1754
+ // if ( userDetails.fcmToken ) {
1755
+ // const fcmToken = userDetails.fcmToken;
1756
+ // await sendPushNotification( title, description, fcmToken );
1757
+ // }
1758
+
1759
+ let time = inputBody?.scheduleEndTime || '11:59 PM';
1760
+ let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
1761
+ for ( let originaldata of inputData ) {
1762
+ let checklistDetails = await checklistService.findOne( { _id: originaldata?.checkListId }, { coverage: 1 } );
1763
+ let data = {
1764
+ checkListName: inputBody.checkListName,
1765
+ checkListDescription: inputBody.checkListDescription,
1766
+ createdBy: req.user._id,
1767
+ createdByName: req.user.userName,
1768
+ publish: true,
1769
+ questionCount: 1,
1770
+ storeCount: 1,
1771
+ scheduleDate: date,
1772
+ scheduleEndTime: time,
1773
+ scheduleEndTimeISO: dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format(),
1774
+ priorityType: 'high',
1775
+ client_id: inputBody.clientId,
1776
+ checkListType: inputBody.checkListType,
1777
+ publishDate: new Date(),
1778
+ locationCount: 1,
1779
+ ...( originaldata?.checkListId ) ? { referenceCheckListId: originaldata?.checkListId } : {},
1780
+ coverage: checklistDetails?.coverage || 'store',
1781
+ };
1782
+
1783
+ if ( req.user.userType == 'tango' || ( req.user.userType == 'client' && [ 'user' ].includes( req.user.role ) ) ) {
1784
+ let userList = await userService.findOne( { clientId: inputBody.clientId, role: 'superadmin' }, { userName: 1, email: 1 } );
1785
+ if ( userList ) {
1786
+ data['approver'] = { name: userList.userName, value: userList.email };
1787
+ }
1788
+ } else {
1789
+ data['approver'] = { name: req.user.userName, value: req.user.email };
1790
+ }
1791
+
1792
+ let response = await taskService.create( data );
1793
+ if ( response?.approver.length ) {
1794
+ let data = [];
1795
+ response?.approver.forEach( ( ele ) => {
1796
+ data.push( {
1797
+ userEmail: ele.value,
1798
+ checkListId: response._id,
1799
+ type: 'task',
1800
+ client_id: inputBody.clientId,
1801
+ checkListName: inputBody?.checkListName || '',
1802
+ } );
1803
+ } );
1804
+ await traxApprover.insertMany( data );
1805
+ }
1806
+
1807
+ if ( response?._id ) {
1808
+ if ( inputBody.question[0].questionReferenceImage.length ) {
1809
+ let images = [];
1810
+ inputBody.question[0].questionReferenceImage.forEach( ( ele ) => {
1811
+ let imgUrl = decodeURIComponent( ele.split( '?' )[0] );
1812
+ let url = imgUrl.split( '/' );
1813
+ if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
1814
+ url.splice( 0, 3 );
1815
+ }
1816
+ images.push( url.join( '/' ) );
1817
+ } );
1818
+ inputBody.question[0].questionReferenceImage = images;
1819
+ }
1820
+ if ( inputBody.question[0].answers[0].referenceImage.length ) {
1821
+ let images = [];
1822
+ inputBody.question[0].answers[0].referenceImage.forEach( ( ele ) => {
1823
+ let imgUrl = decodeURIComponent( ele.split( '?' )[0] );
1824
+ let url = imgUrl.split( '/' );
1825
+ if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
1826
+ url.splice( 0, 3 );
1827
+ }
1828
+ images.push( url.join( '/' ) );
1829
+ } );
1830
+ inputBody.question[0].answers[0].referenceImage = images;
1831
+ }
1832
+ let question = {
1833
+ checkListId: response?._id,
1834
+ question: inputBody.question,
1835
+ section: 'Section 1',
1836
+ checkList: data.checkListName,
1837
+ client_id: inputBody.clientId,
1838
+ };
1839
+ await taskQuestionService.create( question );
1840
+ let storeDetails;
1841
+ if ( originaldata?.storeName ) {
1842
+ storeDetails = await storeService.findOne( { storeName: originaldata.storeName, status: 'active' }, { storeId: 1, storeProfile: 1 } );
1843
+ }
1844
+
1845
+ let userDetails = {
1846
+ userName: originaldata.userName?originaldata.userName:'',
1847
+ userEmail: originaldata.userEmail?originaldata.userEmail:'',
1848
+ store_id: storeDetails?.storeId?storeDetails.storeId:'',
1849
+ storeName: originaldata?.storeName?originaldata?.storeName:'',
1850
+ city: storeDetails?.storeProfile?.city?storeDetails?.storeProfile?.city:'',
1851
+ checkFlag: true,
1852
+ checkListId: response?._id,
1853
+ checkListName: data.checkListName,
1854
+ client_id: inputBody.clientId,
1855
+ userId: userDetailList&&userDetailList._id?userDetailList._id:'',
1856
+ assignId: response?.coverage == 'store' ? storeDetails?._id : userDetailList._id,
1857
+ coverage: response?.coverage || 'store',
1858
+ };
1859
+ await taskAssignService.create( userDetails );
1860
+ console.log( originaldata?.checklistId );
1861
+ if ( inputBody.checkListType == 'checklistTask' ) {
1862
+ let taskDetails = await processedChecklist.findOne( { _id: originaldata?.checklistId }, { questionAnswers: 1, taskStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1 } );
1863
+ console.log( taskDetails );
1864
+ if ( !taskDetails ) {
1865
+ return res.sendError( 'No data found', 204 );
1866
+ }
1867
+ let question = taskDetails.questionAnswers;
1868
+ let sectionIndex = question.findIndex( ( sec ) => sec?.sectionName == req.body?.sectionName );
1869
+ if ( sectionIndex == -1 ) {
1870
+ return res.sendError( 'section is not found', 400 );
1871
+ }
1872
+ let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.qno == req.body.qno );
1873
+
1874
+ let data = { ...question[sectionIndex].questions[findQuestion], taskId: response?._id, task: true };
1875
+ question[sectionIndex].questions[req.body.qno - 1] = data;
1876
+ taskDetails.questionAnswers = question;
1877
+ let updateData = {
1878
+ taskStatus: true,
1879
+ questionAnswers: question,
1880
+ };
1881
+ await processedChecklist.updateOne( { _id: originaldata.checklistId }, updateData );
1882
+ let params = {
1883
+ 'payload': {
1884
+ _id: originaldata.checklistId,
1885
+ section_id: originaldata.section_id,
1886
+ uniqueNo: originaldata.uniqueNo,
1887
+ qno: inputBody.qno,
1888
+ parentQuestion: inputBody.parentQuestion,
1889
+ },
1890
+ 'upsert': {
1891
+ taskId: String( response?._id ),
1892
+ taskStatus: true,
1893
+ task: true,
1894
+ taskDate: dayjs( response.scheduleDate ).format( 'YYYY-MM-DD' ),
1895
+ },
1896
+ };
1897
+
1898
+ const requestOptions = {
1899
+ method: 'POST',
1900
+ headers: {
1901
+ 'Content-Type': 'application/json',
1902
+ },
1903
+ body: JSON.stringify( params ),
1904
+ };
1905
+ let url = JSON.parse( process.env.LAMBDAURL );
1906
+
1907
+ let searchResponse = await fetch( url.redoChecklist, requestOptions );
1908
+ console.log( searchResponse.ok );
1909
+
1910
+
1911
+ if ( !searchResponse.ok ) {
1912
+ return res.sendError( 'Something went wrong', 500 );
1913
+ }
1914
+ }
1915
+ await insertSingleProcessData( response?._id );
1916
+ }
1917
+ }
1918
+ return res.sendSuccess( 'Task created successfully' );
1919
+ } catch ( e ) {
1920
+ logger.error( { functionName: 'createChecklistMultiTask', error: e, message: req.body } );
1921
+ return res.sendError( e, 500 );
1922
+ }
1923
+ }
1924
+
1725
1925
  export async function approveTask( req, res ) {
1726
1926
  try {
1727
1927
  let toDate = new Date( req.body.toDate );
@@ -1879,6 +2079,97 @@ export async function redoTask( req, res ) {
1879
2079
  return res.sendError( e, 500 );
1880
2080
  }
1881
2081
  }
2082
+ export async function redomultiTask( req, res ) {
2083
+ try {
2084
+ let inputData = req.body.payload.coverage==='user'?req.body.payload.userEmail:req.body.payload.storeName;
2085
+
2086
+
2087
+ for ( let originalData of inputData ) {
2088
+ if ( !originalData.checklistId ) {
2089
+ return res.sendError( 'Id is Required', 400 );
2090
+ }
2091
+ if ( !originalData.section_id ) {
2092
+ return res.sendError( 'Section id is Required', 400 );
2093
+ }
2094
+ if ( !req.body.payload.qno ) {
2095
+ return res.sendError( 'Question number is Required', 400 );
2096
+ }
2097
+
2098
+ let taskDetails = await taskProcessedService.findOne( { _id: originalData.checklistId }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1, submitTime: 1, userName: 1, answerType: 1 } );
2099
+ if ( !taskDetails ) {
2100
+ return res.sendError( 'No data found', 204 );
2101
+ }
2102
+ let question = taskDetails.questionAnswers;
2103
+ let sectionIndex = question.findIndex( ( sec ) => sec.section_id == req.body.payload.section_id );
2104
+ if ( sectionIndex == -1 ) {
2105
+ return res.sendError( 'section is not found', 400 );
2106
+ }
2107
+ let data = { ...question[sectionIndex].questions[req.body.payload.qno - 1], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
2108
+ let userAnswer = data.userAnswer;
2109
+
2110
+ question[sectionIndex].questions[req.body.payload.qno - 1] = data;
2111
+ question[sectionIndex].questions[req.body.payload.qno - 1].remarks = '';
2112
+ question[sectionIndex].questions[req.body.payload.qno - 1].userAnswer = [];
2113
+ taskDetails.questionAnswers = question;
2114
+ let updateData = {
2115
+ checklistStatus: 'open',
2116
+ redoStatus: true,
2117
+ questionAnswers: question,
2118
+ ...( dayjs.utc( taskDetails.scheduleEndTime_iso ).format( 'YYYY-MM-DD' ) == dayjs().format( 'YYYY-MM-DD' ) ) ? { scheduleEndTime_iso: dayjs.utc().endOf( 'day' ) } : {},
2119
+ };
2120
+
2121
+ let response = await taskProcessedService.updateOne( { _id: originalData.checklistId }, updateData );
2122
+ // console.log( response );
2123
+ if ( response.modifiedCount || response.matchedCount ) {
2124
+ let storeTimeZone = await storeService.findOne( { storeName: taskDetails.storeName }, { 'storeProfile.timeZone': 1 } );
2125
+ let currentDateTime;
2126
+ if ( storeTimeZone?.storeProfile?.timeZone ) {
2127
+ currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
2128
+ } else {
2129
+ currentDateTime = dayjs();
2130
+ }
2131
+ data = {
2132
+ checklistId: taskDetails.sourceCheckList_id,
2133
+ checkListName: taskDetails.checkListName,
2134
+ checklistDescription: req.body.payload.checklistDescription,
2135
+ sectionId: originalData.section_id,
2136
+ sectionName: question[sectionIndex].sectionName,
2137
+ questionName: question[sectionIndex].questions[req.body.payload.qno - 1].qname,
2138
+ action: 'redo',
2139
+ store_id: taskDetails?.store_id?taskDetails?.store_id:'',
2140
+ storeName: taskDetails.storeName?taskDetails.storeName:'',
2141
+ client_id: taskDetails.client_id,
2142
+ processedChecklistId: taskDetails._id,
2143
+ type: taskDetails.checkListType,
2144
+ userAnswer: userAnswer,
2145
+ initiatedBy: req.user.userName,
2146
+ initiatedTime: dayjs.utc( currentDateTime.format( 'hh:mm:ss A, DD MMM YYYY' ), 'hh:mm:ss A, DD MMM YYYY' ).format(),
2147
+ answerType: question[sectionIndex].questions[req.body.payload.qno - 1].answerType,
2148
+ submitedBy: taskDetails.userName,
2149
+ submitTime: taskDetails.submitTime,
2150
+ };
2151
+ req.body.payload._id=originalData.checklistId;
2152
+ req.body.payload.section_id=originalData.section_id;
2153
+ req.body.payload.uniqueNo=originalData.uniqueNo;
2154
+ await checklistLogs.create( data );
2155
+ const requestOptions = {
2156
+ method: 'POST',
2157
+ headers: {
2158
+ 'Content-Type': 'application/json',
2159
+ },
2160
+ body: JSON.stringify( req.body ),
2161
+ };
2162
+ let url = JSON.parse( process.env.LAMBDAURL );
2163
+ let searchResponse = await fetch( url.redoTask, requestOptions );
2164
+ console.log( searchResponse.ok );
2165
+ }
2166
+ }
2167
+ return res.sendSuccess( 'Question redo successfully' );
2168
+ } catch ( e ) {
2169
+ logger.error( { function: 'redomultiTask', error: e, message: req.body } );
2170
+ return res.sendError( e, 500 );
2171
+ }
2172
+ }
1882
2173
 
1883
2174
 
1884
2175
  export async function getQuestions( req, res ) {
@@ -4149,6 +4440,7 @@ export async function taskcreation( req, res ) {
4149
4440
  checkListName: data.checkListName,
4150
4441
  client_id: inputBody.clientId,
4151
4442
  userId: userId,
4443
+ assignId: storeDetails._id,
4152
4444
  };
4153
4445
  await taskAssignService.create( userDetails );
4154
4446
  await insertSingleProcessData( response?._id );
@@ -15,8 +15,10 @@ taskRouter
15
15
  .post( '/config', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.taskConfig )
16
16
  .post( '/reinitiate', isAllowedSessionHandler, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.reinitiateTask )
17
17
  .post( '/checklistTask', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.createChecklistTask )
18
+ .post( '/checklistMultiTask', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.createChecklistMultiTask )
18
19
  .post( '/updateApprove', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.approveTask )
19
20
  .post( '/redo', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.redoTask )
21
+ .post( '/multiredo', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.redomultiTask )
20
22
  .post( '/taskDropdown', isAllowedSessionHandler, taskController.taskDropdown )
21
23
  .post( '/getQuestions', isAllowedSessionHandler, taskController.getQuestions )
22
24
  .post( '/getAnswers', isAllowedSessionHandler, taskController.getAnswers )