tango-app-api-trax 3.3.1-beta-11 → 3.3.1-beta-12
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 +2 -2
- package/src/controllers/mobileTrax.controller.js +90 -25
- package/src/controllers/teaxFlag.controller.js +116 -349
- package/src/controllers/trax.controller.js +27 -163
- package/src/controllers/traxDashboard.controllers.js +184 -180
- package/src/dtos/validation.dtos.js +2 -2
- package/src/hbs/login-otp.hbs +943 -943
- package/src/routes/trax.routes.js +2 -4
- package/src/routes/traxDashboard.routes.js +1 -3
- package/src/routes/traxFlag.router.js +1 -5
|
@@ -56,6 +56,7 @@ export const checklist = async ( req, res ) => {
|
|
|
56
56
|
$project: {
|
|
57
57
|
checkList: { $toLower: '$checkListName' },
|
|
58
58
|
checkListName: 1,
|
|
59
|
+
coverage: 1,
|
|
59
60
|
createdBy: 1,
|
|
60
61
|
userName: { $toLower: '$createdByName' },
|
|
61
62
|
createdByName: 1,
|
|
@@ -126,7 +127,6 @@ export const checklist = async ( req, res ) => {
|
|
|
126
127
|
}
|
|
127
128
|
};
|
|
128
129
|
|
|
129
|
-
|
|
130
130
|
export const create = async ( req, res ) => {
|
|
131
131
|
try {
|
|
132
132
|
let inputBody = req.body;
|
|
@@ -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
|
|
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,16 +945,9 @@ export const assignedUserDetails = async ( req, res ) => {
|
|
|
945
945
|
} );
|
|
946
946
|
}
|
|
947
947
|
} ) );
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
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
|
-
}
|
|
948
|
+
|
|
949
|
+
userDetails.sort( ( a, b ) => b.teamName - a.teamName );
|
|
950
|
+
console.log( userDetails );
|
|
958
951
|
let limitedData = userDetails.slice( skip, limit + skip );
|
|
959
952
|
return res.sendSuccess( { count: userDetails.length, storeList, userList, users: limitedData } );
|
|
960
953
|
} catch ( e ) {
|
|
@@ -1954,35 +1947,15 @@ export const validateUserv1 = async ( req, res ) => {
|
|
|
1954
1947
|
}
|
|
1955
1948
|
};
|
|
1956
1949
|
|
|
1957
|
-
export async function
|
|
1950
|
+
export async function assignUser( req, res ) {
|
|
1958
1951
|
try {
|
|
1959
1952
|
let inputBody = req.body;
|
|
1960
1953
|
let assignDetails = inputBody.assignUsers;
|
|
1961
|
-
let newUsers = inputBody.newUsers;
|
|
1962
1954
|
if ( inputBody.type == 'upload' ) {
|
|
1963
1955
|
await assignedService.deleteMany( { checkListId: inputBody.checklistId } );
|
|
1964
1956
|
}
|
|
1965
|
-
|
|
1966
|
-
|
|
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 );
|
|
1957
|
+
await Promise.all( assignDetails.map( ( assign ) => {
|
|
1958
|
+
assignUsers( assign );
|
|
1986
1959
|
} ) );
|
|
1987
1960
|
return res.sendSuccess( 'Details updated successfully' );
|
|
1988
1961
|
} catch ( e ) {
|
|
@@ -3022,114 +2995,11 @@ export const selectAssign = async ( req, res ) => {
|
|
|
3022
2995
|
}
|
|
3023
2996
|
};
|
|
3024
2997
|
|
|
3025
|
-
export const checklistV2 = async ( req, res ) => {
|
|
3026
|
-
try {
|
|
3027
|
-
let limit = parseInt( req.query.limit ) || 10;
|
|
3028
|
-
let offset = parseInt( req.query.offset - 1 ) || 0;
|
|
3029
|
-
let page = offset * limit;
|
|
3030
|
-
let query = [];
|
|
3031
|
-
query.push(
|
|
3032
|
-
{
|
|
3033
|
-
$match: {
|
|
3034
|
-
type: 'checklist',
|
|
3035
|
-
client_id: req.query.clientId,
|
|
3036
|
-
isdeleted: false,
|
|
3037
|
-
...( req.user.userType == 'client' && req.user.role != 'superadmin' ) ? { 'owner.value': { $in: [ req.user.email ] } } : {},
|
|
3038
|
-
},
|
|
3039
|
-
},
|
|
3040
|
-
);
|
|
3041
|
-
|
|
3042
|
-
if ( req.query.search && req.query.search != '' ) {
|
|
3043
|
-
req.query.search = req.query.search.replace( /([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1' );
|
|
3044
|
-
query.push( {
|
|
3045
|
-
$match: {
|
|
3046
|
-
checkListName: { $regex: new RegExp( req.query.search, 'i' ) },
|
|
3047
|
-
},
|
|
3048
|
-
} );
|
|
3049
|
-
}
|
|
3050
|
-
|
|
3051
|
-
query.push(
|
|
3052
|
-
{
|
|
3053
|
-
$project: {
|
|
3054
|
-
checkList: { $toLower: '$checkListName' },
|
|
3055
|
-
checkListName: 1,
|
|
3056
|
-
coverage: 1,
|
|
3057
|
-
createdBy: 1,
|
|
3058
|
-
userName: { $toLower: '$createdByName' },
|
|
3059
|
-
createdByName: 1,
|
|
3060
|
-
storeCount: 1,
|
|
3061
|
-
createdAt: 1,
|
|
3062
|
-
publish: 1,
|
|
3063
|
-
checkListType: 1,
|
|
3064
|
-
questionCount: 1,
|
|
3065
|
-
checkListChar: { $substr: [ '$checkListName', 0, 2 ] },
|
|
3066
|
-
},
|
|
3067
|
-
},
|
|
3068
|
-
);
|
|
3069
|
-
|
|
3070
|
-
if ( req.query.sortColumnName && req.query.sortColumnName != '' && req.query.sortBy != '' ) {
|
|
3071
|
-
if ( req.query.sortColumnName == 'status' ) {
|
|
3072
|
-
req.query.sortColumnName = 'publish';
|
|
3073
|
-
}
|
|
3074
|
-
if ( req.query.sortColumnName != 'publish' ) {
|
|
3075
|
-
query.push( {
|
|
3076
|
-
$addFields: { lowerName: { $toLower: `$${req.query.sortColumnName}` } },
|
|
3077
|
-
} );
|
|
3078
|
-
query.push( {
|
|
3079
|
-
$sort: { lowerName: parseInt( req.query.sortBy ) },
|
|
3080
|
-
} );
|
|
3081
|
-
} else {
|
|
3082
|
-
query.push( {
|
|
3083
|
-
$sort: { publish: parseInt( req.query.sortBy ) },
|
|
3084
|
-
} );
|
|
3085
|
-
}
|
|
3086
|
-
} else {
|
|
3087
|
-
query.push(
|
|
3088
|
-
{ $sort: { createdAt: -1 } },
|
|
3089
|
-
);
|
|
3090
|
-
}
|
|
3091
|
-
|
|
3092
|
-
query.push( {
|
|
3093
|
-
$facet: {
|
|
3094
|
-
data: [
|
|
3095
|
-
{ $skip: page },
|
|
3096
|
-
{ $limit: limit },
|
|
3097
|
-
],
|
|
3098
|
-
count: [
|
|
3099
|
-
{ $count: 'totalCount' },
|
|
3100
|
-
],
|
|
3101
|
-
},
|
|
3102
|
-
} );
|
|
3103
|
-
|
|
3104
|
-
let checkList = await checklistService.aggregate( query );
|
|
3105
|
-
|
|
3106
|
-
if ( !checkList[0].data.length ) {
|
|
3107
|
-
return res.sendError( 'no data found', 204 );
|
|
3108
|
-
}
|
|
3109
|
-
|
|
3110
|
-
checkList[0].data.forEach( ( item ) => {
|
|
3111
|
-
if ( item.storeCount > 0 && item.storeCount <= 9 ) {
|
|
3112
|
-
item.storeCount = '0' + item.storeCount;
|
|
3113
|
-
}
|
|
3114
|
-
if ( item.questionCount > 0 && item.questionCount <= 9 ) {
|
|
3115
|
-
item.questionCount = '0' + item.questionCount;
|
|
3116
|
-
}
|
|
3117
|
-
item.createdAt = dayjs( item.createdAt ).format( 'DD MMM, YYYY' );
|
|
3118
|
-
} );
|
|
3119
|
-
|
|
3120
|
-
return res.sendSuccess( { result: checkList[0].data, count: checkList[0].count[0].totalCount } );
|
|
3121
|
-
} catch ( e ) {
|
|
3122
|
-
logger.error( 'checklist V2 =>', e );
|
|
3123
|
-
return res.sendError( e, 500 );
|
|
3124
|
-
}
|
|
3125
|
-
};
|
|
3126
|
-
|
|
3127
2998
|
async function assignUsers( data ) {
|
|
3128
2999
|
let assignedData;
|
|
3129
3000
|
if ( data.coverage == 'store' ) {
|
|
3130
|
-
if ( data
|
|
3131
|
-
let
|
|
3132
|
-
let clusterDetails = await clusterServices.findOneCluster( query, { stores: 1, clusterName: 1 } );
|
|
3001
|
+
if ( data.type == 'cluster' ) {
|
|
3002
|
+
let clusterDetails = await clusterServices.findOneCluster( { _id: data.id }, { stores: 1, clusterName: 1 } );
|
|
3133
3003
|
if ( clusterDetails ) {
|
|
3134
3004
|
assignedData = {
|
|
3135
3005
|
checkFlag: true,
|
|
@@ -3137,15 +3007,13 @@ async function assignUsers( data ) {
|
|
|
3137
3007
|
checkListName: data.checkListName,
|
|
3138
3008
|
client_id: data?.clientId,
|
|
3139
3009
|
clusterName: clusterDetails?.clusterName,
|
|
3140
|
-
assignId: data
|
|
3010
|
+
assignId: data.id,
|
|
3141
3011
|
};
|
|
3142
3012
|
}
|
|
3143
3013
|
} else {
|
|
3144
|
-
let
|
|
3145
|
-
let storeDetails = await storeService.findOne( query );
|
|
3014
|
+
let storeDetails = await storeService.findOne( { _id: data.id } );
|
|
3146
3015
|
if ( storeDetails ) {
|
|
3147
|
-
let
|
|
3148
|
-
let userDetails = await userService.findOne( { email: email, clientId: data.clientId } );
|
|
3016
|
+
let userDetails = await userService.findOne( { userEmail: storeDetails?.spocDetails?.email, clientId: data.clientId } );
|
|
3149
3017
|
if ( !userDetails ) {
|
|
3150
3018
|
let userData = {
|
|
3151
3019
|
userName: storeDetails.spocDetails?.[0]?.name,
|
|
@@ -3153,7 +3021,7 @@ async function assignUsers( data ) {
|
|
|
3153
3021
|
mobileNumber: storeDetails.spocDetails?.[0]?.phone,
|
|
3154
3022
|
clientId: data.clientId,
|
|
3155
3023
|
};
|
|
3156
|
-
|
|
3024
|
+
createUser( userData );
|
|
3157
3025
|
}
|
|
3158
3026
|
assignedData = {
|
|
3159
3027
|
store_id: storeDetails.storeId,
|
|
@@ -3163,19 +3031,18 @@ async function assignUsers( data ) {
|
|
|
3163
3031
|
userEmail: userDetails.email,
|
|
3164
3032
|
userPhone: userDetails?.mobileNumber,
|
|
3165
3033
|
city: storeDetails?.storeProfile?.city,
|
|
3166
|
-
country: storeDetails?.
|
|
3034
|
+
country: storeDetails?.storeprofile?.country,
|
|
3167
3035
|
checkFlag: true,
|
|
3168
3036
|
checkListId: data.checklistId,
|
|
3169
3037
|
checkListName: data.checkListName,
|
|
3170
3038
|
client_id: data.clientId,
|
|
3171
|
-
assignId: data
|
|
3039
|
+
assignId: data.id,
|
|
3172
3040
|
};
|
|
3173
3041
|
}
|
|
3174
3042
|
}
|
|
3175
3043
|
} else {
|
|
3176
3044
|
if ( data.type == 'teams' ) {
|
|
3177
|
-
let
|
|
3178
|
-
let teamDetails = await teamsServices.findOneTeams( query, { users: 1, teamName: 1 } );
|
|
3045
|
+
let teamDetails = await teamsServices.findOneTeams( { _id: data.id }, { users: 1, teamName: 1 } );
|
|
3179
3046
|
if ( teamDetails ) {
|
|
3180
3047
|
assignedData = {
|
|
3181
3048
|
checkFlag: true,
|
|
@@ -3183,12 +3050,11 @@ async function assignUsers( data ) {
|
|
|
3183
3050
|
checkListName: data.checkListName,
|
|
3184
3051
|
client_id: data.clientId,
|
|
3185
3052
|
teamName: teamDetails?.teamName,
|
|
3186
|
-
assignId: data
|
|
3053
|
+
assignId: data.id,
|
|
3187
3054
|
};
|
|
3188
3055
|
}
|
|
3189
3056
|
} else {
|
|
3190
|
-
let
|
|
3191
|
-
let userDetails = await userService.findOne( query );
|
|
3057
|
+
let userDetails = await userService.findOne( { _id: { $in: data.id } } );
|
|
3192
3058
|
if ( userDetails ) {
|
|
3193
3059
|
assignedData = {
|
|
3194
3060
|
userId: userDetails._id,
|
|
@@ -3199,23 +3065,24 @@ async function assignUsers( data ) {
|
|
|
3199
3065
|
checkListId: data.checklistId,
|
|
3200
3066
|
checkListName: data.checkListName,
|
|
3201
3067
|
client_id: data.clientId,
|
|
3202
|
-
assignId: data
|
|
3068
|
+
assignId: data.id,
|
|
3203
3069
|
};
|
|
3204
3070
|
}
|
|
3205
3071
|
}
|
|
3206
3072
|
}
|
|
3207
|
-
|
|
3208
|
-
await assignedService.create( assignedData );
|
|
3209
|
-
}
|
|
3073
|
+
await assignedService.create( assignedData );
|
|
3210
3074
|
}
|
|
3211
3075
|
|
|
3212
3076
|
export async function checklistAssign( req, res ) {
|
|
3213
3077
|
try {
|
|
3078
|
+
if ( !req.body.type ) {
|
|
3079
|
+
return res.sendError( 'Type is required', 400 );
|
|
3080
|
+
}
|
|
3214
3081
|
if ( !req.body.coverage ) {
|
|
3215
3082
|
return res.sendError( 'coverage is required', 400 );
|
|
3216
3083
|
}
|
|
3217
|
-
if ( !req.body.
|
|
3218
|
-
return res.sendError( '
|
|
3084
|
+
if ( !req.body.id ) {
|
|
3085
|
+
return res.sendError( 'coverage is required', 400 );
|
|
3219
3086
|
}
|
|
3220
3087
|
if ( !req.body.checklistId ) {
|
|
3221
3088
|
return res.sendError( 'Checklist id is required', 400 );
|
|
@@ -3228,10 +3095,7 @@ export async function checklistAssign( req, res ) {
|
|
|
3228
3095
|
return res.sendError( 'No data found', 204 );
|
|
3229
3096
|
}
|
|
3230
3097
|
req.body.checkListName = checklistDetails.checkListName;
|
|
3231
|
-
await
|
|
3232
|
-
let storeData = { ...req.body, type: ele.type, id: ele.id };
|
|
3233
|
-
await assignUsers( storeData );
|
|
3234
|
-
} ) );
|
|
3098
|
+
await assignUsers( req.body );
|
|
3235
3099
|
return res.sendSuccess( 'Details updated successfully' );
|
|
3236
3100
|
} catch ( e ) {
|
|
3237
3101
|
logger.error( { functionName: 'checklistAssign', error: e } );
|