tango-app-api-trax 3.7.4-runai-airtelv2-8 → 3.7.12-qid-1

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-8",
3
+ "version": "3.7.12-qid-1",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -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,23 @@ export const create = async ( req, res ) => {
243
248
  // // }
244
249
  // } );
245
250
 
251
+ if ( section.questions && section.questions.length > 0 ) {
252
+ // Find max uniqueqno (ignore missing values)
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
+
246
268
  for ( let [ index, question ] of section.questions.entries() ) {
247
269
  await processNested( index, question );
248
270
  }
@@ -355,6 +377,7 @@ export const create = async ( req, res ) => {
355
377
  runAIFeatures: ans.runAIFeatures,
356
378
  multiReferenceImage: ans.multiReferenceImage,
357
379
  runAIDescription: ans.runAIDescription,
380
+ uniqueqid: question.uniqueqid || '',
358
381
  } );
359
382
  }
360
383
  } );
@@ -783,6 +806,7 @@ export const duplicateChecklist = async ( req, res ) => {
783
806
  dupDetails.createdAt = new Date();
784
807
  dupDetails.updatedAt = new Date();
785
808
  dupDetails.publishDate = '';
809
+ dupDetails.checkListNumber = dupDetails.checkListNumber+1;
786
810
  delete dupDetails._id;
787
811
  let logInsertData = {
788
812
  action: 'duplicateChecklist',
@@ -935,7 +959,39 @@ export const update = async ( req, res ) => {
935
959
  // }
936
960
  // } );
937
961
  // } );
962
+ console.log( 'heelos =>' );
963
+ if ( section.questions && section.questions.length > 0 ) {
964
+ // Find max uniqueqno (cast to number, ignore null/undefined)
965
+ console.log( 'section.questions =>', section.questions );
966
+ console.log( 'section.questions =>', section.questions[0] );
967
+ let qids = section.questions
968
+ .filter( ( q ) => q.uniqueqno != null )
969
+ .map( ( q ) => Number( q.uniqueqno ) );
970
+
971
+ console.log( 'Extracted QIDs =>', qids );
972
+
973
+ let maxQID = Math.max( 0, ...qids );
974
+ console.log( 'maxQID =>', maxQID );
975
+
976
+ for ( let [ index1, questions ] of section.questions.entries() ) {
977
+ if ( !questions.uniqueqno ) {
978
+ maxQID++;
979
+ section.questions[index1].uniqueqno = maxQID;
980
+ }
981
+ if ( !questions.uniqueqid ) {
982
+ section.questions[index1].uniqueqid =
983
+ req.body.clientId +
984
+ '-' +
985
+ checkListDetails.checkListNumber +
986
+ '-' +
987
+ section.sectionNumber +
988
+ '-' +
989
+ maxQID;
990
+ }
991
+ }
992
+ }
938
993
 
994
+ console.log( 'else =>' );
939
995
  for ( let [ index, question ] of section.questions.entries() ) {
940
996
  await processNested( index, question );
941
997
  }
@@ -1147,6 +1203,7 @@ export const update = async ( req, res ) => {
1147
1203
  runAIFeatures: ans.runAIFeatures,
1148
1204
  multiReferenceImage: ans.multiReferenceImage,
1149
1205
  runAIDescription: ans.runAIDescription,
1206
+ uniqueqid: question.uniqueqid || '',
1150
1207
  } );
1151
1208
  }
1152
1209
  } );
@@ -4718,6 +4775,7 @@ export async function updateRunAIRequest( req, res ) {
4718
4775
  sectionNo: inputBody.sectionNo || '',
4719
4776
  qname: inputBody.qname,
4720
4777
  answer: inputBody.answer,
4778
+ uniqueqid: inputBody.uniqueqid,
4721
4779
  };
4722
4780
  let checkRunAIRequest = await runAIRequestServices.findOne( checkRunAIRequestQuery );
4723
4781