tango-app-api-trax 3.3.1-beta-10 → 3.3.1-beta-11
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
|
@@ -900,7 +900,7 @@ export const assignedUserDetails = async ( req, res ) => {
|
|
|
900
900
|
userDetails.push( {
|
|
901
901
|
id: ele._id,
|
|
902
902
|
userName: item.spocDetails?.[0]?.name,
|
|
903
|
-
userEmail: item.spocDetails[0]
|
|
903
|
+
userEmail: item.spocDetails?.[0]?.email,
|
|
904
904
|
store_id: item?.storeId,
|
|
905
905
|
storeName: item?.storeName,
|
|
906
906
|
userPhone: item.spocDetails?.[0]?.phone,
|
|
@@ -945,9 +945,16 @@ export const assignedUserDetails = async ( req, res ) => {
|
|
|
945
945
|
} );
|
|
946
946
|
}
|
|
947
947
|
} ) );
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
948
|
+
if ( req.query.sortColumn && req.query.sortBy ) {
|
|
949
|
+
const sortColumn = req.query.sortColumn;
|
|
950
|
+
const sortBy = parseInt( req.query.sortBy, 10 ) === -1 ? -1 : 1;
|
|
951
|
+
userDetails.sort( ( a, b ) => {
|
|
952
|
+
if ( a[sortColumn] == null || b[sortColumn] == null ) return 0;
|
|
953
|
+
if ( typeof a[sortColumn] === 'string' && typeof b[sortColumn] === 'string' ) {
|
|
954
|
+
return sortBy * a[sortColumn].localeCompare( b[sortColumn] );
|
|
955
|
+
}
|
|
956
|
+
} );
|
|
957
|
+
}
|
|
951
958
|
let limitedData = userDetails.slice( skip, limit + skip );
|
|
952
959
|
return res.sendSuccess( { count: userDetails.length, storeList, userList, users: limitedData } );
|
|
953
960
|
} catch ( e ) {
|
|
@@ -1947,15 +1954,35 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
1947
1954
|
}
|
|
1948
1955
|
};
|
|
1949
1956
|
|
|
1950
|
-
export async function
|
|
1957
|
+
export async function assignChecklistUser( req, res ) {
|
|
1951
1958
|
try {
|
|
1952
1959
|
let inputBody = req.body;
|
|
1953
1960
|
let assignDetails = inputBody.assignUsers;
|
|
1961
|
+
let newUsers = inputBody.newUsers;
|
|
1954
1962
|
if ( inputBody.type == 'upload' ) {
|
|
1955
1963
|
await assignedService.deleteMany( { checkListId: inputBody.checklistId } );
|
|
1956
1964
|
}
|
|
1957
|
-
await
|
|
1958
|
-
|
|
1965
|
+
let checklistDetails = await checklistService.findOne( { _id: inputBody.checklistId } );
|
|
1966
|
+
if ( !checklistDetails ) {
|
|
1967
|
+
return res.sendError( 'No data found', 204 );
|
|
1968
|
+
}
|
|
1969
|
+
await Promise.all( newUsers.map( async ( user ) => {
|
|
1970
|
+
let getUser = inputBody.assignUsers.find( ( ele ) => ele.userEmail.toLowerCase() == user.toLowerCase() );
|
|
1971
|
+
let userData = {
|
|
1972
|
+
userName: getUser.userName,
|
|
1973
|
+
email: user,
|
|
1974
|
+
mobileNumber: getUser?.phone,
|
|
1975
|
+
clientId: inputBody.clientId,
|
|
1976
|
+
};
|
|
1977
|
+
await createUser( userData );
|
|
1978
|
+
} ) );
|
|
1979
|
+
await Promise.all( assignDetails.map( async ( assign ) => {
|
|
1980
|
+
assign.checklistId = inputBody.checklistId;
|
|
1981
|
+
assign.checkListName = checklistDetails.checkListName;
|
|
1982
|
+
assign.coverage = inputBody.coverage;
|
|
1983
|
+
assign.clientId = inputBody.clientId;
|
|
1984
|
+
assign.upload = inputBody.type;
|
|
1985
|
+
await assignUsers( assign );
|
|
1959
1986
|
} ) );
|
|
1960
1987
|
return res.sendSuccess( 'Details updated successfully' );
|
|
1961
1988
|
} catch ( e ) {
|
|
@@ -3100,8 +3127,9 @@ export const checklistV2 = async ( req, res ) => {
|
|
|
3100
3127
|
async function assignUsers( data ) {
|
|
3101
3128
|
let assignedData;
|
|
3102
3129
|
if ( data.coverage == 'store' ) {
|
|
3103
|
-
if ( data
|
|
3104
|
-
let
|
|
3130
|
+
if ( data?.type == 'cluster' ) {
|
|
3131
|
+
let query = !data?.upload ? { _id: data.id } : { clusterName: data.clusterName, clientId: data.clientId };
|
|
3132
|
+
let clusterDetails = await clusterServices.findOneCluster( query, { stores: 1, clusterName: 1 } );
|
|
3105
3133
|
if ( clusterDetails ) {
|
|
3106
3134
|
assignedData = {
|
|
3107
3135
|
checkFlag: true,
|
|
@@ -3109,13 +3137,15 @@ async function assignUsers( data ) {
|
|
|
3109
3137
|
checkListName: data.checkListName,
|
|
3110
3138
|
client_id: data?.clientId,
|
|
3111
3139
|
clusterName: clusterDetails?.clusterName,
|
|
3112
|
-
assignId: data
|
|
3140
|
+
assignId: data?.id || clusterDetails?._id,
|
|
3113
3141
|
};
|
|
3114
3142
|
}
|
|
3115
3143
|
} else {
|
|
3116
|
-
let
|
|
3144
|
+
let query = !data?.upload ? { _id: data.id } : { storeName: data.storeName };
|
|
3145
|
+
let storeDetails = await storeService.findOne( query );
|
|
3117
3146
|
if ( storeDetails ) {
|
|
3118
|
-
let
|
|
3147
|
+
let email = data?.upload ? data.userEmail : storeDetails?.spocDetails?.email;
|
|
3148
|
+
let userDetails = await userService.findOne( { email: email, clientId: data.clientId } );
|
|
3119
3149
|
if ( !userDetails ) {
|
|
3120
3150
|
let userData = {
|
|
3121
3151
|
userName: storeDetails.spocDetails?.[0]?.name,
|
|
@@ -3123,7 +3153,7 @@ async function assignUsers( data ) {
|
|
|
3123
3153
|
mobileNumber: storeDetails.spocDetails?.[0]?.phone,
|
|
3124
3154
|
clientId: data.clientId,
|
|
3125
3155
|
};
|
|
3126
|
-
createUser( userData );
|
|
3156
|
+
userDetails = createUser( userData );
|
|
3127
3157
|
}
|
|
3128
3158
|
assignedData = {
|
|
3129
3159
|
store_id: storeDetails.storeId,
|
|
@@ -3133,18 +3163,19 @@ async function assignUsers( data ) {
|
|
|
3133
3163
|
userEmail: userDetails.email,
|
|
3134
3164
|
userPhone: userDetails?.mobileNumber,
|
|
3135
3165
|
city: storeDetails?.storeProfile?.city,
|
|
3136
|
-
country: storeDetails?.
|
|
3166
|
+
country: storeDetails?.storeProfile?.country,
|
|
3137
3167
|
checkFlag: true,
|
|
3138
3168
|
checkListId: data.checklistId,
|
|
3139
3169
|
checkListName: data.checkListName,
|
|
3140
3170
|
client_id: data.clientId,
|
|
3141
|
-
assignId: data.
|
|
3171
|
+
assignId: data?.id || storeDetails._id,
|
|
3142
3172
|
};
|
|
3143
3173
|
}
|
|
3144
3174
|
}
|
|
3145
3175
|
} else {
|
|
3146
3176
|
if ( data.type == 'teams' ) {
|
|
3147
|
-
let
|
|
3177
|
+
let query = !data?.upload ? { _id: data.id } : { teamName: data.teamName, clientId: data.clientId };
|
|
3178
|
+
let teamDetails = await teamsServices.findOneTeams( query, { users: 1, teamName: 1 } );
|
|
3148
3179
|
if ( teamDetails ) {
|
|
3149
3180
|
assignedData = {
|
|
3150
3181
|
checkFlag: true,
|
|
@@ -3152,11 +3183,12 @@ async function assignUsers( data ) {
|
|
|
3152
3183
|
checkListName: data.checkListName,
|
|
3153
3184
|
client_id: data.clientId,
|
|
3154
3185
|
teamName: teamDetails?.teamName,
|
|
3155
|
-
assignId: data
|
|
3186
|
+
assignId: data?.id || teamDetails?._id,
|
|
3156
3187
|
};
|
|
3157
3188
|
}
|
|
3158
3189
|
} else {
|
|
3159
|
-
let
|
|
3190
|
+
let query = !data?.upload ? { _id: data.id } : { email: data.email, clientId: data.clientId };
|
|
3191
|
+
let userDetails = await userService.findOne( query );
|
|
3160
3192
|
if ( userDetails ) {
|
|
3161
3193
|
assignedData = {
|
|
3162
3194
|
userId: userDetails._id,
|
|
@@ -3167,24 +3199,23 @@ async function assignUsers( data ) {
|
|
|
3167
3199
|
checkListId: data.checklistId,
|
|
3168
3200
|
checkListName: data.checkListName,
|
|
3169
3201
|
client_id: data.clientId,
|
|
3170
|
-
assignId: data
|
|
3202
|
+
assignId: data?.id || userDetails?._id,
|
|
3171
3203
|
};
|
|
3172
3204
|
}
|
|
3173
3205
|
}
|
|
3174
3206
|
}
|
|
3175
|
-
|
|
3207
|
+
if ( assignedData ) {
|
|
3208
|
+
await assignedService.create( assignedData );
|
|
3209
|
+
}
|
|
3176
3210
|
}
|
|
3177
3211
|
|
|
3178
3212
|
export async function checklistAssign( req, res ) {
|
|
3179
3213
|
try {
|
|
3180
|
-
if ( !req.body.type ) {
|
|
3181
|
-
return res.sendError( 'Type is required', 400 );
|
|
3182
|
-
}
|
|
3183
3214
|
if ( !req.body.coverage ) {
|
|
3184
3215
|
return res.sendError( 'coverage is required', 400 );
|
|
3185
3216
|
}
|
|
3186
|
-
if ( !req.body.
|
|
3187
|
-
return res.sendError( '
|
|
3217
|
+
if ( !req.body.idList ) {
|
|
3218
|
+
return res.sendError( 'Id list is required', 400 );
|
|
3188
3219
|
}
|
|
3189
3220
|
if ( !req.body.checklistId ) {
|
|
3190
3221
|
return res.sendError( 'Checklist id is required', 400 );
|
|
@@ -3197,7 +3228,10 @@ export async function checklistAssign( req, res ) {
|
|
|
3197
3228
|
return res.sendError( 'No data found', 204 );
|
|
3198
3229
|
}
|
|
3199
3230
|
req.body.checkListName = checklistDetails.checkListName;
|
|
3200
|
-
await
|
|
3231
|
+
await Promise.all( req.body.idList.map( async ( ele ) => {
|
|
3232
|
+
let storeData = { ...req.body, type: ele.type, id: ele.id };
|
|
3233
|
+
await assignUsers( storeData );
|
|
3234
|
+
} ) );
|
|
3201
3235
|
return res.sendSuccess( 'Details updated successfully' );
|
|
3202
3236
|
} catch ( e ) {
|
|
3203
3237
|
logger.error( { functionName: 'checklistAssign', error: e } );
|
|
@@ -13,7 +13,7 @@ traxRouter
|
|
|
13
13
|
.post( '/runAIInsert', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ 'isEdit' ] } ] } ), validate( runaiValidation ), traxController.runAIInsert )
|
|
14
14
|
.get( '/duplicateChecklist/:checklistId', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ 'isEdit' ] } ] } ), validate( duplicateValidation ), traxController.duplicateChecklist )
|
|
15
15
|
.put( '/checklist/update/:checklistId', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ 'isEdit' ] } ] } ), validate( updateChecklistValidation ), traxController.update )
|
|
16
|
-
.post( '/validateUser', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ 'isEdit' ] } ] } ), validate( uploadUserValidation ), traxController.
|
|
16
|
+
.post( '/validateUser', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ 'isEdit' ] } ] } ), validate( uploadUserValidation ), traxController.validateUserv1 )
|
|
17
17
|
.get( '/userDetails/:checklistId', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ), validate( duplicateValidation ), traxController.assignedUserDetails )
|
|
18
18
|
.post( '/checklistConfigure', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ 'isEdit' ] } ] } ), traxController.updateConfigure )
|
|
19
19
|
.post( '/checklistConfigurev1', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ 'isEdit' ] } ] } ), traxController.updateConfigurev1 )
|
|
@@ -27,6 +27,7 @@ traxRouter
|
|
|
27
27
|
.get( '/checklistV2', isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ), validate( checklistPageSchema ), traxController.checklistV2 )
|
|
28
28
|
.post( '/assign', isAllowedSessionHandler, traxController.checklistAssign )
|
|
29
29
|
.post( '/remove', isAllowedSessionHandler, traxController.removeAssign )
|
|
30
|
-
.post( '/removeAssignList', isAllowedSessionHandler, traxController.deleteAssignList )
|
|
30
|
+
.post( '/removeAssignList', isAllowedSessionHandler, traxController.deleteAssignList )
|
|
31
|
+
.post( '/assignUpload', isAllowedSessionHandler, traxController.assignChecklistUser );
|
|
31
32
|
|
|
32
33
|
// isAllowedSessionHandler, isAllowedClient, accessVerification( { userType: [ 'tango', 'client' ], access: [ { featureName: 'TangoTrax', name: 'checklist', permissions: [ ] } ] } ),
|