tango-app-api-trax 3.4.0-alpha-2 → 3.4.0-alpha-3

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.4.0-alpha-2",
3
+ "version": "3.4.0-alpha-3",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- import { logger } from 'tango-app-api-middleware';
3
+ import { logger, insertOpenSearchData } from 'tango-app-api-middleware';
4
4
  import * as storeService from '../services/store.service.js';
5
5
  import * as groupService from '../services/group.service.js';
6
6
  import * as clusterService from '../services/cluster.service.js';
@@ -383,14 +383,13 @@ export async function redoChecklist( req, res ) {
383
383
  return res.sendError( 'section is not found', 400 );
384
384
  }
385
385
 
386
- let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.qno == req.body.payload.qno );
387
-
386
+ let findQuestion = question[sectionIndex].questions.findIndex( ( ele ) => ele.uniqueNo == req.body.payload.uniqueNo );
388
387
  let data = { ...question[sectionIndex].questions[findQuestion], redo: true, redoComment: req.body.payload?.checklistDescription || '' };
389
388
  // if ( checklistDetails.client_id == '458' ) {
390
389
  data.answers.forEach( ( item ) => {
391
390
  if ( item.showLinked ) {
392
391
  item.nestedQuestion.forEach( ( ele ) => {
393
- let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.qno == parseInt( ele ) );
392
+ let eleIndex = question[sectionIndex].questions.findIndex( ( qn ) => qn.uniqueNo == parseInt( ele ) );
394
393
  let element = { ...question[sectionIndex].questions[eleIndex], redo: true, redoComment: '', linkquestionenabled: false };
395
394
  question[sectionIndex].questions[eleIndex] = element;
396
395
  question[sectionIndex].questions[eleIndex].userAnswer = [];
@@ -245,21 +245,37 @@ export async function startChecklistv1( req, res ) {
245
245
  for ( let [ index, data ] of getchecklist.entries() ) {
246
246
  for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
247
247
  questions = [];
248
- for ( let [ questionIdx, question ] of section.questions.entries() ) {
248
+ for ( let [ questionIndex, question ] of section.questions.entries() ) {
249
249
  let linkedQuestions;
250
+ let uniqueShow = false;
250
251
  if ( !question.linkType ) {
251
- question.uniqueNo = parseInt( getOtp() )+ Date.now() + questionIdx;
252
+ if ( !question?.uniqueNo ) {
253
+ uniqueShow = true;
254
+ question.uniqueNo = parseInt( getOtp() ) + Date.now() + questionIndex;
255
+ }
252
256
  questions.push( question );
253
257
  linkedQuestions = [];
254
- let questionList = new Map( section.questions.map( ( ele ) => [ ele.qno, ele ] ) );
258
+ let questionList;
259
+ if ( uniqueShow ) {
260
+ questionList = new Map( section.questions.map( ( ele ) => [ ele.qno, ele ] ) );
261
+ } else {
262
+ let uniqueList = question.answers.flatMap( ( ele ) => ele.nestedQuestion );
263
+ let filteredQuestion = section.questions.filter( ( ele ) => uniqueList.includes( ele?.uniqueNo ) );
264
+ questionList = new Map( filteredQuestion.map( ( ele ) => [ ele.uniqueNo, ele ] ) );
265
+ }
255
266
  question.answers.forEach( ( answer ) => {
256
267
  if ( answer.linkedQuestion ) {
257
268
  let nesedQuestion = [];
258
- answer.oldNestedQuestion = JSON.parse( JSON.stringify( answer.nestedQuestion ) );
269
+ answer.oldNestedQuestion = !uniqueShow ? JSON.parse( JSON.stringify( answer.oldNestedQuestion ) ) : JSON.parse( JSON.stringify( answer.nestedQuestion ) );
259
270
  answer.nestedQuestion.forEach( ( qn, qidx ) => {
260
271
  let getQn = questionList.get( qn );
261
272
  if ( getQn ) {
262
- let randomNo = parseInt( getOtp() ) + Date.now() + qidx;
273
+ let randomNo;
274
+ if ( !getQn?.uniqueNo || uniqueShow ) {
275
+ randomNo = parseInt( getOtp() ) + Date.now() + qidx;
276
+ } else {
277
+ randomNo = getQn?.uniqueNo;
278
+ }
263
279
  getQn = JSON.parse( JSON.stringify( getQn ) );
264
280
  getQn = { ...getQn, uniqueNo: randomNo };
265
281
  nesedQuestion.push( getQn );
@@ -274,9 +290,9 @@ export async function startChecklistv1( req, res ) {
274
290
  let nestedLinkqn = [];
275
291
  ele.answers.forEach( ( ans ) => {
276
292
  if ( ans.linkedQuestion ) {
277
- ans.oldNestedQuestion = JSON.parse( JSON.stringify( ans.nestedQuestion ) );
293
+ ans.oldNestedQuestion = !uniqueShow ? JSON.parse( JSON.stringify( ans.oldNestedQuestion ) ) : JSON.parse( JSON.stringify( ans.nestedQuestion ) );
278
294
  ans.nestedQuestion.forEach( ( nested, idx ) => {
279
- let findRandom = nesedQuestion.find( ( qn ) => qn.qno == nested && !nestedLinkqn.includes( qn.uniqueNo ) && !qn.updated );
295
+ let findRandom = nesedQuestion.find( ( qn ) => ( uniqueShow ? qn.qno == nested : qn.uniqueNo == nested ) && !nestedLinkqn.includes( qn.uniqueNo ) && !qn.updated );
280
296
  if ( findRandom ) {
281
297
  if ( ans.linkedQuestion == findRandom.qno ) {
282
298
  ans.oldLinkedQuestion = ans.linkedQuestion;
@@ -300,7 +316,9 @@ export async function startChecklistv1( req, res ) {
300
316
  getchecklist[index].questionAnswers[secIndex].questions = questions;
301
317
  }
302
318
  }
303
- await processedchecklist.updateOne( updateQuery, { questionAnswers: getchecklist[0].questionAnswers } );
319
+ if ( !getchecklist[0].redoStatus ) {
320
+ await processedchecklist.updateOne( updateQuery, { questionAnswers: getchecklist[0].questionAnswers } );
321
+ }
304
322
  getupdatedchecklist[0].questionAnswers.forEach( ( section ) => {
305
323
  section.questions.forEach( async ( question ) => {
306
324
  if ( question.questionReferenceImage && question.questionReferenceImage!='' ) {
@@ -3399,8 +3417,9 @@ export async function questionListv1( req, res ) {
3399
3417
  getchecklist[index].questionAnswers[secIndex].questions = questions;
3400
3418
  }
3401
3419
  }
3402
-
3403
- await processedchecklist.updateOne( { _id: requestData.processedcheckListId }, { questionAnswers: getchecklist[0].questionAnswers } );
3420
+ if ( !getchecklist[0].redoStatus ) {
3421
+ await processedchecklist.updateOne( { _id: requestData.processedcheckListId }, { questionAnswers: getchecklist[0].questionAnswers } );
3422
+ }
3404
3423
 
3405
3424
  return res.sendSuccess( getchecklist );
3406
3425
  }