tango-app-api-task 1.0.0-alpha.3 → 1.0.0-alpha.4
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
|
@@ -145,6 +145,8 @@ export async function createUpdateTask( req, res ) {
|
|
|
145
145
|
return res.sendSuccess( { checklistId: checkListId, message: message } );
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
+
} else {
|
|
149
|
+
return res.sendError( { message: 'something went wrong' }, 500 );
|
|
148
150
|
}
|
|
149
151
|
} catch ( e ) {
|
|
150
152
|
logger.error( { functionName: 'createTask', error: e } );
|
|
@@ -588,6 +590,7 @@ export async function taskConfig( req, res ) {
|
|
|
588
590
|
let storeCount = 0;
|
|
589
591
|
let locationCount = 0;
|
|
590
592
|
let checklistDetails;
|
|
593
|
+
inputBody.client_id = inputBody.clientId;
|
|
591
594
|
if ( !inputBody._id ) {
|
|
592
595
|
return res.sendError( { message: 'Task Id is Required' }, 400 );
|
|
593
596
|
}
|
|
@@ -605,7 +608,7 @@ export async function taskConfig( req, res ) {
|
|
|
605
608
|
checkListName: inputBody?.checkListName,
|
|
606
609
|
createdBy: req.user._id,
|
|
607
610
|
createdByName: req.user.userName,
|
|
608
|
-
client_id:
|
|
611
|
+
client_id: inputBody.client_id,
|
|
609
612
|
};
|
|
610
613
|
await checklistLogs.create( logInsertData );
|
|
611
614
|
|
|
@@ -631,7 +634,7 @@ export async function taskConfig( req, res ) {
|
|
|
631
634
|
userEmail: ele.value,
|
|
632
635
|
checkListId: inputBody._id,
|
|
633
636
|
type: 'task',
|
|
634
|
-
client_id:
|
|
637
|
+
client_id: inputBody.client_id,
|
|
635
638
|
} );
|
|
636
639
|
}
|
|
637
640
|
} );
|
|
@@ -653,7 +656,7 @@ export async function taskConfig( req, res ) {
|
|
|
653
656
|
let query = [
|
|
654
657
|
{
|
|
655
658
|
$match: {
|
|
656
|
-
client_id:
|
|
659
|
+
client_id: inputBody.client_id,
|
|
657
660
|
id: { $in: storeList },
|
|
658
661
|
city: { $exists: true },
|
|
659
662
|
},
|
|
@@ -850,6 +853,7 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
|
|
|
850
853
|
element4.publishDate = getCLconfig.publishDate;
|
|
851
854
|
element4.locationCount = getCLconfig.locationCount;
|
|
852
855
|
element4.scheduleRepeatedType = 'daily';
|
|
856
|
+
element4.approvalEnable = getCLconfig.approver.length ? true : false;
|
|
853
857
|
}
|
|
854
858
|
if ( userIdList.length ) {
|
|
855
859
|
allQuestion = allQuestion.filter( ( item ) => typeof item._id == 'undefined' );
|
|
@@ -1047,7 +1051,7 @@ export async function createChecklistTask( req, res ) {
|
|
|
1047
1051
|
client_id: inputBody.clientId,
|
|
1048
1052
|
};
|
|
1049
1053
|
await taskQuestionService.create( question );
|
|
1050
|
-
let storeDetails = await storeService.findOne( { storeName: inputBody.storeName }, { storeId: 1, storeProfile: 1 } );
|
|
1054
|
+
let storeDetails = await storeService.findOne( { storeName: inputBody.storeName, status: 'active' }, { storeId: 1, storeProfile: 1 } );
|
|
1051
1055
|
if ( !storeDetails ) {
|
|
1052
1056
|
return res.sendError( 'No data found', 204 );
|
|
1053
1057
|
}
|
|
@@ -10,8 +10,8 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
10
10
|
let taskIdList = [];
|
|
11
11
|
let checklistIdList = [];
|
|
12
12
|
let resultData;
|
|
13
|
-
if ( ( req?.user?.userType == 'client' && req.user.role == 'superadmin' )
|
|
14
|
-
let clientId = req.user?.clientId
|
|
13
|
+
if ( ( req?.user?.userType == 'client' && req.user.role == 'superadmin' ) ) {
|
|
14
|
+
let clientId = req.user?.clientId;
|
|
15
15
|
query = { client_id: clientId };
|
|
16
16
|
} else {
|
|
17
17
|
query = { userEmail: req.user.userEmail };
|
|
@@ -45,7 +45,7 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
45
45
|
},
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
let taskQuery = [
|
|
49
49
|
{
|
|
50
50
|
$match: {
|
|
51
51
|
date_iso: { $gte: new Date( req.body.date ), $lte: toDate },
|
|
@@ -55,9 +55,8 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
55
55
|
},
|
|
56
56
|
{ ...groupQuery },
|
|
57
57
|
];
|
|
58
|
-
let taskCount = await processedTask.aggregate( query );
|
|
59
58
|
|
|
60
|
-
|
|
59
|
+
let checklistQuery = [
|
|
61
60
|
{
|
|
62
61
|
$match: {
|
|
63
62
|
date_iso: { $gte: new Date( req.body.date ), $lte: toDate },
|
|
@@ -67,7 +66,12 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
67
66
|
},
|
|
68
67
|
{ ...groupQuery },
|
|
69
68
|
];
|
|
70
|
-
|
|
69
|
+
|
|
70
|
+
let [ taskCount, checklistCount ] = await Promise.all( [
|
|
71
|
+
processedTask.aggregate( taskQuery ),
|
|
72
|
+
processedChecklist.aggregate( checklistQuery ),
|
|
73
|
+
] );
|
|
74
|
+
|
|
71
75
|
resultData = { taskCount: taskCount?.[0]?.count || 0, checklistCount: checklistCount?.[0]?.count || 0 };
|
|
72
76
|
return res.sendSuccess( resultData );
|
|
73
77
|
} catch ( error ) {
|
|
@@ -83,10 +87,8 @@ export const approvalTableV1 = async ( req, res ) => {
|
|
|
83
87
|
let taskIdList = [];
|
|
84
88
|
let checklistIdList = [];
|
|
85
89
|
let resultData;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if ( ( req?.user?.userType == 'client' && req.user.role == 'superadmin' ) || req.body?.clientId ) {
|
|
89
|
-
let clientId = req.user?.clientId || req.body?.clientId;
|
|
90
|
+
if ( ( req?.user?.userType == 'client' && req.user.role == 'superadmin' ) ) {
|
|
91
|
+
let clientId = req.user?.clientId;
|
|
90
92
|
query = { client_id: clientId };
|
|
91
93
|
} else {
|
|
92
94
|
query = { userEmail: req.user.userEmail };
|
|
@@ -100,6 +102,7 @@ export const approvalTableV1 = async ( req, res ) => {
|
|
|
100
102
|
.map( ( ele ) => ele.checkListId.toString() ),
|
|
101
103
|
),
|
|
102
104
|
].map( ( item ) => new ObjectId( item ) );
|
|
105
|
+
|
|
103
106
|
checklistIdList = [
|
|
104
107
|
...new Set(
|
|
105
108
|
details
|
|
@@ -158,6 +161,7 @@ export const approvalTableV1 = async ( req, res ) => {
|
|
|
158
161
|
},
|
|
159
162
|
} ];
|
|
160
163
|
|
|
164
|
+
const promises = [];
|
|
161
165
|
|
|
162
166
|
if ( [ 'task', 'all' ].includes( req.body.type ) ) {
|
|
163
167
|
query = [
|
|
@@ -169,8 +173,12 @@ export const approvalTableV1 = async ( req, res ) => {
|
|
|
169
173
|
},
|
|
170
174
|
...groupQuery,
|
|
171
175
|
];
|
|
172
|
-
|
|
176
|
+
promises.push( processedTask.aggregate( query ) );
|
|
177
|
+
} else {
|
|
178
|
+
promises.push( Promise.resolve( null ) );
|
|
173
179
|
}
|
|
180
|
+
|
|
181
|
+
|
|
174
182
|
if ( [ 'checklist', 'all' ].includes( req.body.type ) ) {
|
|
175
183
|
query = [
|
|
176
184
|
{
|
|
@@ -181,9 +189,13 @@ export const approvalTableV1 = async ( req, res ) => {
|
|
|
181
189
|
},
|
|
182
190
|
...groupQuery,
|
|
183
191
|
];
|
|
184
|
-
|
|
185
|
-
|
|
192
|
+
promises.push( processedChecklist.aggregate( query ) );
|
|
193
|
+
} else {
|
|
194
|
+
promises.push( Promise.resolve( null ) );
|
|
186
195
|
}
|
|
196
|
+
|
|
197
|
+
const [ taskResult, checklistResult ] = await Promise.all( promises );
|
|
198
|
+
|
|
187
199
|
const taskSummary = taskResult.reduce(
|
|
188
200
|
( acc, ele ) => {
|
|
189
201
|
if ( ele.unApproveCount === ele.storeCount ) {
|
|
@@ -234,6 +246,7 @@ export const overallCards = async ( req, res ) => {
|
|
|
234
246
|
return res.sendError( error, 500 );
|
|
235
247
|
}
|
|
236
248
|
};
|
|
249
|
+
|
|
237
250
|
async function overallCardsData( requestData ) {
|
|
238
251
|
try {
|
|
239
252
|
let cardData = {
|
|
@@ -251,6 +264,7 @@ async function overallCardsData( requestData ) {
|
|
|
251
264
|
logger.error( { error: error, message: data, function: 'overallCardsData' } );
|
|
252
265
|
}
|
|
253
266
|
}
|
|
267
|
+
|
|
254
268
|
export const approvalTable = async ( req, res ) => {
|
|
255
269
|
try {
|
|
256
270
|
let requestData = req.body;
|
|
@@ -262,6 +276,7 @@ export const approvalTable = async ( req, res ) => {
|
|
|
262
276
|
return res.sendError( error, 500 );
|
|
263
277
|
}
|
|
264
278
|
};
|
|
279
|
+
|
|
265
280
|
async function approvalTableData( requestData ) {
|
|
266
281
|
try {
|
|
267
282
|
let tableData = {
|
|
@@ -329,7 +344,6 @@ async function approvalTableData( requestData ) {
|
|
|
329
344
|
}
|
|
330
345
|
}
|
|
331
346
|
|
|
332
|
-
|
|
333
347
|
export const activityLog = async ( req, res ) => {
|
|
334
348
|
try {
|
|
335
349
|
let requestData = req.body;
|
|
@@ -341,6 +355,7 @@ export const activityLog = async ( req, res ) => {
|
|
|
341
355
|
return res.sendError( error, 500 );
|
|
342
356
|
}
|
|
343
357
|
};
|
|
358
|
+
|
|
344
359
|
async function activityLogData( requestData ) {
|
|
345
360
|
try {
|
|
346
361
|
let activityLogData = {
|
|
@@ -58,7 +58,6 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
58
58
|
let findAndQuery = [];
|
|
59
59
|
|
|
60
60
|
findAndQuery.push(
|
|
61
|
-
{ checkListType: { $eq: 'task' } },
|
|
62
61
|
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
63
62
|
{ client_id: requestData.clientId },
|
|
64
63
|
{ store_id: { $in: requestData.storeId } },
|
|
@@ -67,7 +66,7 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
67
66
|
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
68
67
|
findQuery.push( {
|
|
69
68
|
$group: {
|
|
70
|
-
_id: '$checklistStatus',
|
|
69
|
+
_id: { status: '$checklistStatus', redoType: '$redoStatus', approvalStatus: '$approvalStatus' },
|
|
71
70
|
count: { $sum: 1 },
|
|
72
71
|
},
|
|
73
72
|
},
|
|
@@ -75,11 +74,11 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
75
74
|
$group: {
|
|
76
75
|
_id: null,
|
|
77
76
|
TotalTasks: { $sum: '$count' },
|
|
78
|
-
open: { $sum: { $cond: [ { $eq: [ '$_id', 'open' ] }, '$count', 0 ] } },
|
|
79
|
-
inprogress: { $sum: { $cond: [ { $eq: [ '$_id', 'inprogress' ] }, '$count', 0 ] } },
|
|
80
|
-
reopen: { $sum: { $cond: [ { $eq: [ '$_id', '
|
|
81
|
-
submitted: { $sum: { $cond: [ { $eq: [ '$_id', 'submit' ] }, '$count', 0 ] } },
|
|
82
|
-
closed: { $sum: { $cond: [ { $eq: [ '$_id', '
|
|
77
|
+
open: { $sum: { $cond: [ { $and: [ { $eq: [ '$_id.status', 'open' ] }, { $eq: [ '$_id.redoType', false ] } ] }, '$count', 0 ] } },
|
|
78
|
+
inprogress: { $sum: { $cond: [ { $eq: [ '$_id.status', 'inprogress' ] }, '$count', 0 ] } },
|
|
79
|
+
reopen: { $sum: { $cond: [ { $and: [ { $eq: [ '$_id.status', 'open' ] }, { $eq: [ '$_id.redoType', true ] } ] }, '$count', 0 ] } },
|
|
80
|
+
submitted: { $sum: { $cond: [ { $and: [ { $eq: [ '$_id.status', 'submit' ] }, { $eq: [ '$_id.approvalStatus', false ] } ] }, '$count', 0 ] } },
|
|
81
|
+
closed: { $sum: { $cond: [ { $and: [ { $eq: [ '$_id.status', 'submit' ] }, { $eq: [ '$_id.approvalStatus', true ] } ] }, '$count', 0 ] } },
|
|
83
82
|
},
|
|
84
83
|
},
|
|
85
84
|
{
|
|
@@ -112,7 +111,7 @@ export const taskTableV1 = async ( req, res ) => {
|
|
|
112
111
|
query.push(
|
|
113
112
|
{
|
|
114
113
|
$match: {
|
|
115
|
-
checkListType: 'task',
|
|
114
|
+
// checkListType: 'task',
|
|
116
115
|
client_id: req.body.clientId,
|
|
117
116
|
isdeleted: false,
|
|
118
117
|
},
|
|
@@ -230,11 +229,10 @@ export const taskInfoTableV1 = async ( req, res ) => {
|
|
|
230
229
|
let findAndQuery = [];
|
|
231
230
|
|
|
232
231
|
findAndQuery.push(
|
|
232
|
+
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
233
233
|
{ client_id: requestData.clientId },
|
|
234
234
|
{ store_id: { $in: requestData.storeId } },
|
|
235
|
-
{
|
|
236
|
-
{ date_iso: { $lte: toDate } },
|
|
237
|
-
{ checkListType: { $eq: 'task' } },
|
|
235
|
+
// { checkListType: { $eq: 'task' } },
|
|
238
236
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.taskId ) },
|
|
239
237
|
);
|
|
240
238
|
if ( requestData.checklistStatus && requestData.checklistStatus != 'All' ) {
|
|
@@ -315,12 +313,6 @@ export const taskInfoTableV1 = async ( req, res ) => {
|
|
|
315
313
|
},
|
|
316
314
|
} );
|
|
317
315
|
|
|
318
|
-
let getTotalCount = await processedTaskService.aggregate( findQuery );
|
|
319
|
-
console.log( 'getTotalCount', getTotalCount );
|
|
320
|
-
if ( !getTotalCount.length ) {
|
|
321
|
-
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
322
|
-
}
|
|
323
|
-
|
|
324
316
|
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
|
|
325
317
|
findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
|
|
326
318
|
} else {
|
|
@@ -329,14 +321,30 @@ export const taskInfoTableV1 = async ( req, res ) => {
|
|
|
329
321
|
|
|
330
322
|
let limit = parseInt( requestData?.limit ) || 10;
|
|
331
323
|
let skip = limit * ( requestData?.offset -1 ) || 0;
|
|
332
|
-
|
|
324
|
+
|
|
325
|
+
findQuery.push( {
|
|
326
|
+
$facet: {
|
|
327
|
+
data: [
|
|
328
|
+
{ $skip: skip },
|
|
329
|
+
{ $limit: limit },
|
|
330
|
+
],
|
|
331
|
+
count: [
|
|
332
|
+
{ $count: 'total' },
|
|
333
|
+
],
|
|
334
|
+
},
|
|
335
|
+
} );
|
|
336
|
+
|
|
333
337
|
let taskInfoData = await processedTaskService.aggregate( findQuery );
|
|
334
338
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
339
|
+
if ( !taskInfoData[0].data.length ) {
|
|
340
|
+
return res.sendError( 'no data found', 204 );
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
result.totalCount = taskInfoData[0].count[0].total;
|
|
344
|
+
for ( let i = 0; i < taskInfoData[0].data.length; i++ ) {
|
|
345
|
+
taskInfoData[0].data[i].scheduleEndTime_iso = dayjs( taskInfoData[0].data[i].scheduleEndTime_iso ).format( 'DD MMM YYYY' );
|
|
338
346
|
}
|
|
339
|
-
result.taskInfo = taskInfoData;
|
|
347
|
+
result.taskInfo = taskInfoData[0].data;
|
|
340
348
|
return res.sendSuccess( result );
|
|
341
349
|
} catch ( error ) {
|
|
342
350
|
console.log( 'error =>', error );
|
|
@@ -668,7 +676,7 @@ export const taskDropdownListV1 = async ( req, res ) => {
|
|
|
668
676
|
let findAndQuery = [];
|
|
669
677
|
findAndQuery.push(
|
|
670
678
|
{ client_id: requestData.clientId },
|
|
671
|
-
{ checkListType: 'task' },
|
|
679
|
+
// { checkListType: 'task' },
|
|
672
680
|
{ isdeleted: false },
|
|
673
681
|
);
|
|
674
682
|
findQuery.push( { $match: { $and: findAndQuery } } );
|