tango-app-api-trax 3.7.5-halfshutter-2 → 3.7.12-qid-2

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.5-halfshutter-2",
3
+ "version": "3.7.12-qid-2",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -27,7 +27,7 @@
27
27
  "mongodb": "^6.8.0",
28
28
  "nodemon": "^3.1.4",
29
29
  "path": "^0.12.7",
30
- "tango-api-schema": "^2.4.4",
30
+ "tango-api-schema": "^2.4.5",
31
31
  "tango-app-api-middleware": "^3.5.2",
32
32
  "url": "^0.11.4",
33
33
  "winston": "^3.13.1",
@@ -1088,6 +1088,8 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1088
1088
  let data = { ...requestSection[0] };
1089
1089
  data.answerType = question.answerType;
1090
1090
  data.qno = question.qno;
1091
+ data.uniqueqno = question.uniqueqno;
1092
+ data.uniqueqid = question.uniqueqid;
1091
1093
  data.qname = question.qname;
1092
1094
  data.oldQname = question?.oldQname || question.qname;
1093
1095
  data.answer = 'null';
@@ -1110,6 +1112,8 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1110
1112
  data.sectionName = section.sectionName;
1111
1113
  data.answerType = ele.answerType;
1112
1114
  data.qno = ele.qno;
1115
+ data.uniqueqno = ele.uniqueqno;
1116
+ data.uniqueqid = ele.uniqueqid;
1113
1117
  data.qname = ele.qname;
1114
1118
  data.oldQname = ele?.oldQname || ele.qname;
1115
1119
  data.answer = 'null';
@@ -1171,6 +1175,8 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1171
1175
  }
1172
1176
  let structure = {};
1173
1177
  structure.qno = qaAnswers[j].qno;
1178
+ structure.uniqueqno = qaAnswers[j].uniqueqno;
1179
+ structure.uniqueqid = qaAnswers[j].uniqueqid;
1174
1180
  structure.qname = qaAnswers[j].qname;
1175
1181
  structure.answerType = qaAnswers[j].answerType;
1176
1182
  structure.runAI = qaAnswers[j].runAI;
@@ -1225,6 +1231,8 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1225
1231
  }
1226
1232
  let structure = {};
1227
1233
  structure.qno = qaAnswers[j].qno;
1234
+ structure.uniqueqno = qaAnswers[j].uniqueqno;
1235
+ structure.uniqueqid = qaAnswers[j].uniqueqid;
1228
1236
  structure.qname = qaAnswers[j].qname;
1229
1237
  structure.answerType = qaAnswers[j].answerType;
1230
1238
  structure.runAI = qaAnswers[j].runAI;
@@ -1283,6 +1291,8 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1283
1291
  }
1284
1292
  let structure = {};
1285
1293
  structure.qno = qaAnswers[j].qno;
1294
+ structure.uniqueqno = qaAnswers[j].uniqueqno;
1295
+ structure.qno = qaAnswers[j].qno;
1286
1296
  structure.qname = qaAnswers[j].qname;
1287
1297
  structure.answerType = qaAnswers[j].answerType;
1288
1298
  structure.runAI = qaAnswers[j].runAI;
@@ -1348,6 +1358,8 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1348
1358
  // }
1349
1359
  let structure = {};
1350
1360
  structure.qno = qaAnswers[j].qno;
1361
+ structure.uniqueqno = qaAnswers[j].uniqueqno;
1362
+ structure.uniqueqid = qaAnswers[j].uniqueqid;
1351
1363
  structure.qname = qaAnswers[j].qname;
1352
1364
  structure.answerType = qaAnswers[j].answerType;
1353
1365
  structure.runAI = qaAnswers[j].runAI;
@@ -1413,6 +1425,8 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
1413
1425
  }
1414
1426
  let structure = {};
1415
1427
  structure.qno = qaAnswers[j].qno;
1428
+ structure.uniqueqno = qaAnswers[j].uniqueqno;
1429
+ structure.uniqueqid = qaAnswers[j].uniqueqid;
1416
1430
  structure.qname = qaAnswers[j].qname;
1417
1431
  structure.answerType = qaAnswers[j].answerType;
1418
1432
  structure.runAI = qaAnswers[j].runAI;
@@ -169,12 +169,17 @@ export const create = async ( req, res ) => {
169
169
  // }
170
170
  // }
171
171
 
172
- let getchecklistNumber = await checklistService.findOne( { client_id: req.body.clientId, type: 'checklist' }, { checkListNumber: 1 } );
173
- if ( getchecklistNumber ) {
174
- checkNumber = getchecklistNumber.checkListNumber + 1;
175
- } else {
176
- checkNumber = 1;
177
- }
172
+ // let getchecklistNumber = await checklistService.findOne( { client_id: req.body.clientId, type: 'checklist' }, { checkListNumber: 1 } );
173
+ // if ( getchecklistNumber ) {
174
+ // checkNumber = getchecklistNumber.checkListNumber + 1;
175
+ // } else {
176
+ // checkNumber = 1;
177
+ // }
178
+ let result = await checklistService.aggregate( [
179
+ { $match: { client_id: req.body.clientId, type: 'checklist' } },
180
+ { $group: { _id: null, maxCheckListNumber: { $max: '$checkListNumber' } } },
181
+ ] );
182
+ checkNumber = result.length > 0 ? result[0].maxCheckListNumber+1 : 0;
178
183
 
179
184
  let runAIQuestionCount = 0;
180
185
 
@@ -243,6 +248,43 @@ export const create = async ( req, res ) => {
243
248
  // // }
244
249
  // } );
245
250
 
251
+ // Find max uniqueqno (ignore missing values)
252
+ // if ( section.questions && section.questions.length > 0 ) {
253
+ // let maxQID = Math.max( 0,
254
+ // ...section.questions .filter( ( q ) => q.uniqueqno !== undefined ) .map( ( q ) => q.uniqueqno ),
255
+ // );
256
+ // // Loop through questions
257
+ // for ( let [ index1, question ] of section.questions.entries() ) {
258
+ // if ( !question.uniqueqno ) {
259
+ // maxQID++; // increment
260
+ // section.questions[index1].uniqueqno = maxQID; // assign new ID
261
+ // }
262
+ // if ( !question.uniqueqid ) {
263
+ // section.questions[index1].uniqueqid = req.body.clientId+'-'+ checkNumber+'-'+ section.sectionNumber+'-'+ maxQID; // assign new ID
264
+ // }
265
+ // }
266
+ // }
267
+
268
+ let maxQID = 0;
269
+ if ( section.questions && section.questions.length > 0 ) {
270
+ // let qids = section.questions
271
+ // .filter( ( q ) => q.uniqueqno != null )
272
+ // .map( ( q ) => Number( q.uniqueqno ) );
273
+ // console.log( 'Extracted QIDs =>', qids );
274
+ // let maxQID = Math.max( 0, ...qids );
275
+ // console.log( 'maxQID =>', maxQID );
276
+
277
+ for ( let [ index1, questions ] of section.questions.entries() ) {
278
+ if ( !questions.uniqueqno ) {
279
+ maxQID++;
280
+ section.questions[index1].uniqueqno = maxQID;
281
+ }
282
+ if ( !questions.uniqueqid ) {
283
+ section.questions[index1].uniqueqid = req.body.clientId + '-' + checkListDetails.checkListNumber + '-' + section.sectionNumber + '-' + maxQID;
284
+ }
285
+ }
286
+ }
287
+
246
288
  for ( let [ index, question ] of section.questions.entries() ) {
247
289
  await processNested( index, question );
248
290
  }
@@ -288,6 +330,7 @@ export const create = async ( req, res ) => {
288
330
  question: section.questions,
289
331
  checkList: inputBody.checklistName,
290
332
  sectionNumber: section.sectionNumber,
333
+ maxQuestionNumber: maxQID,
291
334
  };
292
335
  await questionService.create( sectionList ).then( async ( data ) => {
293
336
  if ( i == inputBody.sections.length - 1 ) {
@@ -355,6 +398,7 @@ export const create = async ( req, res ) => {
355
398
  runAIFeatures: ans.runAIFeatures,
356
399
  multiReferenceImage: ans.multiReferenceImage,
357
400
  runAIDescription: ans.runAIDescription,
401
+ uniqueqid: question.uniqueqid || '',
358
402
  } );
359
403
  }
360
404
  } );
@@ -469,6 +513,7 @@ export const getConfigDetails = async ( req, res ) => {
469
513
  oldName: item?.sectionOldName,
470
514
  questions: item.question,
471
515
  sectionNumber: item.sectionNumber,
516
+ maxQuestionNumber: item?.maxQuestionNumber,
472
517
  } );
473
518
  } );
474
519
  sectionList = sections;
@@ -546,12 +591,7 @@ export const zoneList = async ( req, res ) => {
546
591
  try {
547
592
  let inputBody = req.query;
548
593
 
549
- const allowedChecklists = [
550
- 'Outside Business Hours Queue Tracking',
551
- 'Store Half Shutter Detection',
552
- ];
553
-
554
- if ( inputBody.checkListName && allowedChecklists.includes( inputBody.checkListName ) ) {
594
+ if ( inputBody.checkListName && inputBody.checkListName == 'Outside Business Hours Queue Tracking' ) {
555
595
  let query = [
556
596
  {
557
597
  $match: {
@@ -788,6 +828,7 @@ export const duplicateChecklist = async ( req, res ) => {
788
828
  dupDetails.createdAt = new Date();
789
829
  dupDetails.updatedAt = new Date();
790
830
  dupDetails.publishDate = '';
831
+ dupDetails.checkListNumber = dupDetails.checkListNumber+1;
791
832
  delete dupDetails._id;
792
833
  let logInsertData = {
793
834
  action: 'duplicateChecklist',
@@ -941,6 +982,31 @@ export const update = async ( req, res ) => {
941
982
  // } );
942
983
  // } );
943
984
 
985
+ // Find max uniqueqno (cast to number, ignore null/undefined)
986
+ let maxQID;
987
+ if ( section.questions && section.questions.length > 0 ) {
988
+ // let qids = section.questions
989
+ // .filter( ( q ) => q.uniqueqno != null )
990
+ // .map( ( q ) => Number( q.uniqueqno ) );
991
+ // console.log( 'Extracted QIDs =>', qids );
992
+ // let maxQID = Math.max( 0, ...qids );
993
+ // console.log( 'maxQID =>', maxQID );
994
+ if ( section.maxQuestionNumber > 0 ) {
995
+ maxQID = section.maxQuestionNumber || 0;
996
+ } else {
997
+ maxQID = section.questions.length || 0;
998
+ }
999
+ for ( let [ index1, questions ] of section.questions.entries() ) {
1000
+ if ( questions?.uniqueqno == null || questions.uniqueqno === 0 ) {
1001
+ maxQID++;
1002
+ section.questions[index1].uniqueqno = maxQID;
1003
+ }
1004
+ if ( questions?.uniqueqid == null || questions.uniqueqid === '' ) {
1005
+ section.questions[index1].uniqueqid = req.body.clientId + '-' + checkListDetails.checkListNumber + '-' + section.sectionNumber + '-' + maxQID;
1006
+ }
1007
+ }
1008
+ }
1009
+
944
1010
  for ( let [ index, question ] of section.questions.entries() ) {
945
1011
  await processNested( index, question );
946
1012
  }
@@ -987,6 +1053,7 @@ export const update = async ( req, res ) => {
987
1053
  question: section.questions,
988
1054
  checkList: inputBody.checklistName,
989
1055
  sectionNumber: section.sectionNumber,
1056
+ maxQuestionNumber: maxQID,
990
1057
  } );
991
1058
  }
992
1059
  }
@@ -1152,6 +1219,7 @@ export const update = async ( req, res ) => {
1152
1219
  runAIFeatures: ans.runAIFeatures,
1153
1220
  multiReferenceImage: ans.multiReferenceImage,
1154
1221
  runAIDescription: ans.runAIDescription,
1222
+ uniqueqid: question.uniqueqid || '',
1155
1223
  } );
1156
1224
  }
1157
1225
  } );
@@ -3950,7 +4018,7 @@ async function updateOpenSearch( user, data ) {
3950
4018
  export const aiChecklist = async ( req, res ) => {
3951
4019
  try {
3952
4020
  let storeDetails = await storeService.count( { clientId: req.query.clientId, status: 'active' } );
3953
- let aiList = [ 'mobileusagedetection', 'storeopenandclose', 'uniformdetection', 'staffleftinthemiddle', 'customerunattended', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo', 'vehicle_check_in', 'outsidebusinesshoursqueuetracking', 'halfshutter' ];
4021
+ let aiList = [ 'mobileusagedetection', 'storeopenandclose', 'uniformdetection', 'staffleftinthemiddle', 'customerunattended', 'eyetest', 'remoteoptometrist', 'storehygienemonitoring', 'queuealert', 'cleaning', 'scrum', 'suspiciousactivity', 'boxalert', 'suspiciousfootfall', 'drinking', 'bagdetection', 'inventorycount', 'carsattended', 'numberplateinfo', 'vehicle_check_in', 'outsidebusinesshoursqueuetracking' ];
3954
4022
  let checklistDetails = [];
3955
4023
  let publishList = [];
3956
4024
  let unpublishList = [];
@@ -3963,7 +4031,7 @@ export const aiChecklist = async ( req, res ) => {
3963
4031
  checklistDetails = [ ...publishList, ...unpublishList ];
3964
4032
 
3965
4033
  checklistDetails.forEach( ( item ) => {
3966
- if ( ![ 'mobileusagedetection', 'storeopenandclose', 'cleaning', 'scrum', 'uniformdetection', 'staffleftinthemiddle', 'customerunattended', 'outsidebusinesshoursqueuetracking', 'halfshutter' ].includes( item.checkListType ) ) {
4034
+ if ( ![ 'mobileusagedetection', 'storeopenandclose', 'cleaning', 'scrum', 'uniformdetection', 'staffleftinthemiddle', 'customerunattended', 'outsidebusinesshoursqueuetracking' ].includes( item.checkListType ) ) {
3967
4035
  item.storeCount = storeDetails;
3968
4036
  }
3969
4037
  } );
@@ -4723,6 +4791,7 @@ export async function updateRunAIRequest( req, res ) {
4723
4791
  sectionNo: inputBody.sectionNo || '',
4724
4792
  qname: inputBody.qname,
4725
4793
  answer: inputBody.answer,
4794
+ uniqueqid: inputBody.uniqueqid,
4726
4795
  };
4727
4796
  let checkRunAIRequest = await runAIRequestServices.findOne( checkRunAIRequestQuery );
4728
4797