tango-app-api-trax 3.2.1 → 3.3.1-airtel-1
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 +3 -3
- package/src/controllers/download.controller.js +154 -17
- package/src/controllers/gallery.controller.js +124 -31
- package/src/controllers/internalTrax.controller.js +284 -5
- package/src/controllers/mobileTrax.controller.js +200 -40
- package/src/controllers/teaxFlag.controller.js +161 -142
- package/src/controllers/trax.controller.js +1477 -153
- package/src/controllers/traxDashboard.controllers.js +350 -105
- package/src/dtos/dashboardValidation.dtos.js +2 -0
- package/src/dtos/downloadValidation.dtos.js +3 -0
- package/src/dtos/validation.dtos.js +17 -5
- package/src/routes/download.router.js +4 -0
- package/src/routes/gallery.routes.js +5 -1
- package/src/routes/internalTraxApi.router.js +3 -1
- package/src/routes/mobileTrax.routes.js +3 -1
- package/src/routes/trax.routes.js +12 -2
- package/src/routes/traxDashboard.routes.js +3 -1
- package/src/services/checklistAssign.service.js +8 -0
- package/src/services/planogram.service.js +5 -0
- package/src/services/teams.service.js +30 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-trax",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.1-airtel-1",
|
|
4
4
|
"description": "Trax",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"mongodb": "^6.8.0",
|
|
27
27
|
"nodemon": "^3.1.4",
|
|
28
28
|
"path": "^0.12.7",
|
|
29
|
-
"tango-api-schema": "^2.2.
|
|
30
|
-
"tango-app-api-middleware": "^3.1.
|
|
29
|
+
"tango-api-schema": "^2.2.93",
|
|
30
|
+
"tango-app-api-middleware": "^3.1.70",
|
|
31
31
|
"url": "^0.11.4",
|
|
32
32
|
"winston": "^3.13.1",
|
|
33
33
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -6,6 +6,7 @@ import * as processedTaskService from '../services/processedTaskList.service.js'
|
|
|
6
6
|
import * as taskConfigService from '../services/taskConfig.service.js';
|
|
7
7
|
import * as checklistService from '../services/checklist.service.js';
|
|
8
8
|
// import * as processedTaskconfigService from '../services/processedTaskConfig.service.js';
|
|
9
|
+
import * as processedcheklistconfigService from '../services/processedchecklistconfig.services.js';
|
|
9
10
|
import * as clientService from '../services/clients.services.js';
|
|
10
11
|
import * as storeService from '../services/store.service.js';
|
|
11
12
|
|
|
@@ -42,26 +43,46 @@ export const downloadInsert = async ( req, res ) => {
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
}
|
|
46
|
+
console.log( requestData );
|
|
45
47
|
|
|
46
48
|
if ( requestData.sourceCheckList_id && requestData.sourceCheckList_id != '' ) {
|
|
47
49
|
let getChecklistQuery = [];
|
|
48
|
-
getChecklistQuery.push( { $project: { sourceCheckList_id: 1, date_iso: 1, store_id: 1, checklistStatus: 1, redoStatus: 1 } } );
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
getChecklistQuery.push( { $project: { sourceCheckList_id: 1, date_iso: 1, store_id: 1, userEmail: 1, checklistStatus: 1, redoStatus: 1 } } );
|
|
51
|
+
|
|
52
|
+
if ( requestData.filtertype ==='Clusters' ) {
|
|
53
|
+
getChecklistQuery.push( {
|
|
54
|
+
$match: {
|
|
55
|
+
$and: [
|
|
56
|
+
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
|
|
57
|
+
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
58
|
+
{ store_id: { $in: requestData.storeIds } },
|
|
59
|
+
],
|
|
60
|
+
$or: [
|
|
61
|
+
{ checklistStatus: 'submit' },
|
|
62
|
+
{ redoStatus: true },
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
} );
|
|
66
|
+
} else {
|
|
67
|
+
console.log( requestData );
|
|
68
|
+
getChecklistQuery.push( {
|
|
69
|
+
$match: {
|
|
70
|
+
$and: [
|
|
71
|
+
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
|
|
72
|
+
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
73
|
+
{ userEmail: { $in: requestData.userEmailList } },
|
|
74
|
+
],
|
|
75
|
+
$or: [
|
|
76
|
+
{ checklistStatus: 'submit' },
|
|
77
|
+
{ redoStatus: true },
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
} );
|
|
81
|
+
}
|
|
62
82
|
getChecklistQuery.push( { $count: 'totalCount' } );
|
|
63
83
|
|
|
64
84
|
let getChecklistCount = await processedchecklistService.aggregate( getChecklistQuery );
|
|
85
|
+
console.log( getChecklistCount );
|
|
65
86
|
if ( requestData.insertType === 'task' ) {
|
|
66
87
|
getChecklistCount = await processedTaskService.aggregate( getChecklistQuery );
|
|
67
88
|
}
|
|
@@ -121,7 +142,9 @@ export const downloadInsert = async ( req, res ) => {
|
|
|
121
142
|
'searchValue': requestData.searchValue || '',
|
|
122
143
|
'insertType': requestData.insertType || '',
|
|
123
144
|
'viewRedo': requestData.viewRedo || false,
|
|
124
|
-
|
|
145
|
+
'userEmailList': requestData.userEmailList || [],
|
|
146
|
+
'filtertype': requestData.filtertype || 'Clusters',
|
|
147
|
+
'checkListType': requestData.checkListType,
|
|
125
148
|
};
|
|
126
149
|
let resultData = await downloadService.insert( insertData );
|
|
127
150
|
if ( resultData ) {
|
|
@@ -149,7 +172,93 @@ export const downloadInsert = async ( req, res ) => {
|
|
|
149
172
|
return res.sendError( e, 500 );
|
|
150
173
|
}
|
|
151
174
|
};
|
|
152
|
-
|
|
175
|
+
export const downloadInsertAI = async ( req, res ) => {
|
|
176
|
+
try {
|
|
177
|
+
let requestData = req.body;
|
|
178
|
+
let name;
|
|
179
|
+
let fileType = requestData?.fileType || 'pdfzip';
|
|
180
|
+
if ( requestData.fileType == 'pdf' ) {
|
|
181
|
+
if ( requestData?.sourceCheckList_id && requestData?.sourceCheckList_id != '' ) {
|
|
182
|
+
fileType = 'pdfzip';
|
|
183
|
+
}
|
|
184
|
+
if ( requestData?.checklistId && requestData?.checklistId.length > 1 ) {
|
|
185
|
+
fileType = 'pdfzip';
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if ( requestData.checklistName != '' ) {
|
|
189
|
+
name = requestData.checklistName + '_' + dayjs( requestData.fromDate ).format( 'DD/MM/YYYY' );
|
|
190
|
+
if ( requestData?.toDate ) {
|
|
191
|
+
name = name + '-' + dayjs( requestData?.toDate ).format( 'DD/MM/YYYY' );
|
|
192
|
+
}
|
|
193
|
+
let regexName = new RegExp( `^${name.split( '(' )[0]} \\(.*\\)$`, 'i' );
|
|
194
|
+
let type = requestData.fileType || 'pdfzip';
|
|
195
|
+
let downloadDetails = await downloadService.getCount( { $and: [ { $or: [ { name: { $regex: regexName } }, { name: name } ] }, { fileType: type } ] } );
|
|
196
|
+
if ( downloadDetails ) {
|
|
197
|
+
name = name + ' (' + downloadDetails + ')';
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
name = requestData?.checklistName;
|
|
201
|
+
}
|
|
202
|
+
let findchecklist = await processedcheklistconfigService.findOne( { 'checkListType': requestData.checkListType, 'client_id': requestData.clientId } ).sort( { _id: -1 } );
|
|
203
|
+
console.log( findchecklist );
|
|
204
|
+
name = name + '-' + requestData.fileType;
|
|
205
|
+
let insertData = {
|
|
206
|
+
'date_string': requestData.fromDate || '',
|
|
207
|
+
'sourceCheckList_id': requestData?.sourceCheckList_id || '',
|
|
208
|
+
'checklistIdList': requestData?.checklistId || [],
|
|
209
|
+
'status': 'inprogress',
|
|
210
|
+
'client_id': requestData.clientId || '',
|
|
211
|
+
'date_iso': new Date( requestData.fromDate ) || '',
|
|
212
|
+
'createdBy': req.user._id || '',
|
|
213
|
+
'name': name,
|
|
214
|
+
'fileType': fileType,
|
|
215
|
+
'storeIds': requestData.storeIds || [],
|
|
216
|
+
'questions': requestData.questions || [],
|
|
217
|
+
'fromDate': requestData.fromDate || '',
|
|
218
|
+
'toDate': requestData.toDate || '',
|
|
219
|
+
'previewType': requestData.previewType || '',
|
|
220
|
+
'viewFlag': requestData.viewFlag || false,
|
|
221
|
+
'userEmail': req.user.email || '',
|
|
222
|
+
'createdBy': req.user._id || '',
|
|
223
|
+
'downloadInsertFrom': requestData.downloadInsertFrom || '',
|
|
224
|
+
'answerType': requestData.answerType || '',
|
|
225
|
+
'searchValue': requestData.searchValue || '',
|
|
226
|
+
'insertType': requestData.insertType || '',
|
|
227
|
+
'viewRedo': requestData.viewRedo || false,
|
|
228
|
+
'userEmailList': requestData.userEmailList || [],
|
|
229
|
+
'filtertype': requestData.filtertype || 'Clusters',
|
|
230
|
+
'checkListType': requestData.checkListType,
|
|
231
|
+
'checkListName': findchecklist.checkListName,
|
|
232
|
+
'checkListDescription': findchecklist.checkListDescription,
|
|
233
|
+
};
|
|
234
|
+
console.log( requestData );
|
|
235
|
+
console.log( insertData );
|
|
236
|
+
let resultData = await downloadService.insert( insertData );
|
|
237
|
+
console.log( resultData );
|
|
238
|
+
if ( resultData ) {
|
|
239
|
+
let sqsMessageRequestData = {
|
|
240
|
+
'zipId': resultData._id,
|
|
241
|
+
'fileType': fileType || 'zip',
|
|
242
|
+
'storeId': requestData.storeIds || [],
|
|
243
|
+
};
|
|
244
|
+
console.log( sqsMessageRequestData );
|
|
245
|
+
if ( fileType === 'csv' || fileType === 'pdf' || fileType === 'csvzip' || fileType === 'pdfzip' || fileType === 'zipfiles' ) {
|
|
246
|
+
const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).AIchecklistExport}`, JSON.stringify( sqsMessageRequestData ) );
|
|
247
|
+
console.log( 'Send SQS Message CSV/PDF=>', msg );
|
|
248
|
+
}
|
|
249
|
+
if ( fileType === 'ppt' || fileType === 'pptzip' ) {
|
|
250
|
+
const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).AIchecklistExport}`, JSON.stringify( sqsMessageRequestData ) );
|
|
251
|
+
console.log( 'Send SQS Message PPT=>', msg );
|
|
252
|
+
}
|
|
253
|
+
res.sendSuccess( 'Success' );
|
|
254
|
+
} else {
|
|
255
|
+
return res.sendError( 'something went wrong, please try again', 500 );
|
|
256
|
+
}
|
|
257
|
+
} catch ( e ) {
|
|
258
|
+
console.log( 'insertdownloadRequest =>', e );
|
|
259
|
+
return res.sendError( e, 500 );
|
|
260
|
+
}
|
|
261
|
+
};
|
|
153
262
|
export const downloadInsertOld = async ( req, res ) => {
|
|
154
263
|
try {
|
|
155
264
|
let requestData = req.body;
|
|
@@ -418,6 +527,8 @@ export const getChecklistFromZipId = async ( req, res ) => {
|
|
|
418
527
|
resultData.storeIds = getzipdata.storeIds;
|
|
419
528
|
resultData.questions = getzipdata.questions;
|
|
420
529
|
resultData.fileType = getzipdata.fileType;
|
|
530
|
+
resultData.userEmailList = getzipdata.userEmailList;
|
|
531
|
+
resultData.filtertype = getzipdata.filtertype;
|
|
421
532
|
resultData.viewFlag = getzipdata.viewFlag;
|
|
422
533
|
resultData.previewType = getzipdata.previewType || '';
|
|
423
534
|
resultData.answerType = getzipdata.answerType || '';
|
|
@@ -458,7 +569,33 @@ export const getChecklistFromZipId = async ( req, res ) => {
|
|
|
458
569
|
return res.sendError( error, 500 );
|
|
459
570
|
}
|
|
460
571
|
};
|
|
461
|
-
|
|
572
|
+
export const getAiChecklistDataFromZipId = async ( req, res ) => {
|
|
573
|
+
try {
|
|
574
|
+
let reqquery = req.query;
|
|
575
|
+
let getzipdata = await downloadService.findOne( { _id: new mongoose.Types.ObjectId( reqquery.zipId ) } );
|
|
576
|
+
let brandInfo = {
|
|
577
|
+
clientName: '',
|
|
578
|
+
brandLogo: '',
|
|
579
|
+
checkListDescription: '',
|
|
580
|
+
};
|
|
581
|
+
if ( getzipdata ) {
|
|
582
|
+
let getClientData = await clientService.findOne( { clientId: getzipdata.client_id } );
|
|
583
|
+
if ( getClientData ) {
|
|
584
|
+
brandInfo.clientName = getClientData.clientName;
|
|
585
|
+
brandInfo.brandLogo = getzipdata.client_id + '/logo/' + getClientData.profileDetails.logo;
|
|
586
|
+
}
|
|
587
|
+
getzipdata.brandInfo = brandInfo;
|
|
588
|
+
console.log( getzipdata );
|
|
589
|
+
return res.sendSuccess( getzipdata );
|
|
590
|
+
} else {
|
|
591
|
+
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
592
|
+
}
|
|
593
|
+
} catch ( error ) {
|
|
594
|
+
console.log( 'error =>', error );
|
|
595
|
+
logger.error( { error: error, function: 'getChecklistFromZipId' } );
|
|
596
|
+
return res.sendError( error, 500 );
|
|
597
|
+
}
|
|
598
|
+
};
|
|
462
599
|
export const getPDFCSVChecklistDetails = async ( req, res ) => {
|
|
463
600
|
try {
|
|
464
601
|
let requestData = req.body;
|
|
@@ -11,6 +11,8 @@ import * as ApproverModel from '../services/approver.service.js';
|
|
|
11
11
|
|
|
12
12
|
import mongoose from 'mongoose';
|
|
13
13
|
import dayjs from 'dayjs';
|
|
14
|
+
import { aggregateTeams, findteams } from '../services/teams.service.js';
|
|
15
|
+
import { aggregate } from '../services/user.service.js';
|
|
14
16
|
// import axios from 'axios';
|
|
15
17
|
async function LamdaServiceCall( url, data ) {
|
|
16
18
|
try {
|
|
@@ -132,7 +134,7 @@ export async function getcustomerunattendedlist( req, res ) {
|
|
|
132
134
|
export async function storesList( req, res ) {
|
|
133
135
|
try {
|
|
134
136
|
let storeslist = await storeService.find( { clientId: req.body.clientId }, { storeId: 1, storeName: 1 } );
|
|
135
|
-
if ( req.body.groups&&req.body.groups.length>0 ) {
|
|
137
|
+
if ( req.body.groups && req.body.groups.length > 0 ) {
|
|
136
138
|
let stores = [];
|
|
137
139
|
for ( let group of req.body.groups ) {
|
|
138
140
|
let findGroup = await groupService.findOneGroup( { groupName: group.groupName }, { storeList: 1 } );
|
|
@@ -150,7 +152,7 @@ export async function storesList( req, res ) {
|
|
|
150
152
|
export const checklistDropdown = async ( req, res ) => {
|
|
151
153
|
try {
|
|
152
154
|
let requestData = req.body;
|
|
153
|
-
|
|
155
|
+
let fromDate = new Date( requestData.fromDate );
|
|
154
156
|
let toDate = new Date( requestData.toDate );
|
|
155
157
|
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
156
158
|
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
@@ -161,8 +163,8 @@ export const checklistDropdown = async ( req, res ) => {
|
|
|
161
163
|
let findAndQuery = [];
|
|
162
164
|
findAndQuery.push(
|
|
163
165
|
{ client_id: requestData.clientId },
|
|
164
|
-
|
|
165
|
-
|
|
166
|
+
{ date_iso: { $gte: fromDate } },
|
|
167
|
+
{ date_iso: { $lte: toDate } },
|
|
166
168
|
// { checkListType: { $eq: 'custom' } },
|
|
167
169
|
);
|
|
168
170
|
|
|
@@ -178,6 +180,8 @@ export const checklistDropdown = async ( req, res ) => {
|
|
|
178
180
|
scheduleRepeatedType: 1,
|
|
179
181
|
scheduleStartTime: 1,
|
|
180
182
|
scheduleEndTime: 1,
|
|
183
|
+
coverage: 1,
|
|
184
|
+
|
|
181
185
|
},
|
|
182
186
|
} );
|
|
183
187
|
|
|
@@ -192,6 +196,7 @@ export const checklistDropdown = async ( req, res ) => {
|
|
|
192
196
|
scheduleRepeatedType: { $last: '$scheduleRepeatedType' },
|
|
193
197
|
scheduleStartTime: { $last: '$scheduleStartTime' },
|
|
194
198
|
scheduleEndTime: { $last: '$scheduleEndTime' },
|
|
199
|
+
coverage: { $last: '$coverage' },
|
|
195
200
|
},
|
|
196
201
|
} );
|
|
197
202
|
|
|
@@ -230,6 +235,7 @@ export const checklistDropdown = async ( req, res ) => {
|
|
|
230
235
|
scheduleRepeatedType: 1,
|
|
231
236
|
scheduleStartTime: 1,
|
|
232
237
|
scheduleEndTime: 1,
|
|
238
|
+
coverage: 1,
|
|
233
239
|
checkListDescription: '$checklistconfigs.checkListDescription',
|
|
234
240
|
publish: '$checklistconfigs.publish',
|
|
235
241
|
},
|
|
@@ -240,7 +246,7 @@ export const checklistDropdown = async ( req, res ) => {
|
|
|
240
246
|
return res.sendError( { error: 'No Data Found' }, 204 );
|
|
241
247
|
}
|
|
242
248
|
|
|
243
|
-
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
|
|
249
|
+
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy != '' ) {
|
|
244
250
|
findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
|
|
245
251
|
} else {
|
|
246
252
|
findQuery.push( { $sort: { ['checkListName']: -1 } } );
|
|
@@ -248,8 +254,8 @@ export const checklistDropdown = async ( req, res ) => {
|
|
|
248
254
|
|
|
249
255
|
let getChecklistData = await processedchecklistconfigService.aggregate( findQuery );
|
|
250
256
|
|
|
251
|
-
let AiCheklist = getChecklistData.filter( ( data ) => data.checkListType!='custom'
|
|
252
|
-
let CustomCheklist = getChecklistData.filter( ( data ) => data.checkListType=='custom' );
|
|
257
|
+
let AiCheklist = getChecklistData.filter( ( data ) => data.checkListType != 'custom' );
|
|
258
|
+
let CustomCheklist = getChecklistData.filter( ( data ) => data.checkListType == 'custom' );
|
|
253
259
|
|
|
254
260
|
|
|
255
261
|
AiCheklist.forEach( ( data ) => {
|
|
@@ -285,12 +291,14 @@ export async function approveChecklist( req, res ) {
|
|
|
285
291
|
let updateResponse = await processedChecklist.updateMany( { _id: { $in: idList } }, { approvalStatus: true } );
|
|
286
292
|
if ( updateResponse.modifiedCount || updateResponse.matchedCount ) {
|
|
287
293
|
let inputstores = checklistDetails.filter( ( data ) => data.checklistStatus == 'submit' );
|
|
288
|
-
|
|
294
|
+
|
|
295
|
+
|
|
289
296
|
let params = {
|
|
290
297
|
'payload': {
|
|
291
298
|
sourceCheckList_id: req.body.sourceCheckList_id,
|
|
292
299
|
fromDate: req.body.fromDate,
|
|
293
300
|
toDate: req.body.toDate,
|
|
301
|
+
filtertype: req.body.filtertype,
|
|
294
302
|
store_id: inputstores,
|
|
295
303
|
},
|
|
296
304
|
'upsert': {
|
|
@@ -308,10 +316,10 @@ export async function approveChecklist( req, res ) {
|
|
|
308
316
|
let url = JSON.parse( process.env.LAMBDAURL );
|
|
309
317
|
let searchResponse = await fetch( url.approveChecklist, requestOptions );
|
|
310
318
|
|
|
311
|
-
|
|
319
|
+
console.log( searchResponse.ok );
|
|
312
320
|
if ( searchResponse.ok ) {
|
|
313
321
|
let pendingstores = checklistDetails.filter( ( data ) => data.checklistStatus != 'submit' );
|
|
314
|
-
if ( pendingstores&&pendingstores.length>0 ) {
|
|
322
|
+
if ( pendingstores && pendingstores.length > 0 ) {
|
|
315
323
|
return res.sendSuccess( `${pendingstores.length} remain pending approval due to being marked for redo.` );
|
|
316
324
|
}
|
|
317
325
|
return res.sendSuccess( 'Checklist has been approved the submitted stores' );
|
|
@@ -391,6 +399,7 @@ export async function redoChecklist( req, res ) {
|
|
|
391
399
|
};
|
|
392
400
|
|
|
393
401
|
let response = await processedChecklist.updateOne( { _id: req.body.payload._id }, updateData );
|
|
402
|
+
console.log( response );
|
|
394
403
|
if ( response.modifiedCount || response.matchedCount ) {
|
|
395
404
|
let storeTimeZone = await storeService.findOne( { storeName: checklistDetails.storeName }, { 'storeProfile.timeZone': 1 } );
|
|
396
405
|
let currentDateTime;
|
|
@@ -407,8 +416,8 @@ export async function redoChecklist( req, res ) {
|
|
|
407
416
|
sectionName: question[sectionIndex].sectionName,
|
|
408
417
|
questionName: question[sectionIndex].questions[findQuestion].qname,
|
|
409
418
|
action: 'redo',
|
|
410
|
-
store_id: checklistDetails
|
|
411
|
-
storeName: checklistDetails
|
|
419
|
+
store_id: checklistDetails?.store_id?checklistDetails?.store_id:'',
|
|
420
|
+
storeName: checklistDetails?.storeName?checklistDetails?.storeName:'',
|
|
412
421
|
client_id: checklistDetails.client_id,
|
|
413
422
|
processedChecklistId: checklistDetails._id,
|
|
414
423
|
type: checklistDetails.checkListType,
|
|
@@ -419,8 +428,6 @@ export async function redoChecklist( req, res ) {
|
|
|
419
428
|
submitedBy: checklistDetails.userName,
|
|
420
429
|
submitTime: checklistDetails.submitTime,
|
|
421
430
|
};
|
|
422
|
-
|
|
423
|
-
// return;
|
|
424
431
|
await checklistLogs.create( data );
|
|
425
432
|
|
|
426
433
|
const requestOptions = {
|
|
@@ -432,7 +439,7 @@ export async function redoChecklist( req, res ) {
|
|
|
432
439
|
};
|
|
433
440
|
let url = JSON.parse( process.env.LAMBDAURL );
|
|
434
441
|
let searchResponse = await fetch( url.redoChecklist, requestOptions );
|
|
435
|
-
|
|
442
|
+
console.log( searchResponse.ok );
|
|
436
443
|
|
|
437
444
|
if ( searchResponse.ok ) {
|
|
438
445
|
return res.sendSuccess( 'Question redo successfully' );
|
|
@@ -459,7 +466,7 @@ export async function getLogs( req, res ) {
|
|
|
459
466
|
action: 'redo',
|
|
460
467
|
} );
|
|
461
468
|
|
|
462
|
-
let response =[];
|
|
469
|
+
let response = [];
|
|
463
470
|
for ( let data of result ) {
|
|
464
471
|
let userAnswer = {
|
|
465
472
|
actionType: 'answer',
|
|
@@ -494,7 +501,7 @@ export async function approvalstatus( req, res ) {
|
|
|
494
501
|
if ( Approver.length === 0 ) {
|
|
495
502
|
return res.sendSuccess( 'suceess' );
|
|
496
503
|
}
|
|
497
|
-
let filterApprover = Approver.filter( ( data ) => data.userEmail=== req.user.email );
|
|
504
|
+
let filterApprover = Approver.filter( ( data ) => data.userEmail === req.user.email );
|
|
498
505
|
if ( filterApprover.length === 0 ) {
|
|
499
506
|
if ( ( req?.user?.userType == 'client' && req.user.role == 'superadmin' ) ) {
|
|
500
507
|
let url = JSON.parse( process.env.LAMBDAURL );
|
|
@@ -538,9 +545,9 @@ export const headerStoresV2 = async ( req, res ) => {
|
|
|
538
545
|
let totalStores = await getStoresList( getUserEmail, getClientId, getUserType, getRole, req );
|
|
539
546
|
|
|
540
547
|
|
|
541
|
-
if ( totalStores && totalStores.length>0 ) {
|
|
548
|
+
if ( totalStores && totalStores.length > 0 ) {
|
|
542
549
|
let storeQuery = [];
|
|
543
|
-
if ( reqestData.city.length>0 && reqestData.clusters.length>0 ) {
|
|
550
|
+
if ( reqestData.city.length > 0 && reqestData.clusters.length > 0 ) {
|
|
544
551
|
let unqueCityStores = await getLocationStores( getClientId, reqestData.city, req );
|
|
545
552
|
let unqueGroupStores = await getClusterStores( getClientId, reqestData.clusters );
|
|
546
553
|
storeQuery = [
|
|
@@ -561,7 +568,7 @@ export const headerStoresV2 = async ( req, res ) => {
|
|
|
561
568
|
},
|
|
562
569
|
},
|
|
563
570
|
];
|
|
564
|
-
} else if ( reqestData.city.length>0 ) {
|
|
571
|
+
} else if ( reqestData.city.length > 0 ) {
|
|
565
572
|
let uniqueCityStores = await getLocationStores( getClientId, reqestData.city, req );
|
|
566
573
|
storeQuery = [
|
|
567
574
|
{
|
|
@@ -580,7 +587,7 @@ export const headerStoresV2 = async ( req, res ) => {
|
|
|
580
587
|
},
|
|
581
588
|
},
|
|
582
589
|
];
|
|
583
|
-
} else if ( reqestData.clusters.length>0 ) {
|
|
590
|
+
} else if ( reqestData.clusters.length > 0 ) {
|
|
584
591
|
let uniqueclusterStores = await getClusterStores( getClientId, reqestData.clusters );
|
|
585
592
|
storeQuery = [
|
|
586
593
|
{
|
|
@@ -637,18 +644,18 @@ export const headerStoresV2 = async ( req, res ) => {
|
|
|
637
644
|
|
|
638
645
|
async function getStoresList( getUserEmail, getClientId, getUserType, getRole, req ) {
|
|
639
646
|
try {
|
|
640
|
-
if ( getUserEmail && getUserEmail !='' && getClientId && getClientId !='' && getUserType && getUserType !='' && getRole && getRole!='' ) {
|
|
647
|
+
if ( getUserEmail && getUserEmail != '' && getClientId && getClientId != '' && getUserType && getUserType != '' && getRole && getRole != '' ) {
|
|
641
648
|
let overAllStores = [];
|
|
642
649
|
if ( getUserType == 'tango' ) {
|
|
643
650
|
let getAllS = await getAssignedAllStores( getClientId );
|
|
644
|
-
if ( getAllS && getAllS.length >0 ) {
|
|
651
|
+
if ( getAllS && getAllS.length > 0 ) {
|
|
645
652
|
overAllStores = getAllS;
|
|
646
653
|
}
|
|
647
654
|
return overAllStores;
|
|
648
655
|
} else if ( getUserType == 'client' ) {
|
|
649
656
|
if ( getRole == 'superadmin' ) {
|
|
650
657
|
let getAllS = await getAssignedAllStores( getClientId );
|
|
651
|
-
if ( getAllS && getAllS.length >0 ) {
|
|
658
|
+
if ( getAllS && getAllS.length > 0 ) {
|
|
652
659
|
overAllStores = getAllS;
|
|
653
660
|
}
|
|
654
661
|
return overAllStores;
|
|
@@ -667,7 +674,7 @@ async function getStoresList( getUserEmail, getClientId, getUserType, getRole, r
|
|
|
667
674
|
|
|
668
675
|
async function getAssignedAllStores( userClientId ) {
|
|
669
676
|
try {
|
|
670
|
-
if ( userClientId && userClientId !='' ) {
|
|
677
|
+
if ( userClientId && userClientId != '' ) {
|
|
671
678
|
let storeQuery = [
|
|
672
679
|
{
|
|
673
680
|
$match: {
|
|
@@ -684,7 +691,7 @@ async function getAssignedAllStores( userClientId ) {
|
|
|
684
691
|
},
|
|
685
692
|
];
|
|
686
693
|
const storeList = await storeService.aggregate( storeQuery );
|
|
687
|
-
if ( storeList && storeList.length>0 && storeList[0]?.stores.length > 0 ) {
|
|
694
|
+
if ( storeList && storeList.length > 0 && storeList[0]?.stores.length > 0 ) {
|
|
688
695
|
let uniqueStores = [ ...new Set( storeList[0].stores ) ];
|
|
689
696
|
return uniqueStores;
|
|
690
697
|
} else {
|
|
@@ -702,7 +709,7 @@ async function getAssignedAllStores( userClientId ) {
|
|
|
702
709
|
|
|
703
710
|
async function getClusterStores( userClientId, ClusterList ) {
|
|
704
711
|
try {
|
|
705
|
-
if ( userClientId && userClientId !='' && ClusterList && ClusterList.length >0 ) {
|
|
712
|
+
if ( userClientId && userClientId != '' && ClusterList && ClusterList.length > 0 ) {
|
|
706
713
|
let ClusterQuery = [
|
|
707
714
|
{
|
|
708
715
|
$match: {
|
|
@@ -736,7 +743,7 @@ async function getClusterStores( userClientId, ClusterList ) {
|
|
|
736
743
|
},
|
|
737
744
|
];
|
|
738
745
|
const clusterStoreList = await clusterService.aggregateCluster( ClusterQuery );
|
|
739
|
-
if ( clusterStoreList && clusterStoreList.length>0 && clusterStoreList[0]?.storesList.length > 0 ) {
|
|
746
|
+
if ( clusterStoreList && clusterStoreList.length > 0 && clusterStoreList[0]?.storesList.length > 0 ) {
|
|
740
747
|
let storeIds = clusterStoreList[0].storesList.map( ( data ) => data.storeId );
|
|
741
748
|
let uniqueStores = [ ...new Set( storeIds ) ];
|
|
742
749
|
return uniqueStores;
|
|
@@ -755,12 +762,12 @@ async function getClusterStores( userClientId, ClusterList ) {
|
|
|
755
762
|
|
|
756
763
|
async function getLocationStores( userClientId, cityList, req ) {
|
|
757
764
|
try {
|
|
758
|
-
if ( userClientId && userClientId !='' && cityList && cityList.length >0 ) {
|
|
765
|
+
if ( userClientId && userClientId != '' && cityList && cityList.length > 0 ) {
|
|
759
766
|
let filter = [
|
|
760
767
|
{ clientId: { $eq: userClientId } },
|
|
761
768
|
{ 'storeProfile.city': { $in: cityList } },
|
|
762
769
|
];
|
|
763
|
-
if ( req.body.assignedStores&&req.body.assignedStores.length>0 ) {
|
|
770
|
+
if ( req.body.assignedStores && req.body.assignedStores.length > 0 ) {
|
|
764
771
|
filter.push( { storeId: { $in: req.body.assignedStores } } );
|
|
765
772
|
}
|
|
766
773
|
|
|
@@ -784,7 +791,7 @@ async function getLocationStores( userClientId, cityList, req ) {
|
|
|
784
791
|
},
|
|
785
792
|
];
|
|
786
793
|
const cityStoreList = await storeService.aggregate( storeQuery );
|
|
787
|
-
if ( cityStoreList && cityStoreList.length>0 && cityStoreList[0]?.stores.length > 0 ) {
|
|
794
|
+
if ( cityStoreList && cityStoreList.length > 0 && cityStoreList[0]?.stores.length > 0 ) {
|
|
788
795
|
let uniqueStores = [ ...new Set( cityStoreList[0].stores ) ];
|
|
789
796
|
return uniqueStores;
|
|
790
797
|
} else {
|
|
@@ -798,3 +805,89 @@ async function getLocationStores( userClientId, cityList, req ) {
|
|
|
798
805
|
return false;
|
|
799
806
|
}
|
|
800
807
|
}
|
|
808
|
+
|
|
809
|
+
export async function teamsList( req, res ) {
|
|
810
|
+
try {
|
|
811
|
+
let query = [
|
|
812
|
+
{
|
|
813
|
+
$match: {
|
|
814
|
+
clientId: req.query.clientId,
|
|
815
|
+
},
|
|
816
|
+
},
|
|
817
|
+
];
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
if ( req.user&&req.user.userType==='client'&&req.user.role!='superadmin' ) {
|
|
821
|
+
query.push( {
|
|
822
|
+
$match: {
|
|
823
|
+
Teamlead: {
|
|
824
|
+
$elemMatch: {
|
|
825
|
+
email: req.user.email,
|
|
826
|
+
},
|
|
827
|
+
},
|
|
828
|
+
},
|
|
829
|
+
} );
|
|
830
|
+
}
|
|
831
|
+
query.push( {
|
|
832
|
+
$project: {
|
|
833
|
+
teamName: 1,
|
|
834
|
+
clientId: 1,
|
|
835
|
+
},
|
|
836
|
+
} );
|
|
837
|
+
let teamList = await aggregateTeams( query );
|
|
838
|
+
|
|
839
|
+
res.sendSuccess( teamList );
|
|
840
|
+
} catch ( error ) {
|
|
841
|
+
logger.error( { error: error, function: 'teamsList' } );
|
|
842
|
+
return res.sendError( { error: error }, 500 );
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
export async function userList( req, res ) {
|
|
846
|
+
try {
|
|
847
|
+
let query = [
|
|
848
|
+
{
|
|
849
|
+
$match: {
|
|
850
|
+
clientId: req.body.clientId,
|
|
851
|
+
},
|
|
852
|
+
},
|
|
853
|
+
{
|
|
854
|
+
$project: {
|
|
855
|
+
userName: 1,
|
|
856
|
+
userEmail: '$email',
|
|
857
|
+
},
|
|
858
|
+
},
|
|
859
|
+
];
|
|
860
|
+
if ( req.user&&req.user.userType==='client'&&req.user.role!='superadmin' ) {
|
|
861
|
+
let findTeams = await findteams( { Teamlead: {
|
|
862
|
+
$elemMatch: {
|
|
863
|
+
email: req.user.email,
|
|
864
|
+
},
|
|
865
|
+
}, clientId: req.body.clientId } );
|
|
866
|
+
req.body.teams = findTeams.map( ( data ) => data.teamName );
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
if ( req.body.teams && req.body.teams.length > 0 ) {
|
|
870
|
+
let userEmails = [];
|
|
871
|
+
let findTeams = await findteams( { teamName: { $in: req.body.teams }, clientId: req.body.clientId } );
|
|
872
|
+
for ( let team of findTeams ) {
|
|
873
|
+
for ( let lead of team.Teamlead ) {
|
|
874
|
+
userEmails.push( lead.email );
|
|
875
|
+
}
|
|
876
|
+
for ( let user of team.users ) {
|
|
877
|
+
userEmails.push( user.email );
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
query.push( {
|
|
881
|
+
$match: {
|
|
882
|
+
userEmail: { $in: userEmails },
|
|
883
|
+
},
|
|
884
|
+
} );
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
let userList = await aggregate( query );
|
|
888
|
+
res.sendSuccess( userList );
|
|
889
|
+
} catch ( error ) {
|
|
890
|
+
logger.error( { error: error, function: 'userList' } );
|
|
891
|
+
return res.sendError( { error: error }, 500 );
|
|
892
|
+
}
|
|
893
|
+
}
|