tango-app-api-trax 3.4.1-beta-1 → 3.5.0-ai-2
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/index.js +2 -1
- package/package.json +3 -3
- package/src/controllers/activityLog.controller.js +294 -0
- package/src/controllers/download.controller.js +11 -9
- package/src/controllers/gallery.controller.js +213 -9
- package/src/controllers/internalTrax.controller.js +606 -13
- package/src/controllers/mobileTrax.controller.js +292 -10
- package/src/controllers/teaxFlag.controller.js +7 -3
- package/src/controllers/trax.controller.js +590 -136
- package/src/controllers/traxDashboard.controllers.js +18 -5
- package/src/dtos/downloadValidation.dtos.js +1 -0
- package/src/hbs/login-otp.hbs +943 -943
- package/src/routes/activityLog.router.js +18 -0
- package/src/routes/gallery.routes.js +2 -1
- package/src/routes/internalTraxApi.router.js +2 -1
- package/src/routes/mobileTrax.routes.js +1 -0
- package/src/services/camera.service.js +14 -0
|
@@ -68,7 +68,7 @@ export async function PCLchecklistCreationValidator( req, res, next ) {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
export async function
|
|
71
|
+
export async function PCLconfigCreationold( req, res ) {
|
|
72
72
|
try {
|
|
73
73
|
let requestData = req.body;
|
|
74
74
|
let dateList = [ ...requestData.date ];
|
|
@@ -92,13 +92,572 @@ export async function PCLconfigCreation( req, res ) {
|
|
|
92
92
|
req.body = requestData;
|
|
93
93
|
PCLconfigCreation( req, res );
|
|
94
94
|
}
|
|
95
|
-
} else {
|
|
96
|
-
return res.sendSuccess( { message: response.error } );
|
|
95
|
+
} else {
|
|
96
|
+
return res.sendSuccess( { message: response.error } );
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} catch ( e ) {
|
|
100
|
+
logger.error( { function: 'PCLconfigCreation', error: e } );
|
|
101
|
+
return res.sendError( e, 500 );
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export async function PCLconfigCreation( req, res ) {
|
|
106
|
+
try {
|
|
107
|
+
let requestData = req.body;
|
|
108
|
+
let getuniquechecklistquery = {
|
|
109
|
+
client_id: { $in: requestData.client_id },
|
|
110
|
+
type: 'checklist',
|
|
111
|
+
isdeleted: false,
|
|
112
|
+
publish: true,
|
|
113
|
+
};
|
|
114
|
+
let alreadyExist = [];
|
|
115
|
+
let getuniquechecklist = await CLconfig.find( getuniquechecklistquery );
|
|
116
|
+
if ( getuniquechecklist.length ) {
|
|
117
|
+
let checklistList = getuniquechecklist.map( ( ele ) => ele.checkListName );
|
|
118
|
+
logger.info( { checklistList: checklistList.toString() } );
|
|
119
|
+
for ( let [ dateIndex, date ] of requestData.date.entries() ) {
|
|
120
|
+
let currentday = dayjs( date ).format( 'dddd' );
|
|
121
|
+
let currentdate = dayjs( date ).format( 'YYYY-MM-DD' );
|
|
122
|
+
let currentdatedd = dayjs( date ).format( 'DD' );
|
|
123
|
+
let start = new Date( date );
|
|
124
|
+
let userTimezoneOffset = start.getTimezoneOffset() * 60000;
|
|
125
|
+
start = new Date( start.getTime() - userTimezoneOffset );
|
|
126
|
+
start.setUTCHours( 0, 0, 0, 0 );
|
|
127
|
+
let end = new Date( date );
|
|
128
|
+
end = new Date( end.getTime() - userTimezoneOffset );
|
|
129
|
+
end.setUTCHours( 23, 59, 59, 59 );
|
|
130
|
+
let validation;
|
|
131
|
+
validation = false;
|
|
132
|
+
let resultchecklist = [];
|
|
133
|
+
await Promise.all( getuniquechecklist.map( async ( element1 ) => {
|
|
134
|
+
validation = false;
|
|
135
|
+
let scheduledate = dayjs( element1.scheduleDate ).format( 'YYYY-MM-DD' );
|
|
136
|
+
if ( element1.schedule == 'daily' ) {
|
|
137
|
+
let newDate = dayjs.utc( element1.publishDate ).startOf( 'day' );
|
|
138
|
+
if ( element1.scheduleRepeatedDay[0] != '01' && newDate.format( 'YYYY-MM-DD' ) != currentdate ) {
|
|
139
|
+
let checkExists = await processedchecklist.findOne( { sourceCheckList_id: element1._id }, { date_string: 1 } );
|
|
140
|
+
if ( checkExists ) {
|
|
141
|
+
newDate = dayjs.utc( checkExists.date_string ).startOf( 'day' );
|
|
142
|
+
}
|
|
143
|
+
let cdate = dayjs.utc( currentdate ).startOf( 'day' );
|
|
144
|
+
let diff = parseInt( cdate.diff( newDate, 'day' ) );
|
|
145
|
+
diff = diff < 9 ? '0'+ diff : diff;
|
|
146
|
+
if ( diff == parseInt( element1.scheduleRepeatedDay[0] ) ) {
|
|
147
|
+
validation = true;
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
validation = true;
|
|
151
|
+
}
|
|
152
|
+
} else if ( [ 'weekly', 'weekday' ].includes( element1.schedule ) ) {
|
|
153
|
+
if ( element1.scheduleWeekDays.includes( currentday ) ) {
|
|
154
|
+
let newDate = dayjs.utc( element1.publishDate );
|
|
155
|
+
let endWeek = dayjs.utc( element1.publishDate ).endOf( 'week' );
|
|
156
|
+
if ( element1.scheduleRepeatedDay[0] != '01' && currentdate > endWeek.format( 'YYYY-MM-DD' ) ) {
|
|
157
|
+
let checkExists = await processedchecklist.findOne( { sourceCheckList_id: element1._id }, { date_string: 1 } );
|
|
158
|
+
if ( checkExists ) {
|
|
159
|
+
newDate = dayjs.utc( checkExists.date_string );
|
|
160
|
+
}
|
|
161
|
+
let startWeek = dayjs.utc( newDate ).startOf( 'week' );
|
|
162
|
+
let endWeek = dayjs.utc( newDate ).clone().endOf( 'week' );
|
|
163
|
+
let diff = parseInt( dayjs.utc( currentdate ).diff( startWeek, 'week' ) );
|
|
164
|
+
diff = diff < 9 ? '0'+diff : diff;
|
|
165
|
+
if ( diff == element1.scheduleRepeatedDay[0] || ( startWeek.format( 'YYYY-MM-DD' ) <= currentdate && endWeek.format( 'YYYY-MM-DD' ) >= currentdate ) ) {
|
|
166
|
+
validation = true;
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
validation = true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
} else if ( element1.schedule == 'monthly' ) {
|
|
173
|
+
if ( element1.scheduleRepeatedMonthSetup == 'day' && element1.scheduleRepeatedMonthWeek == currentdatedd ) {
|
|
174
|
+
validation = true;
|
|
175
|
+
} else if ( element1.scheduleRepeatedMonthSetup == 'date' ) {
|
|
176
|
+
let days = [];
|
|
177
|
+
let currDate = dayjs.utc( currentdate );
|
|
178
|
+
let dateDat = dayjs.utc( currDate ).startOf( 'month' );
|
|
179
|
+
while ( dateDat.month() === currDate.month() ) {
|
|
180
|
+
if ( dateDat.format( 'dddd' ) === element1.scheduleRepeatedMonthWeek.split( ' ' )[1] ) {
|
|
181
|
+
days.push( dateDat.format( 'YYYY-MM-DD' ) );
|
|
182
|
+
}
|
|
183
|
+
dateDat = dateDat.add( 1, 'day' );
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if ( element1.scheduleRepeatedMonthWeek.split( ' ' )[0] == 5 ) {
|
|
187
|
+
if ( days[days.length -1] == currentdate ) {
|
|
188
|
+
validation = true;
|
|
189
|
+
}
|
|
190
|
+
} else {
|
|
191
|
+
if ( days[parseInt( element1.scheduleRepeatedMonthWeek.split( ' ' )[0] )-1] == currentdate ) {
|
|
192
|
+
validation = true;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
} else if ( element1.scheduleRepeatedMonthSetup == 'specific' ) {
|
|
196
|
+
let currentdatesingleDigit = dayjs( currentdate ).format( 'D' );
|
|
197
|
+
if ( element1.specificDate.includes( parseInt( currentdatesingleDigit ) ) ) {
|
|
198
|
+
validation = true;
|
|
199
|
+
}
|
|
200
|
+
} else {
|
|
201
|
+
validation = false;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if ( validation ) {
|
|
205
|
+
validation = false;
|
|
206
|
+
let newDate = dayjs.utc( element1.publishDate );
|
|
207
|
+
let endMonth = newDate.endOf( 'month' );
|
|
208
|
+
if ( element1.scheduleRepeatedDay[0] != '01' && currentdate > endMonth.format( 'YYYY-MM-DD' ) ) {
|
|
209
|
+
let checkExists = await processedchecklist.findOne( { sourceCheckList_id: element1._id }, { date_string: 1 } );
|
|
210
|
+
if ( checkExists ) {
|
|
211
|
+
newDate = dayjs( checkExists.date_string );
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
let startMonth = newDate.startOf( 'month' );
|
|
215
|
+
let endMonth = newDate.clone().endOf( 'month' );
|
|
216
|
+
|
|
217
|
+
let diff = parseInt( dayjs.utc( currentdate ).diff( startMonth, 'month' ) );
|
|
218
|
+
diff = diff < 9 ? '0'+diff : diff;
|
|
219
|
+
|
|
220
|
+
if ( diff == parseInt( element1.scheduleRepeatedDay[0] ) || ( startMonth.format( 'YYYY-MM-DD' ) <= currentdate && endMonth.format( 'YYYY-MM-DD' ) >= currentdate ) ) {
|
|
221
|
+
validation = true;
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
validation = true;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
} else if ( element1.schedule == 'onetime' ) {
|
|
228
|
+
if ( scheduledate == currentdate ) {
|
|
229
|
+
resultchecklist.push( element1._id );
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
let startDate = dayjs.utc( element1.configStartDate ).format( 'YYYY-MM-DD' );
|
|
233
|
+
let endDate = dayjs.utc( element1.configEndDate ).format( 'YYYY-MM-DD' );
|
|
234
|
+
|
|
235
|
+
if ( startDate <= currentdate && endDate >= currentdate ) {
|
|
236
|
+
if ( !element1?.specificDate?.length ) {
|
|
237
|
+
resultchecklist.push( element1._id );
|
|
238
|
+
} else {
|
|
239
|
+
if ( element1?.specificDate.includes( dayjs( currentdate ).format( 'DD-MM-YYYY' ) ) ) {
|
|
240
|
+
resultchecklist.push( element1._id );
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if ( ![ 'onetime', 'range' ].includes( element1.schedule ) ) {
|
|
246
|
+
if ( validation ) {
|
|
247
|
+
let startDate = element1?.configStartDate ? dayjs.utc( element1?.configStartDate ).format( 'YYYY-MM-DD' ) : '';
|
|
248
|
+
let endDate = element1?.configEndDate ? dayjs.utc( element1?.configEndDate ).format( 'YYYY-MM-DD' ) : '';
|
|
249
|
+
if ( !startDate && !endDate || ( startDate && ( startDate == currentdate || startDate < currentdate ) ) && endDate == '' ) {
|
|
250
|
+
resultchecklist.push( element1._id );
|
|
251
|
+
}
|
|
252
|
+
if ( endDate != '' && startDate <= currentdate && endDate >= currentdate ) {
|
|
253
|
+
resultchecklist.push( element1._id );
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
} ) );
|
|
258
|
+
if ( resultchecklist.length ) {
|
|
259
|
+
await Promise.all( resultchecklist.map( async ( element2 ) => {
|
|
260
|
+
let getCLconfig = getuniquechecklist.find( ( checklist ) => checklist._id.toString() == element2.toString() );
|
|
261
|
+
if ( getCLconfig ) {
|
|
262
|
+
let startTimeIso; let endTimeIso;
|
|
263
|
+
startTimeIso = dayjs.utc( `${currentdate} ${getCLconfig.scheduleStartTime}`, 'YYYY-MM-DD hh:mm A' );
|
|
264
|
+
endTimeIso = dayjs.utc( `${currentdate} ${getCLconfig.scheduleEndTime}`, 'YYYY-MM-DD hh:mm A' );
|
|
265
|
+
let insertdata = {};
|
|
266
|
+
insertdata.date_iso = new Date( currentdate );
|
|
267
|
+
insertdata.date_string = currentdate;
|
|
268
|
+
insertdata.sourceCheckList_id = getCLconfig._id;
|
|
269
|
+
insertdata.checkListName = getCLconfig.checkListName;
|
|
270
|
+
insertdata.checkListDescription = getCLconfig.checkListDescription;
|
|
271
|
+
insertdata.publish = getCLconfig.publish;
|
|
272
|
+
insertdata.scheduleStartTime = getCLconfig.scheduleStartTime;
|
|
273
|
+
insertdata.scheduleStartTime_iso = startTimeIso.format();
|
|
274
|
+
insertdata.scheduleEndTime = getCLconfig.scheduleEndTime;
|
|
275
|
+
insertdata.scheduleEndTime_iso = endTimeIso.format();
|
|
276
|
+
insertdata.allowedOverTime = getCLconfig.allowedOverTime;
|
|
277
|
+
insertdata.allowedStoreLocation = getCLconfig.allowedStoreLocation;
|
|
278
|
+
insertdata.client_id = getCLconfig.client_id;
|
|
279
|
+
insertdata.createdBy = new ObjectId( getCLconfig.createdBy );
|
|
280
|
+
insertdata.createdByName = getCLconfig.createdByName;
|
|
281
|
+
insertdata.checkListType = getCLconfig.checkListType;
|
|
282
|
+
insertdata.storeCount = getCLconfig.storeCount;
|
|
283
|
+
insertdata.questionCount = getCLconfig.questionCount;
|
|
284
|
+
insertdata.publishDate = getCLconfig.publishDate;
|
|
285
|
+
insertdata.locationCount = getCLconfig.locationCount;
|
|
286
|
+
insertdata.scheduleRepeatedType = getCLconfig.scheduleRepeatedType;
|
|
287
|
+
insertdata.allowedMultiSubmit = getCLconfig.allowedMultiSubmit;
|
|
288
|
+
insertdata.rawImageUpload = getCLconfig.rawImageUpload || false;
|
|
289
|
+
insertdata.rawVideoUpload = getCLconfig.rawVideoUpload || false;
|
|
290
|
+
let collectSections = [];
|
|
291
|
+
let sectionQuery = [];
|
|
292
|
+
sectionQuery.push( {
|
|
293
|
+
$match: {
|
|
294
|
+
checkListId: element2,
|
|
295
|
+
isdeleted: false,
|
|
296
|
+
},
|
|
297
|
+
} );
|
|
298
|
+
let getSections = await CLquestions.aggregate( sectionQuery );
|
|
299
|
+
if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo','vehicle_check_in' ].includes( getCLconfig.checkListType ) ) {
|
|
300
|
+
if ( getSections.length ) {
|
|
301
|
+
for ( let element3 of getSections ) {
|
|
302
|
+
let collectQuestions = {};
|
|
303
|
+
collectQuestions.section_id = element3._id;
|
|
304
|
+
collectQuestions.sectionName = element3.section;
|
|
305
|
+
collectQuestions.questions = element3.question;
|
|
306
|
+
collectSections.push( collectQuestions );
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
insertdata.questionAnswers = collectSections;
|
|
310
|
+
insertdata.updatedAt = new Date();
|
|
311
|
+
let insertdataquery = {};
|
|
312
|
+
insertdataquery.date_string = insertdata.date_string;
|
|
313
|
+
insertdataquery.date_iso = insertdata.date_iso;
|
|
314
|
+
insertdataquery.client_id = insertdata.client_id;
|
|
315
|
+
insertdataquery.sourceCheckList_id = insertdata.sourceCheckList_id;
|
|
316
|
+
insertdataquery.startTime = { $exists: true };
|
|
317
|
+
let checkchecklist = await PCLconfig.findOne( insertdataquery );
|
|
318
|
+
if ( !checkchecklist ) {
|
|
319
|
+
delete insertdataquery.startTime;
|
|
320
|
+
let updatedchecklist;
|
|
321
|
+
let checklistDetails = await PCLconfig.findOne( insertdataquery );
|
|
322
|
+
if ( !checklistDetails ) {
|
|
323
|
+
updatedchecklist = await PCLconfig.insert( insertdata );
|
|
324
|
+
} else {
|
|
325
|
+
await PCLconfig.updateOne( { _id: checklistDetails._id }, insertdata );
|
|
326
|
+
updatedchecklist = checklistDetails;
|
|
327
|
+
}
|
|
328
|
+
if ( updatedchecklist ) {
|
|
329
|
+
let getquestionQuery = [];
|
|
330
|
+
getquestionQuery.push( {
|
|
331
|
+
$match: {
|
|
332
|
+
checkListId: element2,
|
|
333
|
+
isdeleted: false,
|
|
334
|
+
},
|
|
335
|
+
} );
|
|
336
|
+
let allQuestion = await CLassign.aggregate( getquestionQuery );
|
|
337
|
+
if ( allQuestion.length && getCLconfig.checkListType == 'custom' ) {
|
|
338
|
+
let assignList = [];
|
|
339
|
+
if ( getCLconfig.coverage == 'store' ) {
|
|
340
|
+
let clusterList = allQuestion.filter( ( ele ) => ele?.clusterName ).map( ( item ) => item.assignId );
|
|
341
|
+
if ( clusterList.length ) {
|
|
342
|
+
let clusterDetails = await clusterServices.findcluster( { _id: { $in: clusterList } } );
|
|
343
|
+
if ( clusterDetails.length ) {
|
|
344
|
+
let idList = clusterDetails.flatMap( ( item ) => item.stores.map( ( ele ) => ele.store ) );
|
|
345
|
+
let getStoreDetails = await storeService.find( { _id: { $in: idList } } );
|
|
346
|
+
if ( getStoreDetails.length ) {
|
|
347
|
+
assignList = await Promise.all( getStoreDetails.map( async ( store ) => {
|
|
348
|
+
let userDetails = await userService.findOne( { email: store?.spocDetails?.[0]?.email, clientId: store.clientId } );
|
|
349
|
+
if ( !userDetails ) {
|
|
350
|
+
let data = {
|
|
351
|
+
clientId: store.clientId,
|
|
352
|
+
userName: store.spocDetails?.[0]?.name,
|
|
353
|
+
mobileNumber: store.spocDetails?.[0]?.phone || '',
|
|
354
|
+
email: store.spocDetails[0].email,
|
|
355
|
+
password: '5dqFKAJj29PsV6P+kL+3Dw==',
|
|
356
|
+
role: 'user',
|
|
357
|
+
userType: 'client',
|
|
358
|
+
rolespermission: [
|
|
359
|
+
{
|
|
360
|
+
featureName: 'Global',
|
|
361
|
+
modules: [
|
|
362
|
+
{
|
|
363
|
+
name: 'Store',
|
|
364
|
+
isAdd: false,
|
|
365
|
+
isEdit: false,
|
|
366
|
+
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
name: 'User',
|
|
370
|
+
isAdd: false,
|
|
371
|
+
isEdit: false,
|
|
372
|
+
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
name: 'Camera',
|
|
376
|
+
isAdd: false,
|
|
377
|
+
isEdit: false,
|
|
378
|
+
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
name: 'Configuration',
|
|
382
|
+
isAdd: false,
|
|
383
|
+
isEdit: false,
|
|
384
|
+
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
name: 'Subscription',
|
|
388
|
+
isAdd: false,
|
|
389
|
+
isEdit: false,
|
|
390
|
+
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
name: 'Billing',
|
|
394
|
+
isAdd: false,
|
|
395
|
+
isEdit: false,
|
|
396
|
+
|
|
397
|
+
},
|
|
398
|
+
],
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
featurName: 'TangoEye',
|
|
402
|
+
modules: [
|
|
403
|
+
{
|
|
404
|
+
name: 'ZoneTag',
|
|
405
|
+
isAdd: false,
|
|
406
|
+
isEdit: false,
|
|
407
|
+
|
|
408
|
+
},
|
|
409
|
+
],
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
featurName: 'TangoTrax',
|
|
413
|
+
modules: [
|
|
414
|
+
{
|
|
415
|
+
name: 'checklist',
|
|
416
|
+
isAdd: false,
|
|
417
|
+
isEdit: false,
|
|
418
|
+
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
name: 'Task',
|
|
422
|
+
isAdd: false,
|
|
423
|
+
isEdit: false,
|
|
424
|
+
|
|
425
|
+
},
|
|
426
|
+
],
|
|
427
|
+
},
|
|
428
|
+
],
|
|
429
|
+
};
|
|
430
|
+
userDetails = await userService.create( data );
|
|
431
|
+
}
|
|
432
|
+
let data = {
|
|
433
|
+
store_id: store?.storeId,
|
|
434
|
+
storeName: store?.storeName,
|
|
435
|
+
userId: userDetails._id,
|
|
436
|
+
userName: userDetails.userName,
|
|
437
|
+
userEmail: userDetails.email,
|
|
438
|
+
userPhone: userDetails?.mobileNumber,
|
|
439
|
+
city: store?.storeProfile?.city,
|
|
440
|
+
country: store?.storeProfile?.country,
|
|
441
|
+
checkFlag: true,
|
|
442
|
+
checkListId: getCLconfig._id,
|
|
443
|
+
checkListName: getCLconfig.checkListName,
|
|
444
|
+
client_id: getCLconfig.client_id,
|
|
445
|
+
};
|
|
446
|
+
return data;
|
|
447
|
+
} ) );
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
allQuestion = allQuestion.filter( ( ele ) => !clusterList.includes( ele.assignId ) );
|
|
452
|
+
}
|
|
453
|
+
if ( getCLconfig.coverage == 'user' ) {
|
|
454
|
+
let teamsList = allQuestion.filter( ( ele ) => ele?.teamName ).map( ( item ) => item.assignId );
|
|
455
|
+
if ( teamsList.length ) {
|
|
456
|
+
let teamDetails = await teamsServices.findteams( { _id: { $in: teamsList } } );
|
|
457
|
+
if ( teamDetails.length ) {
|
|
458
|
+
let idList = [ ...teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) ), ...teamDetails.flatMap( ( item ) => item.Teamlead.map( ( ele ) => ele.userId ) ) ];
|
|
459
|
+
let getUserDetails = await userService.find( { _id: { $in: idList } } );
|
|
460
|
+
if ( getUserDetails.length ) {
|
|
461
|
+
assignList = getUserDetails.map( ( user ) => {
|
|
462
|
+
let data = {
|
|
463
|
+
store_id: '',
|
|
464
|
+
storeName: '',
|
|
465
|
+
userId: user._id,
|
|
466
|
+
userName: user.userName,
|
|
467
|
+
userEmail: user.email,
|
|
468
|
+
userPhone: user?.mobileNumber,
|
|
469
|
+
city: '',
|
|
470
|
+
country: '',
|
|
471
|
+
checkFlag: true,
|
|
472
|
+
checkListId: getCLconfig._id,
|
|
473
|
+
checkListName: getCLconfig.checkListName,
|
|
474
|
+
client_id: getCLconfig.client_id,
|
|
475
|
+
};
|
|
476
|
+
return data;
|
|
477
|
+
} );
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
allQuestion = allQuestion.filter( ( ele ) => !teamsList.includes( ele.assignId ) );
|
|
482
|
+
}
|
|
483
|
+
allQuestion = [ ...allQuestion, ...assignList ];
|
|
484
|
+
let userIdList = [];
|
|
485
|
+
for ( let element4 of allQuestion ) {
|
|
486
|
+
if ( getCLconfig.allowOnce && ![ 'onetime', 'daily' ].includes( getCLconfig.schedule ) ) {
|
|
487
|
+
let query;
|
|
488
|
+
if ( [ 'weekday', 'weekly', 'monthly' ].includes( getCLconfig.schedule ) ) {
|
|
489
|
+
let startDate; let endDate;
|
|
490
|
+
if ( [ 'weekday', 'weekly' ].includes( getCLconfig.schedule ) ) {
|
|
491
|
+
startDate = dayjs.utc( currentdate ).clone().startOf( 'week' );
|
|
492
|
+
endDate = dayjs.utc( currentdate ).clone().endOf( 'week' );
|
|
493
|
+
} else {
|
|
494
|
+
startDate = dayjs.utc( currentdate ).clone().startOf( 'month' );
|
|
495
|
+
endDate = dayjs.utc( currentdate ).clone().endOf( 'month' );
|
|
496
|
+
}
|
|
497
|
+
query = {
|
|
498
|
+
sourceCheckList_id: getCLconfig._id,
|
|
499
|
+
$or: [ {
|
|
500
|
+
checklistStatus: { $in: [ 'submit' ] } },
|
|
501
|
+
{ submitTime: { $exists: true } },
|
|
502
|
+
],
|
|
503
|
+
userId: element4.userId,
|
|
504
|
+
store_id: element4.store_id,
|
|
505
|
+
$and: [ {
|
|
506
|
+
date_iso: {
|
|
507
|
+
$gte: new Date( startDate.format( 'YYYY-MM-DD' ) ),
|
|
508
|
+
$lte: new Date( endDate.format( 'YYYY-MM-DD' ) ) },
|
|
509
|
+
} ],
|
|
510
|
+
};
|
|
511
|
+
} else {
|
|
512
|
+
query = {
|
|
513
|
+
sourceCheckList_id: getCLconfig._id,
|
|
514
|
+
$or: [ {
|
|
515
|
+
checklistStatus: { $in: [ 'submit' ] } },
|
|
516
|
+
{ submitTime: { $exists: true } },
|
|
517
|
+
],
|
|
518
|
+
userId: element4.userId,
|
|
519
|
+
store_id: element4.store_id,
|
|
520
|
+
$and: [ {
|
|
521
|
+
date_iso: {
|
|
522
|
+
$gte: new Date( dayjs( getCLconfig.configStartDate ).format( 'YYYY-MM-DD' ) ),
|
|
523
|
+
$lte: new Date( dayjs( getCLconfig.configEndDate ).format( 'YYYY-MM-DD' ) ) },
|
|
524
|
+
} ],
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
let getsubmitDetails = await processedchecklist.find( query );
|
|
528
|
+
if ( getsubmitDetails.length ) {
|
|
529
|
+
userIdList.push( element4._id );
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
delete element4._id;
|
|
534
|
+
delete element4.checkFlag;
|
|
535
|
+
delete element4.isdeleted;
|
|
536
|
+
delete element4.createdAt;
|
|
537
|
+
delete element4.updatedAt;
|
|
538
|
+
element4.checkListId = updatedchecklist._id;
|
|
539
|
+
element4.checkListName = getCLconfig.checkListName;
|
|
540
|
+
element4.checkListDescription = getCLconfig.checkListDescription;
|
|
541
|
+
element4.date_iso = new Date( currentdate );
|
|
542
|
+
element4.date_string = currentdate;
|
|
543
|
+
element4.allowedOverTime = getCLconfig.allowedOverTime;
|
|
544
|
+
element4.allowedStoreLocation = getCLconfig.allowedStoreLocation;
|
|
545
|
+
element4.scheduleStartTime = getCLconfig.scheduleStartTime;
|
|
546
|
+
element4.scheduleStartTime_iso = startTimeIso.format();
|
|
547
|
+
element4.scheduleEndTime = getCLconfig.scheduleEndTime;
|
|
548
|
+
element4.scheduleEndTime_iso = endTimeIso.format();
|
|
549
|
+
element4.createdBy = new ObjectId( getCLconfig.createdBy );
|
|
550
|
+
element4.createdByName = getCLconfig.createdByName;
|
|
551
|
+
element4.sourceCheckList_id = getCLconfig._id;
|
|
552
|
+
element4.checkListType = getCLconfig.checkListType;
|
|
553
|
+
element4.storeCount = getCLconfig.storeCount;
|
|
554
|
+
element4.questionCount = getCLconfig.questionCount;
|
|
555
|
+
element4.publishDate = getCLconfig.publishDate;
|
|
556
|
+
element4.locationCount = getCLconfig.locationCount;
|
|
557
|
+
element4.scheduleRepeatedType = getCLconfig.scheduleRepeatedType;
|
|
558
|
+
element4.approvalEnable = getCLconfig.approver.length ? true : false;
|
|
559
|
+
element4.remainder = getCLconfig?.remainder || [];
|
|
560
|
+
// if ( getCLconfig?.isPlano ) {
|
|
561
|
+
// let planoDetails = await planoService.findOne( { storeId: element4.store_id, clientId: getCLconfig.client_id }, { _id: 1 } );
|
|
562
|
+
// element4.planoId = planoDetails?._id;
|
|
563
|
+
// element4.isPlano = getCLconfig?.isPlano;
|
|
564
|
+
// }
|
|
565
|
+
element4.rawImageUpload = getCLconfig?.rawImageUpload || false;
|
|
566
|
+
element4.rawVideoUpload = getCLconfig?.rawVideoUpload || false;
|
|
567
|
+
}
|
|
568
|
+
if ( userIdList.length ) {
|
|
569
|
+
allQuestion = allQuestion.filter( ( item ) => typeof item._id == 'undefined' );
|
|
570
|
+
}
|
|
571
|
+
if ( allQuestion ) {
|
|
572
|
+
let assigndeletequery = {};
|
|
573
|
+
assigndeletequery.date_string = insertdata.date_string;
|
|
574
|
+
assigndeletequery.date_iso = insertdata.date_iso;
|
|
575
|
+
assigndeletequery.client_id = insertdata.client_id;
|
|
576
|
+
assigndeletequery.checkListId = updatedchecklist._id;
|
|
577
|
+
assigndeletequery.checklistStatus = { $nin: [ 'submit' ] };
|
|
578
|
+
// if (getCLconfig.scheduleRepeatedType == 'range') {
|
|
579
|
+
// allQuestion.forEach(async item => {
|
|
580
|
+
// assigndeletequery.userId = item.userId
|
|
581
|
+
// await processedchecklist.deleteMany(assigndeletequery);
|
|
582
|
+
// await processedchecklist.insertMany(item);
|
|
583
|
+
// logger.info({function:"PCLconfigCreation Range",query:assigndeletequery})
|
|
584
|
+
// })
|
|
585
|
+
// }
|
|
586
|
+
// else {
|
|
587
|
+
await processedchecklist.deleteMany( assigndeletequery );
|
|
588
|
+
logger.info( { checklistId: getCLconfig._id, insertedCount: allQuestion.length } );
|
|
589
|
+
await processedchecklist.insertMany( allQuestion );
|
|
590
|
+
logger.info( { function: 'PCLconfigCreation', query: assigndeletequery } );
|
|
591
|
+
// }
|
|
592
|
+
}
|
|
593
|
+
} else {
|
|
594
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo','vehicle_check_in' ].includes( getCLconfig.checkListType ) ) {
|
|
595
|
+
let storeNameList = allQuestion.map( ( item ) => item.store_id );
|
|
596
|
+
let storeDetails = await storeService.find( { clientId: getCLconfig.client_id, status: 'active', ...( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning' ].includes( getCLconfig.checkListType ) ) ? { storeId: { $in: storeNameList } } : {} }, { storeId: 1 } );
|
|
597
|
+
let storeList = storeDetails.map( ( store ) => store.storeId );
|
|
598
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning' ].includes( getCLconfig.checkListType ) ) {
|
|
599
|
+
allQuestion = allQuestion.filter( ( ele ) => storeList.includes( ele?.store_id ) );
|
|
600
|
+
} else {
|
|
601
|
+
allQuestion = storeDetails.map( ( item ) => {
|
|
602
|
+
return {
|
|
603
|
+
store_id: item.storeId,
|
|
604
|
+
};
|
|
605
|
+
} );
|
|
606
|
+
}
|
|
607
|
+
let data = {
|
|
608
|
+
checkListId: updatedchecklist._id,
|
|
609
|
+
checkListName: getCLconfig.checkListName,
|
|
610
|
+
date_iso: new Date( currentdate ),
|
|
611
|
+
date_string: currentdate,
|
|
612
|
+
allowedOverTime: getCLconfig.allowedOverTime,
|
|
613
|
+
allowedStoreLocation: getCLconfig.allowedStoreLocation,
|
|
614
|
+
checkListDescription: getCLconfig.checkListDescription,
|
|
615
|
+
scheduleStartTime: getCLconfig.scheduleStartTime,
|
|
616
|
+
scheduleStartTime_iso: startTimeIso.format(),
|
|
617
|
+
scheduleEndTime: getCLconfig.scheduleEndTime,
|
|
618
|
+
scheduleEndTime_iso: endTimeIso.format(),
|
|
619
|
+
createdBy: new ObjectId( getCLconfig.createdBy ),
|
|
620
|
+
createdByName: getCLconfig.createdByName,
|
|
621
|
+
sourceCheckList_id: getCLconfig._id,
|
|
622
|
+
checkListType: getCLconfig.checkListType,
|
|
623
|
+
storeCount: getCLconfig.storeCount,
|
|
624
|
+
questionCount: getCLconfig.questionCount,
|
|
625
|
+
publishDate: getCLconfig.publishDate,
|
|
626
|
+
locationCount: getCLconfig.locationCount,
|
|
627
|
+
scheduleRepeatedType: getCLconfig.scheduleRepeatedType,
|
|
628
|
+
storeCount: storeDetails.length,
|
|
629
|
+
client_id: getCLconfig.client_id,
|
|
630
|
+
aiStoreList: allQuestion.length ? allQuestion.map( ( store ) => store.store_id ) : [],
|
|
631
|
+
};
|
|
632
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning' ].includes( getCLconfig.checkListType ) ) {
|
|
633
|
+
let processData = {
|
|
634
|
+
aiStoreList: allQuestion.length ? allQuestion.map( ( store ) => {
|
|
635
|
+
return { storeName: store.storeName, storeId: store.store_id, events: store.events };
|
|
636
|
+
} ) : [],
|
|
637
|
+
aiConfig: getCLconfig?.aiConfig,
|
|
638
|
+
};
|
|
639
|
+
await PCLconfig.updateOne( { _id: updatedchecklist._id }, processData );
|
|
640
|
+
}
|
|
641
|
+
await processedchecklist.updateOne( { date_string: currentdate, checkListId: updatedchecklist._id, sourceCheckList_id: getCLconfig._id, checkListType: getCLconfig.checkListType }, data );
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
} else {
|
|
646
|
+
alreadyExist.push( { sourceCheckList_id: insertdata.sourceCheckList_id, checkListName: insertdata.checkListName } );
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
} ) );
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
if ( dateIndex == 0 ) {
|
|
654
|
+
res.sendSuccess( { message: 'Processed Daily Check List Created Successfully', error: alreadyExist } );
|
|
655
|
+
}
|
|
97
656
|
}
|
|
98
657
|
}
|
|
99
658
|
} catch ( e ) {
|
|
100
659
|
logger.error( { function: 'PCLconfigCreation', error: e } );
|
|
101
|
-
return res.sendError( e, 500 )
|
|
660
|
+
// return res.sendError( e, 500 );/
|
|
102
661
|
}
|
|
103
662
|
};
|
|
104
663
|
|
|
@@ -295,6 +854,7 @@ async function insertData( requestData ) {
|
|
|
295
854
|
insertdata.scheduleRepeatedType = getCLconfig.scheduleRepeatedType;
|
|
296
855
|
insertdata.allowedMultiSubmit = getCLconfig.allowedMultiSubmit;
|
|
297
856
|
insertdata.rawImageUpload = getCLconfig.rawImageUpload || false;
|
|
857
|
+
insertdata.rawVideoUpload = getCLconfig.rawVideoUpload || false;
|
|
298
858
|
let collectSections = [];
|
|
299
859
|
let sectionQuery = [];
|
|
300
860
|
sectionQuery.push( {
|
|
@@ -304,7 +864,7 @@ async function insertData( requestData ) {
|
|
|
304
864
|
},
|
|
305
865
|
} );
|
|
306
866
|
let getSections = await CLquestions.aggregate( sectionQuery );
|
|
307
|
-
if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection' ].includes( getCLconfig.checkListType ) ) {
|
|
867
|
+
if ( getSections.length || [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo','vehicle_check_in' ].includes( getCLconfig.checkListType ) ) {
|
|
308
868
|
if ( getSections.length ) {
|
|
309
869
|
for ( let element3 of getSections ) {
|
|
310
870
|
let collectQuestions = {};
|
|
@@ -571,6 +1131,7 @@ async function insertData( requestData ) {
|
|
|
571
1131
|
// element4.isPlano = getCLconfig?.isPlano;
|
|
572
1132
|
// }
|
|
573
1133
|
element4.rawImageUpload = getCLconfig?.rawImageUpload || false;
|
|
1134
|
+
element4.rawVideoUpload = getCLconfig?.rawVideoUpload || false;
|
|
574
1135
|
}
|
|
575
1136
|
if ( userIdList.length ) {
|
|
576
1137
|
allQuestion = allQuestion.filter( ( item ) => typeof item._id == 'undefined' );
|
|
@@ -597,11 +1158,11 @@ async function insertData( requestData ) {
|
|
|
597
1158
|
// }
|
|
598
1159
|
}
|
|
599
1160
|
} else {
|
|
600
|
-
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection' ].includes( getCLconfig.checkListType ) ) {
|
|
1161
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo','vehicle_check_in' ].includes( getCLconfig.checkListType ) ) {
|
|
601
1162
|
let storeNameList = allQuestion.map( ( item ) => item.store_id );
|
|
602
|
-
let storeDetails = await storeService.find( { clientId: getCLconfig.client_id, status: 'active', ...( [ 'storeopenandclose', 'mobileusagedetection', '
|
|
1163
|
+
let storeDetails = await storeService.find( { clientId: getCLconfig.client_id, status: 'active', ...( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning' ].includes( getCLconfig.checkListType ) ) ? { storeId: { $in: storeNameList } } : {} }, { storeId: 1 } );
|
|
603
1164
|
let storeList = storeDetails.map( ( store ) => store.storeId );
|
|
604
|
-
if ( [ 'storeopenandclose', 'mobileusagedetection', '
|
|
1165
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning' ].includes( getCLconfig.checkListType ) ) {
|
|
605
1166
|
allQuestion = allQuestion.filter( ( ele ) => storeList.includes( ele?.store_id ) );
|
|
606
1167
|
} else {
|
|
607
1168
|
allQuestion = storeDetails.map( ( item ) => {
|
|
@@ -635,7 +1196,7 @@ async function insertData( requestData ) {
|
|
|
635
1196
|
client_id: getCLconfig.client_id,
|
|
636
1197
|
aiStoreList: allQuestion.length ? allQuestion.map( ( store ) => store.store_id ) : [],
|
|
637
1198
|
};
|
|
638
|
-
if ( [ 'storeopenandclose', 'mobileusagedetection', '
|
|
1199
|
+
if ( [ 'storeopenandclose', 'mobileusagedetection', 'uniformdetection', 'customerunattended', 'staffleftinthemiddle', 'scrum', 'cleaning' ].includes( getCLconfig.checkListType ) ) {
|
|
639
1200
|
let processData = {
|
|
640
1201
|
aiStoreList: allQuestion.length ? allQuestion.map( ( store ) => {
|
|
641
1202
|
return { storeName: store.storeName, storeId: store.store_id, events: store.events };
|
|
@@ -1456,15 +2017,15 @@ export async function getPDFCSVChecklistDetails( req, res ) {
|
|
|
1456
2017
|
|
|
1457
2018
|
export async function AiPushNotificationAlert( req, res ) {
|
|
1458
2019
|
try {
|
|
1459
|
-
console.log( req.body );
|
|
2020
|
+
// console.log( req.body );
|
|
1460
2021
|
let findAichecklist = await PCLconfig.findOne( { checkListType: req.body.checkListType, client_id: req.body.clientId, date_string: req.body.Date }, { aiConfig: 1 } );
|
|
1461
2022
|
if ( findAichecklist.aiConfig&&findAichecklist.aiConfig.alerts&&findAichecklist.aiConfig.alerts.users&&findAichecklist.aiConfig.alerts.users.length>0 ) {
|
|
1462
|
-
console.log( findAichecklist.aiConfig.alerts.users );
|
|
2023
|
+
// console.log( findAichecklist.aiConfig.alerts.users );
|
|
1463
2024
|
for ( let user of findAichecklist.aiConfig.alerts.users ) {
|
|
1464
2025
|
let findOneUser = await userService.findOne( { email: user }, { fcmToken: 1 } );
|
|
1465
|
-
console.log( findOneUser );
|
|
2026
|
+
// console.log( findOneUser );
|
|
1466
2027
|
if ( findOneUser&&findOneUser.fcmToken&&findOneUser.fcmToken!='' ) {
|
|
1467
|
-
console.log( findOneUser.fcmToken );
|
|
2028
|
+
// console.log( findOneUser.fcmToken );
|
|
1468
2029
|
try {
|
|
1469
2030
|
await sendPushNotification( req.body.title, req.body.description, findOneUser.fcmToken );
|
|
1470
2031
|
} catch ( e ) {
|
|
@@ -1752,3 +2313,35 @@ export async function internalAISendPushNotification( req, res ) {
|
|
|
1752
2313
|
else res.sendError( e, 500 );
|
|
1753
2314
|
}
|
|
1754
2315
|
};
|
|
2316
|
+
|
|
2317
|
+
export async function getLiveChecklistClients( req, res ) {
|
|
2318
|
+
try {
|
|
2319
|
+
let inputData = req.body;
|
|
2320
|
+
let query = [
|
|
2321
|
+
{
|
|
2322
|
+
$match: {
|
|
2323
|
+
isdeleted: false,
|
|
2324
|
+
publish: true,
|
|
2325
|
+
client_id: {
|
|
2326
|
+
$nin: inputData.ignoreClientId,
|
|
2327
|
+
$exists: true,
|
|
2328
|
+
$ne: null,
|
|
2329
|
+
},
|
|
2330
|
+
},
|
|
2331
|
+
},
|
|
2332
|
+
{ $group: { _id: '$client_id' } },
|
|
2333
|
+
{ $sort: { _id: 1 } },
|
|
2334
|
+
{ $group: { _id: null, client_ids: { $push: '$_id' } } },
|
|
2335
|
+
];
|
|
2336
|
+
|
|
2337
|
+
let getchecklistsData = await CLconfig.aggregate( query );
|
|
2338
|
+
if ( getchecklistsData && getchecklistsData.length >0 ) {
|
|
2339
|
+
return res.sendSuccess( { liveChecklistClients: getchecklistsData[0].client_ids } );
|
|
2340
|
+
} else {
|
|
2341
|
+
return res.sendError( 'Checklist Not Available', 204 );
|
|
2342
|
+
}
|
|
2343
|
+
} catch ( error ) {
|
|
2344
|
+
if ( error.name === 'ValidationError' ) res.sendBadRequest( error );
|
|
2345
|
+
else res.sendError( error, 500 );
|
|
2346
|
+
}
|
|
2347
|
+
}
|