tango-app-api-task 3.5.0-alpha-8 → 3.6.0-task-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-task",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0-task-3",
|
|
4
4
|
"description": "Task",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"mongodb": "^6.10.0",
|
|
26
26
|
"nodemon": "^3.1.7",
|
|
27
27
|
"npm": "^10.9.2",
|
|
28
|
-
"tango-api-schema": "^2.2.
|
|
28
|
+
"tango-api-schema": "^2.2.147",
|
|
29
29
|
"tango-app-api-middleware": "^3.1.77",
|
|
30
30
|
"winston": "^3.17.0",
|
|
31
31
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -90,6 +90,7 @@ export async function createUpdateTask( req, res ) {
|
|
|
90
90
|
createdByName: req.user.userName,
|
|
91
91
|
questionCount: questionCount,
|
|
92
92
|
client_id: req.body?.clientId,
|
|
93
|
+
checkListFrom: 'manage',
|
|
93
94
|
};
|
|
94
95
|
if ( inputBody._id ) {
|
|
95
96
|
query = { _id: inputBody._id, client_id: req.body?.clientId };
|
|
@@ -1274,6 +1275,7 @@ export async function insertSingleProcessData( checklistId, answerTypechange, in
|
|
|
1274
1275
|
insertdata.approver = getCLconfig?.approver || [];
|
|
1275
1276
|
insertdata.restrictAttendance = getCLconfig?.restrictAttendance;
|
|
1276
1277
|
insertdata.coverage = getCLconfig?.coverage;
|
|
1278
|
+
insertdata.checkListFrom = getCLconfig?.checkListFrom;
|
|
1277
1279
|
let collectSections = [];
|
|
1278
1280
|
let sectionQuery = [];
|
|
1279
1281
|
sectionQuery.push( {
|
|
@@ -1316,7 +1318,7 @@ export async function insertSingleProcessData( checklistId, answerTypechange, in
|
|
|
1316
1318
|
|
|
1317
1319
|
const dateArray = getDaysBeforeEndDate( endDate );
|
|
1318
1320
|
|
|
1319
|
-
for ( const dateVal of dateArray ) {
|
|
1321
|
+
for ( const dateVal of [ dateArray[0] ] ) {
|
|
1320
1322
|
const insertdataquery = {
|
|
1321
1323
|
date_string: dayjs( dateVal ).format( 'YYYY-MM-DD' ),
|
|
1322
1324
|
date_iso: dayjs( dateVal ).toDate(),
|
|
@@ -1520,6 +1522,7 @@ async function insertPCBulkV3( getCLconfig, checklistId, updatedchecklist, date,
|
|
|
1520
1522
|
element4.remainder = getCLconfig?.remainder || [];
|
|
1521
1523
|
element4.restrictAttendance = getCLconfig?.restrictAttendance;
|
|
1522
1524
|
element4.coverage = getCLconfig?.coverage;
|
|
1525
|
+
element4.checkListFrom = getCLconfig?.checkListFrom;
|
|
1523
1526
|
if ( inputBody && inputBody?.streamId ) {
|
|
1524
1527
|
element4.streamId = inputBody?.streamId;
|
|
1525
1528
|
}
|
|
@@ -1905,6 +1908,7 @@ export async function createChecklistTask( req, res ) {
|
|
|
1905
1908
|
locationCount: 1,
|
|
1906
1909
|
...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
|
|
1907
1910
|
coverage: checklistDetails?.coverage || 'store',
|
|
1911
|
+
checkListFrom: 'gallery',
|
|
1908
1912
|
};
|
|
1909
1913
|
|
|
1910
1914
|
if ( req.user.userType == 'tango' || ( req.user.userType == 'client' && [ 'user' ].includes( req.user.role ) ) ) {
|
|
@@ -2133,6 +2137,7 @@ export async function createChecklistMultiTask( req, res ) {
|
|
|
2133
2137
|
locationCount: 1,
|
|
2134
2138
|
...( originaldata?.checkListId ) ? { referenceCheckListId: originaldata?.checkListId } : {},
|
|
2135
2139
|
coverage: checklistDetails?.coverage || 'store',
|
|
2140
|
+
checkListFrom: 'gallery',
|
|
2136
2141
|
};
|
|
2137
2142
|
|
|
2138
2143
|
if ( req.user.userType == 'tango' || ( req.user.userType == 'client' && [ 'user' ].includes( req.user.role ) ) ) {
|
|
@@ -2706,17 +2711,20 @@ export const taskDropdown = async ( req, res ) => {
|
|
|
2706
2711
|
let requestData = req.body;
|
|
2707
2712
|
let fromDate = new Date( requestData.fromDate );
|
|
2708
2713
|
let toDate = new Date( requestData.toDate );
|
|
2709
|
-
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
2710
|
-
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
2711
|
-
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
2714
|
+
// let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
2715
|
+
// toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
2716
|
+
// toDate.setUTCHours( 23, 59, 59, 59 );
|
|
2712
2717
|
let result = {};
|
|
2718
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
2713
2719
|
|
|
2714
2720
|
let findQuery = [];
|
|
2715
2721
|
let findAndQuery = [];
|
|
2716
2722
|
findAndQuery.push(
|
|
2717
2723
|
{ client_id: requestData.clientId },
|
|
2718
|
-
{ date_iso: { $gte: fromDate } },
|
|
2719
|
-
{ date_iso: { $lte: toDate } },
|
|
2724
|
+
// { date_iso: { $gte: fromDate } },
|
|
2725
|
+
// { date_iso: { $lte: toDate } },
|
|
2726
|
+
{ scheduleStartTime_iso: { $lt: toDate } },
|
|
2727
|
+
{ scheduleEndTime_iso: { $gte: fromDate } },
|
|
2720
2728
|
{ checkListType: { $in: [ 'task', 'checklistTask', 'cctv' ] } },
|
|
2721
2729
|
);
|
|
2722
2730
|
|
|
@@ -2863,6 +2871,7 @@ export const taskList = async ( req, res ) => {
|
|
|
2863
2871
|
checkListType: { $in: [ 'task', 'checklistTask', 'cctv' ] },
|
|
2864
2872
|
client_id: req.query.clientId,
|
|
2865
2873
|
isdeleted: false,
|
|
2874
|
+
checkListFrom: { $nin: [ 'api' ] },
|
|
2866
2875
|
},
|
|
2867
2876
|
},
|
|
2868
2877
|
);
|
|
@@ -2892,6 +2901,7 @@ export const taskList = async ( req, res ) => {
|
|
|
2892
2901
|
checkListChar: { $substr: [ '$checkListName', 0, 2 ] },
|
|
2893
2902
|
priorityType: 1,
|
|
2894
2903
|
scheduleEndTimeISO: 1,
|
|
2904
|
+
checkListFrom: 1,
|
|
2895
2905
|
},
|
|
2896
2906
|
},
|
|
2897
2907
|
);
|
|
@@ -3249,27 +3259,25 @@ export async function teamMigrations( req, res ) {
|
|
|
3249
3259
|
}
|
|
3250
3260
|
export async function clusterMigrations( req, res ) {
|
|
3251
3261
|
try {
|
|
3252
|
-
let input =
|
|
3253
|
-
|
|
3254
|
-
];
|
|
3262
|
+
let input =[];
|
|
3255
3263
|
for ( let user of input ) {
|
|
3256
|
-
let userexits = await userService.findOne( { email: user.
|
|
3264
|
+
let userexits = await userService.findOne( { 'email': user.clusterEmail, 'clientId': '11' } );
|
|
3257
3265
|
if ( userexits ) {
|
|
3258
|
-
let findStore = await storeService.findOne( { storeName: user.
|
|
3266
|
+
let findStore = await storeService.findOne( { 'storeName': user.storeName, 'clientId': '11' } );
|
|
3259
3267
|
if ( findStore ) {
|
|
3260
|
-
let clusterExists = await clusterServices.findOneCluster( { clusterName: user.
|
|
3268
|
+
let clusterExists = await clusterServices.findOneCluster( { 'clusterName': user.clusterName, 'clientId': '11' } );
|
|
3261
3269
|
if ( clusterExists ) {
|
|
3262
3270
|
let data = {
|
|
3263
3271
|
storeId: findStore.storeId,
|
|
3264
3272
|
store: findStore._id,
|
|
3265
3273
|
};
|
|
3266
|
-
let updatecluster = await clusterServices.updateCluster( { clusterName: user.
|
|
3274
|
+
let updatecluster = await clusterServices.updateCluster( { 'clusterName': user.clusterName, 'clientId': '11' }, { $push: { stores: data } } );
|
|
3267
3275
|
console.log( updatecluster );
|
|
3268
3276
|
} else {
|
|
3269
3277
|
let payload = {
|
|
3270
|
-
'clusterName': user.
|
|
3278
|
+
'clusterName': user.clusterName,
|
|
3271
3279
|
'clientId': '11',
|
|
3272
|
-
'description': user.
|
|
3280
|
+
'description': user.clusterName,
|
|
3273
3281
|
'stores': [
|
|
3274
3282
|
{
|
|
3275
3283
|
storeId: findStore.storeId,
|
|
@@ -3450,7 +3458,7 @@ export async function createAiChecklist( req, res ) {
|
|
|
3450
3458
|
return res.sendError( e, 500 );
|
|
3451
3459
|
}
|
|
3452
3460
|
}
|
|
3453
|
-
export async function
|
|
3461
|
+
export async function StoreHygienetaskOld( req, res ) {
|
|
3454
3462
|
try {
|
|
3455
3463
|
let inputBody = req.body;
|
|
3456
3464
|
|
|
@@ -3901,6 +3909,7 @@ export async function eyeTesttask( req, res ) {
|
|
|
3901
3909
|
return res.sendError( e, 500 );
|
|
3902
3910
|
}
|
|
3903
3911
|
}
|
|
3912
|
+
|
|
3904
3913
|
export async function createAiTask( req, res ) {
|
|
3905
3914
|
try {
|
|
3906
3915
|
let inputBody = req.body;
|
|
@@ -4745,6 +4754,8 @@ export async function commonAiTask( req, res ) {
|
|
|
4745
4754
|
publishDate: new Date(),
|
|
4746
4755
|
locationCount: 1,
|
|
4747
4756
|
...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
|
|
4757
|
+
coverage: 'store',
|
|
4758
|
+
checkListFrom: 'api',
|
|
4748
4759
|
};
|
|
4749
4760
|
data['approver'] = userAdmin;
|
|
4750
4761
|
let answer = await findAnswer( inputBody?.answerType );
|
|
@@ -5362,3 +5373,622 @@ export async function userMigrations( req, res ) {
|
|
|
5362
5373
|
return res.sendError( error, 500 );
|
|
5363
5374
|
}
|
|
5364
5375
|
}
|
|
5376
|
+
|
|
5377
|
+
export async function StoreHygienetask( req, res ) {
|
|
5378
|
+
try {
|
|
5379
|
+
let inputBody = req.body;
|
|
5380
|
+
|
|
5381
|
+
inputBody.clientId = 11;
|
|
5382
|
+
inputBody.taskDescription = '';
|
|
5383
|
+
let userId;
|
|
5384
|
+
let storeDetails = await storeService.findOne( { storeName: inputBody.storeName, clientId: inputBody.clientId, status: 'active' }, { storeId: 1, storeName: 1, storeProfile: 1 } );
|
|
5385
|
+
if ( !storeDetails ) {
|
|
5386
|
+
return res.sendError( 'Store Not Found', 500 );
|
|
5387
|
+
}
|
|
5388
|
+
|
|
5389
|
+
let url = JSON.parse( process.env.LAMBDAURL );
|
|
5390
|
+
let dailychecklistId = new mongoose.Types.ObjectId( url.dailystoreChecklistId );
|
|
5391
|
+
let KSAchecklistId = new mongoose.Types.ObjectId( url.KSAchecklist );
|
|
5392
|
+
let UAEchecklistId = new mongoose.Types.ObjectId( url.UAEchecklist );
|
|
5393
|
+
let singaporechecklistId = new mongoose.Types.ObjectId( url.singaporechecklist );
|
|
5394
|
+
|
|
5395
|
+
let finduser = await checklistassignconfigModel.findOne( { checkListId: { $in: [ dailychecklistId, KSAchecklistId, UAEchecklistId, singaporechecklistId ] }, store_id: storeDetails.storeId } );
|
|
5396
|
+
if ( !finduser ) {
|
|
5397
|
+
return res.sendError( 'No user Found For this store', 500 );
|
|
5398
|
+
}
|
|
5399
|
+
|
|
5400
|
+
userId = finduser.userId;
|
|
5401
|
+
inputBody.userName = finduser.userName;
|
|
5402
|
+
inputBody.userEmail = finduser.userEmail;
|
|
5403
|
+
let teamList = await findteams( { users: { $elemMatch: { email: finduser.userEmail } } } );
|
|
5404
|
+
|
|
5405
|
+
inputBody.approver = '';
|
|
5406
|
+
for ( let team of teamList ) {
|
|
5407
|
+
for ( let user of team.Teamlead ) {
|
|
5408
|
+
inputBody.approver = user.email + ',' + inputBody.approver;
|
|
5409
|
+
}
|
|
5410
|
+
}
|
|
5411
|
+
inputBody.approver = inputBody.approver.replace( /,$/, '' );
|
|
5412
|
+
let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
|
|
5413
|
+
let time = inputBody?.scheduleEndTime || '11:59 PM';
|
|
5414
|
+
let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
|
|
5415
|
+
let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
|
|
5416
|
+
let userDetails = await userService.findOne( { _id: new mongoose.Types.ObjectId( finduser.userId ) } );
|
|
5417
|
+
if ( userDetails && userDetails.fcmToken ) {
|
|
5418
|
+
const fcmToken = userDetails.fcmToken;
|
|
5419
|
+
await sendPushNotification( title, description, fcmToken );
|
|
5420
|
+
}
|
|
5421
|
+
const inputDateTime = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' );
|
|
5422
|
+
const currentTime = dayjs.utc();
|
|
5423
|
+
if ( inputDateTime.isBefore( currentTime ) ) {
|
|
5424
|
+
return res.sendError( 'The input date-time is before the current time.', 500 );
|
|
5425
|
+
}
|
|
5426
|
+
|
|
5427
|
+
let approverList = inputBody?.approver.split( ',' );
|
|
5428
|
+
let userAdmin = await userService.find( { clientId: inputBody.clientId, email: { $in: approverList }, userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
|
|
5429
|
+
if ( userAdmin && userAdmin.length === 0 ) {
|
|
5430
|
+
userAdmin = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
|
|
5431
|
+
}
|
|
5432
|
+
|
|
5433
|
+
let creator = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true } );
|
|
5434
|
+
if ( creator && creator.length === 0 ) {
|
|
5435
|
+
return res.sendError( 'Invalid Creator Details', 500 );
|
|
5436
|
+
}
|
|
5437
|
+
|
|
5438
|
+
if ( req.body && req.body.referenceImage && req.body.referenceImage.length > 3 ) {
|
|
5439
|
+
return res.sendError( 'Maximum 3 referenceImage only allowed', 500 );
|
|
5440
|
+
}
|
|
5441
|
+
|
|
5442
|
+
let answer = await findAnswer( inputBody?.answerType );
|
|
5443
|
+
if ( answer.length == 0 ) {
|
|
5444
|
+
return res.sendError( 'please enter Valid AnswerType', 500 );
|
|
5445
|
+
}
|
|
5446
|
+
|
|
5447
|
+
// Check this Task Already Exist////
|
|
5448
|
+
let checkTask = await taskService.findOne( { checkListName: inputBody.taskName } );
|
|
5449
|
+
if ( checkTask ) {
|
|
5450
|
+
let singleInsert = await insertStoreHygienetaskSingleProcessedTask( checkTask, inputBody, date, time, storeDetails, finduser, answer );
|
|
5451
|
+
if ( singleInsert ) {
|
|
5452
|
+
return res.sendSuccess( 'Task created successfully' );
|
|
5453
|
+
} else {
|
|
5454
|
+
return res.sendError( 'something went wrong, please try again', 500 );
|
|
5455
|
+
}
|
|
5456
|
+
} else {
|
|
5457
|
+
let data = {
|
|
5458
|
+
// checkListName: `${inputBody.taskName}(${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}-${inputBody.zoneName ? inputBody.zoneName : ''})`,
|
|
5459
|
+
checkListName: inputBody.taskName,
|
|
5460
|
+
checkListDescription: inputBody.taskDescription,
|
|
5461
|
+
createdBy: creator[0]._id,
|
|
5462
|
+
createdByName: creator[0].userName,
|
|
5463
|
+
publish: true,
|
|
5464
|
+
questionCount: 1,
|
|
5465
|
+
storeCount: 1,
|
|
5466
|
+
scheduleDate: date,
|
|
5467
|
+
scheduleEndTime: time,
|
|
5468
|
+
scheduleEndTimeISO: dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format(),
|
|
5469
|
+
priorityType: 'high',
|
|
5470
|
+
client_id: inputBody.clientId,
|
|
5471
|
+
checkListType: 'task',
|
|
5472
|
+
publishDate: new Date(),
|
|
5473
|
+
locationCount: 1,
|
|
5474
|
+
...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
|
|
5475
|
+
coverage: 'store',
|
|
5476
|
+
checkListFrom: 'api',
|
|
5477
|
+
};
|
|
5478
|
+
data['approver'] = userAdmin;
|
|
5479
|
+
|
|
5480
|
+
if ( inputBody?.answerType === 'multiplechoicesingle' || inputBody?.answerType === 'multiplechoicemultiple' ) {
|
|
5481
|
+
if ( inputBody?.options && inputBody?.options.length > 0 ) {
|
|
5482
|
+
let optionsResult = [];
|
|
5483
|
+
let optionList = inputBody?.options.split( ',' );
|
|
5484
|
+
for ( let option of optionList ) {
|
|
5485
|
+
let optiondata = {
|
|
5486
|
+
'answer': '',
|
|
5487
|
+
'sopFlag': false,
|
|
5488
|
+
'validation': false,
|
|
5489
|
+
'validationType': '',
|
|
5490
|
+
'referenceImage': [],
|
|
5491
|
+
'runAI': false,
|
|
5492
|
+
'allowUploadfromGallery': false,
|
|
5493
|
+
'descriptivetype': '',
|
|
5494
|
+
'showLinked': false,
|
|
5495
|
+
'linkedQuestion': 0,
|
|
5496
|
+
'nestedQuestion': [],
|
|
5497
|
+
};
|
|
5498
|
+
optiondata.answer = option;
|
|
5499
|
+
optionsResult.push( optiondata );
|
|
5500
|
+
}
|
|
5501
|
+
answer = optionsResult;
|
|
5502
|
+
} else {
|
|
5503
|
+
return res.sendError( 'please enter Valid Options', 500 );
|
|
5504
|
+
}
|
|
5505
|
+
}
|
|
5506
|
+
|
|
5507
|
+
let response = await taskService.create( data );
|
|
5508
|
+
if ( response?.approver.length ) {
|
|
5509
|
+
let inputData = [];
|
|
5510
|
+
response?.approver.forEach( ( ele ) => {
|
|
5511
|
+
inputData.push( {
|
|
5512
|
+
userEmail: ele.email,
|
|
5513
|
+
checkListId: response._id,
|
|
5514
|
+
type: 'task',
|
|
5515
|
+
client_id: inputBody.clientId,
|
|
5516
|
+
checkListName: data?.checkListName || '',
|
|
5517
|
+
} );
|
|
5518
|
+
} );
|
|
5519
|
+
await traxApprover.insertMany( inputData );
|
|
5520
|
+
}
|
|
5521
|
+
|
|
5522
|
+
if ( response?._id ) {
|
|
5523
|
+
let question = [
|
|
5524
|
+
{
|
|
5525
|
+
'qno': 1,
|
|
5526
|
+
'qname': inputBody.question,
|
|
5527
|
+
'answerType': inputBody?.answerType || 'yes/no',
|
|
5528
|
+
'runAI': false,
|
|
5529
|
+
'runAIDescription': '',
|
|
5530
|
+
'allowUploadfromGallery': false,
|
|
5531
|
+
'linkType': false,
|
|
5532
|
+
'questionReferenceImage': [],
|
|
5533
|
+
'answers': answer,
|
|
5534
|
+
'descriptivetype': 'text',
|
|
5535
|
+
},
|
|
5536
|
+
];
|
|
5537
|
+
|
|
5538
|
+
let images = [];
|
|
5539
|
+
for ( let imgpath of req.body.referenceImage ) {
|
|
5540
|
+
let configURL = JSON.parse( process.env.BUCKET );
|
|
5541
|
+
let inputData = {
|
|
5542
|
+
Bucket: configURL.aiTraxoutput,
|
|
5543
|
+
Key: imgpath,
|
|
5544
|
+
};
|
|
5545
|
+
let output = await getObject( inputData );
|
|
5546
|
+
let image = {
|
|
5547
|
+
data: output.Body,
|
|
5548
|
+
name: imgpath,
|
|
5549
|
+
mimetype: output.ContentType,
|
|
5550
|
+
};
|
|
5551
|
+
let uplaodedImage = await uploadmultiImage( image );
|
|
5552
|
+
let imgUrl = decodeURIComponent( uplaodedImage?.imgUrl.split( '?' )[0] );
|
|
5553
|
+
let url = imgUrl.split( '/' );
|
|
5554
|
+
if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
|
|
5555
|
+
url.splice( 0, 3 );
|
|
5556
|
+
}
|
|
5557
|
+
images.push( url.join( '/' ) );
|
|
5558
|
+
}
|
|
5559
|
+
question[0].questionReferenceImage = images;
|
|
5560
|
+
|
|
5561
|
+
if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
|
|
5562
|
+
answer[0].referenceImage = question[0].questionReferenceImage;
|
|
5563
|
+
}
|
|
5564
|
+
|
|
5565
|
+
question = {
|
|
5566
|
+
checkListId: response?._id,
|
|
5567
|
+
question: question,
|
|
5568
|
+
section: 'Section 1',
|
|
5569
|
+
checkList: data.checkListName,
|
|
5570
|
+
client_id: inputBody.clientId,
|
|
5571
|
+
};
|
|
5572
|
+
await taskQuestionService.create( question );
|
|
5573
|
+
|
|
5574
|
+
let userDetails = {
|
|
5575
|
+
userName: inputBody.userName,
|
|
5576
|
+
userEmail: inputBody.userEmail,
|
|
5577
|
+
store_id: storeDetails.storeId,
|
|
5578
|
+
storeName: storeDetails.storeName,
|
|
5579
|
+
city: storeDetails?.storeProfile?.city,
|
|
5580
|
+
checkFlag: true,
|
|
5581
|
+
checkListId: response?._id,
|
|
5582
|
+
checkListName: data.checkListName,
|
|
5583
|
+
client_id: inputBody.clientId,
|
|
5584
|
+
userId: userId,
|
|
5585
|
+
assignId: storeDetails?._id,
|
|
5586
|
+
};
|
|
5587
|
+
await taskAssignService.create( userDetails );
|
|
5588
|
+
await insertSingleProcessData( response?._id );
|
|
5589
|
+
return res.sendSuccess( 'Task created successfully' );
|
|
5590
|
+
}
|
|
5591
|
+
}
|
|
5592
|
+
} catch ( e ) {
|
|
5593
|
+
console.log( 'e =>', e );
|
|
5594
|
+
logger.error( { function: 'StoreHygienetask', error: e } );
|
|
5595
|
+
return res.sendError( e, 500 );
|
|
5596
|
+
}
|
|
5597
|
+
}
|
|
5598
|
+
|
|
5599
|
+
export async function eyeTesttaskNew( req, res ) {
|
|
5600
|
+
try {
|
|
5601
|
+
let inputBody = req.body;
|
|
5602
|
+
inputBody.clientId = 11;
|
|
5603
|
+
inputBody.taskDescription = '';
|
|
5604
|
+
let userId;
|
|
5605
|
+
let storeDetails = await storeService.findOne( { storeName: inputBody.storeName, clientId: inputBody.clientId, status: 'active' }, { storeId: 1, storeName: 1, storeProfile: 1 } );
|
|
5606
|
+
// console.log( 'storeDetails =>', storeDetails );
|
|
5607
|
+
if ( !storeDetails ) {
|
|
5608
|
+
return res.sendError( 'Store Not Found', 500 );
|
|
5609
|
+
}
|
|
5610
|
+
|
|
5611
|
+
let url = JSON.parse( process.env.LAMBDAURL );
|
|
5612
|
+
let dailychecklistId = new mongoose.Types.ObjectId( url.dailystoreChecklistId );
|
|
5613
|
+
let KSAchecklistId = new mongoose.Types.ObjectId( url.KSAchecklist );
|
|
5614
|
+
let UAEchecklistId = new mongoose.Types.ObjectId( url.UAEchecklist );
|
|
5615
|
+
let singaporechecklistId = new mongoose.Types.ObjectId( url.singaporechecklist );
|
|
5616
|
+
|
|
5617
|
+
let finduser = await checklistassignconfigModel.findOne( { checkListId: { $in: [ dailychecklistId, KSAchecklistId, UAEchecklistId, singaporechecklistId ] }, store_id: storeDetails.storeId } );
|
|
5618
|
+
|
|
5619
|
+
if ( !finduser ) {
|
|
5620
|
+
return res.sendError( 'No user Found For this store', 500 );
|
|
5621
|
+
}
|
|
5622
|
+
|
|
5623
|
+
userId = finduser.userId;
|
|
5624
|
+
inputBody.userName = finduser.userName;
|
|
5625
|
+
inputBody.userEmail = finduser.userEmail;
|
|
5626
|
+
let teamList = await findteams( { users: { $elemMatch: { email: finduser.userEmail } } } );
|
|
5627
|
+
|
|
5628
|
+
inputBody.approver = '';
|
|
5629
|
+
for ( let team of teamList ) {
|
|
5630
|
+
for ( let user of team.Teamlead ) {
|
|
5631
|
+
inputBody.approver = user.email + ',' + inputBody.approver;
|
|
5632
|
+
}
|
|
5633
|
+
}
|
|
5634
|
+
inputBody.approver = inputBody.approver.replace( /,$/, '' );
|
|
5635
|
+
|
|
5636
|
+
let title = `New Task Alert ${inputBody.taskName}-${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )}`;
|
|
5637
|
+
let time = inputBody?.scheduleEndTime || '11:59 PM';
|
|
5638
|
+
let date = inputBody?.scheduleDate || dayjs().format( 'YYYY-MM-DD' );
|
|
5639
|
+
let description = `A new task has been assigned to ${storeDetails.storeName}. Please complete it before the due date of ${date}.`;
|
|
5640
|
+
let userDetails = await userService.findOne( { _id: new mongoose.Types.ObjectId( finduser.userId ) } );
|
|
5641
|
+
if ( userDetails && userDetails.fcmToken ) {
|
|
5642
|
+
const fcmToken = userDetails.fcmToken;
|
|
5643
|
+
await sendPushNotification( title, description, fcmToken );
|
|
5644
|
+
}
|
|
5645
|
+
const inputDateTime = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' );
|
|
5646
|
+
const currentTime = dayjs.utc();
|
|
5647
|
+
if ( inputDateTime.isBefore( currentTime ) ) {
|
|
5648
|
+
return res.sendError( 'The input date-time is before the current time.', 500 );
|
|
5649
|
+
}
|
|
5650
|
+
|
|
5651
|
+
let approverList = inputBody?.approver.split( ',' );
|
|
5652
|
+
let userAdmin = await userService.find( { clientId: inputBody.clientId, email: { $in: approverList }, userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
|
|
5653
|
+
|
|
5654
|
+
if ( userAdmin && userAdmin.length === 0 ) {
|
|
5655
|
+
userAdmin = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true }, { name: '$userName', email: 1 } );
|
|
5656
|
+
}
|
|
5657
|
+
|
|
5658
|
+
let creator = await userService.find( { clientId: inputBody.clientId, email: 'rohit.chawla@lenskart.com', userType: 'client', isActive: true } );
|
|
5659
|
+
if ( creator && creator.length === 0 ) {
|
|
5660
|
+
return res.sendError( 'Invalid Creator Details', 500 );
|
|
5661
|
+
}
|
|
5662
|
+
|
|
5663
|
+
if ( req.body && req.body.referenceImage && req.body.referenceImage.length > 3 ) {
|
|
5664
|
+
return res.sendError( 'Maximum 3 referenceImage only allowed', 500 );
|
|
5665
|
+
}
|
|
5666
|
+
|
|
5667
|
+
let answer = await findAnswer( inputBody?.answerType );
|
|
5668
|
+
if ( answer.length == 0 ) {
|
|
5669
|
+
return res.sendError( 'please enter Valid AnswerType', 500 );
|
|
5670
|
+
}
|
|
5671
|
+
|
|
5672
|
+
// Check this Task Already Exist////
|
|
5673
|
+
let checkTask = await taskService.findOne( { checkListName: inputBody.taskName } );
|
|
5674
|
+
if ( checkTask ) {
|
|
5675
|
+
let singleInsert = await insertEyetestSingleProcessedTask( checkTask, inputBody, date, time, storeDetails, finduser, answer, req );
|
|
5676
|
+
if ( singleInsert ) {
|
|
5677
|
+
return res.sendSuccess( 'Task created successfully' );
|
|
5678
|
+
} else {
|
|
5679
|
+
return res.sendError( 'something went wrong, please try again', 500 );
|
|
5680
|
+
}
|
|
5681
|
+
} else {
|
|
5682
|
+
let data = {
|
|
5683
|
+
// checkListName: `${inputBody.taskName}(${storeDetails.storeName}-${dayjs().format( 'YYYY-MM-DD' )})`,
|
|
5684
|
+
checkListName: inputBody.taskName,
|
|
5685
|
+
checkListDescription: inputBody.taskDescription,
|
|
5686
|
+
createdBy: creator[0]._id,
|
|
5687
|
+
createdByName: creator[0].userName,
|
|
5688
|
+
publish: true,
|
|
5689
|
+
questionCount: 1,
|
|
5690
|
+
storeCount: 1,
|
|
5691
|
+
scheduleDate: date,
|
|
5692
|
+
scheduleEndTime: time,
|
|
5693
|
+
scheduleEndTimeISO: dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format(),
|
|
5694
|
+
priorityType: 'high',
|
|
5695
|
+
client_id: inputBody.clientId,
|
|
5696
|
+
checkListType: 'task',
|
|
5697
|
+
publishDate: new Date(),
|
|
5698
|
+
locationCount: 1,
|
|
5699
|
+
...( inputBody?.checkListId ) ? { referenceCheckListId: inputBody?.checkListId } : {},
|
|
5700
|
+
};
|
|
5701
|
+
data['approver'] = userAdmin;
|
|
5702
|
+
|
|
5703
|
+
if ( inputBody?.answerType === 'multiplechoicesingle' || inputBody?.answerType === 'multiplechoicemultiple' ) {
|
|
5704
|
+
if ( inputBody?.options && inputBody?.options.length > 0 ) {
|
|
5705
|
+
let optionsResult = [];
|
|
5706
|
+
let optionList = inputBody?.options.split( ',' );
|
|
5707
|
+
for ( let option of optionList ) {
|
|
5708
|
+
let optiondata = {
|
|
5709
|
+
'answer': '',
|
|
5710
|
+
'sopFlag': false,
|
|
5711
|
+
'validation': false,
|
|
5712
|
+
'validationType': '',
|
|
5713
|
+
'referenceImage': [],
|
|
5714
|
+
'runAI': false,
|
|
5715
|
+
'allowUploadfromGallery': false,
|
|
5716
|
+
'descriptivetype': '',
|
|
5717
|
+
'showLinked': false,
|
|
5718
|
+
'linkedQuestion': 0,
|
|
5719
|
+
'nestedQuestion': [],
|
|
5720
|
+
};
|
|
5721
|
+
optiondata.answer = option;
|
|
5722
|
+
optionsResult.push( optiondata );
|
|
5723
|
+
}
|
|
5724
|
+
answer = optionsResult;
|
|
5725
|
+
} else {
|
|
5726
|
+
return res.sendError( 'please enter Valid Options', 500 );
|
|
5727
|
+
}
|
|
5728
|
+
}
|
|
5729
|
+
|
|
5730
|
+
let response = await taskService.create( data );
|
|
5731
|
+
if ( response?.approver.length ) {
|
|
5732
|
+
let inputData = [];
|
|
5733
|
+
response?.approver.forEach( ( ele ) => {
|
|
5734
|
+
inputData.push( {
|
|
5735
|
+
userEmail: ele.email,
|
|
5736
|
+
checkListId: response._id,
|
|
5737
|
+
type: 'task',
|
|
5738
|
+
client_id: inputBody.clientId,
|
|
5739
|
+
checkListName: data?.checkListName || '',
|
|
5740
|
+
} );
|
|
5741
|
+
} );
|
|
5742
|
+
await traxApprover.insertMany( inputData );
|
|
5743
|
+
}
|
|
5744
|
+
|
|
5745
|
+
if ( response?._id ) {
|
|
5746
|
+
let question = [
|
|
5747
|
+
{
|
|
5748
|
+
'qno': 1,
|
|
5749
|
+
'qname': inputBody.question,
|
|
5750
|
+
'answerType': inputBody?.answerType || 'yes/no',
|
|
5751
|
+
'runAI': false,
|
|
5752
|
+
'runAIDescription': '',
|
|
5753
|
+
'allowUploadfromGallery': false,
|
|
5754
|
+
'linkType': false,
|
|
5755
|
+
'questionReferenceImage': [],
|
|
5756
|
+
'answers': answer,
|
|
5757
|
+
'descriptivetype': 'text',
|
|
5758
|
+
},
|
|
5759
|
+
];
|
|
5760
|
+
|
|
5761
|
+
if ( req.files && req.files.referenceImage && req.files.referenceImage.length ) {
|
|
5762
|
+
let images = [];
|
|
5763
|
+
for ( let image of req.files.referenceImage ) {
|
|
5764
|
+
let uplaodedImage = await uploadmultiImage( image );
|
|
5765
|
+
let imgUrl = decodeURIComponent( uplaodedImage.imgUrl.split( '?' )[0] );
|
|
5766
|
+
let url = imgUrl.split( '/' );
|
|
5767
|
+
if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
|
|
5768
|
+
url.splice( 0, 3 );
|
|
5769
|
+
}
|
|
5770
|
+
images.push( url.join( '/' ) );
|
|
5771
|
+
}
|
|
5772
|
+
question[0].questionReferenceImage = images;
|
|
5773
|
+
} else {
|
|
5774
|
+
let images = [];
|
|
5775
|
+
if ( req.files && req.files.referenceImage ) {
|
|
5776
|
+
let uplaodedImage = await uploadmultiImage( req.files.referenceImage );
|
|
5777
|
+
let imgUrl = decodeURIComponent( uplaodedImage.imgUrl.split( '?' )[0] );
|
|
5778
|
+
let url = imgUrl.split( '/' );
|
|
5779
|
+
if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
|
|
5780
|
+
url.splice( 0, 3 );
|
|
5781
|
+
}
|
|
5782
|
+
images.push( url.join( '/' ) );
|
|
5783
|
+
question[0].questionReferenceImage = images;
|
|
5784
|
+
}
|
|
5785
|
+
}
|
|
5786
|
+
|
|
5787
|
+
if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
|
|
5788
|
+
answer[0].referenceImage = question[0].questionReferenceImage;
|
|
5789
|
+
}
|
|
5790
|
+
|
|
5791
|
+
question = {
|
|
5792
|
+
checkListId: response?._id,
|
|
5793
|
+
question: question,
|
|
5794
|
+
section: 'Section 1',
|
|
5795
|
+
checkList: data.checkListName,
|
|
5796
|
+
client_id: inputBody.clientId,
|
|
5797
|
+
};
|
|
5798
|
+
await taskQuestionService.create( question );
|
|
5799
|
+
|
|
5800
|
+
let userDetails = {
|
|
5801
|
+
userName: inputBody.userName,
|
|
5802
|
+
userEmail: inputBody.userEmail,
|
|
5803
|
+
store_id: storeDetails.storeId,
|
|
5804
|
+
storeName: storeDetails.storeName,
|
|
5805
|
+
city: storeDetails?.storeProfile?.city,
|
|
5806
|
+
checkFlag: true,
|
|
5807
|
+
checkListId: response?._id,
|
|
5808
|
+
checkListName: data.checkListName,
|
|
5809
|
+
client_id: inputBody.clientId,
|
|
5810
|
+
userId: userId,
|
|
5811
|
+
assignId: storeDetails?._id,
|
|
5812
|
+
};
|
|
5813
|
+
await taskAssignService.create( userDetails );
|
|
5814
|
+
await insertSingleProcessData( response?._id, true, inputBody );
|
|
5815
|
+
return res.sendSuccess( 'Task created successfully' );
|
|
5816
|
+
}
|
|
5817
|
+
}
|
|
5818
|
+
} catch ( e ) {
|
|
5819
|
+
logger.error( { function: 'eyeTesttask', error: e } );
|
|
5820
|
+
return res.sendError( e, 500 );
|
|
5821
|
+
}
|
|
5822
|
+
}
|
|
5823
|
+
|
|
5824
|
+
async function insertStoreHygienetaskSingleProcessedTask( checkTask, inputBody, date, time, storeDetails, finduser, answer ) {
|
|
5825
|
+
try {
|
|
5826
|
+
let getquestion = await taskQuestionService.findOne( { checkListId: checkTask._id } );
|
|
5827
|
+
let getolddata = await taskProcessedService.findOne( { sourceCheckList_id: checkTask._id } );
|
|
5828
|
+
|
|
5829
|
+
// Question Patten Making
|
|
5830
|
+
let question = [
|
|
5831
|
+
{
|
|
5832
|
+
'qno': 1,
|
|
5833
|
+
'qname': inputBody.question,
|
|
5834
|
+
'answerType': inputBody?.answerType || 'yes/no',
|
|
5835
|
+
'runAI': false,
|
|
5836
|
+
'runAIDescription': '',
|
|
5837
|
+
'allowUploadfromGallery': false,
|
|
5838
|
+
'linkType': false,
|
|
5839
|
+
'questionReferenceImage': [],
|
|
5840
|
+
'answers': answer,
|
|
5841
|
+
'descriptivetype': 'text',
|
|
5842
|
+
},
|
|
5843
|
+
];
|
|
5844
|
+
|
|
5845
|
+
let images = [];
|
|
5846
|
+
for ( let imgpath of inputBody.referenceImage ) {
|
|
5847
|
+
let configURL = JSON.parse( process.env.BUCKET );
|
|
5848
|
+
let inputData = {
|
|
5849
|
+
Bucket: configURL.aiTraxoutput,
|
|
5850
|
+
Key: imgpath,
|
|
5851
|
+
};
|
|
5852
|
+
let output = await getObject( inputData );
|
|
5853
|
+
let image = {
|
|
5854
|
+
data: output.Body,
|
|
5855
|
+
name: imgpath,
|
|
5856
|
+
mimetype: output.ContentType,
|
|
5857
|
+
};
|
|
5858
|
+
let uplaodedImage = await uploadmultiImage( image );
|
|
5859
|
+
let imgUrl = decodeURIComponent( uplaodedImage?.imgUrl.split( '?' )[0] );
|
|
5860
|
+
let url = imgUrl.split( '/' );
|
|
5861
|
+
if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
|
|
5862
|
+
url.splice( 0, 3 );
|
|
5863
|
+
}
|
|
5864
|
+
images.push( url.join( '/' ) );
|
|
5865
|
+
}
|
|
5866
|
+
question[0].questionReferenceImage = images;
|
|
5867
|
+
|
|
5868
|
+
if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
|
|
5869
|
+
answer[0].referenceImage = question[0].questionReferenceImage;
|
|
5870
|
+
}
|
|
5871
|
+
|
|
5872
|
+
let questions = {
|
|
5873
|
+
questions: question,
|
|
5874
|
+
sectionName: getquestion.section,
|
|
5875
|
+
section_id: getquestion._id,
|
|
5876
|
+
};
|
|
5877
|
+
|
|
5878
|
+
let newData = getolddata.toObject();
|
|
5879
|
+
delete newData._id;
|
|
5880
|
+
newData.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
|
|
5881
|
+
newData.date_string = dayjs( date ).format( 'YYYY-MM-DD' );
|
|
5882
|
+
newData.scheduleStartTime_iso = date;
|
|
5883
|
+
newData.scheduleEndTime_iso = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format();
|
|
5884
|
+
newData.store_id = storeDetails.storeId;
|
|
5885
|
+
newData.storeName = storeDetails.storeName;
|
|
5886
|
+
newData.country = storeDetails.storeProfile.country;
|
|
5887
|
+
newData.userId = finduser.userId;
|
|
5888
|
+
newData.userName = finduser.userName;
|
|
5889
|
+
newData.userEmail = finduser.userEmail;
|
|
5890
|
+
newData.checklistStatus = 'open';
|
|
5891
|
+
newData.timeFlagStatus = true;
|
|
5892
|
+
newData.checkListFrom = 'api';
|
|
5893
|
+
newData.createdAt = new Date();
|
|
5894
|
+
newData.updatedAt = new Date();
|
|
5895
|
+
newData.questionAnswers = [ questions ];
|
|
5896
|
+
let insertprocessdata = await taskProcessedService.insert( newData );
|
|
5897
|
+
if ( insertprocessdata ) {
|
|
5898
|
+
return true;
|
|
5899
|
+
} else {
|
|
5900
|
+
return false;
|
|
5901
|
+
}
|
|
5902
|
+
} catch ( error ) {
|
|
5903
|
+
logger.error( { error: error, function: 'insertSingleProcessedTask' } );
|
|
5904
|
+
return false;
|
|
5905
|
+
}
|
|
5906
|
+
}
|
|
5907
|
+
|
|
5908
|
+
async function insertEyetestSingleProcessedTask( checkTask, inputBody, date, time, storeDetails, finduser, answer, req ) {
|
|
5909
|
+
try {
|
|
5910
|
+
let getquestion = await taskQuestionService.findOne( { checkListId: checkTask._id } );
|
|
5911
|
+
let getolddata = await taskProcessedService.findOne( { sourceCheckList_id: checkTask._id } );
|
|
5912
|
+
|
|
5913
|
+
// Question Patten Making
|
|
5914
|
+
let question = [
|
|
5915
|
+
{
|
|
5916
|
+
'qno': 1,
|
|
5917
|
+
'qname': inputBody.question,
|
|
5918
|
+
'answerType': inputBody?.answerType || 'yes/no',
|
|
5919
|
+
'runAI': false,
|
|
5920
|
+
'runAIDescription': '',
|
|
5921
|
+
'allowUploadfromGallery': false,
|
|
5922
|
+
'linkType': false,
|
|
5923
|
+
'questionReferenceImage': [],
|
|
5924
|
+
'answers': answer,
|
|
5925
|
+
'descriptivetype': 'text',
|
|
5926
|
+
},
|
|
5927
|
+
];
|
|
5928
|
+
|
|
5929
|
+
if ( req.files && req.files.referenceImage && req.files.referenceImage.length ) {
|
|
5930
|
+
let images = [];
|
|
5931
|
+
for ( let image of req.files.referenceImage ) {
|
|
5932
|
+
let uplaodedImage = await uploadmultiImage( image );
|
|
5933
|
+
let imgUrl = decodeURIComponent( uplaodedImage.imgUrl.split( '?' )[0] );
|
|
5934
|
+
let url = imgUrl.split( '/' );
|
|
5935
|
+
if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
|
|
5936
|
+
url.splice( 0, 3 );
|
|
5937
|
+
}
|
|
5938
|
+
images.push( url.join( '/' ) );
|
|
5939
|
+
}
|
|
5940
|
+
question[0].questionReferenceImage = images;
|
|
5941
|
+
} else {
|
|
5942
|
+
let images = [];
|
|
5943
|
+
if ( req.files && req.files.referenceImage ) {
|
|
5944
|
+
let uplaodedImage = await uploadmultiImage( req.files.referenceImage );
|
|
5945
|
+
let imgUrl = decodeURIComponent( uplaodedImage.imgUrl.split( '?' )[0] );
|
|
5946
|
+
let url = imgUrl.split( '/' );
|
|
5947
|
+
if ( url.includes( 'https:' ) || url.includes( 'http:' ) ) {
|
|
5948
|
+
url.splice( 0, 3 );
|
|
5949
|
+
}
|
|
5950
|
+
images.push( url.join( '/' ) );
|
|
5951
|
+
|
|
5952
|
+
question[0].questionReferenceImage = images;
|
|
5953
|
+
}
|
|
5954
|
+
}
|
|
5955
|
+
|
|
5956
|
+
if ( inputBody?.answerType === 'image' || inputBody?.answerType === 'descriptiveImage' || inputBody?.answerType === 'multipleImage' ) {
|
|
5957
|
+
answer[0].referenceImage = question[0].questionReferenceImage;
|
|
5958
|
+
}
|
|
5959
|
+
|
|
5960
|
+
let questions = {
|
|
5961
|
+
questions: question,
|
|
5962
|
+
sectionName: getquestion.section,
|
|
5963
|
+
section_id: getquestion._id,
|
|
5964
|
+
};
|
|
5965
|
+
|
|
5966
|
+
let newData = getolddata.toObject();
|
|
5967
|
+
delete newData._id;
|
|
5968
|
+
newData.date_iso = new Date( dayjs( date, 'YYYY-MM-DD' ).format( 'YYYY-MM-DD' ) );
|
|
5969
|
+
newData.date_string = dayjs( date ).format( 'YYYY-MM-DD' );
|
|
5970
|
+
newData.scheduleStartTime_iso = dayjs.utc().format( 'YYYY-MM-DD hh:mm A' );
|
|
5971
|
+
newData.scheduleEndTime_iso = dayjs.utc( `${date} ${time}`, 'YYYY-MM-DD hh:mm A' ).format();
|
|
5972
|
+
newData.store_id = storeDetails.storeId;
|
|
5973
|
+
newData.storeName = storeDetails.storeName;
|
|
5974
|
+
newData.country = storeDetails.storeProfile.country;
|
|
5975
|
+
newData.userId = finduser.userId;
|
|
5976
|
+
newData.userName = finduser.userName;
|
|
5977
|
+
newData.userEmail = finduser.userEmail;
|
|
5978
|
+
newData.checklistStatus = 'open';
|
|
5979
|
+
newData.timeFlagStatus = true;
|
|
5980
|
+
newData.checkListFrom = 'api';
|
|
5981
|
+
newData.createdAt = new Date();
|
|
5982
|
+
newData.updatedAt = new Date();
|
|
5983
|
+
newData.questionAnswers = [ questions ];
|
|
5984
|
+
let insertprocessdata = await taskProcessedService.insert( newData );
|
|
5985
|
+
if ( insertprocessdata ) {
|
|
5986
|
+
return true;
|
|
5987
|
+
} else {
|
|
5988
|
+
return false;
|
|
5989
|
+
}
|
|
5990
|
+
} catch ( error ) {
|
|
5991
|
+
logger.error( { error: error, function: 'insertSingleProcessedTask' } );
|
|
5992
|
+
return false;
|
|
5993
|
+
}
|
|
5994
|
+
}
|
|
@@ -39,6 +39,10 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
39
39
|
let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
40
40
|
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
41
41
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
42
|
+
|
|
43
|
+
let taskToDate = new Date( requestData.toDate );
|
|
44
|
+
taskToDate.setDate( taskToDate.getDate() + 1 );
|
|
45
|
+
|
|
42
46
|
let groupQuery = {
|
|
43
47
|
$group: {
|
|
44
48
|
_id: '',
|
|
@@ -55,7 +59,9 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
55
59
|
let taskQuery = [
|
|
56
60
|
{
|
|
57
61
|
$match: {
|
|
58
|
-
date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
|
|
62
|
+
// date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
|
|
63
|
+
scheduleStartTime_iso: { $lt: taskToDate },
|
|
64
|
+
scheduleEndTime_iso: { $gte: fromDate },
|
|
59
65
|
sourceCheckList_id: { $in: taskIdList },
|
|
60
66
|
checklistStatus: 'submit',
|
|
61
67
|
approvalStatus: false,
|
|
@@ -130,6 +136,9 @@ export const approvalTableV1 = async ( req, res ) => {
|
|
|
130
136
|
toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
131
137
|
toDate.setUTCHours( 23, 59, 59, 59 );
|
|
132
138
|
|
|
139
|
+
let taskToDate = new Date( requestData.toDate );
|
|
140
|
+
taskToDate.setDate( taskToDate.getDate() + 1 );
|
|
141
|
+
|
|
133
142
|
let groupQuery = [ {
|
|
134
143
|
$sort: {
|
|
135
144
|
checkListName: 1,
|
|
@@ -202,7 +211,9 @@ export const approvalTableV1 = async ( req, res ) => {
|
|
|
202
211
|
query = [
|
|
203
212
|
{
|
|
204
213
|
$match: {
|
|
205
|
-
date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
|
|
214
|
+
// date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
|
|
215
|
+
scheduleStartTime_iso: { $lt: taskToDate },
|
|
216
|
+
scheduleEndTime_iso: { $gte: fromDate },
|
|
206
217
|
sourceCheckList_id: { $in: taskIdList },
|
|
207
218
|
// ...( req.body?.storeId?.length ) ? { store_id: { $in: req.body.storeId } } :{},
|
|
208
219
|
$or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes || [] } } ],
|
|
@@ -51,9 +51,10 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
51
51
|
let requestData = req.body;
|
|
52
52
|
let fromDate = new Date( requestData.fromDate );
|
|
53
53
|
let toDate = new Date( requestData.toDate );
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
toDate.
|
|
54
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
55
|
+
// let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
56
|
+
// toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
57
|
+
// toDate.setUTCHours( 23, 59, 59, 59 );
|
|
57
58
|
let findQuery = [];
|
|
58
59
|
let findAndQuery = [];
|
|
59
60
|
|
|
@@ -63,7 +64,9 @@ export const overallCardsV1 = async ( req, res ) => {
|
|
|
63
64
|
// End: Get User Based Checklist////
|
|
64
65
|
|
|
65
66
|
findAndQuery.push(
|
|
66
|
-
{ date_iso: { $gte: fromDate, $lte: toDate } },
|
|
67
|
+
// { date_iso: { $gte: fromDate, $lte: toDate } },
|
|
68
|
+
{ scheduleStartTime_iso: { $lt: toDate } },
|
|
69
|
+
{ scheduleEndTime_iso: { $gte: fromDate } },
|
|
67
70
|
{ client_id: requestData.clientId },
|
|
68
71
|
// { store_id: { $in: requestData.storeId } },
|
|
69
72
|
{ $or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes || [] } } ] },
|
|
@@ -228,6 +231,9 @@ export const taskTableV1 = async ( req, res ) => {
|
|
|
228
231
|
export const taskInfoTableV1 = async ( req, res ) => {
|
|
229
232
|
try {
|
|
230
233
|
let requestData = req.body;
|
|
234
|
+
let fromDate = new Date( requestData.fromDate );
|
|
235
|
+
let toDate = new Date( requestData.toDate );
|
|
236
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
231
237
|
let result = {};
|
|
232
238
|
|
|
233
239
|
let findQuery = [];
|
|
@@ -239,7 +245,9 @@ export const taskInfoTableV1 = async ( req, res ) => {
|
|
|
239
245
|
// End: Get User Based Checklist////
|
|
240
246
|
|
|
241
247
|
findAndQuery.push(
|
|
242
|
-
{ date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) } },
|
|
248
|
+
// { date_iso: { $lte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) } },
|
|
249
|
+
{ scheduleStartTime_iso: { $lt: toDate } },
|
|
250
|
+
{ scheduleEndTime_iso: { $gte: fromDate } },
|
|
243
251
|
{ client_id: requestData.clientId },
|
|
244
252
|
{ sourceCheckList_id: new mongoose.Types.ObjectId( requestData.taskId ) },
|
|
245
253
|
// { store_id: { $in: requestData.storeId } },
|
|
@@ -271,40 +279,40 @@ export const taskInfoTableV1 = async ( req, res ) => {
|
|
|
271
279
|
|
|
272
280
|
findQuery.push( { $sort: { date_iso: -1, userName: 1 } } );
|
|
273
281
|
|
|
274
|
-
findQuery.push(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
);
|
|
282
|
+
// findQuery.push(
|
|
283
|
+
// {
|
|
284
|
+
// $group: {
|
|
285
|
+
// _id: { userEmail: '$userEmail', storeId: '$store_id', checklistStatus: '$checklistStatus' },
|
|
286
|
+
// checkListName: { $first: '$checkListName' },
|
|
287
|
+
// createdByName: { $first: '$createdByName' },
|
|
288
|
+
// userName: { $first: '$userName' },
|
|
289
|
+
// userEmail: { $first: '$userEmail' },
|
|
290
|
+
// checklistStatus: { $first: '$checklistStatus' },
|
|
291
|
+
// submitTime_string: { $first: '$submitTime_string' },
|
|
292
|
+
// storeName: { $first: '$storeName' },
|
|
293
|
+
// checkListType: { $first: '$checkListType' },
|
|
294
|
+
// scheduleRepeatedType: { $first: '$scheduleRepeatedType' },
|
|
295
|
+
// date_iso: { $first: '$date_iso' },
|
|
296
|
+
// store_id: { $first: '$store_id' },
|
|
297
|
+
// timeFlag: { $first: '$timeFlag' },
|
|
298
|
+
// date_string: { $first: '$date_string' },
|
|
299
|
+
// sourceCheckList_id: { $first: '$sourceCheckList_id' },
|
|
300
|
+
// reinitiateStatus: { $first: '$reinitiateStatus' },
|
|
301
|
+
// scheduleEndTime_iso: { $first: '$scheduleEndTime_iso' },
|
|
302
|
+
// processedchecklistId: { $first: '$_id' },
|
|
303
|
+
// redoStatus: { $first: '$redoStatus' },
|
|
304
|
+
// priorityType: { $first: '$priorityType' },
|
|
305
|
+
// allowedStoreLocation: { $first: '$allowedStoreLocation' },
|
|
306
|
+
// restrictAttendance: { $first: '$restrictAttendance' },
|
|
307
|
+
// approvalByEmail: { $first: '$approvalByEmail' },
|
|
308
|
+
// approvalTime_string: { $first: '$approvalTime_string' },
|
|
309
|
+
// },
|
|
310
|
+
// },
|
|
311
|
+
// );
|
|
304
312
|
|
|
305
313
|
findQuery.push( {
|
|
306
314
|
$project: {
|
|
307
|
-
_id:
|
|
315
|
+
_id: 1,
|
|
308
316
|
checkListName: 1,
|
|
309
317
|
createdByName: 1,
|
|
310
318
|
userName: 1,
|
|
@@ -331,9 +339,15 @@ export const taskInfoTableV1 = async ( req, res ) => {
|
|
|
331
339
|
},
|
|
332
340
|
} );
|
|
333
341
|
|
|
342
|
+
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
|
|
343
|
+
findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
|
|
344
|
+
} else {
|
|
345
|
+
findQuery.push( { $sort: { userEmail: 1 } } );
|
|
346
|
+
}
|
|
347
|
+
|
|
334
348
|
findQuery.push( {
|
|
335
349
|
$project: {
|
|
336
|
-
_id:
|
|
350
|
+
_id: 1,
|
|
337
351
|
checkListName: 1,
|
|
338
352
|
checkListChar: { $substr: [ '$checkListName', 0, 2 ] },
|
|
339
353
|
createdByName: 1,
|
|
@@ -377,11 +391,6 @@ export const taskInfoTableV1 = async ( req, res ) => {
|
|
|
377
391
|
},
|
|
378
392
|
} );
|
|
379
393
|
|
|
380
|
-
if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
|
|
381
|
-
findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
|
|
382
|
-
} else {
|
|
383
|
-
findQuery.push( { $sort: { userEmail: 1 } } );
|
|
384
|
-
}
|
|
385
394
|
|
|
386
395
|
let limit = parseInt( requestData?.limit ) || 10;
|
|
387
396
|
let skip = limit * ( requestData?.offset -1 ) || 0;
|
|
@@ -399,6 +408,7 @@ export const taskInfoTableV1 = async ( req, res ) => {
|
|
|
399
408
|
} );
|
|
400
409
|
|
|
401
410
|
let taskInfoData = await processedTaskService.aggregate( findQuery );
|
|
411
|
+
console.log( 'taskInfoData =>', taskInfoData.length );
|
|
402
412
|
|
|
403
413
|
if ( !taskInfoData[0].data.length ) {
|
|
404
414
|
return res.sendError( 'no data found', 204 );
|
|
@@ -429,7 +439,7 @@ export const taskInfoTableV1 = async ( req, res ) => {
|
|
|
429
439
|
}
|
|
430
440
|
return res.sendSuccess( result );
|
|
431
441
|
} catch ( error ) {
|
|
432
|
-
|
|
442
|
+
console.log( 'error =>', error );
|
|
433
443
|
logger.error( { error: error, message: req.query, function: 'taskInfo' } );
|
|
434
444
|
return res.sendError( { error: error }, 500 );
|
|
435
445
|
}
|
|
@@ -763,6 +773,9 @@ export const taskDropdownListV1 = async ( req, res ) => {
|
|
|
763
773
|
// { isdeleted: false },
|
|
764
774
|
);
|
|
765
775
|
findQuery.push( { $match: { $and: findAndQuery } }, { $sort: { date_iso: -1 } } );
|
|
776
|
+
|
|
777
|
+
// findQuery.push( { $match: { $or: [ { checkListName: 'Store Hygiene Check' }, { checkListName: 'EyeTest QR Verification' } ] } } );
|
|
778
|
+
|
|
766
779
|
findQuery.push(
|
|
767
780
|
{
|
|
768
781
|
$group: {
|
|
@@ -1026,11 +1039,12 @@ export async function taskDetails( req, res ) {
|
|
|
1026
1039
|
// let loginUser = { clientId: requestData.clientId, role: req.user.role, userType: req.user.userType, userEmail: req.user.email };
|
|
1027
1040
|
// let getUserEmails = await getChecklistUsers( loginUser );
|
|
1028
1041
|
// End: Get User Based Checklist////
|
|
1029
|
-
|
|
1030
|
-
let toDate = new Date(
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
toDate.
|
|
1042
|
+
let fromDate = new Date( requestData.fromDate );
|
|
1043
|
+
let toDate = new Date( requestData.toDate );
|
|
1044
|
+
toDate.setDate( toDate.getDate() + 1 );
|
|
1045
|
+
// let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
|
|
1046
|
+
// toDate = new Date( toDate.getTime() - userTimezoneOffset );
|
|
1047
|
+
// toDate.setUTCHours( 23, 59, 59, 59 );
|
|
1034
1048
|
let limit = req.body?.limit || 10;
|
|
1035
1049
|
let page = req.body?.offset ? ( req.body.offset * req.body.limit ) : 0;
|
|
1036
1050
|
let idList = [];
|
|
@@ -1049,14 +1063,16 @@ export async function taskDetails( req, res ) {
|
|
|
1049
1063
|
let query = [
|
|
1050
1064
|
{
|
|
1051
1065
|
$match: {
|
|
1052
|
-
date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
|
|
1066
|
+
// date_iso: { $gte: new Date( req.body.fromDate ), $lte: toDate },
|
|
1067
|
+
scheduleStartTime_iso: { $lt: toDate },
|
|
1068
|
+
scheduleEndTime_iso: { $gte: fromDate },
|
|
1053
1069
|
client_id: req.body.clientId,
|
|
1054
1070
|
...( idList.length ) ? { sourceCheckList_id: { $in: idList } } : {},
|
|
1055
1071
|
// store_id: { $in: req.body.storeId },
|
|
1056
1072
|
$or: [ { store_id: { $in: requestData.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestData.userEmailes || [] } } ],
|
|
1057
1073
|
},
|
|
1058
1074
|
},
|
|
1059
|
-
{ $sort: {
|
|
1075
|
+
{ $sort: { scheduleStartTime_iso: -1 } },
|
|
1060
1076
|
{
|
|
1061
1077
|
$group: {
|
|
1062
1078
|
'_id': '$sourceCheckList_id',
|