tango-app-api-task 1.0.0-alpha.22 → 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
|
@@ -1522,3 +1522,222 @@ export async function approvalstatus( req, res ) {
|
|
|
1522
1522
|
return res.sendError( error, 500 );
|
|
1523
1523
|
}
|
|
1524
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
|
+
};
|
|
@@ -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
|
-
|
|
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
|
|
720
|
+
let getChecklistData = await processedTaskService.aggregate( findQuery );
|
|
701
721
|
if ( !getChecklistData.length ) {
|
|
702
722
|
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
703
723
|
}
|
|
@@ -929,8 +949,9 @@ export async function taskDetails( req, res ) {
|
|
|
929
949
|
priorityType: { $first: '$priorityType' },
|
|
930
950
|
storeCount: { $first: '$storeCount' },
|
|
931
951
|
submitCount: { $sum: { $cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ] } },
|
|
932
|
-
redoCount: { $sum: { $cond: [ { $eq: [ '$redoStatus', true ] }, 1, 0 ] } },
|
|
952
|
+
redoCount: { $sum: { $cond: [ { $and: [ { $eq: [ '$redoStatus', true ] }, { $ne: [ '$checklistStatus', 'submit' ] } ] }, 1, 0 ] } },
|
|
933
953
|
scheduleEndTime_iso: { $first: '$scheduleEndTime_iso' },
|
|
954
|
+
checkListChar: { $first: { $toUpper: { $substr: [ '$createdByName', 0, 2 ] } } },
|
|
934
955
|
},
|
|
935
956
|
},
|
|
936
957
|
];
|
|
@@ -949,6 +970,10 @@ export async function taskDetails( req, res ) {
|
|
|
949
970
|
query.push( {
|
|
950
971
|
$sort: { [req.body.sortColumnName]: req.body.sortBy },
|
|
951
972
|
} );
|
|
973
|
+
} else {
|
|
974
|
+
query.push( {
|
|
975
|
+
$sort: { checkListName: 1 },
|
|
976
|
+
} );
|
|
952
977
|
}
|
|
953
978
|
|
|
954
979
|
if ( req.body.filter.length ) {
|
|
@@ -976,13 +1001,13 @@ export async function taskDetails( req, res ) {
|
|
|
976
1001
|
for ( let task of taskDetails[0].data ) {
|
|
977
1002
|
exportResult.push( {
|
|
978
1003
|
'Checklist Name': task?.checkListName ||'',
|
|
979
|
-
'Created by': task?.createdByName||'',
|
|
980
|
-
'Created On': task?.publishDate||'',
|
|
981
|
-
'Priority': task?.priorityType || '',
|
|
982
|
-
'Assigned To': task?.storeCount||'',
|
|
983
|
-
'Submitted': task?.submitCount||'',
|
|
984
|
-
'Redo': task?.redoCount||'',
|
|
985
|
-
'Due on': task?.scheduleEndTime_iso||'',
|
|
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' ) || '',
|
|
986
1011
|
} );
|
|
987
1012
|
}
|
|
988
1013
|
await download( exportResult, res );
|
|
@@ -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
|
|