tango-app-api-task 1.0.0-alpha.21 → 1.0.0-alpha.23

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.21",
3
+ "version": "1.0.0-alpha.23",
4
4
  "description": "Task",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -133,21 +133,22 @@ async function insertData( requestData ) {
133
133
  for ( let [ index2, element2 ] of resultchecklist.entries() ) {
134
134
  let getCLconfig = await taskService.findOne( { _id: element2 } );
135
135
  if ( getCLconfig ) {
136
- if ( dayjs( getCLconfig?.scheduleDate ).format( 'YYYY-MM-DD' ) != dayjs( date ).format( 'YYYY-MM-DD' ) ) {
137
- getCLconfig.scheduleEndTime = '11:59 PM';
138
- }
139
- console.log( getCLconfig.scheduleEndTime );
140
-
136
+ // if ( dayjs( getCLconfig?.scheduleDate ).format( 'YYYY-MM-DD' ) != dayjs( date ).format( 'YYYY-MM-DD' ) ) {
137
+ // getCLconfig.scheduleEndTime = '11:59 PM';
138
+ // }
139
+ // console.log( getCLconfig.scheduleEndTime );
140
+ let sTime = dayjs.utc( getCLconfig.publishDate ).format( 'hh:mm A' );
141
141
  let startTimeIso; let endTimeIso;
142
- startTimeIso = dayjs.utc( `${currentdate} 12:00 AM`, 'YYYY-MM-DD hh:mm A' );
143
- endTimeIso = dayjs.utc( `${currentdate} ${getCLconfig.scheduleEndTime}`, 'YYYY-MM-DD hh:mm A' );
142
+ startTimeIso = dayjs.utc( `${currentdate} ${sTime}`, 'YYYY-MM-DD hh:mm A' );
143
+ endTimeIso = dayjs.utc( getCLconfig.scheduleEndTimeISO );
144
144
  console.log( endTimeIso );
145
145
 
146
146
  let insertdata = {};
147
- insertdata.date_iso = startTimeIso.format();
147
+ insertdata.date_iso = new Date( dayjs( currentdate, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
148
148
  insertdata.date_string = currentdate;
149
149
  insertdata.sourceCheckList_id = getCLconfig._id;
150
150
  insertdata.checkListName = getCLconfig.checkListName;
151
+ insertdata.checkListDescription = getCLconfig.checkListName;
151
152
  insertdata.publish = getCLconfig.publish;
152
153
  insertdata.scheduleStartTime = startTimeIso.format();
153
154
  insertdata.scheduleStartTime_iso = startTimeIso.format();
@@ -244,6 +245,7 @@ async function insertData( requestData ) {
244
245
  delete element4.updatedAt;
245
246
  element4.checkListId = updatedchecklist._id;
246
247
  element4.checkListName = getCLconfig.checkListName;
248
+ element4.checkListDescription = getCLconfig.checkListDescription;
247
249
  element4.date_iso = new Date( currentdate );
248
250
  element4.date_string = currentdate;
249
251
  element4.allowedOverTime = false;
@@ -108,11 +108,13 @@ export async function createUpdateTask( req, res ) {
108
108
  section.questionReferenceImage = image;
109
109
  }
110
110
  section.answers.forEach( ( answer ) => {
111
- if ( answer.referenceImage != '' ) {
112
- let imgUrl = decodeURIComponent( answer.referenceImage?.split( '?' )[0] );
113
- let url = imgUrl.split( '/' );
114
- url.splice( 0, 3 );
115
- answer.referenceImage = url.join( '/' );
111
+ if ( answer.referenceImage.length ) {
112
+ answer.referenceImage = answer.referenceImage.map( ( value ) => {
113
+ let imgUrl = decodeURIComponent( value?.split( '?' )[0] );
114
+ let url = imgUrl.split( '/' );
115
+ url.splice( 0, 3 );
116
+ return url.join( '/' );
117
+ } );
116
118
  }
117
119
  } );
118
120
  } );
@@ -256,12 +258,16 @@ export async function taskDetails( req, res ) {
256
258
  }
257
259
  }
258
260
  question.answers.forEach( async ( answer ) => {
259
- if ( answer.referenceImage != '' ) {
260
- let inputData = {
261
- Bucket: bucket.sop,
262
- file_path: decodeURIComponent( answer.referenceImage ),
263
- };
264
- answer.referenceImage = await signedUrl( inputData );
261
+ if ( answer.referenceImage.length > 0 ) {
262
+ let updatedImages = [];
263
+ for ( let refImage of answer.referenceImage ) {
264
+ let inputData = {
265
+ Bucket: bucket.sop,
266
+ file_path: decodeURIComponent( refImage ),
267
+ };
268
+ updatedImages.push( await signedUrl( inputData ) );
269
+ }
270
+ answer.referenceImage = updatedImages;
265
271
  }
266
272
  } );
267
273
  } );
@@ -665,7 +671,7 @@ export async function taskConfig( req, res ) {
665
671
  } ) : [];
666
672
  let endDate = dayjs.utc( configDetails?.scheduleDate ).format( 'YYYY-MM-DD' ) + ' ' + configDetails.scheduleEndTime;
667
673
  configDetails.scheduleEndTimeISO = dayjs.utc( endDate, 'YYYY-MM-DD hh:mm A' ).format();
668
- configDetails.publishDate = dayjs().format();
674
+ configDetails.publishDate = dayjs.utc( dayjs().format( 'hh:mm A' ), 'hh:mm A' ).format();
669
675
 
670
676
  let response = await taskService.updateOne( { _id: inputBody._id }, configDetails );
671
677
  if ( inputBody?.approver.length ) {
@@ -752,7 +758,7 @@ export async function taskConfig( req, res ) {
752
758
  }
753
759
  }
754
760
  } catch ( e ) {
755
- logger.error( { functionName: 'updateConfigure =>', error: e, message: req.body } );
761
+ logger.error( { functionName: 'taskConfig =>', error: e, message: req.body } );
756
762
  return res.sendError( e, 500 );
757
763
  }
758
764
  }
@@ -767,20 +773,21 @@ export async function insertSingleProcessData( checklistId ) {
767
773
  let endDate = dayjs( getCLconfig?.scheduleDate ).format( 'YYYY-MM-DD' ) + ' ' + getCLconfig.scheduleEndTime;
768
774
  endDate = dayjs.utc( endDate, 'YYYY-MM-DD hh:mm A' ).format();
769
775
  if ( endDate >= date ) {
770
- if ( dayjs( getCLconfig?.scheduleDate ).format( 'YYYY-MM-DD' ) != dayjs( currentdate ).format( 'YYYY-MM-DD' ) ) {
771
- getCLconfig.scheduleEndTime = '11:59 PM';
772
- }
776
+ // if ( dayjs( getCLconfig?.scheduleDate ).format( 'YYYY-MM-DD' ) != dayjs( currentdate ).format( 'YYYY-MM-DD' ) ) {
777
+ // getCLconfig.scheduleEndTime = '11:59 PM';
778
+ // }
773
779
  } else {
774
780
  return false;
775
781
  }
776
-
777
- startTimeIso = dayjs.utc( '12:00 AM', 'hh:mm A' );
778
- endTimeIso = dayjs.utc( getCLconfig.scheduleEndTime, 'hh:mm A' );
782
+ let sTime = dayjs.utc( getCLconfig.publishDate ).format( 'hh:mm A' );
783
+ startTimeIso = dayjs.utc( sTime, 'hh:mm A' );
784
+ endTimeIso = dayjs.utc( getCLconfig.scheduleEndTimeISO );
779
785
  let insertdata = {};
780
- insertdata.date_iso = startTimeIso.format();
786
+ insertdata.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
781
787
  insertdata.date_string = dayjs( currentdate ).format( 'YYYY-MM-DD' );
782
788
  insertdata.sourceCheckList_id = getCLconfig._id;
783
789
  insertdata.checkListName = getCLconfig.checkListName;
790
+ insertdata.checkListDescription = getCLconfig.checkListDescription;
784
791
  insertdata.publish = getCLconfig.publish;
785
792
  insertdata.scheduleStartTime = '12:00 AM';
786
793
  insertdata.scheduleStartTime_iso = startTimeIso.format();
@@ -882,7 +889,8 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
882
889
  delete element4.updatedAt;
883
890
  element4.checkListId = updatedchecklist._id;
884
891
  element4.checkListName = getCLconfig.checkListName;
885
- element4.date_iso = startTimeIso.format();
892
+ element4.checkListDescription = getCLconfig.checkListDescription;
893
+ element4.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
886
894
  element4.date_string = dayjs( currentdate ).format( 'YYYY-MM-DD' );
887
895
  element4.allowedOverTime = false;
888
896
  element4.allowedStoreLocation = getCLconfig.allowedStoreLocation;
@@ -910,7 +918,6 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
910
918
  assigndeletequery.date_string = insertdata.date_string;
911
919
  assigndeletequery.date_iso = insertdata.date_iso;
912
920
  assigndeletequery.client_id = insertdata.client_id;
913
- assigndeletequery.brandId = insertdata.brandId;
914
921
  assigndeletequery.checkListId = updatedchecklist._id;
915
922
  assigndeletequery.checklistStatus = { $nin: [ 'submit' ] };
916
923
  await taskProcessedService.deleteMany( assigndeletequery );
@@ -1078,7 +1085,7 @@ export async function createChecklistTask( req, res ) {
1078
1085
  ...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
1079
1086
  };
1080
1087
 
1081
- if ( req.user.userType == 'tango' || ( req.user.userType == 'client' && [ 'user' ].includes( req.uer.role ) ) ) {
1088
+ if ( req.user.userType == 'tango' || ( req.user.userType == 'client' && [ 'user' ].includes( req.user.role ) ) ) {
1082
1089
  let userList = await userService.findOne( { clientId: inputBody.clientId, role: 'superadmin' }, { userName: 1, email: 1 } );
1083
1090
  if ( userList ) {
1084
1091
  data['approver'] = { name: userList.userName, value: userList.email };
@@ -1113,6 +1120,16 @@ export async function createChecklistTask( req, res ) {
1113
1120
  } );
1114
1121
  inputBody.question[0].questionReferenceImage = images;
1115
1122
  }
1123
+ if ( inputBody.question[0].answers[0].referenceImage.length ) {
1124
+ let images = [];
1125
+ inputBody.question[0].answers[0].referenceImage.forEach( ( ele ) => {
1126
+ let imgUrl = decodeURIComponent( ele.split( '?' )[0] );
1127
+ let url = imgUrl.split( '/' );
1128
+ url.splice( 0, 3 );
1129
+ images.push( url.join( '/' ) );
1130
+ } );
1131
+ inputBody.question[0].answers[0].referenceImage = images;
1132
+ }
1116
1133
  let question = {
1117
1134
  checkListId: response?._id,
1118
1135
  question: inputBody.question,
@@ -1505,3 +1522,222 @@ export async function approvalstatus( req, res ) {
1505
1522
  return res.sendError( error, 500 );
1506
1523
  }
1507
1524
  }
1525
+
1526
+ export const taskList = async ( req, res ) => {
1527
+ try {
1528
+ let limit = parseInt( req.query.limit ) || 10;
1529
+ let offset = parseInt( req.query.offset - 1 ) || 0;
1530
+ let page = offset * limit;
1531
+ let query = [];
1532
+ query.push(
1533
+ {
1534
+ $match: {
1535
+ checkListType: 'task',
1536
+ client_id: req.query.clientId,
1537
+ isdeleted: false,
1538
+ ...( req.user.userType == 'client' && req.user.role != 'superadmin' ) ? { 'owner.value': { $in: [ req.user.email ] } } : {},
1539
+ },
1540
+ },
1541
+ );
1542
+
1543
+ if ( req.query.search && req.query.search != '' ) {
1544
+ req.query.search = req.query.search.replace( /([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1' );
1545
+ query.push( {
1546
+ $match: {
1547
+ checkListName: { $regex: new RegExp( req.query.search, 'i' ) },
1548
+ },
1549
+ } );
1550
+ }
1551
+
1552
+ query.push(
1553
+ {
1554
+ $project: {
1555
+ checkList: { $toLower: '$checkListName' },
1556
+ checkListName: 1,
1557
+ createdBy: 1,
1558
+ userName: { $toLower: '$createdByName' },
1559
+ createdByName: 1,
1560
+ storeCount: 1,
1561
+ createdAt: 1,
1562
+ publish: 1,
1563
+ checkListType: 1,
1564
+ questionCount: 1,
1565
+ checkListChar: { $substr: [ '$checkListName', 0, 2 ] },
1566
+ priorityType: 1,
1567
+ scheduleEndTimeISO: 1,
1568
+ },
1569
+ },
1570
+ );
1571
+
1572
+ if ( req.query.sortColumnName && req.query.sortColumnName != '' && req.query.sortBy != '' ) {
1573
+ if ( req.query.sortColumnName == 'status' ) {
1574
+ req.query.sortColumnName = 'publish';
1575
+ }
1576
+ if ( req.query.sortColumnName != 'publish' ) {
1577
+ query.push( {
1578
+ $addFields: { lowerName: { $toLower: `$${req.query.sortColumnName}` } },
1579
+ } );
1580
+ query.push( {
1581
+ $sort: { lowerName: parseInt( req.query.sortBy ) },
1582
+ } );
1583
+ } else {
1584
+ query.push( {
1585
+ $sort: { publish: parseInt( req.query.sortBy ) },
1586
+ } );
1587
+ }
1588
+ } else {
1589
+ query.push(
1590
+ { $sort: { createdAt: -1 } },
1591
+ );
1592
+ }
1593
+
1594
+ query.push( {
1595
+ $facet: {
1596
+ data: [
1597
+ { $skip: page },
1598
+ { $limit: limit },
1599
+ ],
1600
+ count: [
1601
+ { $count: 'totalCount' },
1602
+ ],
1603
+ },
1604
+ } );
1605
+
1606
+ let checkList = await taskService.aggregate( query );
1607
+ if ( !checkList[0].data.length ) {
1608
+ return res.sendError( 'no data found', 204 );
1609
+ }
1610
+
1611
+ checkList[0].data.forEach( ( item ) => {
1612
+ if ( item.storeCount > 0 && item.storeCount <= 9 ) {
1613
+ item.storeCount = '0' + item.storeCount;
1614
+ }
1615
+ if ( item.questionCount > 0 && item.questionCount <= 9 ) {
1616
+ item.questionCount = '0' + item.questionCount;
1617
+ }
1618
+ item.createdAt = dayjs( item.createdAt ).format( 'DD MMM, YYYY' );
1619
+ } );
1620
+
1621
+ return res.sendSuccess( { result: checkList[0].data, count: checkList[0].count[0].totalCount } );
1622
+ } catch ( e ) {
1623
+ logger.error( 'taskList', e );
1624
+ return res.sendError( e, 500 );
1625
+ }
1626
+ };
1627
+
1628
+ export const updatePublish = async ( req, res ) => {
1629
+ try {
1630
+ if ( typeof req?.body?.checklistId == 'undefined' && typeof req.body.type == 'undefined' ) {
1631
+ return res.sendError( { message: 'checklistId or type is required' }, 400 );
1632
+ }
1633
+
1634
+ if ( typeof req?.body?.publish == 'undefined' ) {
1635
+ return res.sendError( { message: 'publish is required' }, 400 );
1636
+ }
1637
+ let getCheckDetails;
1638
+ let query;
1639
+
1640
+ if ( req.body.checklistId ) {
1641
+ query = { _id: req.body.checklistId };
1642
+ getCheckDetails = await taskService.findOne( { _id: req.body.checklistId, client_id: req.body.clientId, checkListType: 'task' } );
1643
+ }
1644
+
1645
+ if ( !getCheckDetails ) {
1646
+ return res.sendError( 'No data found', 204 );
1647
+ }
1648
+
1649
+ if ( getCheckDetails?.publishDate ) {
1650
+ let date = dayjs();
1651
+ let diff = date.diff( dayjs.utc( getCheckDetails?.publishDate ), 'minutes' );
1652
+ if ( diff < 5 ) {
1653
+ let mins = ( 5 - diff ) > 1 ? 'minutes' : 'minute';
1654
+ return res.sendError( `Please try after ${5 - diff} ${mins}`, 400 );
1655
+ }
1656
+ }
1657
+
1658
+ getCheckDetails.publish = req.body.publish;
1659
+ getCheckDetails.publishDate = req.body.publish ? new Date() : getCheckDetails?.publishDate;
1660
+ let currentDate = dayjs();
1661
+ if ( !req.body.publish ) {
1662
+ await taskProcessedConfigService.deleteMany( { date_string: { $gt: currentDate.format( 'YYYY-MM-DD' ) }, date_iso: { $gt: currentDate.format( '' ) }, sourceCheckList_id: req.body.checklistId } );
1663
+ await taskProcessedService.deleteMany( { date_string: { $gt: currentDate.format( 'YYYY-MM-DD' ) }, date_iso: { $gt: currentDate.format( '' ) }, sourceCheckList_id: req.body.checklistId, checklistStatus: { $ne: 'submit' } } );
1664
+ logger.info( { function: 'updatePublish', query: { date_string: { $gt: currentDate.format( 'YYYY-MM-DD' ) }, date_iso: { $gt: currentDate.format( '' ) }, sourceCheckList_id: req.body.checklistId, checklistStatus: { $ne: 'submit' } } } );
1665
+ }
1666
+
1667
+
1668
+ await taskService.updateOne( query, getCheckDetails );
1669
+ if ( getCheckDetails.checkListType == 'task' ) {
1670
+ let currentDate = dayjs.utc().format();
1671
+ let updatedscheduleEndTimeISO = dayjs.utc( getCheckDetails.scheduleEndTimeISO ).format( 'HH:mm:ss' );
1672
+ let newUpdatedDate = dayjs.utc( updatedscheduleEndTimeISO, 'HH:mm:ss' ).format();
1673
+
1674
+ if ( req.body.publish && req.body.publish == true ) {
1675
+ if ( newUpdatedDate > currentDate ) {
1676
+ let deleteQuery = {
1677
+ $and: [
1678
+ { date_string: dayjs().format( 'YYYY-MM-DD' ) },
1679
+ { sourceCheckList_id: new ObjectId( req.body.checklistId ) },
1680
+ { scheduleEndTime_iso: { $gt: currentDate } },
1681
+ ],
1682
+ };
1683
+ deleteQuery.$and.push( { checklistStatus: { $ne: 'submit' } } );
1684
+ let PClicklist = await taskProcessedService.deleteMany( deleteQuery );
1685
+ logger.info( { function: 'updatePublish', query: deleteQuery } );
1686
+ logger.info( `Deleted Checklist Before Insert => Checklist Name: ${getCheckDetails.checkListName}, PChecklist Count: ${PClicklist.deletedCount}` );
1687
+ if ( PClicklist.acknowledged ) {
1688
+ await insertSingleProcessData( req.body.checklistId );
1689
+ } else {
1690
+ res.sendError( 'something went wrong, please try again', 500 );
1691
+ }
1692
+ } else {
1693
+ logger.info( `Schudled End Time Breached Checklist publish true => Checklist Name: ${getCheckDetails.checkListName}` );
1694
+ }
1695
+
1696
+ futureDaysDataRemove( currentDate, req.body.checklistId, getCheckDetails.checkListName, '111' );
1697
+ } else {
1698
+ if ( newUpdatedDate > currentDate ) {
1699
+ let deleteQuery = {
1700
+ $and: [
1701
+ { date_string: dayjs().format( 'YYYY-MM-DD' ) },
1702
+ { sourceCheckList_id: new ObjectId( req.body.checklistId ) },
1703
+ { scheduleEndTime_iso: { $gt: currentDate } },
1704
+ ],
1705
+ };
1706
+ await taskProcessedConfigService.deleteMany( deleteQuery );
1707
+ deleteQuery.$and.push( { checklistStatus: { $ne: 'submit' } } );
1708
+ await taskProcessedService.deleteMany( deleteQuery );
1709
+ logger.info( { function: 'updatePublish', query: deleteQuery } );
1710
+
1711
+ let checklistLogQuery = {};
1712
+ checklistLogQuery.checkListName = getCheckDetails.checkListName;
1713
+ checklistLogQuery.createdAt = { $gte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) };
1714
+ await checklistLogs.deleteMany( checklistLogQuery );
1715
+
1716
+ let checklistDetectionsQuery = {};
1717
+ checklistDetectionsQuery.sourceChecklist_id = new ObjectId( req.body.checklistId );
1718
+ checklistDetectionsQuery.date_iso = { $gte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) };
1719
+ // await processeddetections.deleteMany( checklistDetectionsQuery );
1720
+ logger.info( { function: 'updatePublish', query: checklistDetectionsQuery } );
1721
+ } else {
1722
+ logger.info( `Schudled End Time Breached Checklist Unpublish false => Checklist Name: ${getCheckDetails.checkListName}` );
1723
+ }
1724
+
1725
+ // //Delete Future Data////
1726
+ futureDaysDataRemove( currentDate, req.body.checklistId, getCheckDetails.checkListName, '222' );
1727
+ }
1728
+ }
1729
+ let logInsertData = {
1730
+ action: req.body.publish ? 'publishTask' : 'unPublishTask',
1731
+ checklistId: req.body?.checklistId,
1732
+ checkListName: getCheckDetails.checkListName,
1733
+ createdBy: req.user._id,
1734
+ createdByName: req.user.userName,
1735
+ client_id: req.body.clientId,
1736
+ };
1737
+ await checklistLogs.create( logInsertData );
1738
+ return res.sendSuccess( { checklistName: getCheckDetails.checkListName, message: 'Updated Successfully' } );
1739
+ } catch ( e ) {
1740
+ logger.error( 'updatePublish task erroe =>', e );
1741
+ return res.sendError( e, 500 );
1742
+ }
1743
+ };
@@ -1,6 +1,6 @@
1
1
  import * as taskService from '../service/task.service.js';
2
2
  import * as processedTaskService from '../service/processedTaskList.service.js';
3
- import { logger } from 'tango-app-api-middleware';
3
+ import { logger, download } from 'tango-app-api-middleware';
4
4
  import dayjs from 'dayjs';
5
5
  import mongoose from 'mongoose';
6
6
  // const ObjectId = mongoose.Types.ObjectId;
@@ -218,25 +218,31 @@ export const taskTableV1 = async ( req, res ) => {
218
218
  export const taskInfoTableV1 = async ( req, res ) => {
219
219
  try {
220
220
  let requestData = req.body;
221
- let fromDate = new Date( requestData.fromDate );
222
- let toDate = new Date( requestData.toDate );
223
- let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
224
- toDate = new Date( toDate.getTime() - userTimezoneOffset );
225
- toDate.setUTCHours( 23, 59, 59, 59 );
221
+ // let fromDate = new Date( requestData.fromDate );
222
+ // let toDate = new Date( requestData.toDate );
223
+ // let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
224
+ // toDate = new Date( toDate.getTime() - userTimezoneOffset );
225
+ // toDate.setUTCHours( 23, 59, 59, 59 );
226
226
  let result = {};
227
227
 
228
228
  let findQuery = [];
229
229
  let findAndQuery = [];
230
230
 
231
231
  findAndQuery.push(
232
- { date_iso: { $gte: fromDate, $lte: toDate } },
232
+ // { date_iso: { $gte: fromDate, $lte: toDate } },
233
233
  { client_id: requestData.clientId },
234
234
  { store_id: { $in: requestData.storeId } },
235
235
  // { checkListType: { $eq: 'task' } },
236
236
  { sourceCheckList_id: new mongoose.Types.ObjectId( requestData.taskId ) },
237
237
  );
238
238
  if ( requestData.checklistStatus && requestData.checklistStatus != 'All' ) {
239
- findAndQuery.push( { checklistStatus: requestData.checklistStatus } );
239
+ if ( requestData.checklistStatus == 'redo' ) {
240
+ findAndQuery.push(
241
+ { redoStatus: true },
242
+ { checklistStatus: { $ne: 'submit' } } );
243
+ } else {
244
+ findAndQuery.push( { checklistStatus: requestData.checklistStatus } );
245
+ }
240
246
  }
241
247
 
242
248
  findQuery.push( { $match: { $and: findAndQuery } } );
@@ -677,11 +683,25 @@ export const taskDropdownListV1 = async ( req, res ) => {
677
683
  findAndQuery.push(
678
684
  { client_id: requestData.clientId },
679
685
  // { checkListType: 'task' },
680
- { isdeleted: false },
686
+ // { isdeleted: false },
687
+ );
688
+ findQuery.push( { $match: { $and: findAndQuery } }, { $sort: { date_iso: -1 } } );
689
+ findQuery.push(
690
+ {
691
+ $group: {
692
+ _id: '$sourceCheckList_id',
693
+ checkListName: { $first: '$checkListName' },
694
+ checkListType: { $first: '$checkListType' },
695
+ createdByName: { $first: '$createdByName' },
696
+ storeCount: { $first: '$storeCount' },
697
+ scheduleEndTimeISO: { $first: '$scheduleEndTime_iso' },
698
+ submitTime_string: { $first: '$submitTime_string' },
699
+ },
700
+ },
681
701
  );
682
- findQuery.push( { $match: { $and: findAndQuery } } );
683
702
  findQuery.push( {
684
703
  $project: {
704
+ _id: 1,
685
705
  sourceCheckList_id: '$_id',
686
706
  checkListName: 1,
687
707
  checkListNameLowercase: { $toLower: '$checkListName' },
@@ -697,7 +717,7 @@ export const taskDropdownListV1 = async ( req, res ) => {
697
717
  } else {
698
718
  findQuery.push( { $sort: { ['checkListNameLowercase']: 1 } } );
699
719
  }
700
- let getChecklistData = await taskService.aggregate( findQuery );
720
+ let getChecklistData = await processedTaskService.aggregate( findQuery );
701
721
  if ( !getChecklistData.length ) {
702
722
  return res.sendError( { error: 'No Data Found' }, 204 );
703
723
  }
@@ -893,3 +913,114 @@ export const taskDeleteV1 = async ( req, res ) => {
893
913
  return res.sendError( e, 500 );
894
914
  }
895
915
  };
916
+
917
+
918
+ export async function taskDetails( req, res ) {
919
+ try {
920
+ if ( !req.body.fromDate || !req.body.toDate ) {
921
+ return res.sendError( 'fromDate or toDate is missing', 400 );
922
+ }
923
+ if ( !req.body.clientId ) {
924
+ return res.sendError( 'clientId is required', 400 );
925
+ }
926
+
927
+ let toDate = new Date( req.body.toDate );
928
+ let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
929
+ toDate = new Date( toDate.getTime() - userTimezoneOffset );
930
+ toDate.setUTCHours( 23, 59, 59, 59 );
931
+ let limit = req.body?.limit || 10;
932
+ let page = req.body?.offset ? ( req.body.offset * req.body.limit ) : 0;
933
+
934
+ let query = [
935
+ {
936
+ $match: {
937
+ date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
938
+ client_id: req.body.clientId,
939
+ ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } : {},
940
+ },
941
+ },
942
+ { $sort: { date_iso: -1 } },
943
+ {
944
+ $group: {
945
+ _id: '$sourceCheckList_id',
946
+ checkListName: { $first: '$checkListName' },
947
+ createdByName: { $first: '$createdByName' },
948
+ publishDate: { $first: '$publishDate' },
949
+ priorityType: { $first: '$priorityType' },
950
+ storeCount: { $first: '$storeCount' },
951
+ submitCount: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ] } },
952
+ redoCount: { $sum: { $cond: [ { $and: [ { $eq: [ '$redoStatus', true ] }, { $ne: [ '$checklistStatus', 'submit' ] } ] }, 1, 0 ] } },
953
+ scheduleEndTime_iso: { $first: '$scheduleEndTime_iso' },
954
+ checkListChar: { $first: { $toUpper: { $substr: [ '$createdByName', 0, 2 ] } } },
955
+ },
956
+ },
957
+ ];
958
+
959
+ if ( req.body?.searchValue.trim().length ) {
960
+ query.push(
961
+ {
962
+ $match: {
963
+ checkListName: { $regex: req.body.searchValue, $options: 'i' },
964
+ },
965
+ },
966
+ );
967
+ }
968
+
969
+ if ( req.body.sortColumnName && req.body.sortBy ) {
970
+ query.push( {
971
+ $sort: { [req.body.sortColumnName]: req.body.sortBy },
972
+ } );
973
+ } else {
974
+ query.push( {
975
+ $sort: { checkListName: 1 },
976
+ } );
977
+ }
978
+
979
+ if ( req.body.filter.length ) {
980
+ query.push( {
981
+ $match: { priorityType: { $in: req.body.filter } },
982
+ } );
983
+ }
984
+
985
+ query.push( {
986
+ $facet: {
987
+ data: [
988
+ { $skip: page }, { $limit: limit },
989
+ ],
990
+ count: [
991
+ { $count: 'total' },
992
+ ],
993
+ },
994
+ } );
995
+
996
+
997
+ let taskDetails = await processedTaskService.aggregate( query );
998
+
999
+ if ( req.body.export ) {
1000
+ const exportResult = [];
1001
+ for ( let task of taskDetails[0].data ) {
1002
+ exportResult.push( {
1003
+ 'Checklist Name': task?.checkListName ||'',
1004
+ 'Created by': task?.createdByName ||'--',
1005
+ 'Created On': dayjs.utc( task?.publishDate ).format( 'DD MMM, YYYY' ) || '',
1006
+ 'Priority': task?.priorityType || '--',
1007
+ 'Assigned To': task?.storeCount ||'--',
1008
+ 'Submitted': task?.submitCount ||'--',
1009
+ 'Redo': task?.redoCount ||'--',
1010
+ 'Due on': dayjs.utc( task?.scheduleEndTime_iso ).format( 'DD MMM, YYYY' ) || '',
1011
+ } );
1012
+ }
1013
+ await download( exportResult, res );
1014
+ return;
1015
+ }
1016
+
1017
+ if ( !taskDetails[0].data.length ) {
1018
+ return res.sendError( 'no date found', 204 );
1019
+ }
1020
+
1021
+ return res.sendSuccess( { data: taskDetails?.[0]?.data || [], count: taskDetails?.[0]?.count?.[0]?.total || 0 } );
1022
+ } catch ( e ) {
1023
+ logger.error( { function: 'taskDetails', error: e, message: req.body } );
1024
+ return res.sendError( e, 500 );
1025
+ }
1026
+ }
@@ -21,6 +21,8 @@ taskRouter
21
21
  .post( '/getQuestions', isAllowedSessionHandler, taskController.getQuestions )
22
22
  .post( '/getAnswers', isAllowedSessionHandler, taskController.getAnswers )
23
23
  .post( '/getAnswerCount', isAllowedSessionHandler, taskController.getAnswerCount )
24
- .post( '/approvalstatus', isAllowedSessionHandler, taskController.approvalstatus );
24
+ .post( '/approvalstatus', isAllowedSessionHandler, taskController.approvalstatus )
25
+ .get( '/task-list', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ ] } ] } ), taskController.taskList )
26
+ .put( '/publish', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [ 'isEdit' ] } ] } ), taskController.updatePublish );
25
27
 
26
28
 
@@ -3,7 +3,7 @@ export const taskDashboardRouter = express.Router();
3
3
  import { isAllowedSessionHandler, accessVerification, isAllowedClient } from 'tango-app-api-middleware';
4
4
 
5
5
  import {
6
- overallCards, taskTable, taskInfoTable, taskDropdownList, taskTableV1, overallCardsV1, taskInfoTableV1, taskDropdownListV1, taskDeleteV1,
6
+ overallCards, taskTable, taskInfoTable, taskDropdownList, taskTableV1, overallCardsV1, taskInfoTableV1, taskDropdownListV1, taskDeleteV1, taskDetails,
7
7
  } from '../controllers/taskDashboard.controllers.js';
8
8
 
9
9
  taskDashboardRouter
@@ -15,6 +15,7 @@ taskDashboardRouter
15
15
  .post( '/taskInfoTableV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskInfoTableV1 )
16
16
  .post( '/taskDropdownList', isAllowedSessionHandler, taskDropdownList )
17
17
  .post( '/taskDropdownListV1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'Task', permissions: [] } ] } ), taskDropdownListV1 )
18
- .post( '/taskDeleteV1', isAllowedSessionHandler, taskDeleteV1 );
18
+ .post( '/taskDeleteV1', isAllowedSessionHandler, taskDeleteV1 )
19
+ .post( '/taskDetails', isAllowedSessionHandler, taskDetails );
19
20
 
20
21
  export default taskDashboardRouter;