tango-app-api-trax 3.7.4-runai-airtelv2-11 → 3.7.4-runai-airtelv2-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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-trax",
3
- "version": "3.7.4-runai-airtelv2-11",
3
+ "version": "3.7.4-runai-airtelv2-12",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1081,7 +1081,222 @@ async function getLocationStores( userClientId, cityList, req ) {
1081
1081
  return false;
1082
1082
  }
1083
1083
  }
1084
+ export async function headerClustersV2( req, res ) {
1085
+ try {
1086
+ let requestData = req.body;
1087
+ let getUserEmail = req.user.email;
1088
+ let clientId = req?.user?.clientId;
1089
+ let getUserType = req.user.userType;
1090
+ let getRole = req.user.role;
1091
+ let clusterNames=[];
1092
+ if ( requestData.city && requestData.city.length>0 ) {
1093
+ let getcityclustes = await getCityClusters( requestData.clientId, getUserEmail, getRole, requestData.city, getUserType, req );
1094
+ if ( getcityclustes && getcityclustes.length>0 ) {
1095
+ clusterNames = getcityclustes;
1096
+ } else {
1097
+ clusterNames = [];
1098
+ }
1099
+ } else {
1100
+ if ( getUserType == 'tango' ) {
1101
+ clusterNames = await getclusterList( requestData.clientId, getUserType, getRole, req );
1102
+ } else if ( getUserType == 'client' ) {
1103
+ if ( getRole == 'superadmin' ) {
1104
+ clusterNames = await getclusterList( clientId, getUserType, getRole, req );
1105
+ } else {
1106
+ clusterNames = await getclusterList( clientId, getUserType, getRole, req );
1107
+ }
1108
+ }
1109
+ }
1110
+ if ( clusterNames.length>0 ) {
1111
+ const dataObjects = clusterNames.map( ( item ) => ( { groupName: item } ) );
1112
+ res.sendSuccess( { groupData: dataObjects } );
1113
+ } else {
1114
+ res.sendSuccess( { groupData: [] } );
1115
+ }
1116
+ } catch ( error ) {
1117
+ logger.error( { error: error, message: req.query, function: 'headerClustersV2' } );
1118
+ return res.sendError( { error: error }, 500 );
1119
+ }
1120
+ }
1121
+ async function getCityClusters( userClientId, getUserEmail, getRole, requestCity, getUserType, req ) {
1122
+ try {
1123
+ if ( userClientId && userClientId !='' && getUserEmail && getUserEmail !='', getRole && getRole !='', requestCity && requestCity.length>0 ) {
1124
+ let cityStores = await getLocationStores( userClientId, requestCity, req );
1125
+ if ( cityStores && cityStores.length > 0 ) {
1126
+ let storeGroups = await getClusterStoresIds( userClientId, cityStores, getRole, getUserType, getUserEmail, req );
1127
+ if ( storeGroups && storeGroups.length > 0 ) {
1128
+ return storeGroups;
1129
+ } else {
1130
+ return false;
1131
+ }
1132
+ } else {
1133
+ return false;
1134
+ }
1135
+ } else {
1136
+ return false;
1137
+ }
1138
+ } catch ( error ) {
1139
+ logger.error( { error: error, function: 'getCityClusters' } );
1140
+ return false;
1141
+ }
1142
+ }
1143
+ async function getclusterList( userClientId, getUserType, getRole, req ) {
1144
+ try {
1145
+ if ( userClientId && userClientId !='' || getUserType === 'tango' ) {
1146
+ let filter = [];
1147
+ if ( userClientId && userClientId !='' ) {
1148
+ filter.push( { clientId: { $eq: userClientId } },
1149
+ );
1150
+ }
1151
+ if ( req.body.assignedStores&&req.body.assignedStores.length>0 ) {
1152
+ filter.push( { 'stores.storeId': { $in: req.body.assignedStores } } );
1153
+ }
1154
+ if ( getUserType == 'client'&&getRole!='superadmin' ) {
1155
+ filter.push( { 'Teamlead.email': req.user.email } );
1156
+ }
1157
+ let clusterQuery = [];
1158
+
1159
+ if ( filter.length > 0 ) {
1160
+ clusterQuery.push( { $match: { $and: filter } } );
1161
+ }
1162
+
1163
+ clusterQuery.push( {
1164
+ $group: {
1165
+ _id: null,
1166
+ clusterName: { $push: '$clusterName' },
1167
+ },
1168
+ } );
1169
+ const clusterIds = await clusterService.aggregateCluster( clusterQuery );
1170
+ if ( clusterIds && clusterIds.length>0 && clusterIds[0]?.clusterName.length > 0 ) {
1171
+ let uniqueclusterIds = [ ...new Set( clusterIds[0].clusterName ) ];
1172
+ return uniqueclusterIds;
1173
+ } else {
1174
+ return false;
1175
+ }
1176
+ } else {
1177
+ return false;
1178
+ }
1179
+ } catch ( error ) {
1180
+ logger.error( { error: error, function: 'getclusterList' } );
1181
+ return false;
1182
+ }
1183
+ }
1184
+ async function getClusterStoresIds( userClientId, storeIds, getRole, getUserType, getUserEmail, req ) {
1185
+ try {
1186
+ if ( userClientId && userClientId !='' && storeIds && storeIds !='' && getRole && getRole !='' && getUserType && getUserType !='', getUserEmail && getUserEmail !='' ) {
1187
+ let clusterQuery = [];
1188
+ if ( getUserType == 'client' ) {
1189
+ if ( getRole == 'superadmin' ) {
1190
+ clusterQuery = [
1191
+ {
1192
+ $match: {
1193
+ $and: [
1194
+ { clientId: { $eq: userClientId } },
1195
+ { 'stores.storeId': { $in: storeIds } },
1196
+ ],
1197
+ },
1198
+ },
1199
+ {
1200
+ $group: {
1201
+ _id: null,
1202
+ clusterName: { $push: '$clusterName' },
1203
+ },
1204
+ },
1205
+ ];
1206
+ } else {
1207
+ let getAssignedGroupIds = [
1208
+ {
1209
+ $match: {
1210
+ $and: [
1211
+ { clientId: { $eq: userClientId } },
1212
+ { 'stores.storeId': { $in: storeIds } },
1213
+ { 'Teamlead.email': req.user.email },
1214
+ ],
1215
+ },
1216
+ },
1217
+ {
1218
+ $group: {
1219
+ _id: null,
1220
+ clusterName: { $push: '$clusterName' },
1221
+ },
1222
+ },
1223
+ ];
1224
+ const assignedclusters = await clusterService.aggregateCluster( getAssignedGroupIds );
1225
+ if ( assignedclusters && assignedclusters.length>0 && assignedclusters[0]?.clusterName.length > 0 ) {
1226
+ let uniqueclusters = [ ...new Set( assignedclusters[0].clusterName ) ];
1227
+ return uniqueclusters;
1228
+ }
1229
+ }
1230
+ } else if ( getUserType == 'tango' ) {
1231
+ clusterQuery = [
1232
+ {
1233
+ $match: {
1234
+ $and: [
1235
+ { clientId: { $eq: userClientId } },
1236
+ { 'stores.storeId': { $in: storeIds } },
1237
+ ],
1238
+ },
1239
+ },
1240
+ {
1241
+ $group: {
1242
+ _id: null,
1243
+ clusterName: { $push: '$clusterName' },
1244
+ },
1245
+ },
1246
+ ];
1247
+ }
1084
1248
 
1249
+ const assignedclusters = await clusterService.aggregateCluster( clusterQuery );
1250
+ if ( assignedclusters && assignedclusters.length>0 && assignedclusters[0]?.clusterName.length > 0 ) {
1251
+ let uniqueclusters = [ ...new Set( assignedclusters[0].clusterName ) ];
1252
+ return uniqueclusters;
1253
+ } else {
1254
+ return false;
1255
+ }
1256
+ } else {
1257
+ return false;
1258
+ }
1259
+ } catch ( error ) {
1260
+ logger.error( { error: error, function: 'getGroupIds' } );
1261
+ return false;
1262
+ }
1263
+ }
1264
+ export const headerLocationsV2 = async ( req, res ) => {
1265
+ try {
1266
+ let reqestData = req.body;
1267
+ let getUserEmail = req.user.email;
1268
+ let getUserType = req.user.userType;
1269
+ let getRole = req.user.role;
1270
+ let getClientId = reqestData.clientId;
1271
+ let totalStores = await getStoresList( getUserEmail, getClientId, getUserType, getRole, req );
1272
+ if ( totalStores && totalStores.length>0 ) {
1273
+ let storeQuery = [];
1274
+ storeQuery.push( { $match: { $and: [ { clientId: { $eq: getClientId } }, { storeId: { $in: totalStores } } ] } } );
1275
+
1276
+ if ( reqestData.country && reqestData.country.length>0 ) {
1277
+ storeQuery.push( { $match: { $and: [ { 'storeProfile.country': { $in: reqestData.country || [] } } ] } } );
1278
+ }
1279
+
1280
+ storeQuery.push(
1281
+ { $group: { _id: '$storeProfile.city' } },
1282
+ { $project: { _id: 0, city: '$_id' } },
1283
+ { $sort: { city: -1 } },
1284
+ );
1285
+ const cityList = await storeService.aggregate( storeQuery );
1286
+ if ( cityList && cityList.length > 0 ) {
1287
+ let city = cityList.filter( ( data ) => data.city!='' );
1288
+ return res.sendSuccess( { locationData: city } );
1289
+ } else {
1290
+ return res.sendError( 'No City', 400 );
1291
+ }
1292
+ } else {
1293
+ return res.sendError( 'No stores', 400 );
1294
+ }
1295
+ } catch ( error ) {
1296
+ logger.error( { error: error, message: req.query, function: 'trafficCards' } );
1297
+ return res.sendError( { error: error }, 500 );
1298
+ }
1299
+ };
1085
1300
  export async function teamsList( req, res ) {
1086
1301
  try {
1087
1302
  let query = [
@@ -1,185 +1,193 @@
1
1
  import joi from 'joi';
2
2
 
3
- export const checklistSchema = joi.object( {
3
+ export const checklistSchema = joi.object({
4
4
  checklistName: joi.string().required(),
5
- checklistDescription: joi.string().optional().allow( '' ),
5
+ checklistDescription: joi.string().optional().allow(''),
6
6
  sections: joi.array().required(),
7
7
  submitType: joi.string().required(),
8
8
  clientId: joi.string().required(),
9
- } );
9
+ });
10
10
 
11
11
  export const checklistValidation = {
12
12
  body: checklistSchema,
13
13
  };
14
- export const validateHeaderSchemav2 = joi.object( {
14
+ export const validateHeaderSchema = joi.object({
15
+ clientId: joi.string().required().allow(''),
16
+ city: joi.array().required(),
17
+ group: joi.array().required(),
18
+ country: joi.array().optional().empty(),
19
+ });
20
+ export const validateHeaderSchemav2 = joi.object({
15
21
  clientId: joi.string().required(),
16
22
  city: joi.array().required(),
17
23
  clusters: joi.array().required(),
18
- } );
24
+ });
19
25
  export const validateHeaderParamsv2 = {
20
26
  body: validateHeaderSchemav2,
21
27
  };
28
+ export const validateHeaderParams = {
29
+ body: validateHeaderSchema,
30
+ };
22
31
 
23
-
24
- export const checklistDetailsSchema = joi.object( {
32
+ export const checklistDetailsSchema = joi.object({
25
33
  checkListId: joi.string().optional(),
26
34
  type: joi.string().optional(),
27
35
  clientId: joi.string().optional(),
28
- } );
36
+ });
29
37
 
30
38
  export const checklistDetailsValidation = {
31
39
  query: checklistDetailsSchema,
32
40
  };
33
41
 
34
- export const duplicateSchema = joi.object( {
42
+ export const duplicateSchema = joi.object({
35
43
  checklistId: joi.string().required(),
36
- } );
44
+ });
37
45
 
38
46
  export const duplicateValidation = {
39
47
  params: duplicateSchema,
40
48
  };
41
49
 
42
- export const updateChecklistSchema = joi.object( {
50
+ export const updateChecklistSchema = joi.object({
43
51
  checklistName: joi.string().required(),
44
- checklistDescription: joi.string().optional().allow( '' ),
52
+ checklistDescription: joi.string().optional().allow(''),
45
53
  sections: joi.array().required(),
46
54
  submitType: joi.string().required(),
47
55
  clientId: joi.string().required(),
48
- } );
56
+ });
49
57
 
50
58
  export const updateChecklistValidation = {
51
59
  body: updateChecklistSchema,
52
60
  params: duplicateSchema,
53
61
  };
54
62
 
55
- export const runaiSchema = joi.object( {
56
- checklistName: joi.string().optional().allow( '' ),
57
- questionName: joi.string().optional().allow( '' ),
58
- runAIDescription: joi.string().optional().allow( '' ),
59
- answerType: joi.string().optional().allow( '' ),
60
- referenceImage: joi.array().items( joi.any() ).min( 0 ),
61
- clientId: joi.string().optional().allow( '' ),
62
- } );
63
+ export const runaiSchema = joi.object({
64
+ checklistName: joi.string().optional().allow(''),
65
+ questionName: joi.string().optional().allow(''),
66
+ runAIDescription: joi.string().optional().allow(''),
67
+ answerType: joi.string().optional().allow(''),
68
+ referenceImage: joi.array().items(joi.any()).min(0),
69
+ clientId: joi.string().optional().allow(''),
70
+ });
63
71
 
64
72
  export const runaiValidation = {
65
73
  body: runaiSchema,
66
74
  };
67
75
 
68
- export const checklistPageSchema = joi.object( {
76
+ export const checklistPageSchema = joi.object({
69
77
  clientId: joi.string().required(),
70
78
  startDate: joi.string().required(),
71
79
  endDate: joi.string().required(),
72
80
  limit: joi.string().required(),
73
81
  offset: joi.string().required(),
74
- sortColumn: joi.string().optional().allow( '' ),
75
- sortBy: joi.string().optional().allow( '' ),
76
- search: joi.string().optional().allow( '' ),
77
- } );
82
+ sortColumn: joi.string().optional().allow(''),
83
+ sortBy: joi.string().optional().allow(''),
84
+ search: joi.string().optional().allow(''),
85
+ });
78
86
 
79
87
  export const checklistPageValidation = {
80
88
  body: checklistSchema,
81
89
  };
82
90
 
83
- export const uploadUserSchema = joi.object( {
91
+ export const uploadUserSchema = joi.object({
84
92
  id: joi.string().optional(),
85
93
  checklistId: joi.string().optional(),
86
94
  assignedUsers: joi.array().optional(),
87
95
  uploadUser: joi.boolean().optional(),
88
- type: joi.string().optional().allow( '' ),
96
+ type: joi.string().optional().allow(''),
89
97
  addUser: joi.boolean().optional(),
90
98
  delete: joi.boolean().optional(),
91
99
  clientId: joi.string().optional(),
92
100
  coverage: joi.string().optional(),
93
- } );
101
+ });
94
102
 
95
103
  export const uploadUserValidation = {
96
104
  body: uploadUserSchema,
97
105
  };
98
106
 
99
- export const aichecklistSchema = joi.object( {
107
+ export const aichecklistSchema = joi.object({
100
108
  clientId: joi.string().required(),
101
- } );
109
+ });
102
110
 
103
111
  export const aichecklistValidation = {
104
112
  query: aichecklistSchema,
105
113
  };
106
114
 
107
- export const publishValidationSchema = joi.object( {
115
+ export const publishValidationSchema = joi.object({
108
116
  type: joi.string().optional(),
109
117
  clientId: joi.string().optional(),
110
118
  checklistId: joi.string().optional(),
111
119
  publish: joi.boolean().required(),
112
- } );
120
+ });
113
121
 
114
122
  export const publishValidation = {
115
123
  body: publishValidationSchema,
116
124
  };
117
125
 
118
- export const dashboardSchema = joi.object( {
119
- store_id: joi.string().optional().allow( '' ),
126
+ export const dashboardSchema = joi.object({
127
+ store_id: joi.string().optional().allow(''),
120
128
  date: joi.string().required(),
121
- } );
129
+ });
122
130
 
123
131
  export const dashboardValidation = {
124
132
  query: dashboardSchema,
125
133
  };
126
134
 
127
- export const mobileChecklistSchema = joi.object( {
135
+ export const mobileChecklistSchema = joi.object({
128
136
  limit: joi.string().optional(),
129
137
  offset: joi.string().optional(),
130
138
  date: joi.string().optional(),
131
- store_id: joi.string().optional().allow( '' ),
132
- checklistStatus: joi.string().optional().allow( '' ),
133
- searchValue: joi.string().optional().allow( '' ),
134
- } );
139
+ store_id: joi.string().optional().allow(''),
140
+ checklistStatus: joi.string().optional().allow(''),
141
+ searchValue: joi.string().optional().allow(''),
142
+ });
135
143
 
136
144
  export const mobileChecklistValidation = {
137
145
  query: mobileChecklistSchema,
138
146
  };
139
147
 
140
- export const startSchema = joi.object( {
148
+ export const startSchema = joi.object({
141
149
  date: joi.string().required(),
142
150
  processedcheckListId: joi.string().required(),
143
- currentTime: joi.string().optional().allow( '' ),
144
- } );
151
+ currentTime: joi.string().optional().allow(''),
152
+ });
145
153
 
146
154
  export const startValidation = {
147
155
  body: startSchema,
148
156
  };
149
157
 
150
- export const selectAssignSchema = joi.object( {
158
+ export const selectAssignSchema = joi.object({
151
159
  clientId: joi.string().required(),
152
160
  coverage: joi.string().required(),
153
161
  assignType: joi.string().required(),
154
- } );
162
+ });
155
163
 
156
164
  export const selectAssign = {
157
165
  body: selectAssignSchema,
158
166
  };
159
167
 
160
- export const createChecklistNameSchema = joi.object( {
168
+ export const createChecklistNameSchema = joi.object({
161
169
  clientId: joi.string().required(),
162
170
  checkListName: joi.string().required(),
163
171
  checklistDescription: joi.string().optional(),
164
- } );
172
+ });
165
173
 
166
174
  export const createChecklistNameValidation = {
167
175
  body: createChecklistNameSchema,
168
176
  };
169
177
 
170
- export const runAIRequestSchema = joi.object( {
178
+ export const runAIRequestSchema = joi.object({
171
179
  clientId: joi.string().required(),
172
180
  checkListId: joi.string().required(),
173
- checkListName: joi.string().optional().allow( '' ),
181
+ checkListName: joi.string().optional().allow(''),
174
182
  sectionNo: joi.number().required(),
175
- sectionName: joi.string().optional().allow( '' ),
183
+ sectionName: joi.string().optional().allow(''),
176
184
  qname: joi.string().required(),
177
- answerType: joi.string().optional().allow( '' ),
178
- answer: joi.string().optional().allow( '' ),
185
+ answerType: joi.string().optional().allow(''),
186
+ answer: joi.string().optional().allow(''),
179
187
  runAI: joi.boolean().required(),
180
- runAIFeatures: joi.array().optional().allow( '' ),
181
- referenceImages: joi.array().items( joi.any() ).min( 0 ),
182
- } );
188
+ runAIFeatures: joi.array().optional().allow(''),
189
+ referenceImages: joi.array().items(joi.any()).min(0),
190
+ });
183
191
 
184
192
  export const runAIRequestValidation = {
185
193
  body: runAIRequestSchema,