tango-app-api-trax 3.5.2-alpha-10 → 3.5.2-alpha-12
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
|
|
|
3
|
-
import { logger, insertOpenSearchData } from 'tango-app-api-middleware';
|
|
3
|
+
import { logger, insertOpenSearchData, sendTeamsNotification } from 'tango-app-api-middleware';
|
|
4
4
|
import * as storeService from '../services/store.service.js';
|
|
5
5
|
import * as groupService from '../services/group.service.js';
|
|
6
6
|
import * as clusterService from '../services/cluster.service.js';
|
|
@@ -288,19 +288,18 @@ export async function approveChecklist( req, res ) {
|
|
|
288
288
|
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
289
289
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
290
290
|
let query = { sourceCheckList_id: req.body.sourceCheckList_id, date_iso: { $gte: req.body.fromDate, $lte: toDate }, $or: [ { checklistStatus: 'submit' }, { redoStatus: true } ], approvalEnable: true };
|
|
291
|
+
if ( !( req.body.assignedStores && req.body.assignedStores.length >0 ) ) {
|
|
292
|
+
req.body.assignedStores = req.body.storeId;
|
|
293
|
+
}
|
|
291
294
|
if ( req.body?.storeId?.length ) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
query['store_id'] = { $in: filteredStoreIds };
|
|
295
|
-
} else {
|
|
296
|
-
const filteredStoreIds = req.body?.storeId;
|
|
297
|
-
query['store_id'] = { $in: filteredStoreIds };
|
|
298
|
-
}
|
|
295
|
+
const filteredStoreIds = req.body.storeId.filter( ( store ) => req.body.assignedStores.includes( store ) );
|
|
296
|
+
query['store_id'] = { $in: filteredStoreIds };
|
|
299
297
|
}
|
|
300
298
|
if ( req.body?.userEmail?.length ) {
|
|
301
299
|
query['userEmail'] = { $in: req.body?.userEmail };
|
|
302
300
|
}
|
|
303
|
-
let checklistDetails = await processedChecklist.find( query, { _id: 1, checklistStatus: 1, storeName: 1, store_id: 1, userEmail: 1, client_id: 1, coverage: 1, checkListName: 1 } );
|
|
301
|
+
let checklistDetails = await processedChecklist.find( query, { _id: 1, checklistStatus: 1, storeName: 1, store_id: 1, userEmail: 1, client_id: 1, coverage: 1, checkListName: 1, sourceCheckList_id: 1 } );
|
|
302
|
+
// console.log( 'checklistDetails =>', checklistDetails );
|
|
304
303
|
if ( !checklistDetails.length ) {
|
|
305
304
|
return res.sendError( 'No data found', 204 );
|
|
306
305
|
}
|
|
@@ -315,7 +314,19 @@ export async function approveChecklist( req, res ) {
|
|
|
315
314
|
approvalByEmail: req.user.email,
|
|
316
315
|
};
|
|
317
316
|
let updateResponse = await processedChecklist.updateMany( { _id: { $in: idList }, approvalStatus: false }, approvalUpdateData );
|
|
317
|
+
|
|
318
|
+
let teamsMsg;
|
|
319
|
+
let teamsAlertUrls = process.env.teamsAlertURL ? JSON.parse( process.env.teamsAlertURL ) : '';
|
|
320
|
+
teamsMsg = 'ClientId: '+ checklistDetails[0].client_id + ', Type: Checklist, Process: started, Action: Approval, ChecklistId: '+ checklistDetails[0].sourceCheckList_id + ', Checklist Name: '+ checklistDetails[0].checkListName +', UpDatedBy: '+ req.user.email;
|
|
321
|
+
if ( teamsAlertUrls && teamsAlertUrls.approvalAlert ) {
|
|
322
|
+
sendTeamsNotification( teamsAlertUrls.approvalAlert, teamsMsg );
|
|
323
|
+
}
|
|
324
|
+
|
|
318
325
|
if ( updateResponse.modifiedCount || updateResponse.matchedCount ) {
|
|
326
|
+
teamsMsg = 'ClientId: '+ checklistDetails[0].client_id + ', Type: Checklist, Process: Completed, Updated Count: '+updateResponse.modifiedCount+' Action: Approval, ChecklistId: '+ checklistDetails[0].sourceCheckList_id + ', Checklist Name: '+ checklistDetails[0].checkListName +', UpDatedBy: '+ req.user.email;
|
|
327
|
+
if ( teamsAlertUrls && teamsAlertUrls.approvalAlert ) {
|
|
328
|
+
sendTeamsNotification( teamsAlertUrls.approvalAlert, teamsMsg );
|
|
329
|
+
}
|
|
319
330
|
let inputstores = checklistDetails.filter( ( data ) => data.checklistStatus == 'submit' );
|
|
320
331
|
let storeNames = inputstores.map( ( data ) => data.storeName );
|
|
321
332
|
|
|
@@ -336,7 +347,7 @@ export async function approveChecklist( req, res ) {
|
|
|
336
347
|
approvalByEmail: req.user.email,
|
|
337
348
|
},
|
|
338
349
|
};
|
|
339
|
-
|
|
350
|
+
console.log( params );
|
|
340
351
|
const requestOptions = {
|
|
341
352
|
method: 'POST',
|
|
342
353
|
headers: {
|
|
@@ -366,6 +377,7 @@ export async function approveChecklist( req, res ) {
|
|
|
366
377
|
},
|
|
367
378
|
'userType': req.user.userType,
|
|
368
379
|
'requestedStores': filteredStoreIds,
|
|
380
|
+
'requestedUsers': req.body.userEmail,
|
|
369
381
|
};
|
|
370
382
|
console.log( 'logData', logData );
|
|
371
383
|
let urlopensearch = JSON.parse( process.env.OPENSEARCH );
|
|
@@ -386,7 +398,7 @@ export async function approveChecklist( req, res ) {
|
|
|
386
398
|
return res.sendError( `${redoList.length} stores has not been approved since those stores are not submitted`, 400 );
|
|
387
399
|
}
|
|
388
400
|
} catch ( e ) {
|
|
389
|
-
console.log( 'e', e );
|
|
401
|
+
// console.log( 'e', e );
|
|
390
402
|
logger.error( { function: 'approveChecklist', error: e } );
|
|
391
403
|
return res.sendError( e, 500 );
|
|
392
404
|
}
|