tango-app-api-trax 3.4.0-alpha-2 → 3.4.0-alpha-5
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
|
|
|
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.
|
|
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.
|
|
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 [
|
|
248
|
+
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
249
249
|
let linkedQuestions;
|
|
250
|
+
let uniqueShow = false;
|
|
250
251
|
if ( !question.linkType ) {
|
|
251
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -3205,7 +3205,9 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3205
3205
|
let findQuestion = getsubmitDetails[0].questionAnswers[index].questions.findIndex( ( ele ) => ele.qname.trim() == qns?.oldQname?.trim() || ele.qname.trim() == qns.qname.trim() );
|
|
3206
3206
|
if ( findQuestion != -1 ) {
|
|
3207
3207
|
let data = JSON.parse( JSON.stringify( getsubmitDetails[0].questionAnswers[index].questions[findQuestion] ) );
|
|
3208
|
-
getsubmitDetails[0].questionAnswers[index].questions[findQuestion].qno
|
|
3208
|
+
if ( getsubmitDetails[0].questionAnswers[index].questions[findQuestion].qno != qns.qno ) {
|
|
3209
|
+
question.push( { question: qns, type: 'noChange' } );
|
|
3210
|
+
}
|
|
3209
3211
|
delete data.userAnswer;
|
|
3210
3212
|
delete data.parentanswer;
|
|
3211
3213
|
delete data.remarks;
|
|
@@ -3246,13 +3248,44 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3246
3248
|
}
|
|
3247
3249
|
} );
|
|
3248
3250
|
// getsubmitDetails[0].questionAnswers[index].questions = question;
|
|
3249
|
-
|
|
3251
|
+
if ( question.length ) {
|
|
3252
|
+
sectionList.push( { sectionName: section.sectionName, oldName: section.sectionOldName, question: question, type: 'edit' } );
|
|
3253
|
+
}
|
|
3250
3254
|
} else {
|
|
3251
3255
|
modifiedCount++;
|
|
3252
3256
|
sectionList.push( { section: section, type: 'add' } );
|
|
3253
3257
|
}
|
|
3254
3258
|
}
|
|
3259
|
+
let removed = [];
|
|
3260
|
+
getsubmitDetails[0].questionAnswers.forEach( ( section, sectionIdx ) => {
|
|
3261
|
+
let sectionIndex = questionList.findIndex( ( sec ) => section.sectionName == sec?.sectionOldName || section.sectionName == sec.sectionName );
|
|
3262
|
+
if ( sectionIndex == -1 ) {
|
|
3263
|
+
removed.push( { section: section.sectionName, type: 'delete' } );
|
|
3264
|
+
} else {
|
|
3265
|
+
let question = [];
|
|
3266
|
+
section.questions.forEach( ( qn ) => {
|
|
3267
|
+
let questionIndex = questionList[sectionIndex].questions.findIndex( ( ele ) => qn.qname.trim() == ele?.oldQname?.trim() || qn.qname.trim() == ele.qname.trim() );
|
|
3268
|
+
if ( questionIndex == -1 ) {
|
|
3269
|
+
question.push( qn.qname );
|
|
3270
|
+
}
|
|
3271
|
+
} );
|
|
3272
|
+
if ( question.length ) {
|
|
3273
|
+
removed.push( { section: section.sectionName, question: question, type: 'qnDelete' } );
|
|
3274
|
+
}
|
|
3275
|
+
}
|
|
3276
|
+
} );
|
|
3277
|
+
removed.forEach( ( ele ) => {
|
|
3278
|
+
if ( ele?.type == 'delete' ) {
|
|
3279
|
+
getsubmitDetails[0].questionAnswers = getsubmitDetails[0].questionAnswers.filter( ( section ) => section.sectionName != ele.section );
|
|
3280
|
+
} else {
|
|
3281
|
+
let sectionIndex = getsubmitDetails[0].questionAnswers.findIndex( ( section ) => section.sectionName == ele?.section );
|
|
3282
|
+
getsubmitDetails[0].questionAnswers[sectionIndex].questions = getsubmitDetails[0].questionAnswers[sectionIndex].questions.filter( ( qns ) => !qns.qname.includes( ele.question ) );
|
|
3283
|
+
}
|
|
3284
|
+
} );
|
|
3285
|
+
|
|
3255
3286
|
// getsubmitDetails[0].questionAnswers = sectionList;
|
|
3287
|
+
logger.info( 'removedSections =>', { data: JSON.stringify( removed ) } );
|
|
3288
|
+
logger.info( 'modifiedSections =>', { data: JSON.stringify( sectionList ) } );
|
|
3256
3289
|
sectionList.forEach( ( sec ) => {
|
|
3257
3290
|
if ( sec.type == 'add' ) {
|
|
3258
3291
|
getsubmitDetails[0].questionAnswers.push( sec.section );
|
|
@@ -3268,7 +3301,7 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3268
3301
|
}
|
|
3269
3302
|
return acc;
|
|
3270
3303
|
}, [] );
|
|
3271
|
-
if ( questions.length && [ 'qnEdit', 'nameChange' ].includes( qn.type ) ) {
|
|
3304
|
+
if ( questions.length && [ 'qnEdit', 'nameChange', 'noChange' ].includes( qn.type ) ) {
|
|
3272
3305
|
if ( qn.type == 'qnEdit' ) {
|
|
3273
3306
|
let checkLinkType = getsubmitDetails[0].questionAnswers[sectionDetails].questions[questions[0]].linkType;
|
|
3274
3307
|
if ( checkLinkType && !qn.question.linkType ) {
|
|
@@ -3309,7 +3342,11 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3309
3342
|
} );
|
|
3310
3343
|
getsubmitDetails[0].questionAnswers[sectionDetails].questions[qnIdx] = qn.question;
|
|
3311
3344
|
} else {
|
|
3312
|
-
|
|
3345
|
+
if ( qn.type == 'nameChange' ) {
|
|
3346
|
+
getsubmitDetails[0].questionAnswers[sectionDetails].questions[qnIdx].qname = qn.question.qname;
|
|
3347
|
+
} else {
|
|
3348
|
+
getsubmitDetails[0].questionAnswers[sectionDetails].questions[qnIdx].qno = qn.question.qno;
|
|
3349
|
+
}
|
|
3313
3350
|
}
|
|
3314
3351
|
} );
|
|
3315
3352
|
}
|
|
@@ -3325,6 +3362,7 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3325
3362
|
getsubmitDetails[0].approvalStatus = false;
|
|
3326
3363
|
}
|
|
3327
3364
|
let data = { ...getsubmitDetails[0]._doc };
|
|
3365
|
+
logger.info( 'modifiedData =>', { data: JSON.stringify( data ) } );
|
|
3328
3366
|
await processedchecklist.updateOne( { _id: getsubmitDetails[0]._id }, data );
|
|
3329
3367
|
if ( editSubmit && getsubmitDetails[0].checklistStatus == 'submit' ) {
|
|
3330
3368
|
let user = {
|