tango-app-api-trax 1.0.0-alpha.113 → 1.0.0-alpha.115
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
|
@@ -14,8 +14,56 @@ import mongoose from 'mongoose';
|
|
|
14
14
|
export const downloadInsert = async ( req, res ) => {
|
|
15
15
|
try {
|
|
16
16
|
let requestData = req.body;
|
|
17
|
+
let fromDate = new Date( requestData.fromDate );
|
|
18
|
+
let toDate = new Date( requestData.toDate );
|
|
19
|
+
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
20
|
+
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
21
|
+
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
17
22
|
let name;
|
|
18
23
|
let fileType = requestData?.fileType || 'pdfzip';
|
|
24
|
+
|
|
25
|
+
if ( requestData.searchValue && requestData.searchValue != '' ) {
|
|
26
|
+
let storeList = requestData.searchValue.split( ',' ).map( ( item ) => item.trim().toLowerCase() );
|
|
27
|
+
let getStoreIDQuery = [];
|
|
28
|
+
if ( storeList.length > 1 ) {
|
|
29
|
+
getStoreIDQuery.push( { $project: { storeName: 1, storeId: 1 } } );
|
|
30
|
+
getStoreIDQuery.push( { $addFields: { store: { $toLower: '$storeName' } } } );
|
|
31
|
+
getStoreIDQuery.push( { $match: { store: { $in: storeList } } } );
|
|
32
|
+
getStoreIDQuery.push( { $group: { _id: null, storeId: { $push: '$storeId' } } } );
|
|
33
|
+
getStoreIDQuery.push( { $project: { storeId: 1, _id: 0 } } );
|
|
34
|
+
}
|
|
35
|
+
let getStoreId = await storeService.aggregate( getStoreIDQuery );
|
|
36
|
+
if ( getStoreId.length > 0 ) {
|
|
37
|
+
if ( getStoreId[0].storeId && getStoreId[0].storeId.length > 0 ) {
|
|
38
|
+
requestData.storeIds = getStoreId[0].storeId;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if ( requestData.sourceCheckList_id && requestData.sourceCheckList_id !='' ) {
|
|
44
|
+
let getChecklistQuery = [];
|
|
45
|
+
getChecklistQuery.push( { $project: { sourceCheckList_id: 1, date_iso: 1, store_id: 1, checklistStatus: 1 } } );
|
|
46
|
+
getChecklistQuery.push( {
|
|
47
|
+
$match: {
|
|
48
|
+
$and: [
|
|
49
|
+
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
|
|
50
|
+
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
51
|
+
{ store_id: { $in: requestData.storeIds } },
|
|
52
|
+
{ checklistStatus: 'submit' },
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
} );
|
|
56
|
+
getChecklistQuery.push( { $count: 'totalCount' } );
|
|
57
|
+
let getChecklistCount = await processedchecklistService.aggregate( getChecklistQuery );
|
|
58
|
+
|
|
59
|
+
if ( getChecklistCount && getChecklistCount[0]?.totalCount && getChecklistCount[0].totalCount >0 ) {
|
|
60
|
+
// console.log( 'if' );
|
|
61
|
+
// console.log( 'getChecklistCountgetChecklistCount[0].totalCount =>', getChecklistCount[0]?.totalCount );
|
|
62
|
+
} else {
|
|
63
|
+
return res.sendError( { error: 'No Data Found' }, 400 );
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
19
67
|
if ( requestData.fileType == 'pdf' ) {
|
|
20
68
|
if ( requestData?.sourceCheckList_id && requestData?.sourceCheckList_id !='' ) {
|
|
21
69
|
fileType = 'pdfzip';
|
|
@@ -61,6 +109,7 @@ export const downloadInsert = async ( req, res ) => {
|
|
|
61
109
|
'createdBy': req.user._id || '',
|
|
62
110
|
'downloadInsertFrom': requestData.downloadInsertFrom || '',
|
|
63
111
|
'answerType': requestData.answerType || '',
|
|
112
|
+
'searchValue': requestData.searchValue || '',
|
|
64
113
|
};
|
|
65
114
|
let resultData = await downloadService.insert( insertData );
|
|
66
115
|
if ( resultData ) {
|
|
@@ -828,7 +828,8 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
828
828
|
checkListChar: { $last: { $substr: [ '$checkListName', 0, 2 ] } },
|
|
829
829
|
sourceCheckList_id: { $last: '$sourceCheckList_id' },
|
|
830
830
|
checkListType: { $last: '$checkListType' },
|
|
831
|
-
|
|
831
|
+
storeCount: { $sum: 1 },
|
|
832
|
+
// assignedStores: { $max: '$storeCount' },
|
|
832
833
|
flaggedStores: {
|
|
833
834
|
$addToSet: {
|
|
834
835
|
$cond: [
|
|
@@ -899,12 +900,12 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
899
900
|
|
|
900
901
|
findQuery.push( {
|
|
901
902
|
$project: {
|
|
903
|
+
assignedStores: '$storeCount',
|
|
902
904
|
checkListName: 1,
|
|
903
905
|
checkListChar: 1,
|
|
904
906
|
sourceCheckList_id: 1,
|
|
905
907
|
checkListType: 1,
|
|
906
908
|
flagType: 1,
|
|
907
|
-
assignedStores: 1,
|
|
908
909
|
uniqueFlaggedStores: 1,
|
|
909
910
|
flaggedStores: { $size: '$flaggedStores' },
|
|
910
911
|
flagCount: 1,
|
|
@@ -19,6 +19,7 @@ export const validateDownloadInsertSchema = joi.object( {
|
|
|
19
19
|
downloadInsertFrom: joi.string().optional().allow( '' ),
|
|
20
20
|
userId: joi.string().optional().allow( '' ),
|
|
21
21
|
answerType: joi.string().optional().allow( '' ),
|
|
22
|
+
searchValue: joi.string().optional().allow( '' ),
|
|
22
23
|
} );
|
|
23
24
|
|
|
24
25
|
export const validateDownloadInsertParams = {
|