tango-app-api-task 3.2.1-beta-24 → 3.2.1-beta-25
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
|
@@ -738,6 +738,7 @@ export async function taskConfig( req, res ) {
|
|
|
738
738
|
checkListName: checklistDetails.checkListName,
|
|
739
739
|
checklistId: checklistDetails._id,
|
|
740
740
|
coverage: inputBody.coverage,
|
|
741
|
+
insert: true,
|
|
741
742
|
};
|
|
742
743
|
await assignUsers( data );
|
|
743
744
|
} ) );
|
|
@@ -3354,71 +3355,29 @@ export async function taskAssign( req, res ) {
|
|
|
3354
3355
|
if ( !taskDetails ) {
|
|
3355
3356
|
return res.sendError( 'No data found', 204 );
|
|
3356
3357
|
}
|
|
3357
|
-
let
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
let
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
}
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
let userDetails = await userService.findOne( { email: store?.spocDetails?.[0]?.email, clientId: store.clientId } );
|
|
3376
|
-
if ( !userDetails ) {
|
|
3377
|
-
let data = {
|
|
3378
|
-
clientId: store.clientId,
|
|
3379
|
-
userName: store.spocDetails?.[0]?.name,
|
|
3380
|
-
mobileNumber: store.spocDetails?.[0]?.phone || '',
|
|
3381
|
-
email: store.spocDetails[0].email,
|
|
3382
|
-
};
|
|
3383
|
-
userDetails = await createUser( data );
|
|
3358
|
+
let assignList = [];
|
|
3359
|
+
|
|
3360
|
+
await Promise.all( req.body.idList.map( async ( data ) => {
|
|
3361
|
+
let assignedData = {
|
|
3362
|
+
...data,
|
|
3363
|
+
clientId: req.body.clientId,
|
|
3364
|
+
checkListName: taskDetails.checkListName,
|
|
3365
|
+
checklistId: taskDetails._id,
|
|
3366
|
+
coverage: req.body.coverage,
|
|
3367
|
+
insert: false,
|
|
3368
|
+
};
|
|
3369
|
+
// console.log( assignedData, 'daterthj' );
|
|
3370
|
+
let uploadData = await assignUsers( assignedData );
|
|
3371
|
+
if ( uploadData ) {
|
|
3372
|
+
if ( Array.isArray( uploadData ) ) {
|
|
3373
|
+
assignList.push( ...uploadData );
|
|
3374
|
+
} else {
|
|
3375
|
+
assignList.push( uploadData );
|
|
3384
3376
|
}
|
|
3385
|
-
let data = {
|
|
3386
|
-
store_id: store.storeId,
|
|
3387
|
-
storeName: store.storeName,
|
|
3388
|
-
userId: userDetails._id,
|
|
3389
|
-
userName: userDetails.userName,
|
|
3390
|
-
userEmail: userDetails.email,
|
|
3391
|
-
userPhone: userDetails?.mobileNumber,
|
|
3392
|
-
clusterName: clusterDetails?.clusterName,
|
|
3393
|
-
};
|
|
3394
|
-
return data;
|
|
3395
|
-
} ) );
|
|
3396
|
-
} else {
|
|
3397
|
-
let teamDetails = await teamsServices.findteams( { _id: { $in: req.body.idList } }, { users: 1, teamName: 1 } );
|
|
3398
|
-
if ( teamDetails.length ) {
|
|
3399
|
-
let teamList = teamDetails.map( ( ele ) => ele._id.toString() );
|
|
3400
|
-
idList = [
|
|
3401
|
-
...teamDetails.flatMap( ( item ) => item.users.map( ( ele ) => ele.userId ) ),
|
|
3402
|
-
...req.body.idList.filter( ( ele ) => !teamList.includes( ele._id ) ),
|
|
3403
|
-
];
|
|
3404
|
-
} else {
|
|
3405
|
-
idList = req.body.idList;
|
|
3406
|
-
}
|
|
3407
|
-
let userDetails = await userService.find( { _id: { $in: idList } } );
|
|
3408
|
-
if ( !userDetails.length ) {
|
|
3409
|
-
return res.sendError( 'No data found', 204 );
|
|
3410
3377
|
}
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
userId: user._id,
|
|
3415
|
-
userName: user.userName,
|
|
3416
|
-
userEmail: user.email,
|
|
3417
|
-
userPhone: user?.mobileNumber,
|
|
3418
|
-
teamName: teamDetails?.teamName,
|
|
3419
|
-
} );
|
|
3420
|
-
} );
|
|
3421
|
-
}
|
|
3378
|
+
} ) );
|
|
3379
|
+
|
|
3380
|
+
|
|
3422
3381
|
return res.sendSuccess( { count: assignList.length, assignList } );
|
|
3423
3382
|
} catch ( e ) {
|
|
3424
3383
|
logger.error( { functionName: 'checklistAssign', error: e } );
|
|
@@ -3439,7 +3398,7 @@ async function assignUsers( data ) {
|
|
|
3439
3398
|
{
|
|
3440
3399
|
$match: {
|
|
3441
3400
|
clientId: data.clientId,
|
|
3442
|
-
...( !data?.
|
|
3401
|
+
...( !data?.clusterName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { cluster: data.clusterName.toLowerCase() },
|
|
3443
3402
|
},
|
|
3444
3403
|
},
|
|
3445
3404
|
{
|
|
@@ -3451,7 +3410,7 @@ async function assignUsers( data ) {
|
|
|
3451
3410
|
];
|
|
3452
3411
|
let clusterDetails = await clusterServices.aggregateCluster( query );
|
|
3453
3412
|
if ( clusterDetails.length ) {
|
|
3454
|
-
if (
|
|
3413
|
+
if ( data.insert ) {
|
|
3455
3414
|
assignedData = {
|
|
3456
3415
|
checkFlag: true,
|
|
3457
3416
|
checkListId: data.checklistId,
|
|
@@ -3466,10 +3425,10 @@ async function assignUsers( data ) {
|
|
|
3466
3425
|
let storeDetails = await storeService.find( { _id: { $in: clusterList }, status: 'active' } );
|
|
3467
3426
|
assignedData = await Promise.all( storeDetails.map( async ( store ) => {
|
|
3468
3427
|
let userDetails = await userService.findOne( { email: store.spocDetails?.[0]?.email, clientId: data.clientId } );
|
|
3469
|
-
if ( !userDetails ) {
|
|
3428
|
+
if ( !userDetails && store?.spocDetails?.length ) {
|
|
3470
3429
|
let userData = {
|
|
3471
3430
|
userName: store.spocDetails?.[0]?.name,
|
|
3472
|
-
email: store.spocDetails[0]
|
|
3431
|
+
email: store.spocDetails[0]?.email,
|
|
3473
3432
|
mobileNumber: store.spocDetails?.[0]?.phone,
|
|
3474
3433
|
clientId: data.clientId,
|
|
3475
3434
|
};
|
|
@@ -3486,7 +3445,9 @@ async function assignUsers( data ) {
|
|
|
3486
3445
|
client_id: data.clientId,
|
|
3487
3446
|
assignId: data?.id || clusterDetails?.[0]?._id,
|
|
3488
3447
|
coverage: 'store',
|
|
3489
|
-
|
|
3448
|
+
clusterName: clusterDetails?.[0]?.clusterName,
|
|
3449
|
+
storeId: store.storeId,
|
|
3450
|
+
storeName: store.storeName,
|
|
3490
3451
|
};
|
|
3491
3452
|
return userData;
|
|
3492
3453
|
} ) );
|
|
@@ -3502,13 +3463,13 @@ async function assignUsers( data ) {
|
|
|
3502
3463
|
{
|
|
3503
3464
|
$match: {
|
|
3504
3465
|
clientId: data.clientId,
|
|
3505
|
-
...( !data.
|
|
3466
|
+
...( !data.storeName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { store: data.storeName.toLowerCase() },
|
|
3506
3467
|
},
|
|
3507
3468
|
},
|
|
3508
3469
|
];
|
|
3509
3470
|
let storeDetails = await storeService.aggregate( query );
|
|
3510
3471
|
if ( storeDetails.length ) {
|
|
3511
|
-
let email = data?.
|
|
3472
|
+
let email = !data?.insert ? data.userEmail : storeDetails?.[0]?.spocDetails?.[0]?.email;
|
|
3512
3473
|
let userDetails = await userService.findOne( { email: email, clientId: data.clientId } );
|
|
3513
3474
|
if ( !userDetails ) {
|
|
3514
3475
|
let userData = {
|
|
@@ -3548,13 +3509,13 @@ async function assignUsers( data ) {
|
|
|
3548
3509
|
{
|
|
3549
3510
|
$match: {
|
|
3550
3511
|
clientId: data.clientId,
|
|
3551
|
-
...( !data?.
|
|
3512
|
+
...( !data?.teamName ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { team: data.teamName.toLowerCase() },
|
|
3552
3513
|
},
|
|
3553
3514
|
},
|
|
3554
3515
|
];
|
|
3555
3516
|
let teamDetails = await teamsServices.aggregateTeams( query );
|
|
3556
3517
|
if ( teamDetails.length ) {
|
|
3557
|
-
if (
|
|
3518
|
+
if ( data.insert ) {
|
|
3558
3519
|
assignedData = {
|
|
3559
3520
|
checkFlag: true,
|
|
3560
3521
|
checkListId: data.checklistId,
|
|
@@ -3595,17 +3556,19 @@ async function assignUsers( data ) {
|
|
|
3595
3556
|
{
|
|
3596
3557
|
$match: {
|
|
3597
3558
|
clientId: data.clientId,
|
|
3598
|
-
...( !data?.
|
|
3559
|
+
...( !data?.userEmail ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { userEmail: data.userEmail.toLowerCase() },
|
|
3599
3560
|
},
|
|
3600
3561
|
},
|
|
3601
3562
|
];
|
|
3563
|
+
// console.log( 'data?.userEmail=>', data.userEmail );
|
|
3602
3564
|
let userDetails = await userService.aggregate( query );
|
|
3603
3565
|
if ( !userDetails.length ) {
|
|
3604
3566
|
let userData = {
|
|
3605
|
-
userName: data
|
|
3567
|
+
userName: data?.userEmail?.split( '@' )[0],
|
|
3606
3568
|
email: data.userEmail,
|
|
3607
3569
|
clientId: data.clientId,
|
|
3608
3570
|
};
|
|
3571
|
+
// console.log( userData, 'userData', data );
|
|
3609
3572
|
let details = await createUser( userData );
|
|
3610
3573
|
userDetails = [ details ];
|
|
3611
3574
|
}
|
|
@@ -3625,8 +3588,10 @@ async function assignUsers( data ) {
|
|
|
3625
3588
|
}
|
|
3626
3589
|
}
|
|
3627
3590
|
}
|
|
3628
|
-
|
|
3629
|
-
|
|
3591
|
+
|
|
3592
|
+
// console.log( assignedData, 'test', data );
|
|
3593
|
+
if ( assignedData && !data.upload && data.insert ) {
|
|
3594
|
+
await assignedService.updateOne( { checkListId: assignedData.checkListId, assignId: assignedData.assignId }, assignedData );
|
|
3630
3595
|
} else {
|
|
3631
3596
|
return assignedData;
|
|
3632
3597
|
}
|