tango-app-api-trax 3.4.1-alpha-20 → 3.4.1-beta-0
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 +3 -3
- package/src/controllers/download.controller.js +117 -3
- package/src/controllers/internalTrax.controller.js +114 -6
- package/src/controllers/mobileTrax.controller.js +31 -931
- package/src/controllers/teaxFlag.controller.js +467 -2
- package/src/controllers/trax.controller.js +294 -155
- package/src/controllers/traxDashboard.controllers.js +1 -2
- package/src/dtos/downloadValidation.dtos.js +1 -1
- package/src/routes/download.router.js +4 -0
- package/src/routes/internalTraxApi.router.js +3 -1
- package/src/routes/mobileTrax.routes.js +0 -3
- package/src/routes/trax.routes.js +5 -3
- package/src/routes/traxFlag.router.js +13 -1
- package/src/services/processedchecklistconfig.services.js +1 -1
|
@@ -90,242 +90,6 @@ export async function storeListv1( req, res ) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
export async function startChecklistv1( req, res ) {
|
|
94
|
-
try {
|
|
95
|
-
let requestData = req.body;
|
|
96
|
-
let findQuery = [];
|
|
97
|
-
findQuery.push( {
|
|
98
|
-
$match: {
|
|
99
|
-
$and: [
|
|
100
|
-
{ _id: new ObjectId( requestData.processedcheckListId ) },
|
|
101
|
-
{ userId: req.user._id },
|
|
102
|
-
{ date_string: requestData.date },
|
|
103
|
-
],
|
|
104
|
-
},
|
|
105
|
-
} );
|
|
106
|
-
|
|
107
|
-
let getBeforeChecklist = await processedchecklist.aggregate( findQuery );
|
|
108
|
-
if ( !getBeforeChecklist.length ) {
|
|
109
|
-
return res.sendError( 'Check List Got Edited Please Fill Again', 422 );
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if ( getBeforeChecklist[0].checklistStatus != 'open' ) {
|
|
113
|
-
return res.sendError( 'already check list started', 400 );
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
logger.info( `v5 => Checklist Started => store Name: ${getBeforeChecklist[0].storeName || ''}, User Email: ${getBeforeChecklist[0].userEmail}, Checklist Name: ${getBeforeChecklist[0].checkListName}` );
|
|
117
|
-
let PCLQusestion = await PCLconfig.findOne( { _id: new ObjectId( getBeforeChecklist[0].checkListId ) } );
|
|
118
|
-
let updateQuery = {};
|
|
119
|
-
updateQuery._id = new ObjectId( requestData.processedcheckListId );
|
|
120
|
-
updateQuery.userId = req.user._id;
|
|
121
|
-
updateQuery.date_string = requestData.date;
|
|
122
|
-
|
|
123
|
-
if ( PCLQusestion && PCLQusestion?.questionAnswers && PCLQusestion?.questionAnswers.length > 0 ) {
|
|
124
|
-
await PCLQusestion.questionAnswers.forEach( ( section ) => {
|
|
125
|
-
section.questions.forEach( ( question ) => {
|
|
126
|
-
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
127
|
-
let Multianswer = [];
|
|
128
|
-
if ( question.answers.length > 0 ) {
|
|
129
|
-
question.answers.forEach( ( answer, ansIndex ) => {
|
|
130
|
-
Multianswer.push( { 'answer': null, 'no': ansIndex, 'validationAnswer': null } );
|
|
131
|
-
answer.index = ansIndex;
|
|
132
|
-
} );
|
|
133
|
-
question.Multianswer = Multianswer;
|
|
134
|
-
}
|
|
135
|
-
} else if ( question.answerType == 'multipleImage' ) {
|
|
136
|
-
let Multianswer = [];
|
|
137
|
-
if ( question.answers.length > 0 ) {
|
|
138
|
-
question.answers.forEach( ( answer, ansIndex ) => {
|
|
139
|
-
Multianswer.push( { 'answer': null, 'no': ansIndex, 'validationAnswer': null } );
|
|
140
|
-
answer.index = ansIndex;
|
|
141
|
-
} );
|
|
142
|
-
question.Multianswer = Multianswer;
|
|
143
|
-
}
|
|
144
|
-
} else {
|
|
145
|
-
question.Multianswer = [];
|
|
146
|
-
}
|
|
147
|
-
} );
|
|
148
|
-
} );
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
let updateData = {};
|
|
152
|
-
let currentDateTime;
|
|
153
|
-
if ( getBeforeChecklist[0].storeName && getBeforeChecklist[0].storeName!='' ) {
|
|
154
|
-
let storeTimeZone = await storeService.findOne( { storeName: { $regex: getBeforeChecklist[0].storeName, $options: 'i' }, clientId: getBeforeChecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
|
|
155
|
-
if ( storeTimeZone?.storeProfile?.timeZone ) {
|
|
156
|
-
currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
|
|
157
|
-
} else {
|
|
158
|
-
currentDateTime = dayjs();
|
|
159
|
-
}
|
|
160
|
-
} else {
|
|
161
|
-
currentDateTime = dayjs();
|
|
162
|
-
}
|
|
163
|
-
updateData.checklistStatus = 'inprogress';
|
|
164
|
-
updateData.startMobileTime = requestData?.currentTime;
|
|
165
|
-
updateData.questionAnswers = getBeforeChecklist[0]?.redoStatus ? getBeforeChecklist[0].questionAnswers : PCLQusestion.questionAnswers;
|
|
166
|
-
// const newDateTime = currentDateTime.add(5, 'hours').add(30, 'minutes');
|
|
167
|
-
// updateData.startTime_string = newDateTime.format('hh:mm A, DD MMM');
|
|
168
|
-
updateData.startTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
|
|
169
|
-
updateData.startTime = dayjs.utc( updateData.startTime_string, 'hh:mm A, DD MMM YYYY' ).format();
|
|
170
|
-
|
|
171
|
-
let updatechecklist = await processedchecklist.updateOne( updateQuery, updateData );
|
|
172
|
-
PCLQusestion.startTime = dayjs.utc( updateData.startTime_string, 'hh:mm A, DD MMM YYYY' ).format();
|
|
173
|
-
PCLQusestion.save();
|
|
174
|
-
if ( updatechecklist.modifiedCount > 0 ) {
|
|
175
|
-
findQuery.push( {
|
|
176
|
-
$project: {
|
|
177
|
-
checkListName: { $ifNull: [ '$checkListName', '' ] },
|
|
178
|
-
coverage: { $ifNull: [ '$coverage', '' ] },
|
|
179
|
-
client_id: { $ifNull: [ '$client_id', '' ] },
|
|
180
|
-
scheduleStartTime: { $ifNull: [ '$scheduleStartTime', '' ] },
|
|
181
|
-
scheduleStartTime_iso: { $ifNull: [ '$scheduleStartTime_iso', '' ] },
|
|
182
|
-
scheduleEndTime: { $ifNull: [ '$scheduleEndTime', '' ] },
|
|
183
|
-
scheduleEndTime_iso: { $ifNull: [ '$scheduleEndTime_iso', '' ] },
|
|
184
|
-
checklistStatus: { $ifNull: [ '$checklistStatus', '' ] },
|
|
185
|
-
checkListId: { $ifNull: [ '$checkListId', '' ] },
|
|
186
|
-
startTime: { $ifNull: [ '$startTime', '' ] },
|
|
187
|
-
submitTime: { $ifNull: [ '$submitTime', '' ] },
|
|
188
|
-
allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
|
|
189
|
-
// allowedStoreLocation: { $ifNull: [ '$checallowedStoreLocationkListName', false ] },
|
|
190
|
-
allowedStoreLocation: {
|
|
191
|
-
$cond: {
|
|
192
|
-
if: { $eq: [ '$client_id', '11' ] },
|
|
193
|
-
then: false,
|
|
194
|
-
else: {
|
|
195
|
-
'$cond': {
|
|
196
|
-
'if': { '$eq': [ '$coverage', 'user' ] },
|
|
197
|
-
'then': false,
|
|
198
|
-
'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
|
|
204
|
-
redoStatus: { $ifNull: [ '$redoStatus', '' ] },
|
|
205
|
-
},
|
|
206
|
-
} );
|
|
207
|
-
let getupdatedchecklist = await processedchecklist.aggregate( findQuery );
|
|
208
|
-
// let bucket = JSON.parse( process.env.BUCKET );
|
|
209
|
-
|
|
210
|
-
let logInsertData = {
|
|
211
|
-
store_id: getBeforeChecklist[0]?.store_id || '',
|
|
212
|
-
storeName: getBeforeChecklist[0]?.storeName || '',
|
|
213
|
-
action: 'started',
|
|
214
|
-
checklistId: getBeforeChecklist[0].sourceCheckList_id,
|
|
215
|
-
processedChecklistId: getBeforeChecklist[0]._id,
|
|
216
|
-
checkListName: getBeforeChecklist[0].checkListName,
|
|
217
|
-
type: getBeforeChecklist[0].checkListType,
|
|
218
|
-
client_id: req.user.clientId,
|
|
219
|
-
userEmail: getBeforeChecklist[0].userEmail || '',
|
|
220
|
-
userName: getBeforeChecklist[0].userName || '',
|
|
221
|
-
coverage: getBeforeChecklist[0].coverage || '',
|
|
222
|
-
};
|
|
223
|
-
await checklistLogs.create( logInsertData );
|
|
224
|
-
let getchecklist = getupdatedchecklist;
|
|
225
|
-
let questions = [];
|
|
226
|
-
// function processQuestion( question, section, questions, nested=false ) {
|
|
227
|
-
// let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
|
|
228
|
-
// if ( findExists && nested ) {
|
|
229
|
-
// let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
|
|
230
|
-
// questions.splice( findIndex, 1 );
|
|
231
|
-
// questions.push( question );
|
|
232
|
-
// }
|
|
233
|
-
// if ( !findExists ) {
|
|
234
|
-
// questions.push( question );
|
|
235
|
-
// for ( let answer of question.answers ) {
|
|
236
|
-
// if ( answer.showLinked && answer?.linkedQuestion != '' ) {
|
|
237
|
-
// let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
|
|
238
|
-
// if ( linkedQuestion ) {
|
|
239
|
-
// processQuestion( linkedQuestion, section, questions, true );
|
|
240
|
-
// }
|
|
241
|
-
// }
|
|
242
|
-
// }
|
|
243
|
-
// }
|
|
244
|
-
// }
|
|
245
|
-
for ( let [ index, data ] of getchecklist.entries() ) {
|
|
246
|
-
for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
|
|
247
|
-
questions = [];
|
|
248
|
-
for ( let [ questionIdx, question ] of section.questions.entries() ) {
|
|
249
|
-
let linkedQuestions;
|
|
250
|
-
if ( !question.linkType ) {
|
|
251
|
-
question.uniqueNo = parseInt( getOtp() )+ Date.now() + questionIdx;
|
|
252
|
-
questions.push( question );
|
|
253
|
-
linkedQuestions = [];
|
|
254
|
-
let questionList = new Map( section.questions.map( ( ele ) => [ ele.qno, ele ] ) );
|
|
255
|
-
question.answers.forEach( ( answer ) => {
|
|
256
|
-
if ( answer.linkedQuestion ) {
|
|
257
|
-
let nesedQuestion = [];
|
|
258
|
-
answer.oldNestedQuestion = JSON.parse( JSON.stringify( answer.nestedQuestion ) );
|
|
259
|
-
answer.nestedQuestion.forEach( ( qn, qidx ) => {
|
|
260
|
-
let getQn = questionList.get( qn );
|
|
261
|
-
if ( getQn ) {
|
|
262
|
-
let randomNo = parseInt( getOtp() ) + Date.now() + qidx;
|
|
263
|
-
getQn = JSON.parse( JSON.stringify( getQn ) );
|
|
264
|
-
getQn = { ...getQn, uniqueNo: randomNo };
|
|
265
|
-
nesedQuestion.push( getQn );
|
|
266
|
-
if ( answer.linkedQuestion == getQn.qno ) {
|
|
267
|
-
answer.oldLinkedQuestion = answer.linkedQuestion;
|
|
268
|
-
answer.linkedQuestion = randomNo;
|
|
269
|
-
}
|
|
270
|
-
answer.nestedQuestion[qidx] = randomNo;
|
|
271
|
-
}
|
|
272
|
-
} );
|
|
273
|
-
nesedQuestion.forEach( ( ele ) => {
|
|
274
|
-
let nestedLinkqn = [];
|
|
275
|
-
ele.answers.forEach( ( ans ) => {
|
|
276
|
-
if ( ans.linkedQuestion ) {
|
|
277
|
-
ans.oldNestedQuestion = JSON.parse( JSON.stringify( ans.nestedQuestion ) );
|
|
278
|
-
ans.nestedQuestion.forEach( ( nested, idx ) => {
|
|
279
|
-
let findRandom = nesedQuestion.find( ( qn ) => qn.qno == nested && !nestedLinkqn.includes( qn.uniqueNo ) && !qn.updated );
|
|
280
|
-
if ( findRandom ) {
|
|
281
|
-
if ( ans.linkedQuestion == findRandom.qno ) {
|
|
282
|
-
ans.oldLinkedQuestion = ans.linkedQuestion;
|
|
283
|
-
ans.linkedQuestion = findRandom.uniqueNo;
|
|
284
|
-
}
|
|
285
|
-
ans.nestedQuestion[idx] = findRandom.uniqueNo;
|
|
286
|
-
nestedLinkqn.push( findRandom.uniqueNo );
|
|
287
|
-
}
|
|
288
|
-
} );
|
|
289
|
-
}
|
|
290
|
-
} );
|
|
291
|
-
ele.updated = true;
|
|
292
|
-
} );
|
|
293
|
-
linkedQuestions.push( ...nesedQuestion );
|
|
294
|
-
}
|
|
295
|
-
} );
|
|
296
|
-
questions.push( ...linkedQuestions );
|
|
297
|
-
}
|
|
298
|
-
// processQuestion( question, section, questions );
|
|
299
|
-
}
|
|
300
|
-
getchecklist[index].questionAnswers[secIndex].questions = questions;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
await processedchecklist.updateOne( updateQuery, { questionAnswers: getchecklist[0].questionAnswers } );
|
|
304
|
-
getupdatedchecklist[0].questionAnswers.forEach( ( section ) => {
|
|
305
|
-
section.questions.forEach( async ( question ) => {
|
|
306
|
-
if ( question.questionReferenceImage && question.questionReferenceImage!='' ) {
|
|
307
|
-
question.questionReferenceImage = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + question.questionReferenceImage;
|
|
308
|
-
// question.questionReferenceImage = await signedUrl( { Bucket: bucket.sop, file_path: decodeURIComponent( question.questionReferenceImage ) } );
|
|
309
|
-
}
|
|
310
|
-
question.answers.forEach( async ( answer ) => {
|
|
311
|
-
if ( answer.referenceImage != '' ) {
|
|
312
|
-
answer.referenceImage = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + answer.referenceImage;
|
|
313
|
-
// answer.referenceImage = await signedUrl( { Bucket: bucket.sop, file_path: decodeURIComponent( answer.referenceImage ) } );
|
|
314
|
-
}
|
|
315
|
-
} );
|
|
316
|
-
} );
|
|
317
|
-
} );
|
|
318
|
-
return res.sendSuccess( getchecklist );
|
|
319
|
-
} else {
|
|
320
|
-
return res.sendError( 'something went wrong please try again', 500 );
|
|
321
|
-
}
|
|
322
|
-
} catch ( e ) {
|
|
323
|
-
console.log( 'e =>', e );
|
|
324
|
-
logger.error( { function: 'startChecklist', error: e, body: req.body } );
|
|
325
|
-
return res.sendError( e, 500 );
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
93
|
export async function startChecklist( req, res ) {
|
|
330
94
|
try {
|
|
331
95
|
let requestData = req.body;
|
|
@@ -855,368 +619,29 @@ export async function sopMobileTaskQuestionValidator( req, res, next ) {
|
|
|
855
619
|
validationCount++;
|
|
856
620
|
}
|
|
857
621
|
}
|
|
858
|
-
} );
|
|
859
|
-
} );
|
|
860
|
-
} );
|
|
861
|
-
if ( validationCount ) {
|
|
862
|
-
return res.sendError( 'Please Fill all Required Fields', 400 );
|
|
863
|
-
} else {
|
|
864
|
-
next();
|
|
865
|
-
}
|
|
866
|
-
} else {
|
|
867
|
-
next();
|
|
868
|
-
}
|
|
869
|
-
} catch ( e ) {
|
|
870
|
-
logger.error( { function: 'sopMobileTaskQuestionValidator', error: e, body: req.body } );
|
|
871
|
-
return res.sendError( e, 500 );
|
|
872
|
-
}
|
|
873
|
-
};
|
|
874
|
-
|
|
875
|
-
export async function sopMobilechecklistMultiSectionFormatter( req, res, next ) {
|
|
876
|
-
try {
|
|
877
|
-
let requestData = req.body;
|
|
878
|
-
requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
|
|
879
|
-
let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1 } );
|
|
880
|
-
let reqAnswers = requestData.questionAnswers;
|
|
881
|
-
let CLQAnswers = getChecklistQA.questionAnswers;
|
|
882
|
-
|
|
883
|
-
if ( requestData.submittype == 'submit' ) {
|
|
884
|
-
reqAnswers.forEach( ( reqA ) => {
|
|
885
|
-
if ( ![ 'multiplechoicemultiple', 'multipleImage' ].includes( reqA?.answerType ) ) {
|
|
886
|
-
if ( ( !reqA.linkType && ( reqA.answer == null || reqA.answer == '' ) ) || ( reqA.linkType && reqA.linkquestionenabled && ( reqA.answer == null || reqA.answer == '' ) ) ) {
|
|
887
|
-
return res.sendError( 'Please Fill All Fields', 400 );
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
} );
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
let sectionFormat = [];
|
|
894
|
-
let uniqueSections = {};
|
|
895
|
-
reqAnswers.forEach( ( item ) => {
|
|
896
|
-
const key = `${item.section_id}-${item.sectionName}`;
|
|
897
|
-
if ( !uniqueSections[key] ) {
|
|
898
|
-
uniqueSections[key] = { id: item.section_id, name: item.sectionName };
|
|
899
|
-
}
|
|
900
|
-
} );
|
|
901
|
-
const uniqueArray = Object.values( uniqueSections );
|
|
902
|
-
for ( let section of uniqueArray ) {
|
|
903
|
-
let CLQSection = CLQAnswers.find( ( item ) => item.section_id == section.id );
|
|
904
|
-
if ( CLQSection ) {
|
|
905
|
-
let newArray = [];
|
|
906
|
-
let qaAnswers = CLQSection.questions;
|
|
907
|
-
let requestSection = reqAnswers.filter( ( item ) => item.section_id == section.id );
|
|
908
|
-
for ( let i = 0; i < requestSection.length; i++ ) {
|
|
909
|
-
for ( let j = 0; j < qaAnswers.length; j++ ) {
|
|
910
|
-
if ( requestSection[i].qno == qaAnswers[j].qno ) {
|
|
911
|
-
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
912
|
-
let qaans = qaAnswers[j].answers;
|
|
913
|
-
let yn = [];
|
|
914
|
-
for ( let k = 0; k < qaans.length; k++ ) {
|
|
915
|
-
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
916
|
-
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
917
|
-
if ( requestSection[i].validationAnswer ) {
|
|
918
|
-
let validateAns = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
919
|
-
if ( validateAns.length ) {
|
|
920
|
-
let splitImgUrl = validateAns.split( '/' );
|
|
921
|
-
if ( splitImgUrl.length > 1 ) {
|
|
922
|
-
splitImgUrl.splice( 0, 3 );
|
|
923
|
-
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
} else {
|
|
928
|
-
qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
929
|
-
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
930
|
-
}
|
|
931
|
-
yn.push( qaans[k] );
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
let structure = {};
|
|
935
|
-
structure.qno = qaAnswers[j].qno;
|
|
936
|
-
structure.qname = qaAnswers[j].qname;
|
|
937
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
938
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
939
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
940
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
941
|
-
structure.remarks = requestSection[i].remarks;
|
|
942
|
-
structure.answers = qaAnswers[j].answers;
|
|
943
|
-
structure.userAnswer = yn;
|
|
944
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
945
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
946
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
947
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
948
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
949
|
-
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
950
|
-
if ( qaAnswers[j]?.taskId ) {
|
|
951
|
-
structure.taskId = qaAnswers[j]?.taskId;
|
|
952
|
-
structure.task = true;
|
|
953
|
-
}
|
|
954
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
955
|
-
structure.redo = false;
|
|
956
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
957
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
958
|
-
}
|
|
959
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
960
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
961
|
-
};
|
|
962
|
-
newArray.push( structure );
|
|
963
|
-
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle' ) {
|
|
964
|
-
let qaans = qaAnswers[j].answers;
|
|
965
|
-
let ms = [];
|
|
966
|
-
for ( let k = 0; k < qaans.length; k++ ) {
|
|
967
|
-
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
968
|
-
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
969
|
-
if ( requestSection[i].validationAnswer ) {
|
|
970
|
-
let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
971
|
-
if ( validationAnswer.length ) {
|
|
972
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
973
|
-
if ( splitImgUrl.length > 1 ) {
|
|
974
|
-
splitImgUrl.splice( 0, 3 );
|
|
975
|
-
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
} else {
|
|
980
|
-
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
981
|
-
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
982
|
-
}
|
|
983
|
-
ms.push( qaans[k] );
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
let structure = {};
|
|
987
|
-
structure.qno = qaAnswers[j].qno;
|
|
988
|
-
structure.qname = qaAnswers[j].qname;
|
|
989
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
990
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
991
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
992
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
993
|
-
structure.remarks = requestSection[i].remarks;
|
|
994
|
-
structure.answers = qaAnswers[j].answers;
|
|
995
|
-
structure.userAnswer = ms;
|
|
996
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
997
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
998
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
999
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1000
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1001
|
-
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1002
|
-
if ( qaAnswers[j]?.taskId ) {
|
|
1003
|
-
structure.taskId = qaAnswers[j]?.taskId;
|
|
1004
|
-
structure.task = true;
|
|
1005
|
-
}
|
|
1006
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1007
|
-
structure.redo = false;
|
|
1008
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1009
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
1010
|
-
}
|
|
1011
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
1012
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1013
|
-
};
|
|
1014
|
-
newArray.push( structure );
|
|
1015
|
-
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' ) {
|
|
1016
|
-
let qaans = qaAnswers[j].answers;
|
|
1017
|
-
let mcmo = [];
|
|
1018
|
-
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1019
|
-
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1020
|
-
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1021
|
-
if ( separatedArray[s].answer == qaans[k].answer ) {
|
|
1022
|
-
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1023
|
-
if ( separatedArray[s].validationAnswer ) {
|
|
1024
|
-
let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
|
|
1025
|
-
if ( validationAnswer.length ) {
|
|
1026
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
1027
|
-
if ( splitImgUrl.length > 1 ) {
|
|
1028
|
-
splitImgUrl.splice( 0, 3 );
|
|
1029
|
-
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1030
|
-
}
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
} else {
|
|
1034
|
-
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1035
|
-
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
mcmo.push( qaans[k] );
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
let structure = {};
|
|
1043
|
-
structure.qno = qaAnswers[j].qno;
|
|
1044
|
-
structure.qname = qaAnswers[j].qname;
|
|
1045
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
1046
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
1047
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1048
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1049
|
-
structure.remarks = requestSection[i].remarks;
|
|
1050
|
-
structure.answers = qaAnswers[j].answers;
|
|
1051
|
-
structure.userAnswer = mcmo;
|
|
1052
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
1053
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1054
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
1055
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1056
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1057
|
-
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1058
|
-
if ( qaAnswers[j]?.taskId ) {
|
|
1059
|
-
structure.taskId = qaAnswers[j]?.taskId;
|
|
1060
|
-
structure.task = true;
|
|
1061
|
-
}
|
|
1062
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1063
|
-
structure.redo = false;
|
|
1064
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1065
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
1066
|
-
}
|
|
1067
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
1068
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1069
|
-
};
|
|
1070
|
-
newArray.push( structure );
|
|
1071
|
-
} else if ( qaAnswers[j].answerType == 'multipleImage' ) {
|
|
1072
|
-
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1073
|
-
let mcmi = [];
|
|
1074
|
-
// for (let k = 0; k < qaans.length; k++) {
|
|
1075
|
-
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1076
|
-
if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
|
|
1077
|
-
let newAnswer = {};
|
|
1078
|
-
let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
|
|
1079
|
-
if ( validationAnswer.length ) {
|
|
1080
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
1081
|
-
if ( splitImgUrl.length > 1 ) {
|
|
1082
|
-
splitImgUrl.splice( 0, 3 );
|
|
1083
|
-
newAnswer.answer = splitImgUrl.join( '/' ) || '';
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
newAnswer.answeroptionNumber = 0;
|
|
1088
|
-
newAnswer.sopFlag = false;
|
|
1089
|
-
newAnswer.validation = false;
|
|
1090
|
-
newAnswer.validationType = '';
|
|
1091
|
-
newAnswer.referenceImage = '';
|
|
1092
|
-
newAnswer.allowUploadfromGallery = false;
|
|
1093
|
-
newAnswer.runAI = false;
|
|
1094
|
-
newAnswer.descriptivetype = '';
|
|
1095
|
-
newAnswer.showLinked = false;
|
|
1096
|
-
newAnswer.linkedQuestion = 0;
|
|
1097
|
-
newAnswer.nestedQuestion = [];
|
|
1098
|
-
newAnswer.index = s;
|
|
1099
|
-
mcmi.push( newAnswer );
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
// }
|
|
1103
|
-
let structure = {};
|
|
1104
|
-
structure.qno = qaAnswers[j].qno;
|
|
1105
|
-
structure.qname = qaAnswers[j].qname;
|
|
1106
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
1107
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
1108
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1109
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1110
|
-
structure.remarks = requestSection[i].remarks;
|
|
1111
|
-
structure.answers = qaAnswers[j].answers;
|
|
1112
|
-
structure.userAnswer = mcmi;
|
|
1113
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
1114
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1115
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
1116
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1117
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1118
|
-
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1119
|
-
if ( qaAnswers[j]?.taskId ) {
|
|
1120
|
-
structure.taskId = qaAnswers[j]?.taskId;
|
|
1121
|
-
structure.task = true;
|
|
1122
|
-
}
|
|
1123
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1124
|
-
structure.redo = false;
|
|
1125
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1126
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
1127
|
-
}
|
|
1128
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
1129
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1130
|
-
};
|
|
1131
|
-
newArray.push( structure );
|
|
1132
|
-
} else {
|
|
1133
|
-
let des = [];
|
|
1134
|
-
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1135
|
-
let validationAnswer = '';
|
|
1136
|
-
if ( requestSection[i].answer.split( '?' ).length > 1 ) {
|
|
1137
|
-
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1138
|
-
}
|
|
1139
|
-
if ( validationAnswer.length ) {
|
|
1140
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
1141
|
-
if ( splitImgUrl.length > 1 ) {
|
|
1142
|
-
splitImgUrl.splice( 0, 3 );
|
|
1143
|
-
requestSection[i].answer = splitImgUrl.join( '/' );
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
let ansstructure = {
|
|
1147
|
-
answer: requestSection[i].answer,
|
|
1148
|
-
answeroptionNumber: 1,
|
|
1149
|
-
sopFlag: false,
|
|
1150
|
-
validation: false,
|
|
1151
|
-
validationType: '',
|
|
1152
|
-
validationAnswer: '',
|
|
1153
|
-
referenceImage: qaAnswers[j].answers[0].referenceImage,
|
|
1154
|
-
showLinked: qaAnswers[j].answers[0].showLinked,
|
|
1155
|
-
linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
|
|
1156
|
-
};
|
|
1157
|
-
if ( qaAnswers[j].answerType == 'date' ) {
|
|
1158
|
-
ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
|
|
1159
|
-
}
|
|
1160
|
-
des.push( ansstructure );
|
|
1161
|
-
}
|
|
1162
|
-
let structure = {};
|
|
1163
|
-
structure.qno = qaAnswers[j].qno;
|
|
1164
|
-
structure.qname = qaAnswers[j].qname;
|
|
1165
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
1166
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
1167
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1168
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1169
|
-
structure.remarks = requestSection[i].remarks;
|
|
1170
|
-
structure.answers = qaAnswers[j].answers;
|
|
1171
|
-
structure.userAnswer = des;
|
|
1172
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
1173
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1174
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
1175
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1176
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1177
|
-
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1178
|
-
if ( qaAnswers[j]?.taskId ) {
|
|
1179
|
-
structure.taskId = qaAnswers[j]?.taskId;
|
|
1180
|
-
structure.task = true;
|
|
1181
|
-
}
|
|
1182
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1183
|
-
structure.redo = false;
|
|
1184
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1185
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
1186
|
-
}
|
|
1187
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
1188
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1189
|
-
};
|
|
1190
|
-
newArray.push( structure );
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
let sectionData = {
|
|
1196
|
-
'section_id': section.id,
|
|
1197
|
-
'sectionName': section.name,
|
|
1198
|
-
'questions': newArray,
|
|
1199
|
-
};
|
|
1200
|
-
sectionFormat.push( sectionData );
|
|
622
|
+
} );
|
|
623
|
+
} );
|
|
624
|
+
} );
|
|
625
|
+
if ( validationCount ) {
|
|
626
|
+
return res.sendError( 'Please Fill all Required Fields', 400 );
|
|
627
|
+
} else {
|
|
628
|
+
next();
|
|
1201
629
|
}
|
|
630
|
+
} else {
|
|
631
|
+
next();
|
|
1202
632
|
}
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
next();
|
|
1207
|
-
} catch ( error ) {
|
|
1208
|
-
logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
|
|
1209
|
-
return res.sendError( error, 500 );
|
|
633
|
+
} catch ( e ) {
|
|
634
|
+
logger.error( { function: 'sopMobileTaskQuestionValidator', error: e, body: req.body } );
|
|
635
|
+
return res.sendError( e, 500 );
|
|
1210
636
|
}
|
|
1211
637
|
};
|
|
1212
638
|
|
|
1213
|
-
export async function
|
|
639
|
+
export async function sopMobilechecklistMultiSectionFormatter( req, res, next ) {
|
|
1214
640
|
try {
|
|
1215
641
|
let requestData = req.body;
|
|
1216
642
|
requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
|
|
1217
643
|
let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1 } );
|
|
1218
644
|
let reqAnswers = requestData.questionAnswers;
|
|
1219
|
-
logger.error( { functionName: 'updatedPayload', message: reqAnswers } );
|
|
1220
645
|
let CLQAnswers = getChecklistQA.questionAnswers;
|
|
1221
646
|
|
|
1222
647
|
if ( requestData.submittype == 'submit' ) {
|
|
@@ -1229,58 +654,6 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1229
654
|
} );
|
|
1230
655
|
}
|
|
1231
656
|
|
|
1232
|
-
if ( requestData?.editSubmit && requestData?.editSubmit == 'true' ) {
|
|
1233
|
-
let sampleData = reqAnswers[0];
|
|
1234
|
-
CLQAnswers.forEach( ( section ) => {
|
|
1235
|
-
let requestSection = reqAnswers.filter( ( reqSection ) => reqSection.sectionName == section?.sectionOldName || reqSection.sectionName == section?.sectionName );
|
|
1236
|
-
if ( requestSection.length ) {
|
|
1237
|
-
requestSection.forEach( ( item ) => item.section_id = section.section_id );
|
|
1238
|
-
section.questions.forEach( ( question ) => {
|
|
1239
|
-
let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qname == question.oldQname || secQuestion.qname == question.qname );
|
|
1240
|
-
if ( !sectionQuestion.length ) {
|
|
1241
|
-
let data = { ...requestSection[0] };
|
|
1242
|
-
data.answerType = question.answerType;
|
|
1243
|
-
data.qno = question.qno;
|
|
1244
|
-
data.qname = question.qname;
|
|
1245
|
-
data.oldQname = question?.oldQname || question.qname;
|
|
1246
|
-
data.answer = 'null';
|
|
1247
|
-
data.remarks = '';
|
|
1248
|
-
data.validationAnswer = '';
|
|
1249
|
-
data.Multianswer = [];
|
|
1250
|
-
data.linkType = question.linkType;
|
|
1251
|
-
data.linkquestionenabled = question.linkType;
|
|
1252
|
-
data.linkedQuestion = null;
|
|
1253
|
-
data.showLinked = null;
|
|
1254
|
-
data.parentanswer = '';
|
|
1255
|
-
data.dateRangeType = false;
|
|
1256
|
-
reqAnswers.push( data );
|
|
1257
|
-
}
|
|
1258
|
-
} );
|
|
1259
|
-
} else {
|
|
1260
|
-
section.questions.forEach( ( ele ) => {
|
|
1261
|
-
let data = { ...sampleData };
|
|
1262
|
-
data.section_id = section.section_id;
|
|
1263
|
-
data.sectionName = section.sectionName;
|
|
1264
|
-
data.answerType = ele.answerType;
|
|
1265
|
-
data.qno = ele.qno;
|
|
1266
|
-
data.qname = ele.qname;
|
|
1267
|
-
data.oldQname = ele?.oldQname || ele.qname;
|
|
1268
|
-
data.answer = 'null';
|
|
1269
|
-
data.remarks = '';
|
|
1270
|
-
data.validationAnswer = '';
|
|
1271
|
-
data.Multianswer = [];
|
|
1272
|
-
data.linkType = ele.linkType;
|
|
1273
|
-
data.linkquestionenabled = ele.linkType;
|
|
1274
|
-
data.linkedQuestion = null;
|
|
1275
|
-
data.showLinked = null;
|
|
1276
|
-
data.parentanswer = '';
|
|
1277
|
-
data.dateRangeType = false;
|
|
1278
|
-
reqAnswers.push( data );
|
|
1279
|
-
} );
|
|
1280
|
-
}
|
|
1281
|
-
} );
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
657
|
let sectionFormat = [];
|
|
1285
658
|
let uniqueSections = {};
|
|
1286
659
|
reqAnswers.forEach( ( item ) => {
|
|
@@ -1291,23 +664,18 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1291
664
|
} );
|
|
1292
665
|
const uniqueArray = Object.values( uniqueSections );
|
|
1293
666
|
for ( let section of uniqueArray ) {
|
|
1294
|
-
let CLQSection = CLQAnswers.find( ( item ) => item.section_id
|
|
667
|
+
let CLQSection = CLQAnswers.find( ( item ) => item.section_id == section.id );
|
|
1295
668
|
if ( CLQSection ) {
|
|
1296
669
|
let newArray = [];
|
|
1297
670
|
let qaAnswers = CLQSection.questions;
|
|
1298
671
|
let requestSection = reqAnswers.filter( ( item ) => item.section_id == section.id );
|
|
1299
672
|
for ( let i = 0; i < requestSection.length; i++ ) {
|
|
1300
673
|
for ( let j = 0; j < qaAnswers.length; j++ ) {
|
|
1301
|
-
if (
|
|
674
|
+
if ( requestSection[i].qno == qaAnswers[j].qno ) {
|
|
1302
675
|
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
1303
676
|
let qaans = qaAnswers[j].answers;
|
|
1304
677
|
let yn = [];
|
|
1305
678
|
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1306
|
-
// let requestAnswer = typeof requestSection[i].questionAnswers == 'string' ? JSON.parse( requestSection[i].questionAnswers ) : requestSection[i].questionAnswers;
|
|
1307
|
-
// let findAnswer = requestAnswer.find( ( ele ) => ele.answer == qaans[k].answer && ele.);
|
|
1308
|
-
// if ( findAnswer ) {
|
|
1309
|
-
// qaans[k].nestedQuestion = typeof findAnswer.nestedQuestion == 'string' ? JSON.parse( findAnswer.nestedQuestion ) : findAnswer.nestedQuestion;
|
|
1310
|
-
// }
|
|
1311
679
|
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1312
680
|
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1313
681
|
if ( requestSection[i].validationAnswer ) {
|
|
@@ -1321,7 +689,7 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1321
689
|
}
|
|
1322
690
|
}
|
|
1323
691
|
} else {
|
|
1324
|
-
|
|
692
|
+
qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1325
693
|
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1326
694
|
}
|
|
1327
695
|
yn.push( qaans[k] );
|
|
@@ -1342,15 +710,14 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1342
710
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1343
711
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1344
712
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1345
|
-
structure.
|
|
1346
|
-
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
713
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1347
714
|
if ( qaAnswers[j]?.taskId ) {
|
|
1348
715
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
1349
716
|
structure.task = true;
|
|
1350
717
|
}
|
|
1351
718
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1352
719
|
structure.redo = false;
|
|
1353
|
-
} else if (
|
|
720
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1354
721
|
structure.redo = qaAnswers[j]?.redo;
|
|
1355
722
|
}
|
|
1356
723
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -1361,11 +728,6 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1361
728
|
let qaans = qaAnswers[j].answers;
|
|
1362
729
|
let ms = [];
|
|
1363
730
|
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1364
|
-
// let requestAnswer = typeof requestSection[i].questionAnswers == 'string' ? JSON.parse( requestSection[i].questionAnswers ) : requestSection[i].questionAnswers;
|
|
1365
|
-
// let findAnswer= requestAnswer.find( ( ele ) => ele.answer == qaans[k].answer );
|
|
1366
|
-
// if ( findAnswer ) {
|
|
1367
|
-
// qaans[k].nestedQuestion = typeof findAnswer.nestedQuestion == 'string' ? JSON.parse( findAnswer.nestedQuestion ) : findAnswer.nestedQuestion;
|
|
1368
|
-
// }
|
|
1369
731
|
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1370
732
|
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1371
733
|
if ( requestSection[i].validationAnswer ) {
|
|
@@ -1400,15 +762,14 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1400
762
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1401
763
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1402
764
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1403
|
-
structure.
|
|
1404
|
-
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
765
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1405
766
|
if ( qaAnswers[j]?.taskId ) {
|
|
1406
767
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
1407
768
|
structure.task = true;
|
|
1408
769
|
}
|
|
1409
770
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1410
771
|
structure.redo = false;
|
|
1411
|
-
} else if (
|
|
772
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1412
773
|
structure.redo = qaAnswers[j]?.redo;
|
|
1413
774
|
}
|
|
1414
775
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -1457,15 +818,14 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1457
818
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1458
819
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1459
820
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1460
|
-
structure.
|
|
1461
|
-
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
821
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1462
822
|
if ( qaAnswers[j]?.taskId ) {
|
|
1463
823
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
1464
824
|
structure.task = true;
|
|
1465
825
|
}
|
|
1466
826
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1467
827
|
structure.redo = false;
|
|
1468
|
-
} else if (
|
|
828
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1469
829
|
structure.redo = qaAnswers[j]?.redo;
|
|
1470
830
|
}
|
|
1471
831
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -1519,15 +879,14 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1519
879
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1520
880
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1521
881
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1522
|
-
structure.
|
|
1523
|
-
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
882
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1524
883
|
if ( qaAnswers[j]?.taskId ) {
|
|
1525
884
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
1526
885
|
structure.task = true;
|
|
1527
886
|
}
|
|
1528
887
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1529
888
|
structure.redo = false;
|
|
1530
|
-
} else if (
|
|
889
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1531
890
|
structure.redo = qaAnswers[j]?.redo;
|
|
1532
891
|
}
|
|
1533
892
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -1538,7 +897,7 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1538
897
|
let des = [];
|
|
1539
898
|
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1540
899
|
let validationAnswer = '';
|
|
1541
|
-
if ( requestSection[i].answer.
|
|
900
|
+
if ( requestSection[i].answer.split( '?' ).length > 1 ) {
|
|
1542
901
|
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1543
902
|
}
|
|
1544
903
|
if ( validationAnswer.length ) {
|
|
@@ -1579,15 +938,14 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1579
938
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1580
939
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1581
940
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1582
|
-
structure.
|
|
1583
|
-
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
941
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1584
942
|
if ( qaAnswers[j]?.taskId ) {
|
|
1585
943
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
1586
944
|
structure.task = true;
|
|
1587
945
|
}
|
|
1588
946
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1589
947
|
structure.redo = false;
|
|
1590
|
-
} else if (
|
|
948
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1591
949
|
structure.redo = qaAnswers[j]?.redo;
|
|
1592
950
|
}
|
|
1593
951
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -1609,7 +967,6 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1609
967
|
|
|
1610
968
|
|
|
1611
969
|
requestData.questionAnswers = sectionFormat;
|
|
1612
|
-
logger.error( { message: requestData.questionAnswers, error: 'QuestionanswersPayload' } );
|
|
1613
970
|
next();
|
|
1614
971
|
} catch ( error ) {
|
|
1615
972
|
logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
|
|
@@ -2397,6 +1754,7 @@ export async function submitChecklist( req, res ) {
|
|
|
2397
1754
|
let flagCount = QuestionFlag( req, res );
|
|
2398
1755
|
updateData.questionFlag = flagCount;
|
|
2399
1756
|
updateData.submitTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
|
|
1757
|
+
updateData.deviceDetails = requestData?.deviceDetails || {};
|
|
2400
1758
|
if ( requestData.submittype == 'draft' ) {
|
|
2401
1759
|
logger.info( `v5 => Checklist Save => store Name: ${getchecklist[0].storeName}, User Email: ${getchecklist[0].userEmail}, Checklist Name: ${getchecklist[0].checkListName}` );
|
|
2402
1760
|
updateData.questionAnswers = requestData.questionAnswers;
|
|
@@ -3155,261 +2513,6 @@ export async function checklistv1( req, res ) {
|
|
|
3155
2513
|
}
|
|
3156
2514
|
}
|
|
3157
2515
|
|
|
3158
|
-
export async function questionListv1( req, res ) {
|
|
3159
|
-
try {
|
|
3160
|
-
let requestData = req.query;
|
|
3161
|
-
if ( !requestData.processedcheckListId ) {
|
|
3162
|
-
res.sendError( 'processedcheckListId is Required', 400 );
|
|
3163
|
-
}
|
|
3164
|
-
|
|
3165
|
-
let findQuery = [];
|
|
3166
|
-
let findAndQuery = [];
|
|
3167
|
-
findAndQuery.push( { _id: new ObjectId( requestData.processedcheckListId ) } );
|
|
3168
|
-
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
3169
|
-
|
|
3170
|
-
findQuery.push( {
|
|
3171
|
-
$project: {
|
|
3172
|
-
checkListName: { $ifNull: [ '$checkListName', '' ] },
|
|
3173
|
-
scheduleStartTime: { $ifNull: [ '$scheduleStartTime', '' ] },
|
|
3174
|
-
scheduleStartTime_iso: { $ifNull: [ '$scheduleStartTime_iso', '' ] },
|
|
3175
|
-
scheduleEndTime: { $ifNull: [ '$scheduleEndTime', '' ] },
|
|
3176
|
-
scheduleEndTime_iso: { $ifNull: [ '$scheduleEndTime_iso', '' ] },
|
|
3177
|
-
checklistStatus: { $ifNull: [ '$checklistStatus', '' ] },
|
|
3178
|
-
checkListId: { $ifNull: [ '$checkListId', '' ] },
|
|
3179
|
-
startTime: { $ifNull: [ '$startTime', '' ] },
|
|
3180
|
-
submitTime: { $ifNull: [ '$submitTime', '' ] },
|
|
3181
|
-
allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
|
|
3182
|
-
// allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
|
|
3183
|
-
allowedStoreLocation: {
|
|
3184
|
-
$cond: {
|
|
3185
|
-
if: { $eq: [ '$client_id', '11' ] },
|
|
3186
|
-
then: false,
|
|
3187
|
-
else: {
|
|
3188
|
-
'$cond': {
|
|
3189
|
-
'if': { '$eq': [ '$coverage', 'user' ] },
|
|
3190
|
-
'then': false,
|
|
3191
|
-
'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
|
|
3192
|
-
},
|
|
3193
|
-
},
|
|
3194
|
-
},
|
|
3195
|
-
},
|
|
3196
|
-
reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
|
|
3197
|
-
questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
|
|
3198
|
-
getchecklist: { $ifNull: [ '$getchecklist', '' ] },
|
|
3199
|
-
userEmail: { $ifNull: [ '$userEmail', '' ] },
|
|
3200
|
-
storeName: { $ifNull: [ '$storeName', '' ] },
|
|
3201
|
-
redoStatus: { $ifNull: [ '$redoStatus', false ] },
|
|
3202
|
-
rawImageUpload: { $ifNull: [ '$rawImageUpload', false ] },
|
|
3203
|
-
},
|
|
3204
|
-
} );
|
|
3205
|
-
|
|
3206
|
-
let getchecklist = await processedchecklist.aggregate( findQuery );
|
|
3207
|
-
if ( !getchecklist.length ) {
|
|
3208
|
-
return res.sendError( 'Check List Got Edited Please Fill Again', 422 );
|
|
3209
|
-
} else {
|
|
3210
|
-
logger.info( `v5 => Checklist Continue => store Name: ${getchecklist[0].storeName}, User Email: ${getchecklist[0].userEmail}, Checklist Name: ${getchecklist[0].checkListName}` );
|
|
3211
|
-
// let bucket = JSON.parse( process.env.BUCKET );
|
|
3212
|
-
for ( let [ secIndex, section ] of getchecklist[0].questionAnswers.entries() ) {
|
|
3213
|
-
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
3214
|
-
let Multianswer = [];
|
|
3215
|
-
if ( getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage && getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage !='' ) {
|
|
3216
|
-
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage = await signedUrl( { file_path: decodeURIComponent( getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage ), Bucket: bucket.sop } );
|
|
3217
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage;
|
|
3218
|
-
}
|
|
3219
|
-
for ( let [ ansIndex, answer ] of question.answers.entries() ) {
|
|
3220
|
-
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3221
|
-
let checkvalidation = null;
|
|
3222
|
-
if ( answer.validationAnswer && answer.validationAnswer !='' ) {
|
|
3223
|
-
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
3224
|
-
// checkvalidation = await signedUrl( { file_path: decodeURIComponent( answer.validationAnswer ), Bucket: bucket.sop } );
|
|
3225
|
-
checkvalidation = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + answer.validationAnswer;
|
|
3226
|
-
} else {
|
|
3227
|
-
checkvalidation = answer.validationAnswer;
|
|
3228
|
-
}
|
|
3229
|
-
}
|
|
3230
|
-
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
|
|
3231
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
3232
|
-
}
|
|
3233
|
-
if ( answer.referenceImage != '' ) {
|
|
3234
|
-
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage = await signedUrl( { file_path: decodeURIComponent( answer.referenceImage ), Bucket: bucket.sop } );
|
|
3235
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + answer.referenceImage;
|
|
3236
|
-
}
|
|
3237
|
-
if ( ( answer.validationType == 'Capture Image' || answer.validationType == 'Capture Video' ) && answer.validationAnswer && answer.validationAnswer != '' ) {
|
|
3238
|
-
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer = await signedUrl( { file_path: decodeURIComponent( answer.validationAnswer ), Bucket: bucket.sop } );
|
|
3239
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + answer.validationAnswer;
|
|
3240
|
-
}
|
|
3241
|
-
}
|
|
3242
|
-
if ( question?.userAnswer ) {
|
|
3243
|
-
for ( let [ userAnsIndex, userAns ] of question.userAnswer.entries() ) {
|
|
3244
|
-
if ( ( userAns.validationType == 'Capture Image' || userAns.validationType == 'Capture Video' ) && userAns.validationAnswer && userAns.validationAnswer != '' ) {
|
|
3245
|
-
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer = await signedUrl( { file_path: decodeURIComponent( userAns.validationAnswer ), Bucket: bucket.sop } );
|
|
3246
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + userAns.validationAnswer;
|
|
3247
|
-
}
|
|
3248
|
-
if ( [ 'image', 'descriptiveImage', 'video' ].includes( question.answerType ) && userAns.answer != '' ) {
|
|
3249
|
-
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer = await signedUrl( { file_path: decodeURIComponent( userAns.answer ), Bucket: bucket.sop } );
|
|
3250
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + userAns.answer;
|
|
3251
|
-
}
|
|
3252
|
-
if ( userAns.referenceImage != '' ) {
|
|
3253
|
-
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage = await signedUrl( { file_path: decodeURIComponent( userAns.referenceImage ), Bucket: bucket.sop } );
|
|
3254
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + userAns.referenceImage;
|
|
3255
|
-
}
|
|
3256
|
-
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3257
|
-
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == userAns.answer );
|
|
3258
|
-
if ( ansIndex ) {
|
|
3259
|
-
Multianswer[ansIndex].validationAnswer = userAns.validationAnswer;
|
|
3260
|
-
}
|
|
3261
|
-
}
|
|
3262
|
-
if ( question.answerType == 'multipleImage' ) {
|
|
3263
|
-
if ( userAns && userAns.answer && userAns.answer !='' ) {
|
|
3264
|
-
// let manswer = await signedUrl( { file_path: decodeURIComponent( userAns.answer ), Bucket: bucket.sop } );
|
|
3265
|
-
let manswer = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + userAns.answer;
|
|
3266
|
-
Multianswer.push( { 'answer': manswer, 'no': userAnsIndex, 'validationAnswer': '' } );
|
|
3267
|
-
} else {
|
|
3268
|
-
|
|
3269
|
-
}
|
|
3270
|
-
}
|
|
3271
|
-
}
|
|
3272
|
-
}
|
|
3273
|
-
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3274
|
-
Multianswer.forEach( ( item ) => {
|
|
3275
|
-
if ( item.validationAnswer == null ) {
|
|
3276
|
-
item.answer = null;
|
|
3277
|
-
}
|
|
3278
|
-
} );
|
|
3279
|
-
if ( Multianswer.length ) {
|
|
3280
|
-
question.Multianswer = Multianswer;
|
|
3281
|
-
} else {
|
|
3282
|
-
question.Multianswer = Multianswer;
|
|
3283
|
-
}
|
|
3284
|
-
}
|
|
3285
|
-
if ( question.answerType == 'multipleImage' ) {
|
|
3286
|
-
if ( Multianswer.length ) {
|
|
3287
|
-
question.Multianswer = Multianswer;
|
|
3288
|
-
} else {
|
|
3289
|
-
Multianswer.push( { 'answer': null, 'no': 0, 'validationAnswer': null } );
|
|
3290
|
-
question.Multianswer = Multianswer;
|
|
3291
|
-
}
|
|
3292
|
-
}
|
|
3293
|
-
}
|
|
3294
|
-
}
|
|
3295
|
-
|
|
3296
|
-
let questions = [];
|
|
3297
|
-
// function processQuestion( question, section, questions, nested=false ) {
|
|
3298
|
-
// let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
|
|
3299
|
-
// if ( findExists && nested ) {
|
|
3300
|
-
// let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
|
|
3301
|
-
// questions.splice( findIndex, 1 );
|
|
3302
|
-
// questions.push( question );
|
|
3303
|
-
// for ( let answer of question.answers ) {
|
|
3304
|
-
// if ( answer.showLinked && answer?.linkedQuestion != '' ) {
|
|
3305
|
-
// let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
|
|
3306
|
-
// if ( linkedQuestion ) {
|
|
3307
|
-
// processQuestion( linkedQuestion, section, questions, true );
|
|
3308
|
-
// }
|
|
3309
|
-
// }
|
|
3310
|
-
// }
|
|
3311
|
-
// }
|
|
3312
|
-
// if ( !findExists ) {
|
|
3313
|
-
// questions.push( question );
|
|
3314
|
-
// for ( let answer of question.answers ) {
|
|
3315
|
-
// if ( answer.showLinked && answer?.linkedQuestion != '' ) {
|
|
3316
|
-
// let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
|
|
3317
|
-
// if ( linkedQuestion ) {
|
|
3318
|
-
// processQuestion( linkedQuestion, section, questions, true );
|
|
3319
|
-
// }
|
|
3320
|
-
// }
|
|
3321
|
-
// }
|
|
3322
|
-
// }
|
|
3323
|
-
// }
|
|
3324
|
-
|
|
3325
|
-
for ( let [ index, data ] of getchecklist.entries() ) {
|
|
3326
|
-
for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
|
|
3327
|
-
questions = [];
|
|
3328
|
-
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
3329
|
-
let linkedQuestions;
|
|
3330
|
-
let uniqueShow = false;
|
|
3331
|
-
if ( !question.linkType ) {
|
|
3332
|
-
if ( !question?.uniqueNo ) {
|
|
3333
|
-
uniqueShow = true;
|
|
3334
|
-
question.uniqueNo = parseInt( getOtp() ) + Date.now() + questionIndex;
|
|
3335
|
-
}
|
|
3336
|
-
questions.push( question );
|
|
3337
|
-
linkedQuestions = [];
|
|
3338
|
-
let questionList;
|
|
3339
|
-
if ( uniqueShow ) {
|
|
3340
|
-
questionList = new Map( section.questions.map( ( ele ) => [ ele.qno, ele ] ) );
|
|
3341
|
-
} else {
|
|
3342
|
-
let uniqueList = question.answers.flatMap( ( ele ) => ele.nestedQuestion );
|
|
3343
|
-
let filteredQuestion = section.questions.filter( ( ele ) => uniqueList.includes( ele?.uniqueNo ) );
|
|
3344
|
-
questionList = new Map( filteredQuestion.map( ( ele ) => [ ele.uniqueNo, ele ] ) );
|
|
3345
|
-
}
|
|
3346
|
-
question.answers.forEach( ( answer ) => {
|
|
3347
|
-
if ( answer.linkedQuestion ) {
|
|
3348
|
-
let nesedQuestion = [];
|
|
3349
|
-
answer.oldNestedQuestion = !uniqueShow ? JSON.parse( JSON.stringify( answer.oldNestedQuestion ) ) : JSON.parse( JSON.stringify( answer.nestedQuestion ) );
|
|
3350
|
-
answer.nestedQuestion.forEach( ( qn, qidx ) => {
|
|
3351
|
-
let getQn = questionList.get( qn );
|
|
3352
|
-
if ( getQn ) {
|
|
3353
|
-
let randomNo;
|
|
3354
|
-
if ( !getQn?.uniqueNo || uniqueShow ) {
|
|
3355
|
-
randomNo = parseInt( getOtp() ) + Date.now() + qidx;
|
|
3356
|
-
} else {
|
|
3357
|
-
randomNo = getQn?.uniqueNo;
|
|
3358
|
-
}
|
|
3359
|
-
getQn = JSON.parse( JSON.stringify( getQn ) );
|
|
3360
|
-
getQn = { ...getQn, uniqueNo: randomNo };
|
|
3361
|
-
nesedQuestion.push( getQn );
|
|
3362
|
-
if ( answer.linkedQuestion == getQn.qno ) {
|
|
3363
|
-
answer.oldLinkedQuestion = answer.linkedQuestion;
|
|
3364
|
-
answer.linkedQuestion = randomNo;
|
|
3365
|
-
}
|
|
3366
|
-
answer.nestedQuestion[qidx] = randomNo;
|
|
3367
|
-
}
|
|
3368
|
-
} );
|
|
3369
|
-
console.log( nesedQuestion );
|
|
3370
|
-
nesedQuestion.forEach( ( ele ) => {
|
|
3371
|
-
let nestedLinkqn = [];
|
|
3372
|
-
ele.answers.forEach( ( ans ) => {
|
|
3373
|
-
if ( ans.linkedQuestion ) {
|
|
3374
|
-
ans.oldNestedQuestion = !uniqueShow ? JSON.parse( JSON.stringify( ans.oldNestedQuestion ) ) : JSON.parse( JSON.stringify( ans.nestedQuestion ) );
|
|
3375
|
-
ans.nestedQuestion.forEach( ( nested, idx ) => {
|
|
3376
|
-
console.log( nested, uniqueShow, 'nested', nestedLinkqn );
|
|
3377
|
-
let findRandom = nesedQuestion.find( ( qn ) => ( uniqueShow ? qn.qno == nested : qn.uniqueNo == nested ) && !nestedLinkqn.includes( qn.uniqueNo ) && !qn.updated );
|
|
3378
|
-
console.log( findRandom );
|
|
3379
|
-
if ( findRandom ) {
|
|
3380
|
-
if ( ans.linkedQuestion == findRandom.qno ) {
|
|
3381
|
-
ans.oldLinkedQuestion = ans.linkedQuestion;
|
|
3382
|
-
ans.linkedQuestion = findRandom.uniqueNo;
|
|
3383
|
-
}
|
|
3384
|
-
ans.nestedQuestion[idx] = findRandom.uniqueNo;
|
|
3385
|
-
nestedLinkqn.push( findRandom.uniqueNo );
|
|
3386
|
-
}
|
|
3387
|
-
} );
|
|
3388
|
-
}
|
|
3389
|
-
} );
|
|
3390
|
-
ele.updated = true;
|
|
3391
|
-
} );
|
|
3392
|
-
linkedQuestions.push( ...nesedQuestion );
|
|
3393
|
-
}
|
|
3394
|
-
} );
|
|
3395
|
-
questions.push( ...linkedQuestions );
|
|
3396
|
-
}
|
|
3397
|
-
// processQuestion( question, section, questions );
|
|
3398
|
-
}
|
|
3399
|
-
getchecklist[index].questionAnswers[secIndex].questions = questions;
|
|
3400
|
-
}
|
|
3401
|
-
}
|
|
3402
|
-
|
|
3403
|
-
await processedchecklist.updateOne( { _id: requestData.processedcheckListId }, { questionAnswers: getchecklist[0].questionAnswers } );
|
|
3404
|
-
|
|
3405
|
-
return res.sendSuccess( getchecklist );
|
|
3406
|
-
}
|
|
3407
|
-
} catch ( e ) {
|
|
3408
|
-
logger.error( { function: 'questionList', error: e, body: req.body } );
|
|
3409
|
-
return res.sendError( e, 500 );
|
|
3410
|
-
}
|
|
3411
|
-
}
|
|
3412
|
-
|
|
3413
2516
|
export async function questionList( req, res ) {
|
|
3414
2517
|
try {
|
|
3415
2518
|
let requestData = req.query;
|
|
@@ -3984,12 +3087,10 @@ export async function uploadAnswerImage( req, res ) {
|
|
|
3984
3087
|
}
|
|
3985
3088
|
|
|
3986
3089
|
if ( imageUrl != '' ) {
|
|
3987
|
-
|
|
3988
|
-
imageUrl = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + imageUrl.Key;
|
|
3090
|
+
imageUrl = await signedUrl( { file_path: imageUrl.Key, Bucket: bucket.sop } );
|
|
3989
3091
|
|
|
3990
3092
|
return res.sendSuccess( {
|
|
3991
3093
|
bucketName: bucket.sop,
|
|
3992
|
-
path: imageUrl.Key,
|
|
3993
3094
|
imageUrl: imageUrl,
|
|
3994
3095
|
message: 'Image uploaded successfully!',
|
|
3995
3096
|
} );
|
|
@@ -4297,8 +3398,8 @@ export async function clientConfig( req, res ) {
|
|
|
4297
3398
|
try {
|
|
4298
3399
|
let requestData = req.body;
|
|
4299
3400
|
if ( requestData.clientId && requestData.clientId !='' ) {
|
|
4300
|
-
let getClientData = await clientService.findOne( { clientId: requestData.clientId }, { traxRAWImageUpload: 1, clientId: 1, clientName: 1 } );
|
|
4301
|
-
console.log( ' getClientData=>', getClientData );
|
|
3401
|
+
let getClientData = await clientService.findOne( { clientId: requestData.clientId }, { traxRAWImageUpload: 1, clientId: 1, clientName: 1, traxBlockMobileTimeUpdate: 1, traxSectionSave: 1 } );
|
|
3402
|
+
// console.log( ' getClientData=>', getClientData );
|
|
4302
3403
|
if ( getClientData ) {
|
|
4303
3404
|
return res.sendSuccess( getClientData );
|
|
4304
3405
|
} else {
|
|
@@ -4308,7 +3409,6 @@ export async function clientConfig( req, res ) {
|
|
|
4308
3409
|
return res.sendError( 'clientId is Required', 400 );
|
|
4309
3410
|
}
|
|
4310
3411
|
} catch ( e ) {
|
|
4311
|
-
console.log( 'e =>', e );
|
|
4312
3412
|
logger.error( { error: e, function: 'clientConfig' } );
|
|
4313
3413
|
return res.sendError( e, 500 );
|
|
4314
3414
|
}
|