tango-app-api-trax 3.8.24-nike → 3.8.25-nike
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
|
@@ -1081,6 +1081,535 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
1081
1081
|
};
|
|
1082
1082
|
|
|
1083
1083
|
export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next ) {
|
|
1084
|
+
try {
|
|
1085
|
+
let requestData = req.body;
|
|
1086
|
+
requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
|
|
1087
|
+
let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1, redoEdit: 1 } );
|
|
1088
|
+
let reqAnswers = requestData.questionAnswers;
|
|
1089
|
+
logger.error( { functionName: 'updatedPayload', message: reqAnswers } );
|
|
1090
|
+
let CLQAnswers = getChecklistQA.questionAnswers;
|
|
1091
|
+
|
|
1092
|
+
if ( requestData.submittype == 'submit' ) {
|
|
1093
|
+
if ( getChecklistQA?.redoEdit ) {
|
|
1094
|
+
requestData.submittype = 'draft';
|
|
1095
|
+
}
|
|
1096
|
+
reqAnswers.forEach( ( reqA ) => {
|
|
1097
|
+
if ( ![ 'multiplechoicemultiple', 'multipleImage', 'image/video' ].includes( reqA?.answerType ) && ( reqA.answerType == 'dropDown' && !reqA.allowMultiple ) ) {
|
|
1098
|
+
if ( ( !reqA.linkType && ( reqA.answer == null || reqA.answer == '' ) ) || ( reqA.linkType && reqA.linkquestionenabled && ( reqA.answer == null || reqA.answer == '' ) ) ) {
|
|
1099
|
+
return res.sendError( 'Please Fill All Fields', 400 );
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
} );
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
if ( requestData?.editSubmit && requestData?.editSubmit == 'true' ) {
|
|
1106
|
+
let sampleData = reqAnswers[0];
|
|
1107
|
+
CLQAnswers.forEach( ( section ) => {
|
|
1108
|
+
let requestSection = reqAnswers.filter( ( reqSection ) => reqSection.sectionName == section?.sectionOldName || reqSection.sectionName == section?.sectionName );
|
|
1109
|
+
if ( requestSection.length ) {
|
|
1110
|
+
requestSection.forEach( ( item ) => item.section_id = section.section_id );
|
|
1111
|
+
section.questions.forEach( ( question ) => {
|
|
1112
|
+
let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qname == question.oldQname || secQuestion.qname == question.qname );
|
|
1113
|
+
if ( !sectionQuestion.length ) {
|
|
1114
|
+
let data = { ...requestSection[0] };
|
|
1115
|
+
data.answerType = question.answerType;
|
|
1116
|
+
data.qno = question.qno;
|
|
1117
|
+
data.uniqueqno = question.uniqueqno;
|
|
1118
|
+
data.uniqueqid = question.uniqueqid;
|
|
1119
|
+
data.qname = question.qname;
|
|
1120
|
+
data.oldQname = question?.oldQname || question.qname;
|
|
1121
|
+
data.answer = 'null';
|
|
1122
|
+
data.remarks = '';
|
|
1123
|
+
data.validationAnswer = '';
|
|
1124
|
+
data.Multianswer = [];
|
|
1125
|
+
data.linkType = question.linkType;
|
|
1126
|
+
data.linkquestionenabled = question.linkType;
|
|
1127
|
+
data.linkedQuestion = null;
|
|
1128
|
+
data.showLinked = null;
|
|
1129
|
+
data.parentanswer = '';
|
|
1130
|
+
data.dateRangeType = false;
|
|
1131
|
+
reqAnswers.push( data );
|
|
1132
|
+
}
|
|
1133
|
+
} );
|
|
1134
|
+
} else {
|
|
1135
|
+
section.questions.forEach( ( ele ) => {
|
|
1136
|
+
let data = { ...sampleData };
|
|
1137
|
+
data.section_id = section.section_id;
|
|
1138
|
+
data.sectionName = section.sectionName;
|
|
1139
|
+
data.answerType = ele.answerType;
|
|
1140
|
+
data.qno = ele.qno;
|
|
1141
|
+
data.uniqueqno = ele.uniqueqno;
|
|
1142
|
+
data.uniqueqid = ele.uniqueqid;
|
|
1143
|
+
data.qname = ele.qname;
|
|
1144
|
+
data.oldQname = ele?.oldQname || ele.qname;
|
|
1145
|
+
data.answer = 'null';
|
|
1146
|
+
data.remarks = '';
|
|
1147
|
+
data.validationAnswer = '';
|
|
1148
|
+
data.Multianswer = [];
|
|
1149
|
+
data.linkType = ele.linkType;
|
|
1150
|
+
data.linkquestionenabled = ele.linkType;
|
|
1151
|
+
data.linkedQuestion = null;
|
|
1152
|
+
data.showLinked = null;
|
|
1153
|
+
data.parentanswer = '';
|
|
1154
|
+
data.dateRangeType = false;
|
|
1155
|
+
reqAnswers.push( data );
|
|
1156
|
+
} );
|
|
1157
|
+
}
|
|
1158
|
+
} );
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
let sectionFormat = [];
|
|
1162
|
+
let uniqueSections = {};
|
|
1163
|
+
reqAnswers.forEach( ( item ) => {
|
|
1164
|
+
const key = `${item.section_id}-${item.sectionName}`;
|
|
1165
|
+
if ( !uniqueSections[key] ) {
|
|
1166
|
+
uniqueSections[key] = { id: item.section_id, name: item.sectionName };
|
|
1167
|
+
}
|
|
1168
|
+
} );
|
|
1169
|
+
const uniqueArray = Object.values( uniqueSections );
|
|
1170
|
+
for ( let section of uniqueArray ) {
|
|
1171
|
+
let CLQSection = CLQAnswers.find( ( item ) => item.section_id.toString() == section.id.toString() );
|
|
1172
|
+
if ( CLQSection ) {
|
|
1173
|
+
let newArray = [];
|
|
1174
|
+
let qaAnswers = CLQSection.questions;
|
|
1175
|
+
let requestSection = reqAnswers.filter( ( item ) => item.section_id == section.id );
|
|
1176
|
+
for ( let i = 0; i < requestSection.length; i++ ) {
|
|
1177
|
+
for ( let j = 0; j < qaAnswers.length; j++ ) {
|
|
1178
|
+
if ( requestSection[i].qname == qaAnswers[j].oldQname || requestSection[i].qname == qaAnswers[j].qname ) {
|
|
1179
|
+
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
1180
|
+
let qaans = JSON.parse( JSON.stringify( qaAnswers[j].answers ) );
|
|
1181
|
+
let yn = [];
|
|
1182
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1183
|
+
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1184
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1185
|
+
if ( requestSection[i].validationAnswer ) {
|
|
1186
|
+
let validateAns = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
1187
|
+
if ( validateAns.length ) {
|
|
1188
|
+
let splitImgUrl = validateAns.split( '/' );
|
|
1189
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1190
|
+
splitImgUrl.splice( 0, 3 );
|
|
1191
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
} else {
|
|
1196
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1197
|
+
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1198
|
+
}
|
|
1199
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1200
|
+
qaans[k].runAIData = requestSection[i].runAIData;
|
|
1201
|
+
}
|
|
1202
|
+
yn.push( qaans[k] );
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
let structure = {};
|
|
1207
|
+
structure.qno = qaAnswers[j].qno;
|
|
1208
|
+
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
1209
|
+
structure.uniqueqid = qaAnswers[j].uniqueqid;
|
|
1210
|
+
structure.qname = qaAnswers[j].qname;
|
|
1211
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1212
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1213
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1214
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1215
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1216
|
+
structure.remarks = requestSection[i].remarks;
|
|
1217
|
+
}
|
|
1218
|
+
structure.answers = qaAnswers[j].answers;
|
|
1219
|
+
structure.userAnswer = yn;
|
|
1220
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1221
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1222
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1223
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1224
|
+
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1225
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1226
|
+
structure.compliance = qaAnswers[j]?.compliance;
|
|
1227
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1228
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1229
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1230
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1231
|
+
structure.task = true;
|
|
1232
|
+
}
|
|
1233
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1234
|
+
structure.redo = false;
|
|
1235
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1236
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1237
|
+
}
|
|
1238
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1239
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1240
|
+
};
|
|
1241
|
+
newArray.push( structure );
|
|
1242
|
+
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle' || ( qaAnswers[j].answerType == 'dropdown' && !qaAnswers[j].allowMultiple ) ) {
|
|
1243
|
+
let qaans = JSON.parse( JSON.stringify( qaAnswers[j].answers ) ); ;
|
|
1244
|
+
let ms = [];
|
|
1245
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1246
|
+
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1247
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1248
|
+
if ( requestSection[i].validationAnswer ) {
|
|
1249
|
+
let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
1250
|
+
if ( validationAnswer.length ) {
|
|
1251
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1252
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1253
|
+
splitImgUrl.splice( 0, 3 );
|
|
1254
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
} else {
|
|
1259
|
+
if ( qaans[k].validationType == 'Capture Multiple Image with description' ) {
|
|
1260
|
+
qaans[k]['validationImage']=[];
|
|
1261
|
+
if ( requestSection[i].validationImage.length ) {
|
|
1262
|
+
for ( let image of requestSection[i].validationImage ) {
|
|
1263
|
+
let validationAnswer = decodeURIComponent( image.split( '?' )[0] );
|
|
1264
|
+
if ( validationAnswer.length ) {
|
|
1265
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1266
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1267
|
+
splitImgUrl.splice( 0, 3 );
|
|
1268
|
+
qaans[k].validationImage.push( splitImgUrl.join( '/' ) || '' );
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1275
|
+
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1276
|
+
}
|
|
1277
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1278
|
+
qaans[k].runAIData = requestSection[i].runAIData;
|
|
1279
|
+
}
|
|
1280
|
+
ms.push( qaans[k] );
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
let structure = {};
|
|
1284
|
+
structure.qno = qaAnswers[j].qno;
|
|
1285
|
+
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
1286
|
+
structure.uniqueqid = qaAnswers[j].uniqueqid;
|
|
1287
|
+
structure.qname = qaAnswers[j].qname;
|
|
1288
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1289
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1290
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1291
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1292
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1293
|
+
structure.remarks = requestSection[i].remarks;
|
|
1294
|
+
}
|
|
1295
|
+
structure.answers = qaAnswers[j].answers;
|
|
1296
|
+
structure.userAnswer = ms;
|
|
1297
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1298
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1299
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1300
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1301
|
+
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1302
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1303
|
+
structure.allowMultiple = qaAnswers[j].allowMultiple;
|
|
1304
|
+
structure.compliance = qaAnswers[j]?.compliance;
|
|
1305
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1306
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1307
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1308
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1309
|
+
structure.task = true;
|
|
1310
|
+
}
|
|
1311
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1312
|
+
structure.redo = false;
|
|
1313
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1314
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1315
|
+
}
|
|
1316
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1317
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1318
|
+
};
|
|
1319
|
+
newArray.push( structure );
|
|
1320
|
+
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' || ( qaAnswers[j].answerType == 'dropdown' && qaAnswers[j].allowMultiple ) ) {
|
|
1321
|
+
let qaans = JSON.parse( JSON.stringify( qaAnswers[j].answers ) );
|
|
1322
|
+
let mcmo = [];
|
|
1323
|
+
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1324
|
+
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1325
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1326
|
+
if ( ( separatedArray[s].answer == qaans[k].answer ) ) {
|
|
1327
|
+
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1328
|
+
if ( separatedArray[s].validationAnswer ) {
|
|
1329
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
|
|
1330
|
+
if ( validationAnswer.length ) {
|
|
1331
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1332
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1333
|
+
splitImgUrl.splice( 0, 3 );
|
|
1334
|
+
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
} else {
|
|
1339
|
+
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1340
|
+
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1341
|
+
}
|
|
1342
|
+
if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
|
|
1343
|
+
qaans[k].runAIData = separatedArray[s].runAIData;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
mcmo.push( qaans[k] );
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
qaAnswers[j].answers.forEach( ( ele ) => {
|
|
1352
|
+
if ( typeof ele?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1353
|
+
ele.redo = false;
|
|
1354
|
+
}
|
|
1355
|
+
} );
|
|
1356
|
+
|
|
1357
|
+
let structure = {};
|
|
1358
|
+
structure.qno = qaAnswers[j].qno;
|
|
1359
|
+
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
1360
|
+
structure.qno = qaAnswers[j].qno;
|
|
1361
|
+
structure.qname = qaAnswers[j].qname;
|
|
1362
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1363
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1364
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1365
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1366
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1367
|
+
structure.remarks = requestSection[i].remarks;
|
|
1368
|
+
}
|
|
1369
|
+
structure.answers = qaAnswers[j].answers;
|
|
1370
|
+
structure.userAnswer = mcmo;
|
|
1371
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1372
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1373
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1374
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1375
|
+
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1376
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1377
|
+
structure.allowMultiple = qaAnswers[j].allowMultiple;
|
|
1378
|
+
structure.compliance = qaAnswers[j]?.compliance;
|
|
1379
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1380
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1381
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1382
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1383
|
+
structure.task = true;
|
|
1384
|
+
}
|
|
1385
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1386
|
+
structure.redo = false;
|
|
1387
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1388
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1389
|
+
}
|
|
1390
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1391
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1392
|
+
};
|
|
1393
|
+
newArray.push( structure );
|
|
1394
|
+
} else if ( [ 'image/video', 'multipleImage' ].includes( qaAnswers[j].answerType ) ) {
|
|
1395
|
+
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1396
|
+
let mcmi = [];
|
|
1397
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1398
|
+
// for (let k = 0; k < qaans.length; k++) {
|
|
1399
|
+
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1400
|
+
if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
|
|
1401
|
+
let newAnswer = {};
|
|
1402
|
+
let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
|
|
1403
|
+
if ( validationAnswer.length ) {
|
|
1404
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1405
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1406
|
+
splitImgUrl.splice( 0, 3 );
|
|
1407
|
+
newAnswer.answer = splitImgUrl.join( '/' ) || '';
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
newAnswer.answeroptionNumber = 0;
|
|
1412
|
+
newAnswer.sopFlag = false;
|
|
1413
|
+
newAnswer.validation = false;
|
|
1414
|
+
newAnswer.validationType = '';
|
|
1415
|
+
newAnswer.referenceImage = '';
|
|
1416
|
+
newAnswer.allowUploadfromGallery = false;
|
|
1417
|
+
newAnswer.descriptivetype = '';
|
|
1418
|
+
newAnswer.showLinked = false;
|
|
1419
|
+
newAnswer.linkedQuestion = 0;
|
|
1420
|
+
newAnswer.nestedQuestion = [];
|
|
1421
|
+
newAnswer.index = s;
|
|
1422
|
+
newAnswer.runAI = qaAnswers[j].answers[0]?.runAI || false;
|
|
1423
|
+
newAnswer.runAIFeatures = qaAnswers[j].answers[0]?.runAIFeatures || [];
|
|
1424
|
+
newAnswer.runAIDescription = qaAnswers[j].answers[0]?.runAIDescription || '';
|
|
1425
|
+
if ( qaAnswers[j].answerType == 'image/video' ) {
|
|
1426
|
+
newAnswer.answerType = separatedArray[s].answerType;
|
|
1427
|
+
}
|
|
1428
|
+
if ( separatedArray[s]?.runAIData && separatedArray[s]?.runAIData?.length ) {
|
|
1429
|
+
newAnswer.runAIData = separatedArray[s].runAIData;
|
|
1430
|
+
}
|
|
1431
|
+
mcmi.push( newAnswer );
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
// }
|
|
1436
|
+
let structure = {};
|
|
1437
|
+
structure.qno = qaAnswers[j].qno;
|
|
1438
|
+
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
1439
|
+
structure.uniqueqid = qaAnswers[j].uniqueqid;
|
|
1440
|
+
structure.qname = qaAnswers[j].qname;
|
|
1441
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1442
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1443
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1444
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1445
|
+
if ( ( getChecklistQA?.redoEdit && qaAnswers[j].redo == requestSection[i].redo ) || !getChecklistQA?.redoEdit ) {
|
|
1446
|
+
structure.remarks = requestSection[i].remarks;
|
|
1447
|
+
}
|
|
1448
|
+
structure.answers = qaAnswers[j].answers;
|
|
1449
|
+
structure.userAnswer = mcmi;
|
|
1450
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1451
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1452
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1453
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1454
|
+
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1455
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1456
|
+
structure.compliance = qaAnswers[j]?.compliance;
|
|
1457
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1458
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1459
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1460
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1461
|
+
structure.task = true;
|
|
1462
|
+
}
|
|
1463
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1464
|
+
structure.redo = false;
|
|
1465
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1466
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1467
|
+
}
|
|
1468
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1469
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1470
|
+
};
|
|
1471
|
+
newArray.push( structure );
|
|
1472
|
+
} else {
|
|
1473
|
+
let des = [];
|
|
1474
|
+
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1475
|
+
let validationAnswer = '';
|
|
1476
|
+
if ( requestSection[i].answer.split( '?' ).length > 1 || requestSection[i].answer.includes( 'https://' ) ) {
|
|
1477
|
+
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1478
|
+
}
|
|
1479
|
+
if ( validationAnswer.length ) {
|
|
1480
|
+
let splitImgUrl = validationAnswer.split( '/' );
|
|
1481
|
+
if ( splitImgUrl.length > 1 ) {
|
|
1482
|
+
splitImgUrl.splice( 0, 3 );
|
|
1483
|
+
requestSection[i].answer = splitImgUrl.join( '/' );
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
let ansstructure = {
|
|
1487
|
+
answer: requestSection[i].answer,
|
|
1488
|
+
answeroptionNumber: 1,
|
|
1489
|
+
sopFlag: false,
|
|
1490
|
+
validation: false,
|
|
1491
|
+
validationType: '',
|
|
1492
|
+
validationAnswer: '',
|
|
1493
|
+
referenceImage: qaAnswers[j].answers[0].referenceImage || '',
|
|
1494
|
+
multiReferenceImage: qaAnswers[j].answers[0].multiReferenceImage || [],
|
|
1495
|
+
showLinked: qaAnswers[j].answers[0].showLinked,
|
|
1496
|
+
linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
|
|
1497
|
+
runAI: qaAnswers[j].answers[0]?.runAI || false,
|
|
1498
|
+
runAIFeatures: qaAnswers[j]?.answers[0]?.runAIFeatures || [],
|
|
1499
|
+
runAIDescription: qaAnswers[j].answers[0]?.runAIDescription || '',
|
|
1500
|
+
};
|
|
1501
|
+
if ( qaAnswers[j].answerType == 'date' ) {
|
|
1502
|
+
ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
|
|
1503
|
+
if ( qaAnswers[j].compliance ) {
|
|
1504
|
+
if ( qaAnswers[j].compliance ) {
|
|
1505
|
+
let ansArray = requestSection[i].answer.split( ',' );
|
|
1506
|
+
if ( ansArray.includes( '-' ) ) {
|
|
1507
|
+
ansArray = requestSection[i].answer.split( '-' );
|
|
1508
|
+
}
|
|
1509
|
+
if ( ansArray.length > 1 && ansArray.some( ( date ) => dayjs( date, 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate && dayjs( date, 'DD MMM YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) ) {
|
|
1510
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1511
|
+
} else if ( ansArray.length > 1 && ( dayjs( ansArray?.[0], 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate && dayjs( ansArray?.[1], 'DD MMM YYYY' ).format( 'DD-MM-YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) ) {
|
|
1512
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1513
|
+
} else if ( dayjs( requestSection[i].answer, 'DD MMM YYYY' ) >= qaAnswers[j]?.answers[0]?.startDate && dayjs( requestSection[i].answer, 'DD MMM YYYY' ) <= qaAnswers[j]?.answers[0]?.endDate ) {
|
|
1514
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1515
|
+
} else {
|
|
1516
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
if ( qaAnswers[j].answerType == 'linearscale' ) {
|
|
1522
|
+
if ( qaAnswers[j].compliance ) {
|
|
1523
|
+
let linearAnswer = requestSection[i].answer.split( 'to' );
|
|
1524
|
+
if ( parseInt( linearAnswer?.[0] ) >= qaAnswers[j]?.answers[0]?.minValue && parseInt( linearAnswer?.[1] ) <= qaAnswers[j]?.answers[0]?.maxValue ) {
|
|
1525
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1526
|
+
} else {
|
|
1527
|
+
ansstructure.complianceScore = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
ansstructure.linearType = qaAnswers[j]?.answers[0]?.linearType;
|
|
1531
|
+
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1532
|
+
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1533
|
+
}
|
|
1534
|
+
if ( qaAnswers[j].answerType == 'image' ) {
|
|
1535
|
+
ansstructure.matchedCount = qaAnswers[j]?.answers[0]?.matchedCount;
|
|
1536
|
+
ansstructure.notMatchedCount = qaAnswers[j]?.answers[0]?.notMatchedCount;
|
|
1537
|
+
}
|
|
1538
|
+
if ( requestSection[i]?.runAIData && requestSection[i]?.runAIData?.length ) {
|
|
1539
|
+
ansstructure.runAIData = requestSection[i].runAIData;
|
|
1540
|
+
}
|
|
1541
|
+
des.push( ansstructure );
|
|
1542
|
+
}
|
|
1543
|
+
let structure = {};
|
|
1544
|
+
structure.qno = qaAnswers[j].qno;
|
|
1545
|
+
structure.uniqueqno = qaAnswers[j].uniqueqno;
|
|
1546
|
+
structure.uniqueqid = qaAnswers[j].uniqueqid;
|
|
1547
|
+
structure.qname = qaAnswers[j].qname;
|
|
1548
|
+
structure.answerType = qaAnswers[j].answerType;
|
|
1549
|
+
structure.runAI = qaAnswers[j].runAI;
|
|
1550
|
+
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1551
|
+
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1552
|
+
structure.remarks = requestSection[i].remarks;
|
|
1553
|
+
structure.answers = qaAnswers[j].answers;
|
|
1554
|
+
structure.userAnswer = des;
|
|
1555
|
+
structure.linkType = qaAnswers[j].linkType;
|
|
1556
|
+
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1557
|
+
structure.parentanswer = requestSection[i].parentanswer;
|
|
1558
|
+
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage || '';
|
|
1559
|
+
structure.multiQuestionReferenceImage = qaAnswers[j].multiQuestionReferenceImage || [];
|
|
1560
|
+
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1561
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1562
|
+
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1563
|
+
structure.compliance = qaAnswers[j]?.compliance;
|
|
1564
|
+
if ( qaAnswers[j]?.taskId ) {
|
|
1565
|
+
structure.taskId = qaAnswers[j]?.taskId;
|
|
1566
|
+
structure.task = true;
|
|
1567
|
+
}
|
|
1568
|
+
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1569
|
+
structure.redo = false;
|
|
1570
|
+
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1571
|
+
structure.redo = qaAnswers[j]?.redo;
|
|
1572
|
+
}
|
|
1573
|
+
if ( qaAnswers[j]?.redoComment ) {
|
|
1574
|
+
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1575
|
+
};
|
|
1576
|
+
newArray.push( structure );
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
let sectionData = {
|
|
1582
|
+
'section_id': section.id,
|
|
1583
|
+
'sectionName': section.name,
|
|
1584
|
+
'questions': newArray,
|
|
1585
|
+
};
|
|
1586
|
+
sectionFormat.push( sectionData );
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
|
|
1591
|
+
requestData.questionAnswers = sectionFormat;
|
|
1592
|
+
logger.error( { message: requestData.questionAnswers, error: 'QuestionanswersPayload' } );
|
|
1593
|
+
|
|
1594
|
+
if ( requestData.submittype == 'submit' ) {
|
|
1595
|
+
for ( let section of sectionFormat ) {
|
|
1596
|
+
for ( let question of section.questions ) {
|
|
1597
|
+
let mustValidate = !question.linkType || ( question.linkType && question.linkquestionenabled );
|
|
1598
|
+
if ( mustValidate && ( !question.userAnswer || !question.userAnswer.length ) ) {
|
|
1599
|
+
return res.sendError( 'Please Fill All Fields', 400 );
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
next();
|
|
1606
|
+
} catch ( error ) {
|
|
1607
|
+
logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
|
|
1608
|
+
return res.sendError( error, 500 );
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
|
|
1612
|
+
export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next ) {
|
|
1084
1613
|
try {
|
|
1085
1614
|
let requestData = req.body;
|
|
1086
1615
|
requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
|
|
@@ -12,6 +12,7 @@ mobileRouter
|
|
|
12
12
|
.post( '/startTask', isAllowedSessionHandler, validate( startValidation ), mobileController.startTask )
|
|
13
13
|
.post( '/submitCheckList', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistQuestionValidator, mobileController.sopMobilechecklistMultiSectionFormatter, mobileController.submitChecklist )
|
|
14
14
|
.post( '/submitCheckListv5', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistQuestionValidatorv1, mobileController.sopMobilechecklistMultiSectionFormatterv1, mobileController.submitChecklist )
|
|
15
|
+
.post( '/submitCheckListv6', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobilechecklistQuestionValidatorv1, mobileController.sopMobilechecklistMultiSectionFormatterv2, mobileController.submitChecklist )
|
|
15
16
|
.post( '/submitTask', isAllowedSessionHandler, mobileController.sopMobilechecklistValidater, mobileController.sopMobileTaskQuestionValidator, mobileController.sopMobileTaskMultiSectionFormatter, mobileController.submitTask )
|
|
16
17
|
.post( '/submiteyeTestTask', isAllowedSessionHandler, mobileController.submiteyeTestTask )
|
|
17
18
|
.get( '/dashboard', isAllowedSessionHandler, validate( dashboardValidation ), mobileController.dashboard )
|