tango-app-api-trax 3.3.1-beta-10 → 3.3.1-beta-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 +2 -2
- package/src/controllers/mobileTrax.controller.js +90 -25
- package/src/controllers/teaxFlag.controller.js +116 -349
- package/src/controllers/trax.controller.js +1 -103
- package/src/controllers/traxDashboard.controllers.js +184 -180
- package/src/dtos/validation.dtos.js +2 -2
- package/src/hbs/login-otp.hbs +943 -943
- package/src/routes/trax.routes.js +0 -1
- package/src/routes/traxDashboard.routes.js +1 -3
- package/src/routes/traxFlag.router.js +1 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { download, logger } from 'tango-app-api-middleware';
|
|
1
|
+
import { download, logger, getChecklistUsers } from 'tango-app-api-middleware';
|
|
2
2
|
import { aggregate } from '../services/processedchecklist.services.js';
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
4
|
import * as processedchecklistService from '../services/processedchecklist.services.js';
|
|
@@ -12,6 +12,11 @@ import mongoose from 'mongoose';
|
|
|
12
12
|
|
|
13
13
|
export const overallFlagMetrics = async ( req, res ) => {
|
|
14
14
|
try {
|
|
15
|
+
let requestData = req.body;
|
|
16
|
+
// Get User Based Checklist //
|
|
17
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
18
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
19
|
+
// End: Get User Based Checklist////
|
|
15
20
|
const pipeline = [
|
|
16
21
|
{
|
|
17
22
|
$facet: {
|
|
@@ -20,21 +25,11 @@ export const overallFlagMetrics = async ( req, res ) => {
|
|
|
20
25
|
$match: {
|
|
21
26
|
$and: [
|
|
22
27
|
{ client_id: req.body.clientId },
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
date_iso: {
|
|
30
|
-
$gte: new Date( req.body.startDate ),
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
date_iso: {
|
|
35
|
-
$lte: new Date( req.body.endDate ),
|
|
36
|
-
},
|
|
37
|
-
},
|
|
28
|
+
{ date_iso: { $gte: new Date( req.body.startDate ) } },
|
|
29
|
+
{ date_iso: { $lte: new Date( req.body.endDate ) } },
|
|
30
|
+
// { store_id: { $in: req.body.stores } },
|
|
31
|
+
{ userEmail: { $in: getUserEmails } },
|
|
32
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
38
33
|
],
|
|
39
34
|
},
|
|
40
35
|
},
|
|
@@ -108,21 +103,13 @@ export const overallFlagMetrics = async ( req, res ) => {
|
|
|
108
103
|
$match: {
|
|
109
104
|
$and: [
|
|
110
105
|
{ client_id: req.body.clientId },
|
|
111
|
-
{
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
$gte: dayjs.utc( req.body.endDate ).subtract( 7, 'days' ).startOf( 'day' ).toDate(),
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
date_iso: {
|
|
123
|
-
$lte: dayjs.utc( req.body.startDate ).subtract( 1, 'day' ).startOf( 'day' ).toDate(),
|
|
124
|
-
},
|
|
125
|
-
},
|
|
106
|
+
{ date_iso: { $gte: dayjs.utc( req.body.endDate ).subtract( 7, 'days' ).startOf( 'day' ).toDate() } },
|
|
107
|
+
{ date_iso: { $lte: dayjs.utc( req.body.startDate ).subtract( 1, 'day' ).startOf( 'day' ).toDate() } },
|
|
108
|
+
// { store_id: { $in: req.body.stores } },
|
|
109
|
+
{ '$or': [
|
|
110
|
+
{ '$and': findORQuery1 },
|
|
111
|
+
{ '$and': findORQuery2 },
|
|
112
|
+
] },
|
|
126
113
|
],
|
|
127
114
|
},
|
|
128
115
|
},
|
|
@@ -271,34 +258,27 @@ export const overallFlagMetrics = async ( req, res ) => {
|
|
|
271
258
|
|
|
272
259
|
export const checklistFlagsTable = async ( req, res ) => {
|
|
273
260
|
try {
|
|
261
|
+
let requestData = req.body;
|
|
262
|
+
// Get User Based Checklist //
|
|
263
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
264
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
265
|
+
// End: Get User Based Checklist////
|
|
274
266
|
const matchStage = {
|
|
275
267
|
$match: {
|
|
276
268
|
$and: [
|
|
277
269
|
{ client_id: req.body.clientId },
|
|
278
|
-
{
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
},
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
|
|
290
|
-
$lte: new Date( req.body.endDate ),
|
|
291
|
-
},
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
$or: [
|
|
295
|
-
{ timeFlag: { $gt: 0 } },
|
|
296
|
-
{ questionFlag: { $gt: 0 } },
|
|
297
|
-
{ mobileDetectionFlag: { $gt: 0 } },
|
|
298
|
-
{ storeOpenCloseFlag: { $gt: 0 } },
|
|
299
|
-
{ uniformDetectionFlag: { $gt: 0 } },
|
|
300
|
-
],
|
|
301
|
-
},
|
|
270
|
+
{ date_iso: { $gte: new Date( req.body.startDate ) } },
|
|
271
|
+
{ date_iso: { $lte: new Date( req.body.endDate ) } },
|
|
272
|
+
{ $or: [
|
|
273
|
+
{ timeFlag: { $gt: 0 } },
|
|
274
|
+
{ questionFlag: { $gt: 0 } },
|
|
275
|
+
{ mobileDetectionFlag: { $gt: 0 } },
|
|
276
|
+
{ storeOpenCloseFlag: { $gt: 0 } },
|
|
277
|
+
{ uniformDetectionFlag: { $gt: 0 } },
|
|
278
|
+
] },
|
|
279
|
+
// { store_id: { $in: req.body.stores } },
|
|
280
|
+
{ userEmail: { $in: getUserEmails } },
|
|
281
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
302
282
|
],
|
|
303
283
|
},
|
|
304
284
|
};
|
|
@@ -560,6 +540,12 @@ export const flagCardsV1 = async ( req, res ) => {
|
|
|
560
540
|
detectionFlag: { count: 0 },
|
|
561
541
|
};
|
|
562
542
|
|
|
543
|
+
let requestData = req.body;
|
|
544
|
+
// Get User Based Checklist //
|
|
545
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
546
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
547
|
+
// End: Get User Based Checklist////
|
|
548
|
+
|
|
563
549
|
const findQuery = [
|
|
564
550
|
{
|
|
565
551
|
$match: {
|
|
@@ -569,6 +555,8 @@ export const flagCardsV1 = async ( req, res ) => {
|
|
|
569
555
|
{ aiStoreList: { $in: storeId } },
|
|
570
556
|
],
|
|
571
557
|
date_iso: { $gte: adjustedFromDate, $lte: adjustedToDate },
|
|
558
|
+
userEmail: { $in: getUserEmails },
|
|
559
|
+
$or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ],
|
|
572
560
|
},
|
|
573
561
|
},
|
|
574
562
|
{
|
|
@@ -699,13 +687,20 @@ export const flagComparisonCardsV1 = async ( req, res ) => {
|
|
|
699
687
|
rangeTwoToDate.setUTCHours( 23, 59, 59, 59 );
|
|
700
688
|
}
|
|
701
689
|
|
|
690
|
+
// Get User Based Checklist //
|
|
691
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
692
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
693
|
+
// End: Get User Based Checklist////
|
|
702
694
|
const createFindQuery = ( fromDate, toDate ) => [
|
|
703
695
|
{ $match: { client_id: requestData.clientId,
|
|
704
696
|
$or: [
|
|
705
697
|
{ store_id: { $in: requestData.storeId } },
|
|
706
698
|
{ aiStoreList: { $in: requestData.storeId } },
|
|
707
699
|
],
|
|
708
|
-
date_iso: { $gte: fromDate, $lte: toDate }
|
|
700
|
+
date_iso: { $gte: fromDate, $lte: toDate },
|
|
701
|
+
userEmail: { $in: getUserEmails },
|
|
702
|
+
$or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ],
|
|
703
|
+
} },
|
|
709
704
|
{
|
|
710
705
|
$project: {
|
|
711
706
|
timeFlag: 1,
|
|
@@ -821,6 +816,11 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
821
816
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
822
817
|
let result = {};
|
|
823
818
|
|
|
819
|
+
// Get User Based Checklist //
|
|
820
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
821
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
822
|
+
// End: Get User Based Checklist////
|
|
823
|
+
|
|
824
824
|
let findQuery = [];
|
|
825
825
|
let findAndQuery = [];
|
|
826
826
|
findAndQuery.push(
|
|
@@ -828,6 +828,8 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
828
828
|
{ $or: [ { store_id: { $in: requestData.storeId } }, { aiStoreList: { $in: requestData.storeId } } ] },
|
|
829
829
|
{ date_iso: { $gte: fromDate } },
|
|
830
830
|
{ date_iso: { $lte: toDate } },
|
|
831
|
+
{ userEmail: { $in: getUserEmails } },
|
|
832
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
831
833
|
);
|
|
832
834
|
|
|
833
835
|
if ( requestData?.filter === 'all' ) {
|
|
@@ -853,6 +855,7 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
853
855
|
sourceCheckList_id: 1,
|
|
854
856
|
checkListId: 1,
|
|
855
857
|
checkListName: 1,
|
|
858
|
+
coverage: 1,
|
|
856
859
|
storeCount: 1,
|
|
857
860
|
createdBy: 1,
|
|
858
861
|
createdByName: 1,
|
|
@@ -875,6 +878,7 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
875
878
|
_id: '$sourceCheckList_id',
|
|
876
879
|
checkListName: { $last: '$checkListName' },
|
|
877
880
|
checkListChar: { $last: { $substr: [ '$checkListName', 0, 2 ] } },
|
|
881
|
+
coverage: { $last: '$coverage' },
|
|
878
882
|
sourceCheckList_id: { $last: '$sourceCheckList_id' },
|
|
879
883
|
checkListType: { $last: '$checkListType' },
|
|
880
884
|
storeCount: { $sum: 1 },
|
|
@@ -952,6 +956,7 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
952
956
|
assignedStores: '$storeCount',
|
|
953
957
|
assignedStoresAi: '$storeCountAi',
|
|
954
958
|
checkListName: 1,
|
|
959
|
+
coverage: 1,
|
|
955
960
|
checkListChar: 1,
|
|
956
961
|
sourceCheckList_id: 1,
|
|
957
962
|
checkListType: 1,
|
|
@@ -978,6 +983,7 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
978
983
|
$project: {
|
|
979
984
|
checkListName: 1,
|
|
980
985
|
checkListChar: 1,
|
|
986
|
+
coverage: 1,
|
|
981
987
|
sourceCheckList_id: 1,
|
|
982
988
|
checkListType: 1,
|
|
983
989
|
flagType: 1,
|
|
@@ -1839,7 +1845,6 @@ async function checklistDropdownData( checklistType ) {
|
|
|
1839
1845
|
}
|
|
1840
1846
|
}
|
|
1841
1847
|
|
|
1842
|
-
|
|
1843
1848
|
// Lamda Service Call //
|
|
1844
1849
|
async function LamdaServiceCall( url, data ) {
|
|
1845
1850
|
try {
|
|
@@ -1866,6 +1871,10 @@ async function LamdaServiceCall( url, data ) {
|
|
|
1866
1871
|
export const flagChecklistCardsV1 = async ( req, res ) => {
|
|
1867
1872
|
try {
|
|
1868
1873
|
let reqestData = req.body;
|
|
1874
|
+
// Get User Based Checklist //
|
|
1875
|
+
let loginUser = { clientId: reqestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
1876
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
1877
|
+
// End: Get User Based Checklist////
|
|
1869
1878
|
|
|
1870
1879
|
if ( reqestData.ChecklistType == 'custom' ) {
|
|
1871
1880
|
const pipeline = [
|
|
@@ -1873,10 +1882,12 @@ export const flagChecklistCardsV1 = async ( req, res ) => {
|
|
|
1873
1882
|
$match: {
|
|
1874
1883
|
$and: [
|
|
1875
1884
|
{ client_id: reqestData?.clientId },
|
|
1876
|
-
{ store_id: { $in: reqestData?.storeId } },
|
|
1877
1885
|
{ date_iso: { $gte: new Date( reqestData?.fromDate ) } },
|
|
1878
1886
|
{ date_iso: { $lte: dayjs.utc( reqestData.toDate ).endOf( 'day' ).toDate() } },
|
|
1879
1887
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( reqestData.sourceCheckList_id ) },
|
|
1888
|
+
// { store_id: { $in: reqestData?.storeId } },
|
|
1889
|
+
{ userEmail: { $in: getUserEmails } },
|
|
1890
|
+
{ $or: [ { store_id: { $in: reqestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
1880
1891
|
],
|
|
1881
1892
|
},
|
|
1882
1893
|
},
|
|
@@ -1975,18 +1986,15 @@ export const flagChecklistCardsV1 = async ( req, res ) => {
|
|
|
1975
1986
|
const pipeline = [
|
|
1976
1987
|
{
|
|
1977
1988
|
$match:
|
|
1978
|
-
{
|
|
1979
|
-
date_iso: {
|
|
1980
|
-
$gte: new Date( reqestData.fromDate ),
|
|
1981
|
-
},
|
|
1982
|
-
date_iso: {
|
|
1983
|
-
$lte: dayjs.utc( reqestData.toDate ).endOf( 'day' ).toDate(),
|
|
1984
|
-
},
|
|
1985
|
-
store_id: {
|
|
1986
|
-
$in: reqestData.storeId,
|
|
1987
|
-
},
|
|
1989
|
+
{ date_iso: { $gte: new Date( reqestData.fromDate ) },
|
|
1990
|
+
date_iso: { $lte: dayjs.utc( reqestData.toDate ).endOf( 'day' ).toDate() },
|
|
1988
1991
|
client_id: reqestData.clientId,
|
|
1989
1992
|
sourceCheckList_id: new mongoose.Types.ObjectId( reqestData.sourceCheckList_id ),
|
|
1993
|
+
// store_id: { $in: reqestData.storeId },
|
|
1994
|
+
$or: [
|
|
1995
|
+
{ '$and': findORQuery1 },
|
|
1996
|
+
{ '$and': findORQuery2 },
|
|
1997
|
+
],
|
|
1990
1998
|
},
|
|
1991
1999
|
},
|
|
1992
2000
|
{
|
|
@@ -2088,6 +2096,10 @@ export const flagChecklistComparisonCardsV1 = async ( req, res ) => {
|
|
|
2088
2096
|
},
|
|
2089
2097
|
};
|
|
2090
2098
|
|
|
2099
|
+
// Get User Based Checklist //
|
|
2100
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
2101
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
2102
|
+
// End: Get User Based Checklist////
|
|
2091
2103
|
|
|
2092
2104
|
if ( requestData.ChecklistType == 'custom' ) {
|
|
2093
2105
|
const range1pipeline = [
|
|
@@ -2095,10 +2107,12 @@ export const flagChecklistComparisonCardsV1 = async ( req, res ) => {
|
|
|
2095
2107
|
$match: {
|
|
2096
2108
|
$and: [
|
|
2097
2109
|
{ client_id: requestData?.clientId },
|
|
2098
|
-
{ store_id: { $in: requestData?.storeId } },
|
|
2099
2110
|
{ date_iso: { $gte: rangeOneFromDate } },
|
|
2100
2111
|
{ date_iso: { $lte: rangeOneToDate } },
|
|
2101
2112
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
|
|
2113
|
+
// { store_id: { $in: requestData?.storeId } },
|
|
2114
|
+
{ userEmail: { $in: getUserEmails } },
|
|
2115
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
2102
2116
|
],
|
|
2103
2117
|
},
|
|
2104
2118
|
},
|
|
@@ -2176,10 +2190,14 @@ export const flagChecklistComparisonCardsV1 = async ( req, res ) => {
|
|
|
2176
2190
|
$match: {
|
|
2177
2191
|
$and: [
|
|
2178
2192
|
{ client_id: requestData?.clientId },
|
|
2179
|
-
{ store_id: { $in: requestData?.storeId } },
|
|
2180
2193
|
{ date_iso: { $gte: rangeTwoFromDate } },
|
|
2181
2194
|
{ date_iso: { $lte: rangeTwoToDate } },
|
|
2182
2195
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
|
|
2196
|
+
// { store_id: { $in: requestData?.storeId } },
|
|
2197
|
+
{ '$or': [
|
|
2198
|
+
{ '$and': findORQuery1 },
|
|
2199
|
+
{ '$and': findORQuery2 },
|
|
2200
|
+
] },
|
|
2183
2201
|
],
|
|
2184
2202
|
},
|
|
2185
2203
|
},
|
|
@@ -2288,18 +2306,15 @@ export const flagChecklistComparisonCardsV1 = async ( req, res ) => {
|
|
|
2288
2306
|
const fromPipeline = [
|
|
2289
2307
|
{
|
|
2290
2308
|
$match:
|
|
2291
|
-
{
|
|
2292
|
-
date_iso: {
|
|
2293
|
-
$gte: rangeOneFromDate,
|
|
2294
|
-
},
|
|
2295
|
-
date_iso: {
|
|
2296
|
-
$lte: rangeOneToDate,
|
|
2297
|
-
},
|
|
2298
|
-
store_id: {
|
|
2299
|
-
$in: requestData.storeId,
|
|
2300
|
-
},
|
|
2309
|
+
{ date_iso: { $gte: rangeOneFromDate },
|
|
2310
|
+
date_iso: { $lte: rangeOneToDate },
|
|
2301
2311
|
client_id: requestData.clientId,
|
|
2302
2312
|
sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ),
|
|
2313
|
+
// store_id: { $in: requestData.storeId },
|
|
2314
|
+
$or: [
|
|
2315
|
+
{ '$and': findORQuery1 },
|
|
2316
|
+
{ '$and': findORQuery2 },
|
|
2317
|
+
],
|
|
2303
2318
|
},
|
|
2304
2319
|
},
|
|
2305
2320
|
{
|
|
@@ -2320,18 +2335,15 @@ export const flagChecklistComparisonCardsV1 = async ( req, res ) => {
|
|
|
2320
2335
|
const toPipeline = [
|
|
2321
2336
|
{
|
|
2322
2337
|
$match:
|
|
2323
|
-
{
|
|
2324
|
-
date_iso: {
|
|
2325
|
-
$gte: rangeTwoFromDate,
|
|
2326
|
-
},
|
|
2327
|
-
date_iso: {
|
|
2328
|
-
$lte: rangeTwoToDate,
|
|
2329
|
-
},
|
|
2330
|
-
store_id: {
|
|
2331
|
-
$in: requestData.storeId,
|
|
2332
|
-
},
|
|
2338
|
+
{ date_iso: { $gte: rangeTwoFromDate },
|
|
2339
|
+
date_iso: { $lte: rangeTwoToDate },
|
|
2333
2340
|
client_id: requestData.clientId,
|
|
2334
2341
|
sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ),
|
|
2342
|
+
// store_id: { $in: requestData.storeId },
|
|
2343
|
+
$or: [
|
|
2344
|
+
{ '$and': findORQuery1 },
|
|
2345
|
+
{ '$and': findORQuery2 },
|
|
2346
|
+
],
|
|
2335
2347
|
},
|
|
2336
2348
|
},
|
|
2337
2349
|
{
|
|
@@ -2374,12 +2386,15 @@ export const flagChecklistComparisonCardsV1 = async ( req, res ) => {
|
|
|
2374
2386
|
export const flagChecklistTableV1 = async ( req, res ) => {
|
|
2375
2387
|
try {
|
|
2376
2388
|
let reqestData = req.body;
|
|
2389
|
+
// Get User Based Checklist //
|
|
2390
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
2391
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
2392
|
+
// End: Get User Based Checklist////
|
|
2377
2393
|
if ( reqestData.ChecklistType == 'custom' ) {
|
|
2378
2394
|
const match = {
|
|
2379
2395
|
$match: {
|
|
2380
2396
|
$and: [
|
|
2381
2397
|
{ client_id: reqestData?.clientId },
|
|
2382
|
-
{ store_id: { $in: reqestData?.storeId } },
|
|
2383
2398
|
{ date_iso: { $gte: new Date( reqestData?.fromDate ) } },
|
|
2384
2399
|
{ date_iso: { $lte: dayjs.utc( reqestData.toDate ).endOf( 'day' ).toDate() } },
|
|
2385
2400
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( reqestData.sourceCheckList_id ) },
|
|
@@ -2389,6 +2404,9 @@ export const flagChecklistTableV1 = async ( req, res ) => {
|
|
|
2389
2404
|
// { questionFlag: { $gt: 0 } },
|
|
2390
2405
|
// ],
|
|
2391
2406
|
// },
|
|
2407
|
+
// { store_id: { $in: reqestData?.storeId } },
|
|
2408
|
+
{ userEmail: { $in: getUserEmails } },
|
|
2409
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
2392
2410
|
],
|
|
2393
2411
|
},
|
|
2394
2412
|
};
|
|
@@ -2641,6 +2659,11 @@ export const checklistDropdownV1 = async ( req, res ) => {
|
|
|
2641
2659
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
2642
2660
|
let result = {};
|
|
2643
2661
|
|
|
2662
|
+
// Get User Based Checklist //
|
|
2663
|
+
let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
2664
|
+
let getUserEmails = await getChecklistUsers( loginUser );
|
|
2665
|
+
// End: Get User Based Checklist////
|
|
2666
|
+
|
|
2644
2667
|
let findQuery = [
|
|
2645
2668
|
{ $match: { $and: [
|
|
2646
2669
|
{ client_id: requestData.clientId },
|
|
@@ -2659,6 +2682,8 @@ export const checklistDropdownV1 = async ( req, res ) => {
|
|
|
2659
2682
|
{ checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection' ] } },
|
|
2660
2683
|
],
|
|
2661
2684
|
},
|
|
2685
|
+
{ userEmail: { $in: getUserEmails } },
|
|
2686
|
+
{ $or: [ { store_id: { $in: requestData.storeId || '' } }, { store_id: { $eq: '' } } ] },
|
|
2662
2687
|
] } },
|
|
2663
2688
|
{
|
|
2664
2689
|
$project: {
|
|
@@ -2745,261 +2770,3 @@ export const checklistDropdownV1 = async ( req, res ) => {
|
|
|
2745
2770
|
return res.sendError( { error: error }, 500 );
|
|
2746
2771
|
}
|
|
2747
2772
|
};
|
|
2748
|
-
|
|
2749
|
-
export const flagTablesV2 = async ( req, res ) => {
|
|
2750
|
-
try {
|
|
2751
|
-
let requestData = req.body;
|
|
2752
|
-
let fromDate = new Date( requestData.fromDate );
|
|
2753
|
-
let toDate = new Date( requestData.toDate );
|
|
2754
|
-
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
2755
|
-
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
2756
|
-
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
2757
|
-
let result = {};
|
|
2758
|
-
|
|
2759
|
-
let findQuery = [];
|
|
2760
|
-
let findAndQuery = [];
|
|
2761
|
-
findAndQuery.push(
|
|
2762
|
-
{ client_id: requestData.clientId },
|
|
2763
|
-
{ $or: [ { store_id: { $in: requestData.storeId } }, { aiStoreList: { $in: requestData.storeId } } ] },
|
|
2764
|
-
{ date_iso: { $gte: fromDate } },
|
|
2765
|
-
{ date_iso: { $lte: toDate } },
|
|
2766
|
-
);
|
|
2767
|
-
|
|
2768
|
-
if ( requestData?.filter === 'all' ) {
|
|
2769
|
-
findAndQuery.push( { $or: [ { questionFlag: { $gte: 1 } }, { timeFlag: { $gte: 1 } }, { checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection' ] } } ] } );
|
|
2770
|
-
} else if ( requestData?.filter === 'question' ) {
|
|
2771
|
-
findAndQuery.push( { checkListType: 'custom' } );
|
|
2772
|
-
findAndQuery.push( { questionFlag: { $gte: 1 } } );
|
|
2773
|
-
} else if ( requestData?.filter === 'time' ) {
|
|
2774
|
-
findAndQuery.push( { checkListType: 'custom' } );
|
|
2775
|
-
findAndQuery.push( { timeFlag: { $gte: 1 } } );
|
|
2776
|
-
} else if ( requestData?.filter === 'detection' ) {
|
|
2777
|
-
findAndQuery.push( { checkListType: { $in: [ 'customerunattended', 'mobileusagedetection', 'staffleftinthemiddle', 'storeopenandclose', 'uniformdetection' ] } } );
|
|
2778
|
-
}
|
|
2779
|
-
|
|
2780
|
-
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
2781
|
-
|
|
2782
|
-
if ( requestData.searchValue && requestData.searchValue != '' ) {
|
|
2783
|
-
findQuery.push( { $match: { $or: [ { checkListName: { $regex: requestData.searchValue, $options: 'i' } } ] } } );
|
|
2784
|
-
}
|
|
2785
|
-
|
|
2786
|
-
findQuery.push( {
|
|
2787
|
-
$project: {
|
|
2788
|
-
sourceCheckList_id: 1,
|
|
2789
|
-
checkListId: 1,
|
|
2790
|
-
checkListName: 1,
|
|
2791
|
-
coverage: 1,
|
|
2792
|
-
storeCount: 1,
|
|
2793
|
-
createdBy: 1,
|
|
2794
|
-
createdByName: 1,
|
|
2795
|
-
checklistStatus: 1,
|
|
2796
|
-
timeFlag: 1,
|
|
2797
|
-
questionFlag: 1,
|
|
2798
|
-
questionCount: 1,
|
|
2799
|
-
mobileDetectionFlag: 1,
|
|
2800
|
-
storeOpenCloseFlag: 1,
|
|
2801
|
-
uniformDetectionFlag: 1,
|
|
2802
|
-
checkListType: 1,
|
|
2803
|
-
scheduleRepeatedType: 1,
|
|
2804
|
-
store_id: 1,
|
|
2805
|
-
aiStoreList: 1,
|
|
2806
|
-
},
|
|
2807
|
-
} );
|
|
2808
|
-
|
|
2809
|
-
findQuery.push( {
|
|
2810
|
-
$group: {
|
|
2811
|
-
_id: '$sourceCheckList_id',
|
|
2812
|
-
checkListName: { $last: '$checkListName' },
|
|
2813
|
-
coverage: { $last: '$coverage' },
|
|
2814
|
-
checkListChar: { $last: { $substr: [ '$checkListName', 0, 2 ] } },
|
|
2815
|
-
sourceCheckList_id: { $last: '$sourceCheckList_id' },
|
|
2816
|
-
checkListType: { $last: '$checkListType' },
|
|
2817
|
-
storeCount: { $sum: 1 },
|
|
2818
|
-
storeCountAi: { $max: '$storeCount' },
|
|
2819
|
-
flaggedStores: {
|
|
2820
|
-
$addToSet: {
|
|
2821
|
-
$cond: [
|
|
2822
|
-
{
|
|
2823
|
-
$or: [
|
|
2824
|
-
{ $gt: [ '$timeFlag', 0 ] },
|
|
2825
|
-
{ $gt: [ '$questionFlag', 0 ] },
|
|
2826
|
-
{ $gt: [ '$mobileDetectionFlag', 0 ] },
|
|
2827
|
-
{ $gt: [ '$storeOpenCloseFlag', 0 ] },
|
|
2828
|
-
{ $gt: [ '$uniformDetectionFlag', 0 ] },
|
|
2829
|
-
{ $gt: [ '$customerUnattended', 0 ] },
|
|
2830
|
-
{ $gt: [ '$staffLeftInTheMiddle', 0 ] },
|
|
2831
|
-
],
|
|
2832
|
-
},
|
|
2833
|
-
'$store_id',
|
|
2834
|
-
'$$REMOVE',
|
|
2835
|
-
],
|
|
2836
|
-
},
|
|
2837
|
-
},
|
|
2838
|
-
flagCount: {
|
|
2839
|
-
$sum: {
|
|
2840
|
-
$add: [ '$questionFlag', '$timeFlag' ],
|
|
2841
|
-
},
|
|
2842
|
-
},
|
|
2843
|
-
submittedChecklist: {
|
|
2844
|
-
$sum: {
|
|
2845
|
-
$cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, 1, 0 ],
|
|
2846
|
-
},
|
|
2847
|
-
},
|
|
2848
|
-
questionFlag: {
|
|
2849
|
-
$sum: '$questionFlag',
|
|
2850
|
-
},
|
|
2851
|
-
timeFlag: {
|
|
2852
|
-
$sum: '$timeFlag',
|
|
2853
|
-
},
|
|
2854
|
-
questionCount: {
|
|
2855
|
-
$sum: '$questionCount',
|
|
2856
|
-
},
|
|
2857
|
-
aiStoreList: { $max: '$aiStoreList' },
|
|
2858
|
-
submittedQuestionCount: {
|
|
2859
|
-
$sum: {
|
|
2860
|
-
$cond: [ { $eq: [ '$checklistStatus', 'submit' ] }, '$questionCount', 0 ],
|
|
2861
|
-
},
|
|
2862
|
-
},
|
|
2863
|
-
},
|
|
2864
|
-
} );
|
|
2865
|
-
|
|
2866
|
-
findQuery.push( {
|
|
2867
|
-
$project: {
|
|
2868
|
-
assignedStores: '$storeCount',
|
|
2869
|
-
assignedStoresAi: '$storeCountAi',
|
|
2870
|
-
checkListName: 1,
|
|
2871
|
-
coverage: 1,
|
|
2872
|
-
checkListChar: 1,
|
|
2873
|
-
sourceCheckList_id: 1,
|
|
2874
|
-
checkListType: 1,
|
|
2875
|
-
flagType: 1,
|
|
2876
|
-
uniqueFlaggedStores: 1,
|
|
2877
|
-
flaggedStores: { $size: '$flaggedStores' },
|
|
2878
|
-
flagCount: 1,
|
|
2879
|
-
questionCount: 1,
|
|
2880
|
-
correctAnswers: { $subtract: [ '$submittedQuestionCount', '$questionFlag' ] },
|
|
2881
|
-
customQuestionFlagCount: '$questionFlag',
|
|
2882
|
-
customTimeFlagCount: '$timeFlag',
|
|
2883
|
-
aiStoreList: 1,
|
|
2884
|
-
},
|
|
2885
|
-
} );
|
|
2886
|
-
|
|
2887
|
-
findQuery.push( {
|
|
2888
|
-
$project: {
|
|
2889
|
-
checkListName: 1,
|
|
2890
|
-
coverage: 1,
|
|
2891
|
-
checkListChar: 1,
|
|
2892
|
-
sourceCheckList_id: 1,
|
|
2893
|
-
checkListType: 1,
|
|
2894
|
-
flagType: 1,
|
|
2895
|
-
assignedStores: 1,
|
|
2896
|
-
assignedStoresAi: 1,
|
|
2897
|
-
flaggedStores: 1,
|
|
2898
|
-
flagCount: 1,
|
|
2899
|
-
uniqueFlaggedStores: 1,
|
|
2900
|
-
complianceRate: {
|
|
2901
|
-
$cond: {
|
|
2902
|
-
if: { $eq: [ '$questionCount', 0 ] },
|
|
2903
|
-
then: 0,
|
|
2904
|
-
else: {
|
|
2905
|
-
$round: [ { $multiply: [ { $divide: [ '$correctAnswers', '$questionCount' ] }, 100 ] }, 2 ],
|
|
2906
|
-
},
|
|
2907
|
-
},
|
|
2908
|
-
},
|
|
2909
|
-
customQuestionFlagCount: 1,
|
|
2910
|
-
customTimeFlagCount: 1,
|
|
2911
|
-
aiStoreList: 1,
|
|
2912
|
-
|
|
2913
|
-
},
|
|
2914
|
-
} );
|
|
2915
|
-
|
|
2916
|
-
let getTotalCount = await processedchecklistService.aggregate( findQuery );
|
|
2917
|
-
if ( !getTotalCount.length ) {
|
|
2918
|
-
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
2919
|
-
}
|
|
2920
|
-
|
|
2921
|
-
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
|
|
2922
|
-
findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
|
|
2923
|
-
} else {
|
|
2924
|
-
findQuery.push( { $sort: { ['submittedChecklist']: -1 } } );
|
|
2925
|
-
}
|
|
2926
|
-
|
|
2927
|
-
if ( !requestData.export ) {
|
|
2928
|
-
let limit = parseInt( requestData?.limit ) || 10;
|
|
2929
|
-
let skip = limit * ( requestData?.offset ) || 0;
|
|
2930
|
-
findQuery.push( { $skip: skip }, { $limit: limit } );
|
|
2931
|
-
}
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
let getChecklistPerformanceData = await processedchecklistService.aggregate( findQuery );
|
|
2935
|
-
|
|
2936
|
-
if ( getChecklistPerformanceData.length ) {
|
|
2937
|
-
const detectionChecklists = getChecklistPerformanceData?.filter( ( val ) => val?.checkListType !== 'custom' );
|
|
2938
|
-
|
|
2939
|
-
if ( detectionChecklists?.length ) {
|
|
2940
|
-
const detectionPayload = {
|
|
2941
|
-
'fromDate': requestData.fromDate,
|
|
2942
|
-
'toDate': requestData.toDate,
|
|
2943
|
-
'storeId': requestData.storeId,
|
|
2944
|
-
'clientId': requestData.clientId,
|
|
2945
|
-
};
|
|
2946
|
-
|
|
2947
|
-
let LamdaURL = 'https://f65azvtljclaxp6l7rnx65cdmm0lcgvp.lambda-url.ap-south-1.on.aws/';
|
|
2948
|
-
let resultData = await LamdaServiceCall( LamdaURL, detectionPayload );
|
|
2949
|
-
if ( resultData ) {
|
|
2950
|
-
if ( resultData.status_code == '200' ) {
|
|
2951
|
-
for ( let index = 0; index < getChecklistPerformanceData.length; index++ ) {
|
|
2952
|
-
if ( getChecklistPerformanceData[index].checkListType !== 'custom' ) {
|
|
2953
|
-
getChecklistPerformanceData[index].coverage = 'Store';
|
|
2954
|
-
getChecklistPerformanceData[index].flagCount = resultData?.[getChecklistPerformanceData[index]?.checkListType] || 0;
|
|
2955
|
-
getChecklistPerformanceData[index].flaggedStores = resultData?.[`${getChecklistPerformanceData[index]?.checkListType}_flaggedstores`] || 0;
|
|
2956
|
-
getChecklistPerformanceData[index].assignedStores = getChecklistPerformanceData[index]?.aiStoreList?.filter( ( element ) => requestData.storeId.includes( element ) )?.length || 0;
|
|
2957
|
-
getChecklistPerformanceData[index].complianceRate = ( 100- ( getChecklistPerformanceData[index].flaggedStores / getChecklistPerformanceData[index].assignedStores ) * 100 );
|
|
2958
|
-
getChecklistPerformanceData[index].complianceRate = Math.min( 100, Math.max( 0, getChecklistPerformanceData[index].complianceRate ) );
|
|
2959
|
-
getChecklistPerformanceData[index].complianceRate = ( getChecklistPerformanceData[index].complianceRate % 1 === 0 ) ? getChecklistPerformanceData[index].complianceRate.toFixed( 0 ) : getChecklistPerformanceData[index].complianceRate.toFixed( 2 );
|
|
2960
|
-
}
|
|
2961
|
-
}
|
|
2962
|
-
}
|
|
2963
|
-
}
|
|
2964
|
-
}
|
|
2965
|
-
}
|
|
2966
|
-
|
|
2967
|
-
if ( requestData.export ) {
|
|
2968
|
-
const exportdata = [];
|
|
2969
|
-
getChecklistPerformanceData.forEach( ( element ) => {
|
|
2970
|
-
const data = {
|
|
2971
|
-
'Checklist Name': element.checkListName,
|
|
2972
|
-
'Coverage': element.coverage || 'Store',
|
|
2973
|
-
'Flag Type': element?.checkListType === 'custom' ? 'Question' : 'Detection',
|
|
2974
|
-
'Assigned Stores': element?.assignedStores,
|
|
2975
|
-
'Flagged Stores': element?.flaggedStores,
|
|
2976
|
-
'Compliance': element?.complianceRate,
|
|
2977
|
-
'Flagged Count': element?.flagCount,
|
|
2978
|
-
'Question Flags': element?.customQuestionFlagCount,
|
|
2979
|
-
'Not Submitted Flags': element?.customTimeFlagCount,
|
|
2980
|
-
};
|
|
2981
|
-
if ( requestData?.filter === 'question' ) {
|
|
2982
|
-
delete data['Flagged Count'];
|
|
2983
|
-
delete data['Not Submitted Flags'];
|
|
2984
|
-
} else if ( requestData?.filter === 'time' ) {
|
|
2985
|
-
delete data['Flagged Count'];
|
|
2986
|
-
delete data['Question Flags'];
|
|
2987
|
-
} else if ( requestData?.filter === 'detection' ) {
|
|
2988
|
-
delete data['Not Submitted Flags'];
|
|
2989
|
-
delete data['Question Flags'];
|
|
2990
|
-
}
|
|
2991
|
-
exportdata.push( data );
|
|
2992
|
-
} );
|
|
2993
|
-
return await download( exportdata, res );
|
|
2994
|
-
}
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
result.totalCount = getTotalCount.length;
|
|
2998
|
-
result.checklistPerformance = getChecklistPerformanceData;
|
|
2999
|
-
return res.sendSuccess( result );
|
|
3000
|
-
} catch ( error ) {
|
|
3001
|
-
console.log( 'error =>', error );
|
|
3002
|
-
logger.error( { error: error, message: req.query, function: 'checklistPerformance' } );
|
|
3003
|
-
return res.sendError( { error: error }, 500 );
|
|
3004
|
-
}
|
|
3005
|
-
};
|