tango-app-api-trax 3.3.1-beta-50 → 3.3.1-beta-51
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
|
@@ -961,7 +961,12 @@ export const flagTablesV1 = async ( req, res ) => {
|
|
|
961
961
|
$project: {
|
|
962
962
|
checkListName: 1,
|
|
963
963
|
checkListChar: 1,
|
|
964
|
-
coverage:
|
|
964
|
+
coverage: {
|
|
965
|
+
$concat: [
|
|
966
|
+
{ $toUpper: { $substr: [ { $ifNull: [ '$coverage', '' ] }, 0, 1 ] } },
|
|
967
|
+
{ $substr: [ { $ifNull: [ '$coverage', '' ] }, 1, { $strLenCP: { $ifNull: [ '$coverage', '' ] } } ] },
|
|
968
|
+
],
|
|
969
|
+
},
|
|
965
970
|
sourceCheckList_id: 1,
|
|
966
971
|
checkListType: 1,
|
|
967
972
|
flagType: 1,
|
|
@@ -396,7 +396,7 @@ export const getConfigDetails = async ( req, res ) => {
|
|
|
396
396
|
}
|
|
397
397
|
let query = {
|
|
398
398
|
checkListId: storechecklistdetails._id,
|
|
399
|
-
...( storechecklistdetails.coverage == 'store' ) ? { $or: [ { store_id: { $exists: true } }, { clusterName: { $exists: true } } ] } : { $or: [ { userEmail: { $exists: true } }, {
|
|
399
|
+
...( storechecklistdetails.coverage == 'store' ) ? { $or: [ { store_id: { $exists: true } }, { clusterName: { $exists: true } } ] } : { $or: [ { userEmail: { $exists: true } }, { teamName: { $exists: true } } ] },
|
|
400
400
|
};
|
|
401
401
|
let assignList = await assignedService.find( query, { _id: 1, store_id: 1, clusterName: 1, userEmail: 1, teamName: 1, assignId: 1 } );
|
|
402
402
|
let singleAssign;
|
|
@@ -1593,20 +1593,6 @@ export const updateConfigurev1 =async ( req, res ) => {
|
|
|
1593
1593
|
response = await checklistService.create( configDetails );
|
|
1594
1594
|
id = response._id;
|
|
1595
1595
|
}
|
|
1596
|
-
if ( inputBody.checkListDetails.assignedUsers.length ) {
|
|
1597
|
-
await assignedService.deleteMany( { checkListId: inputBody.checkListDetails._id } );
|
|
1598
|
-
await Promise.all( inputBody.checkListDetails.assignedUsers.map( async ( user ) => {
|
|
1599
|
-
let data = {
|
|
1600
|
-
...user,
|
|
1601
|
-
clientId: req.body.clientId,
|
|
1602
|
-
checkListName: checklistDetails.checkListName,
|
|
1603
|
-
checklistId: checklistDetails._id,
|
|
1604
|
-
coverage: inputBody?.checkListDetails.coverage,
|
|
1605
|
-
insert: true,
|
|
1606
|
-
};
|
|
1607
|
-
await assignUsers( data );
|
|
1608
|
-
} ) );
|
|
1609
|
-
}
|
|
1610
1596
|
if ( inputBody.submitType == 'publish' ) {
|
|
1611
1597
|
if ( inputBody.checkListDetails.checkListType == 'custom' ) {
|
|
1612
1598
|
let currentDate = dayjs.utc().format();
|
|
@@ -1983,6 +1969,54 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
1983
1969
|
|
|
1984
1970
|
let assignDetails = req.body.assignedUsers;
|
|
1985
1971
|
|
|
1972
|
+
if ( req.body.coverage == 'store' ) {
|
|
1973
|
+
const duplicateStore = assignDetails.reduce( ( acc, obj ) => {
|
|
1974
|
+
if ( !acc[obj.storeName.toLowerCase()] ) {
|
|
1975
|
+
acc[obj.storeName.toLowerCase()] = {
|
|
1976
|
+
email: [ obj.userEmail.toLowerCase() ],
|
|
1977
|
+
count: 1,
|
|
1978
|
+
};
|
|
1979
|
+
} else {
|
|
1980
|
+
if ( acc[obj.storeName.toLowerCase()] ) {
|
|
1981
|
+
if ( acc[obj.storeName.toLowerCase()].email.includes( obj.userEmail.toLowerCase() ) ) {
|
|
1982
|
+
acc[obj.storeName.toLowerCase()].count++;
|
|
1983
|
+
} else {
|
|
1984
|
+
acc[obj.storeName.toLowerCase()].email.push( obj.userEmail.toLowerCase() );
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
return acc;
|
|
1989
|
+
}, {} );
|
|
1990
|
+
|
|
1991
|
+
const duplicateStores = Object.keys( duplicateStore ).filter( ( storeName ) => duplicateStore[storeName].count > 1 );
|
|
1992
|
+
if ( duplicateStores.length ) {
|
|
1993
|
+
return res.sendSuccess( { validate: false, ExistsEmail: duplicateStores, message: 'Store and email is duplicated' } );
|
|
1994
|
+
}
|
|
1995
|
+
} else {
|
|
1996
|
+
const duplicateUser = assignDetails.reduce( ( acc, obj ) => {
|
|
1997
|
+
if ( !acc[obj.userEmail.toLowerCase()] ) {
|
|
1998
|
+
acc[obj.userEmail.toLowerCase()] = {
|
|
1999
|
+
name: [ obj.userName.toLowerCase() ],
|
|
2000
|
+
count: 1,
|
|
2001
|
+
};
|
|
2002
|
+
} else {
|
|
2003
|
+
if ( acc[obj.userEmail.toLowerCase()] ) {
|
|
2004
|
+
if ( acc[obj.userEmail.toLowerCase()].name.includes( obj.userName.toLowerCase() ) ) {
|
|
2005
|
+
acc[obj.userEmail.toLowerCase()].count++;
|
|
2006
|
+
} else {
|
|
2007
|
+
acc[obj.userEmail.toLowerCase()].name.push( obj.userEmail.toLowerCase() );
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
return acc;
|
|
2012
|
+
}, {} );
|
|
2013
|
+
|
|
2014
|
+
const duplicateUsers = Object.keys( duplicateUser ).filter( ( storeName ) => duplicateUser[storeName].count > 1 );
|
|
2015
|
+
if ( duplicateUsers.length ) {
|
|
2016
|
+
return res.sendSuccess( { validate: false, ExistsEmail: duplicateUsers, message: 'Email is Duplicated' } );
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
|
|
1986
2020
|
if ( req.body.hasOwnProperty( 'addSingle' ) ) {
|
|
1987
2021
|
let checkExists = await assignedService.findOne( { userEmail: assignDetails[0]?.userEmail, storeName: assignDetails[0]?.storeName, checkListId: req.body.id } );
|
|
1988
2022
|
if ( checkExists ) {
|
|
@@ -2044,75 +2078,87 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
2044
2078
|
},
|
|
2045
2079
|
];
|
|
2046
2080
|
|
|
2047
|
-
console.log( storeQuery );
|
|
2048
|
-
|
|
2049
2081
|
let [ userDetails, storeDetails, existEmail ] = await Promise.all( [
|
|
2050
2082
|
await userService.aggregate( userQuery ),
|
|
2051
2083
|
await storeService.aggregate( storeQuery ),
|
|
2052
2084
|
await userService.aggregate( emailCheckQuery ),
|
|
2053
2085
|
] );
|
|
2054
2086
|
|
|
2055
|
-
let existUSerEmail = userDetails.map( ( ele ) => ele.email );
|
|
2056
2087
|
|
|
2057
|
-
|
|
2088
|
+
let existUserEmail = userDetails.map( ( ele ) => ele.newEmail );
|
|
2089
|
+
let newUserList = userEmailList.filter( ( ele ) => !existUserEmail.includes( ele ) );
|
|
2058
2090
|
|
|
2059
|
-
let existsStore = storeDetails.map( ( ele ) => ele
|
|
2060
|
-
|
|
2091
|
+
let existsStore = storeDetails.map( ( ele ) => ele?.storeName );
|
|
2092
|
+
let newStoreList = storeList.filter( ( ele ) => ele != null && !existsStore.includes( ele.toLowerCase() ) );
|
|
2093
|
+
if ( req.body.coverage == 'store' ) {
|
|
2094
|
+
assignDetails.forEach( ( item ) => {
|
|
2095
|
+
let getStoreId = storeDetails.find( ( store ) => store.storeName.toLowerCase() == item.storeName.toLowerCase() );
|
|
2096
|
+
if ( getStoreId ) {
|
|
2097
|
+
item._id = getStoreId._id;
|
|
2098
|
+
}
|
|
2099
|
+
} );
|
|
2100
|
+
} else {
|
|
2101
|
+
assignDetails.forEach( ( item ) => {
|
|
2102
|
+
let getUserId = userDetails.find( ( user ) => user.newEmail.toLowerCase() == item.userEmail.toLowerCase() );
|
|
2103
|
+
if ( getUserId ) {
|
|
2104
|
+
item._id = getUserId._id;
|
|
2105
|
+
}
|
|
2106
|
+
} );
|
|
2107
|
+
}
|
|
2061
2108
|
|
|
2062
|
-
if (
|
|
2063
|
-
return res.sendError( { validate: false, user:
|
|
2109
|
+
if ( newUserList.length || newStoreList.length || existEmail.length ) {
|
|
2110
|
+
return res.sendError( { validate: false, user: newUserList, store: newStoreList, existEmail, data: assignDetails }, 400 );
|
|
2064
2111
|
}
|
|
2065
|
-
return res.sendSuccess( { validate: true } );
|
|
2112
|
+
return res.sendSuccess( { validate: true, data: assignDetails } );
|
|
2066
2113
|
} catch ( e ) {
|
|
2067
2114
|
logger.error( 'validateUser 2=>', e );
|
|
2068
2115
|
return res.sendError( e, 500 );
|
|
2069
2116
|
}
|
|
2070
2117
|
};
|
|
2071
2118
|
|
|
2072
|
-
export async function assignChecklistUser( req, res ) {
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
}
|
|
2115
|
-
|
|
2119
|
+
// export async function assignChecklistUser( req, res ) {
|
|
2120
|
+
// try {
|
|
2121
|
+
// let inputBody = req.body;
|
|
2122
|
+
// let assignDetails = inputBody.assignUsers;
|
|
2123
|
+
// let newUsers = inputBody.newUsers;
|
|
2124
|
+
// let checklistDetails = await checklistService.findOne( { _id: inputBody.checklistId } );
|
|
2125
|
+
// if ( !checklistDetails ) {
|
|
2126
|
+
// return res.sendError( 'No data found', 204 );
|
|
2127
|
+
// }
|
|
2128
|
+
// await Promise.all( newUsers.map( async ( user ) => {
|
|
2129
|
+
// let getUser = inputBody.assignUsers.find( ( ele ) => ele.userEmail.toLowerCase() == user.toLowerCase() );
|
|
2130
|
+
// let userData = {
|
|
2131
|
+
// userName: getUser.userName,
|
|
2132
|
+
// email: user,
|
|
2133
|
+
// mobileNumber: getUser?.phone,
|
|
2134
|
+
// clientId: inputBody.clientId,
|
|
2135
|
+
// };
|
|
2136
|
+
// await createUser( userData );
|
|
2137
|
+
// } ) );
|
|
2138
|
+
// let assignData = [];
|
|
2139
|
+
// await Promise.all( assignDetails.map( async ( assign ) => {
|
|
2140
|
+
// assign.checklistId = inputBody.taskId;
|
|
2141
|
+
// assign.checkListName = checklistDetails.checkListName;
|
|
2142
|
+
// assign.coverage = inputBody.coverage;
|
|
2143
|
+
// assign.clientId = inputBody.clientId;
|
|
2144
|
+
// assign.upload = inputBody.type;
|
|
2145
|
+
// let uploadData = await assignUsers( assign );
|
|
2146
|
+
// if ( uploadData ) {
|
|
2147
|
+
// if ( Array.isArray( uploadData ) ) {
|
|
2148
|
+
// assignData.push( ...uploadData );
|
|
2149
|
+
// } else {
|
|
2150
|
+
// assignData.push( uploadData );
|
|
2151
|
+
// }
|
|
2152
|
+
// }
|
|
2153
|
+
// } ) );
|
|
2154
|
+
// return res.sendSuccess( { idList: [ ...new Set( assignData.map( ( item ) => {
|
|
2155
|
+
// return { id: item?.assignId?.toString(), type: inputBody.coverage == 'store' ? typeof item.clusterName == 'undefined' ? 'store' : 'cluster' : typeof item.teamsName == 'undefined' ? 'user' : 'teams' };
|
|
2156
|
+
// } ) ) ], assignData } );
|
|
2157
|
+
// } catch ( e ) {
|
|
2158
|
+
// logger.error( { functionName: 'assignUser', error: e } );
|
|
2159
|
+
// return res.sendError( e, 500 );
|
|
2160
|
+
// }
|
|
2161
|
+
// }
|
|
2116
2162
|
|
|
2117
2163
|
async function uploadUser( req, res ) {
|
|
2118
2164
|
try {
|
|
@@ -3492,7 +3538,18 @@ export const selectAssign = async ( req, res ) => {
|
|
|
3492
3538
|
if ( requestData.assignType == 'store' ) {
|
|
3493
3539
|
let storeQuery = [
|
|
3494
3540
|
{ $match: { clientId: requestData.clientId, status: 'active' } },
|
|
3495
|
-
{
|
|
3541
|
+
{
|
|
3542
|
+
$project: {
|
|
3543
|
+
storeName: 1,
|
|
3544
|
+
storeId: 1,
|
|
3545
|
+
type: 'store',
|
|
3546
|
+
userName: { $arrayElemAt: [ '$spocDetails.name', 0 ] },
|
|
3547
|
+
userEmail: { $arrayElemAt: [ '$spocDetails.email', 0 ] },
|
|
3548
|
+
contact: { $arrayElemAt: [ '$spocDetails.contact', 0 ] },
|
|
3549
|
+
city: '$storeProfile.city',
|
|
3550
|
+
},
|
|
3551
|
+
},
|
|
3552
|
+
|
|
3496
3553
|
];
|
|
3497
3554
|
resuldData = await storeService.aggregate( storeQuery );
|
|
3498
3555
|
} else {
|
|
@@ -3509,7 +3566,7 @@ export const selectAssign = async ( req, res ) => {
|
|
|
3509
3566
|
if ( requestData.assignType == 'user' ) {
|
|
3510
3567
|
let userQuery = [
|
|
3511
3568
|
{ $match: { clientId: requestData.clientId } },
|
|
3512
|
-
{ $project: { '
|
|
3569
|
+
{ $project: { 'email': 1, 'userName': 1, 'type': 'user' } },
|
|
3513
3570
|
];
|
|
3514
3571
|
resuldData = await userService.aggregate( userQuery );
|
|
3515
3572
|
} else {
|
|
@@ -3535,213 +3592,40 @@ export const selectAssign = async ( req, res ) => {
|
|
|
3535
3592
|
|
|
3536
3593
|
async function assignUsers( data ) {
|
|
3537
3594
|
let assignedData;
|
|
3538
|
-
if ( data
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
},
|
|
3552
|
-
{
|
|
3553
|
-
$project: {
|
|
3554
|
-
stores: 1,
|
|
3555
|
-
clusterName: 1,
|
|
3556
|
-
},
|
|
3557
|
-
},
|
|
3558
|
-
];
|
|
3559
|
-
let clusterDetails = await clusterServices.aggregateCluster( query );
|
|
3560
|
-
if ( clusterDetails.length ) {
|
|
3561
|
-
if ( data.insert ) {
|
|
3562
|
-
assignedData = {
|
|
3563
|
-
checkFlag: true,
|
|
3564
|
-
checkListId: data.checklistId,
|
|
3565
|
-
checkListName: data.checkListName,
|
|
3566
|
-
client_id: data?.clientId,
|
|
3567
|
-
clusterName: clusterDetails?.[0]?.clusterName,
|
|
3568
|
-
assignId: data?.id || clusterDetails?.[0]?._id,
|
|
3569
|
-
coverage: 'store',
|
|
3570
|
-
};
|
|
3571
|
-
} else {
|
|
3572
|
-
let clusterList = clusterDetails[0].stores.map( ( ele ) => ele.store );
|
|
3573
|
-
let storeDetails = await storeService.find( { _id: { $in: clusterList }, status: 'active' } );
|
|
3574
|
-
assignedData = await Promise.all( storeDetails.map( async ( store ) => {
|
|
3575
|
-
let userDetails = await userService.findOne( { email: store.spocDetails?.[0]?.email, clientId: data.clientId } );
|
|
3576
|
-
if ( !userDetails && store?.spocDetails?.length ) {
|
|
3577
|
-
let userData = {
|
|
3578
|
-
userName: store.spocDetails?.[0]?.name,
|
|
3579
|
-
email: store.spocDetails[0]?.email,
|
|
3580
|
-
mobileNumber: store.spocDetails?.[0]?.phone,
|
|
3581
|
-
clientId: data.clientId,
|
|
3582
|
-
};
|
|
3583
|
-
userDetails = await createUser( userData );
|
|
3584
|
-
}
|
|
3585
|
-
let userData = {
|
|
3586
|
-
userId: userDetails?._id,
|
|
3587
|
-
userName: userDetails?.userName,
|
|
3588
|
-
userEmail: userDetails?.email,
|
|
3589
|
-
userPhone: userDetails?.mobileNumber,
|
|
3590
|
-
checkFlag: true,
|
|
3591
|
-
checkListId: data.checklistId,
|
|
3592
|
-
checkListName: data.checkListName,
|
|
3593
|
-
client_id: data.clientId,
|
|
3594
|
-
assignId: data?.id || clusterDetails?.[0]?._id,
|
|
3595
|
-
coverage: 'store',
|
|
3596
|
-
clusterName: clusterDetails?.[0]?.clusterName,
|
|
3597
|
-
storeId: store.storeId,
|
|
3598
|
-
storeName: store.storeName,
|
|
3599
|
-
};
|
|
3600
|
-
return userData;
|
|
3601
|
-
} ) );
|
|
3602
|
-
}
|
|
3603
|
-
}
|
|
3604
|
-
} else {
|
|
3605
|
-
let query = [
|
|
3606
|
-
{
|
|
3607
|
-
$addFields: {
|
|
3608
|
-
store: { $toLower: '$storeName' },
|
|
3609
|
-
},
|
|
3610
|
-
},
|
|
3611
|
-
{
|
|
3612
|
-
$match: {
|
|
3613
|
-
clientId: data.clientId,
|
|
3614
|
-
...( data?.id ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { store: data.storeName.toLowerCase() },
|
|
3615
|
-
},
|
|
3616
|
-
},
|
|
3617
|
-
];
|
|
3618
|
-
let storeDetails = await storeService.aggregate( query );
|
|
3619
|
-
if ( storeDetails.length ) {
|
|
3620
|
-
let email = data?.userEmail ? data.userEmail : storeDetails?.[0]?.spocDetails?.[0]?.email;
|
|
3621
|
-
let userDetails = await userService.findOne( { email: email, clientId: data.clientId } );
|
|
3622
|
-
if ( !userDetails ) {
|
|
3623
|
-
let userData = {
|
|
3624
|
-
userName: storeDetails?.[0]?.spocDetails?.[0]?.name,
|
|
3625
|
-
email: data?.userEmail || storeDetails?.[0]?.spocDetails[0].email,
|
|
3626
|
-
mobileNumber: storeDetails?.[0]?.spocDetails?.[0]?.phone,
|
|
3627
|
-
clientId: data.clientId,
|
|
3628
|
-
};
|
|
3629
|
-
userDetails = await createUser( userData );
|
|
3630
|
-
}
|
|
3631
|
-
assignedData = {
|
|
3632
|
-
store_id: storeDetails?.[0]?.storeId,
|
|
3633
|
-
storeName: storeDetails?.[0]?.storeName,
|
|
3634
|
-
userId: userDetails._id,
|
|
3635
|
-
userName: userDetails.userName,
|
|
3636
|
-
userEmail: userDetails.email,
|
|
3637
|
-
userPhone: userDetails?.mobileNumber,
|
|
3638
|
-
city: storeDetails?.[0]?.storeProfile?.city,
|
|
3639
|
-
country: storeDetails?.[0]?.storeProfile?.country,
|
|
3640
|
-
checkFlag: true,
|
|
3641
|
-
checkListId: data.checklistId,
|
|
3642
|
-
checkListName: data.checkListName,
|
|
3643
|
-
client_id: data.clientId,
|
|
3644
|
-
assignId: data?.id || storeDetails?.[0]?._id,
|
|
3645
|
-
coverage: 'store',
|
|
3595
|
+
if ( data?.type == 'cluster' ) {
|
|
3596
|
+
let clusterDetails = await clusterServices.findcluster( { clientId: data.clientId, _id: new mongoose.Types.ObjectId( data.id ) } );
|
|
3597
|
+
if ( clusterDetails.length ) {
|
|
3598
|
+
let clusterList = clusterDetails[0].stores.map( ( ele ) => ele.store );
|
|
3599
|
+
let storeDetails = await storeService.find( { _id: { $in: clusterList }, status: 'active' } );
|
|
3600
|
+
assignedData = await Promise.all( storeDetails.map( async ( store ) => {
|
|
3601
|
+
let userData = {
|
|
3602
|
+
storeId: store.storeId,
|
|
3603
|
+
storeName: store.storeName,
|
|
3604
|
+
userName: store.spocDetails?.[0]?.name,
|
|
3605
|
+
userEmail: store.spocDetails?.[0]?.email,
|
|
3606
|
+
clusterName: clusterDetails?.[0]?.clusterName,
|
|
3607
|
+
id: clusterDetails?.[0]?._id,
|
|
3646
3608
|
};
|
|
3647
|
-
|
|
3609
|
+
return userData;
|
|
3610
|
+
} ) );
|
|
3648
3611
|
}
|
|
3649
3612
|
} else {
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
},
|
|
3656
|
-
},
|
|
3657
|
-
{
|
|
3658
|
-
$match: {
|
|
3659
|
-
clientId: data.clientId,
|
|
3660
|
-
...( data?.id ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { team: data.teamName.toLowerCase() },
|
|
3661
|
-
},
|
|
3662
|
-
},
|
|
3663
|
-
];
|
|
3664
|
-
let teamDetails = await teamsServices.aggregateTeams( query );
|
|
3665
|
-
if ( teamDetails.length ) {
|
|
3666
|
-
if ( data.insert ) {
|
|
3667
|
-
assignedData = {
|
|
3668
|
-
checkFlag: true,
|
|
3669
|
-
checkListId: data.checklistId,
|
|
3670
|
-
checkListName: data.checkListName,
|
|
3671
|
-
client_id: data.clientId,
|
|
3672
|
-
teamName: teamDetails?.[0]?.teamName,
|
|
3673
|
-
assignId: data?.id || teamDetails?.[0]?._id,
|
|
3674
|
-
coverage: 'user',
|
|
3675
|
-
};
|
|
3676
|
-
} else {
|
|
3677
|
-
let userIdList = teamDetails[0].users.map( ( ele ) => ele.userId );
|
|
3678
|
-
let userDetails = await userService.find( { _id: userIdList } );
|
|
3679
|
-
assignedData = userDetails.map( ( user ) => {
|
|
3680
|
-
let userData = {
|
|
3681
|
-
userId: user._id,
|
|
3682
|
-
userName: user.userName,
|
|
3683
|
-
userEmail: user.email,
|
|
3684
|
-
userPhone: user.mobileNumber,
|
|
3685
|
-
checkFlag: true,
|
|
3686
|
-
checkListId: data.checklistId,
|
|
3687
|
-
checkListName: data.checkListName,
|
|
3688
|
-
client_id: data.clientId,
|
|
3689
|
-
assignId: data?.id || teamDetails?.[0]?._id,
|
|
3690
|
-
coverage: 'user',
|
|
3691
|
-
teamName: teamDetails?.[0]?.teamName,
|
|
3692
|
-
};
|
|
3693
|
-
return userData;
|
|
3694
|
-
} );
|
|
3695
|
-
}
|
|
3696
|
-
}
|
|
3697
|
-
} else {
|
|
3698
|
-
let query = [
|
|
3699
|
-
{
|
|
3700
|
-
$addFields: {
|
|
3701
|
-
userEmail: { $toLower: '$email' },
|
|
3702
|
-
},
|
|
3703
|
-
},
|
|
3704
|
-
{
|
|
3705
|
-
$match: {
|
|
3706
|
-
clientId: data.clientId,
|
|
3707
|
-
...( data?.id ) ? { _id: new mongoose.Types.ObjectId( data.id ) } : { userEmail: data.userEmail.toLowerCase() },
|
|
3708
|
-
},
|
|
3709
|
-
},
|
|
3710
|
-
];
|
|
3711
|
-
// console.log( 'data?.userEmail=>', data.userEmail );
|
|
3712
|
-
let userDetails = await userService.aggregate( query );
|
|
3713
|
-
if ( !userDetails.length ) {
|
|
3613
|
+
let teamDetails = await teamsServices.findteams( { clientId: data.clientId, _id: new mongoose.Types.ObjectId( data.id ) } );
|
|
3614
|
+
if ( teamDetails.length ) {
|
|
3615
|
+
let userIdList = teamDetails[0].users.map( ( ele ) => ele.userId );
|
|
3616
|
+
let userDetails = await userService.find( { _id: userIdList } );
|
|
3617
|
+
assignedData = userDetails.map( ( user ) => {
|
|
3714
3618
|
let userData = {
|
|
3715
|
-
userName:
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
// console.log( userData, 'userData', data );
|
|
3720
|
-
let details = await createUser( userData );
|
|
3721
|
-
userDetails = [ details ];
|
|
3722
|
-
}
|
|
3723
|
-
if ( userDetails.length ) {
|
|
3724
|
-
assignedData = {
|
|
3725
|
-
userId: userDetails?.[0]?._id,
|
|
3726
|
-
userName: userDetails?.[0]?.userName,
|
|
3727
|
-
userEmail: userDetails?.[0]?.email,
|
|
3728
|
-
userPhone: userDetails?.[0]?.mobileNumber,
|
|
3729
|
-
checkFlag: true,
|
|
3730
|
-
checkListId: data.checklistId,
|
|
3731
|
-
checkListName: data.checkListName,
|
|
3732
|
-
client_id: data.clientId,
|
|
3733
|
-
assignId: data?.id || userDetails?.[0]?._id,
|
|
3734
|
-
coverage: 'user',
|
|
3619
|
+
userName: user.userName,
|
|
3620
|
+
userEmail: user.email,
|
|
3621
|
+
teamName: teamDetails?.[0]?.teamName,
|
|
3622
|
+
id: teamDetails?.[0]?._id,
|
|
3735
3623
|
};
|
|
3736
|
-
|
|
3624
|
+
return userData;
|
|
3625
|
+
} );
|
|
3737
3626
|
}
|
|
3738
3627
|
}
|
|
3739
|
-
|
|
3740
|
-
if ( assignedData && data?.insert ) {
|
|
3741
|
-
await assignedService.updateOne( { checkListId: assignedData.checkListId, assignId: assignedData.assignId }, assignedData );
|
|
3742
|
-
} else {
|
|
3743
|
-
return assignedData;
|
|
3744
|
-
}
|
|
3628
|
+
return assignedData;
|
|
3745
3629
|
}
|
|
3746
3630
|
|
|
3747
3631
|
export async function checklistAssign( req, res ) {
|
|
@@ -3767,20 +3651,9 @@ export async function checklistAssign( req, res ) {
|
|
|
3767
3651
|
let assignedData = {
|
|
3768
3652
|
...data,
|
|
3769
3653
|
clientId: req.body.clientId,
|
|
3770
|
-
checkListName: checklistDetails.checkListName,
|
|
3771
|
-
checklistId: checklistDetails._id,
|
|
3772
|
-
coverage: req.body.coverage,
|
|
3773
|
-
insert: false,
|
|
3774
3654
|
};
|
|
3775
|
-
// console.log( assignedData, 'daterthj' );
|
|
3776
3655
|
let uploadData = await assignUsers( assignedData );
|
|
3777
|
-
|
|
3778
|
-
if ( Array.isArray( uploadData ) ) {
|
|
3779
|
-
uniqueArr.push( ...uploadData );
|
|
3780
|
-
} else {
|
|
3781
|
-
uniqueArr.push( uploadData );
|
|
3782
|
-
}
|
|
3783
|
-
}
|
|
3656
|
+
uniqueArr.push( ...uploadData );
|
|
3784
3657
|
} ) );
|
|
3785
3658
|
|
|
3786
3659
|
return res.sendSuccess( { count: uniqueArr.length, uniqueArr } );
|
|
@@ -3790,3 +3663,78 @@ export async function checklistAssign( req, res ) {
|
|
|
3790
3663
|
}
|
|
3791
3664
|
}
|
|
3792
3665
|
|
|
3666
|
+
export async function updateAssign( req, res ) {
|
|
3667
|
+
try {
|
|
3668
|
+
console.log( req.body );
|
|
3669
|
+
if ( !req.body.assignedList.length && !req.body.assignedGroup.length ) {
|
|
3670
|
+
return res.sendError( 'No data found', 204 );
|
|
3671
|
+
}
|
|
3672
|
+
let checklistDetails = await checklistService.findOne( { _id: req.body.checkListId, client_id: req.body.clientId } );
|
|
3673
|
+
if ( !checklistDetails ) {
|
|
3674
|
+
return res.sendError( 'No data found', 204 );
|
|
3675
|
+
}
|
|
3676
|
+
await assignedService.deleteMany( { checkListId: req.body.checkListId } );
|
|
3677
|
+
let assignedUserList = [];
|
|
3678
|
+
await Promise.all( req.body.assignedList.map( async ( assign ) => {
|
|
3679
|
+
delete assign.id;
|
|
3680
|
+
let query = [
|
|
3681
|
+
{
|
|
3682
|
+
$addFields: {
|
|
3683
|
+
emailToLower: { $toLower: '$email' },
|
|
3684
|
+
},
|
|
3685
|
+
},
|
|
3686
|
+
{
|
|
3687
|
+
$match: {
|
|
3688
|
+
clientId: req.body.clientId,
|
|
3689
|
+
emailToLower: assign.userEmail.toLowerCase(),
|
|
3690
|
+
},
|
|
3691
|
+
},
|
|
3692
|
+
];
|
|
3693
|
+
let userDetails = await userService.aggregate( query );
|
|
3694
|
+
if ( !userDetails.length ) {
|
|
3695
|
+
let userData = {
|
|
3696
|
+
userName: assign.userName,
|
|
3697
|
+
email: assign.userEmail,
|
|
3698
|
+
mobileNumber: assign?.phone || '',
|
|
3699
|
+
clientId: req.body.clientId,
|
|
3700
|
+
};
|
|
3701
|
+
userDetails = await createUser( userData );
|
|
3702
|
+
}
|
|
3703
|
+
let data = {
|
|
3704
|
+
...assign,
|
|
3705
|
+
store_id: assign.storeId,
|
|
3706
|
+
client_id: req.body.clientId,
|
|
3707
|
+
checkListId: req.body.checkListId,
|
|
3708
|
+
coverage: req.body.coverage,
|
|
3709
|
+
assignId: assign._id,
|
|
3710
|
+
userId: userDetails._id,
|
|
3711
|
+
checkListName: checklistDetails.checkListName,
|
|
3712
|
+
};
|
|
3713
|
+
assignedUserList.push( data );
|
|
3714
|
+
} ) );
|
|
3715
|
+
await Promise.all( req.body.assignedGroup.map( async ( assign ) => {
|
|
3716
|
+
let groupDetails;
|
|
3717
|
+
if ( req.body.coverage == 'store' ) {
|
|
3718
|
+
groupDetails = await clusterServices.findOneCluster( { _id: assign.id } );
|
|
3719
|
+
} else {
|
|
3720
|
+
groupDetails = await teamsServices.findOneTeams( { _id: assign.id } );
|
|
3721
|
+
}
|
|
3722
|
+
if ( groupDetails ) {
|
|
3723
|
+
let groupData = {
|
|
3724
|
+
client_id: req.body.clientId,
|
|
3725
|
+
checkListId: req.body.checkListId,
|
|
3726
|
+
coverage: req.body.coverage,
|
|
3727
|
+
assignId: assign.id,
|
|
3728
|
+
checkListName: checklistDetails.checkListName,
|
|
3729
|
+
...( req.body.coverage == 'store' ) ? { clusterName: groupDetails?.clusterName } : { teamName: groupDetails?.teamName },
|
|
3730
|
+
};
|
|
3731
|
+
assignedUserList.push( groupData );
|
|
3732
|
+
}
|
|
3733
|
+
} ) );
|
|
3734
|
+
await assignedService.insertMany( assignedUserList );
|
|
3735
|
+
return res.sendSuccess( 'Assign details updated successfully' );
|
|
3736
|
+
} catch ( e ) {
|
|
3737
|
+
logger.error( { functionName: 'updateAssign', error: e } );
|
|
3738
|
+
return res.sendError( e, 500 );
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
@@ -27,6 +27,8 @@ traxRouter
|
|
|
27
27
|
.get( '/predefinedChecklist', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ), validate( aichecklistValidation ), traxController.preDefinedChecklist )
|
|
28
28
|
.post( '/selectAssign', validate( selectAssign ), traxController.selectAssign )
|
|
29
29
|
.post( '/assign', isAllowedSessionHandler, traxController.checklistAssign )
|
|
30
|
-
.post( '/assignUpload', isAllowedSessionHandler, traxController.assignChecklistUser )
|
|
30
|
+
// .post( '/assignUpload', isAllowedSessionHandler, traxController.assignChecklistUser )
|
|
31
|
+
.post( '/updateAssign', isAllowedSessionHandler, traxController.updateAssign );
|
|
32
|
+
;
|
|
31
33
|
|
|
32
34
|
// isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ),
|