tango-app-api-trax 3.4.0-soplink2-0 → 3.4.1-activitylog-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -0
- package/package.json +3 -3
- package/src/controllers/activityLog.controller.js +49 -27
- package/src/controllers/download.controller.js +117 -3
- package/src/controllers/gallery.controller.js +18 -14
- package/src/controllers/internalTrax.controller.js +675 -10
- package/src/controllers/mobileTrax.controller.js +38 -962
- package/src/controllers/teaxFlag.controller.js +61 -3
- package/src/controllers/trax.controller.js +541 -289
- package/src/controllers/traxDashboard.controllers.js +1 -2
- package/src/dtos/downloadValidation.dtos.js +1 -1
- package/src/hbs/login-otp.hbs +943 -943
- 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 +5 -1
- package/src/services/processedchecklistconfig.services.js +1 -1
|
@@ -27,7 +27,6 @@ dayjs.extend( timeZone );
|
|
|
27
27
|
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore.js';
|
|
28
28
|
dayjs.extend( isSameOrBefore );
|
|
29
29
|
|
|
30
|
-
|
|
31
30
|
export async function storeList( req, res ) {
|
|
32
31
|
try {
|
|
33
32
|
if ( !req.query?.date ) {
|
|
@@ -91,260 +90,6 @@ export async function storeListv1( req, res ) {
|
|
|
91
90
|
}
|
|
92
91
|
}
|
|
93
92
|
|
|
94
|
-
export async function startChecklistv1( req, res ) {
|
|
95
|
-
try {
|
|
96
|
-
let requestData = req.body;
|
|
97
|
-
let findQuery = [];
|
|
98
|
-
findQuery.push( {
|
|
99
|
-
$match: {
|
|
100
|
-
$and: [
|
|
101
|
-
{ _id: new ObjectId( requestData.processedcheckListId ) },
|
|
102
|
-
{ userId: req.user._id },
|
|
103
|
-
{ date_string: requestData.date },
|
|
104
|
-
],
|
|
105
|
-
},
|
|
106
|
-
} );
|
|
107
|
-
|
|
108
|
-
let getBeforeChecklist = await processedchecklist.aggregate( findQuery );
|
|
109
|
-
if ( !getBeforeChecklist.length ) {
|
|
110
|
-
return res.sendError( 'Check List Got Edited Please Fill Again', 422 );
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if ( getBeforeChecklist[0].checklistStatus != 'open' ) {
|
|
114
|
-
return res.sendError( 'already check list started', 400 );
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
logger.info( `v5 => Checklist Started => store Name: ${getBeforeChecklist[0].storeName || ''}, User Email: ${getBeforeChecklist[0].userEmail}, Checklist Name: ${getBeforeChecklist[0].checkListName}` );
|
|
118
|
-
let PCLQusestion = await PCLconfig.findOne( { _id: new ObjectId( getBeforeChecklist[0].checkListId ) } );
|
|
119
|
-
let updateQuery = {};
|
|
120
|
-
updateQuery._id = new ObjectId( requestData.processedcheckListId );
|
|
121
|
-
updateQuery.userId = req.user._id;
|
|
122
|
-
updateQuery.date_string = requestData.date;
|
|
123
|
-
|
|
124
|
-
if ( PCLQusestion && PCLQusestion?.questionAnswers && PCLQusestion?.questionAnswers.length > 0 ) {
|
|
125
|
-
await PCLQusestion.questionAnswers.forEach( ( section ) => {
|
|
126
|
-
section.questions.forEach( ( question ) => {
|
|
127
|
-
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
128
|
-
let Multianswer = [];
|
|
129
|
-
if ( question.answers.length > 0 ) {
|
|
130
|
-
question.answers.forEach( ( answer, ansIndex ) => {
|
|
131
|
-
Multianswer.push( { 'answer': null, 'no': ansIndex, 'validationAnswer': null } );
|
|
132
|
-
answer.index = ansIndex;
|
|
133
|
-
} );
|
|
134
|
-
question.Multianswer = Multianswer;
|
|
135
|
-
}
|
|
136
|
-
} else if ( question.answerType == 'multipleImage' ) {
|
|
137
|
-
let Multianswer = [];
|
|
138
|
-
if ( question.answers.length > 0 ) {
|
|
139
|
-
question.answers.forEach( ( answer, ansIndex ) => {
|
|
140
|
-
Multianswer.push( { 'answer': null, 'no': ansIndex, 'validationAnswer': null } );
|
|
141
|
-
answer.index = ansIndex;
|
|
142
|
-
} );
|
|
143
|
-
question.Multianswer = Multianswer;
|
|
144
|
-
}
|
|
145
|
-
} else {
|
|
146
|
-
question.Multianswer = [];
|
|
147
|
-
}
|
|
148
|
-
} );
|
|
149
|
-
} );
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
let updateData = {};
|
|
153
|
-
let currentDateTime;
|
|
154
|
-
if ( getBeforeChecklist[0].storeName && getBeforeChecklist[0].storeName!='' ) {
|
|
155
|
-
let storeTimeZone = await storeService.findOne( { storeName: { $regex: getBeforeChecklist[0].storeName, $options: 'i' }, clientId: getBeforeChecklist[0].client_id }, { 'storeProfile.timeZone': 1 } );
|
|
156
|
-
if ( storeTimeZone?.storeProfile?.timeZone ) {
|
|
157
|
-
currentDateTime = dayjs().tz( storeTimeZone?.storeProfile?.timeZone );
|
|
158
|
-
} else {
|
|
159
|
-
currentDateTime = dayjs();
|
|
160
|
-
}
|
|
161
|
-
} else {
|
|
162
|
-
currentDateTime = dayjs();
|
|
163
|
-
}
|
|
164
|
-
updateData.checklistStatus = 'inprogress';
|
|
165
|
-
updateData.startMobileTime = requestData?.currentTime;
|
|
166
|
-
updateData.questionAnswers = getBeforeChecklist[0]?.redoStatus ? getBeforeChecklist[0].questionAnswers : PCLQusestion.questionAnswers;
|
|
167
|
-
// const newDateTime = currentDateTime.add(5, 'hours').add(30, 'minutes');
|
|
168
|
-
// updateData.startTime_string = newDateTime.format('hh:mm A, DD MMM');
|
|
169
|
-
updateData.startTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
|
|
170
|
-
updateData.startTime = dayjs.utc( updateData.startTime_string, 'hh:mm A, DD MMM YYYY' ).format();
|
|
171
|
-
|
|
172
|
-
let updatechecklist = await processedchecklist.updateOne( updateQuery, updateData );
|
|
173
|
-
PCLQusestion.startTime = dayjs.utc( updateData.startTime_string, 'hh:mm A, DD MMM YYYY' ).format();
|
|
174
|
-
PCLQusestion.save();
|
|
175
|
-
if ( updatechecklist.modifiedCount > 0 ) {
|
|
176
|
-
findQuery.push( {
|
|
177
|
-
$project: {
|
|
178
|
-
checkListName: { $ifNull: [ '$checkListName', '' ] },
|
|
179
|
-
coverage: { $ifNull: [ '$coverage', '' ] },
|
|
180
|
-
client_id: { $ifNull: [ '$client_id', '' ] },
|
|
181
|
-
scheduleStartTime: { $ifNull: [ '$scheduleStartTime', '' ] },
|
|
182
|
-
scheduleStartTime_iso: { $ifNull: [ '$scheduleStartTime_iso', '' ] },
|
|
183
|
-
scheduleEndTime: { $ifNull: [ '$scheduleEndTime', '' ] },
|
|
184
|
-
scheduleEndTime_iso: { $ifNull: [ '$scheduleEndTime_iso', '' ] },
|
|
185
|
-
checklistStatus: { $ifNull: [ '$checklistStatus', '' ] },
|
|
186
|
-
checkListId: { $ifNull: [ '$checkListId', '' ] },
|
|
187
|
-
startTime: { $ifNull: [ '$startTime', '' ] },
|
|
188
|
-
submitTime: { $ifNull: [ '$submitTime', '' ] },
|
|
189
|
-
allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
|
|
190
|
-
// allowedStoreLocation: { $ifNull: [ '$checallowedStoreLocationkListName', false ] },
|
|
191
|
-
allowedStoreLocation: {
|
|
192
|
-
$cond: {
|
|
193
|
-
if: { $eq: [ '$client_id', '11' ] },
|
|
194
|
-
then: false,
|
|
195
|
-
else: {
|
|
196
|
-
'$cond': {
|
|
197
|
-
'if': { '$eq': [ '$coverage', 'user' ] },
|
|
198
|
-
'then': false,
|
|
199
|
-
'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
|
|
205
|
-
redoStatus: { $ifNull: [ '$redoStatus', '' ] },
|
|
206
|
-
},
|
|
207
|
-
} );
|
|
208
|
-
let getupdatedchecklist = await processedchecklist.aggregate( findQuery );
|
|
209
|
-
// let bucket = JSON.parse( process.env.BUCKET );
|
|
210
|
-
|
|
211
|
-
let logInsertData = {
|
|
212
|
-
store_id: getBeforeChecklist[0]?.store_id || '',
|
|
213
|
-
storeName: getBeforeChecklist[0]?.storeName || '',
|
|
214
|
-
action: 'started',
|
|
215
|
-
checklistId: getBeforeChecklist[0].sourceCheckList_id,
|
|
216
|
-
processedChecklistId: getBeforeChecklist[0]._id,
|
|
217
|
-
checkListName: getBeforeChecklist[0].checkListName,
|
|
218
|
-
type: getBeforeChecklist[0].checkListType,
|
|
219
|
-
client_id: req.user.clientId,
|
|
220
|
-
userEmail: getBeforeChecklist[0].userEmail || '',
|
|
221
|
-
userName: getBeforeChecklist[0].userName || '',
|
|
222
|
-
coverage: getBeforeChecklist[0].coverage || '',
|
|
223
|
-
};
|
|
224
|
-
await checklistLogs.create( logInsertData );
|
|
225
|
-
let getchecklist = getupdatedchecklist;
|
|
226
|
-
let questions = [];
|
|
227
|
-
// function processQuestion( question, section, questions, nested=false ) {
|
|
228
|
-
// let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
|
|
229
|
-
// if ( findExists && nested ) {
|
|
230
|
-
// let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
|
|
231
|
-
// questions.splice( findIndex, 1 );
|
|
232
|
-
// questions.push( question );
|
|
233
|
-
// }
|
|
234
|
-
// if ( !findExists ) {
|
|
235
|
-
// questions.push( question );
|
|
236
|
-
// for ( let answer of question.answers ) {
|
|
237
|
-
// if ( answer.showLinked && answer?.linkedQuestion != '' ) {
|
|
238
|
-
// let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
|
|
239
|
-
// if ( linkedQuestion ) {
|
|
240
|
-
// processQuestion( linkedQuestion, section, questions, true );
|
|
241
|
-
// }
|
|
242
|
-
// }
|
|
243
|
-
// }
|
|
244
|
-
// }
|
|
245
|
-
// }
|
|
246
|
-
for ( let [ index, data ] of getchecklist.entries() ) {
|
|
247
|
-
for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
|
|
248
|
-
questions = [];
|
|
249
|
-
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
250
|
-
let linkedQuestions;
|
|
251
|
-
let uniqueShow = false;
|
|
252
|
-
if ( !question.linkType ) {
|
|
253
|
-
if ( !question?.uniqueNo ) {
|
|
254
|
-
uniqueShow = true;
|
|
255
|
-
question.uniqueNo = parseInt( getOtp() ) + Date.now() + questionIndex;
|
|
256
|
-
}
|
|
257
|
-
questions.push( question );
|
|
258
|
-
linkedQuestions = [];
|
|
259
|
-
let questionList;
|
|
260
|
-
if ( uniqueShow ) {
|
|
261
|
-
questionList = new Map( section.questions.map( ( ele ) => [ ele.qno, ele ] ) );
|
|
262
|
-
} else {
|
|
263
|
-
let uniqueList = question.answers.flatMap( ( ele ) => ele.nestedQuestion );
|
|
264
|
-
let filteredQuestion = section.questions.filter( ( ele ) => uniqueList.includes( ele?.uniqueNo ) );
|
|
265
|
-
questionList = new Map( filteredQuestion.map( ( ele ) => [ ele.uniqueNo, ele ] ) );
|
|
266
|
-
}
|
|
267
|
-
question.answers.forEach( ( answer ) => {
|
|
268
|
-
if ( answer.linkedQuestion ) {
|
|
269
|
-
let nesedQuestion = [];
|
|
270
|
-
answer.oldNestedQuestion = !uniqueShow ? JSON.parse( JSON.stringify( answer.oldNestedQuestion ) ) : JSON.parse( JSON.stringify( answer.nestedQuestion ) );
|
|
271
|
-
answer.nestedQuestion.forEach( ( qn, qidx ) => {
|
|
272
|
-
let getQn = questionList.get( qn );
|
|
273
|
-
if ( getQn ) {
|
|
274
|
-
let randomNo;
|
|
275
|
-
if ( !getQn?.uniqueNo || uniqueShow ) {
|
|
276
|
-
randomNo = parseInt( getOtp() ) + Date.now() + qidx;
|
|
277
|
-
} else {
|
|
278
|
-
randomNo = getQn?.uniqueNo;
|
|
279
|
-
}
|
|
280
|
-
getQn = JSON.parse( JSON.stringify( getQn ) );
|
|
281
|
-
getQn = { ...getQn, uniqueNo: randomNo };
|
|
282
|
-
nesedQuestion.push( getQn );
|
|
283
|
-
if ( answer.linkedQuestion == getQn.qno ) {
|
|
284
|
-
answer.oldLinkedQuestion = answer.linkedQuestion;
|
|
285
|
-
answer.linkedQuestion = randomNo;
|
|
286
|
-
}
|
|
287
|
-
answer.nestedQuestion[qidx] = randomNo;
|
|
288
|
-
}
|
|
289
|
-
} );
|
|
290
|
-
nesedQuestion.forEach( ( ele ) => {
|
|
291
|
-
let nestedLinkqn = [];
|
|
292
|
-
ele.answers.forEach( ( ans ) => {
|
|
293
|
-
if ( ans.linkedQuestion ) {
|
|
294
|
-
ans.oldNestedQuestion = !uniqueShow ? JSON.parse( JSON.stringify( ans.oldNestedQuestion ) ) : JSON.parse( JSON.stringify( ans.nestedQuestion ) );
|
|
295
|
-
ans.nestedQuestion.forEach( ( nested, idx ) => {
|
|
296
|
-
let findRandom = nesedQuestion.find( ( qn ) => ( uniqueShow ? qn.qno == nested : qn.uniqueNo == nested ) && !nestedLinkqn.includes( qn.uniqueNo ) && !qn.updated );
|
|
297
|
-
if ( findRandom ) {
|
|
298
|
-
if ( ans.linkedQuestion == findRandom.qno ) {
|
|
299
|
-
ans.oldLinkedQuestion = ans.linkedQuestion;
|
|
300
|
-
ans.linkedQuestion = findRandom.uniqueNo;
|
|
301
|
-
}
|
|
302
|
-
ans.nestedQuestion[idx] = findRandom.uniqueNo;
|
|
303
|
-
nestedLinkqn.push( findRandom.uniqueNo );
|
|
304
|
-
}
|
|
305
|
-
} );
|
|
306
|
-
}
|
|
307
|
-
} );
|
|
308
|
-
ele.updated = true;
|
|
309
|
-
} );
|
|
310
|
-
linkedQuestions.push( ...nesedQuestion );
|
|
311
|
-
}
|
|
312
|
-
} );
|
|
313
|
-
questions.push( ...linkedQuestions );
|
|
314
|
-
}
|
|
315
|
-
// processQuestion( question, section, questions );
|
|
316
|
-
}
|
|
317
|
-
getchecklist[index].questionAnswers[secIndex].questions = questions;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
if ( !getchecklist[0].redoStatus ) {
|
|
321
|
-
await processedchecklist.updateOne( updateQuery, { questionAnswers: getchecklist[0].questionAnswers } );
|
|
322
|
-
}
|
|
323
|
-
getupdatedchecklist[0].questionAnswers.forEach( ( section ) => {
|
|
324
|
-
section.questions.forEach( async ( question ) => {
|
|
325
|
-
if ( question.questionReferenceImage && question.questionReferenceImage!='' ) {
|
|
326
|
-
question.questionReferenceImage = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + question.questionReferenceImage;
|
|
327
|
-
// question.questionReferenceImage = await signedUrl( { Bucket: bucket.sop, file_path: decodeURIComponent( question.questionReferenceImage ) } );
|
|
328
|
-
}
|
|
329
|
-
question.answers.forEach( async ( answer ) => {
|
|
330
|
-
if ( answer.referenceImage != '' ) {
|
|
331
|
-
answer.referenceImage = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + answer.referenceImage;
|
|
332
|
-
// answer.referenceImage = await signedUrl( { Bucket: bucket.sop, file_path: decodeURIComponent( answer.referenceImage ) } );
|
|
333
|
-
}
|
|
334
|
-
} );
|
|
335
|
-
} );
|
|
336
|
-
} );
|
|
337
|
-
return res.sendSuccess( getchecklist );
|
|
338
|
-
} else {
|
|
339
|
-
return res.sendError( 'something went wrong please try again', 500 );
|
|
340
|
-
}
|
|
341
|
-
} catch ( e ) {
|
|
342
|
-
console.log( 'e =>', e );
|
|
343
|
-
logger.error( { function: 'startChecklist', error: e, body: req.body } );
|
|
344
|
-
return res.sendError( e, 500 );
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
93
|
export async function startChecklist( req, res ) {
|
|
349
94
|
try {
|
|
350
95
|
let requestData = req.body;
|
|
@@ -533,11 +278,10 @@ export async function startChecklist( req, res ) {
|
|
|
533
278
|
createdBy: getBeforeChecklist[0]?.userName || '',
|
|
534
279
|
coverage: getBeforeChecklist[0]?.coverage || '',
|
|
535
280
|
logDetails: {},
|
|
281
|
+
userType: req.user.userType,
|
|
536
282
|
};
|
|
537
283
|
// let insertOS = await insertOpenSearchData( 'test-traxlogs', inserttraxlogs );
|
|
538
|
-
|
|
539
|
-
let insertOS = await insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
|
|
540
|
-
console.log( 'insertOS', insertOS );
|
|
284
|
+
insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
|
|
541
285
|
return res.sendSuccess( getchecklist );
|
|
542
286
|
} else {
|
|
543
287
|
return res.sendError( 'something went wrong please try again', 500 );
|
|
@@ -728,8 +472,7 @@ export async function startTask( req, res ) {
|
|
|
728
472
|
};
|
|
729
473
|
// let insertOS = await insertOpenSearchData( 'test-traxlogs', inserttraxlogs );
|
|
730
474
|
console.log( 'inserttraxlogs', inserttraxlogs );
|
|
731
|
-
|
|
732
|
-
console.log( 'insertOS', insertOS );
|
|
475
|
+
insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
|
|
733
476
|
return res.sendSuccess( getUpdatedTask );
|
|
734
477
|
} catch ( error ) {
|
|
735
478
|
logger.error( { function: 'startTask', error, body: req.body } );
|
|
@@ -919,365 +662,26 @@ export async function sopMobileTaskQuestionValidator( req, res, next ) {
|
|
|
919
662
|
} );
|
|
920
663
|
} );
|
|
921
664
|
} );
|
|
922
|
-
if ( validationCount ) {
|
|
923
|
-
return res.sendError( 'Please Fill all Required Fields', 400 );
|
|
924
|
-
} else {
|
|
925
|
-
next();
|
|
926
|
-
}
|
|
927
|
-
} else {
|
|
928
|
-
next();
|
|
929
|
-
}
|
|
930
|
-
} catch ( e ) {
|
|
931
|
-
logger.error( { function: 'sopMobileTaskQuestionValidator', error: e, body: req.body } );
|
|
932
|
-
return res.sendError( e, 500 );
|
|
933
|
-
}
|
|
934
|
-
};
|
|
935
|
-
|
|
936
|
-
export async function sopMobilechecklistMultiSectionFormatter( req, res, next ) {
|
|
937
|
-
try {
|
|
938
|
-
let requestData = req.body;
|
|
939
|
-
requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
|
|
940
|
-
let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1 } );
|
|
941
|
-
let reqAnswers = requestData.questionAnswers;
|
|
942
|
-
let CLQAnswers = getChecklistQA.questionAnswers;
|
|
943
|
-
|
|
944
|
-
if ( requestData.submittype == 'submit' ) {
|
|
945
|
-
reqAnswers.forEach( ( reqA ) => {
|
|
946
|
-
if ( ![ 'multiplechoicemultiple', 'multipleImage' ].includes( reqA?.answerType ) ) {
|
|
947
|
-
if ( ( !reqA.linkType && ( reqA.answer == null || reqA.answer == '' ) ) || ( reqA.linkType && reqA.linkquestionenabled && ( reqA.answer == null || reqA.answer == '' ) ) ) {
|
|
948
|
-
return res.sendError( 'Please Fill All Fields', 400 );
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
} );
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
let sectionFormat = [];
|
|
955
|
-
let uniqueSections = {};
|
|
956
|
-
reqAnswers.forEach( ( item ) => {
|
|
957
|
-
const key = `${item.section_id}-${item.sectionName}`;
|
|
958
|
-
if ( !uniqueSections[key] ) {
|
|
959
|
-
uniqueSections[key] = { id: item.section_id, name: item.sectionName };
|
|
960
|
-
}
|
|
961
|
-
} );
|
|
962
|
-
const uniqueArray = Object.values( uniqueSections );
|
|
963
|
-
for ( let section of uniqueArray ) {
|
|
964
|
-
let CLQSection = CLQAnswers.find( ( item ) => item.section_id == section.id );
|
|
965
|
-
if ( CLQSection ) {
|
|
966
|
-
let newArray = [];
|
|
967
|
-
let qaAnswers = CLQSection.questions;
|
|
968
|
-
let requestSection = reqAnswers.filter( ( item ) => item.section_id == section.id );
|
|
969
|
-
for ( let i = 0; i < requestSection.length; i++ ) {
|
|
970
|
-
for ( let j = 0; j < qaAnswers.length; j++ ) {
|
|
971
|
-
if ( requestSection[i].qno == qaAnswers[j].qno ) {
|
|
972
|
-
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
973
|
-
let qaans = qaAnswers[j].answers;
|
|
974
|
-
let yn = [];
|
|
975
|
-
for ( let k = 0; k < qaans.length; k++ ) {
|
|
976
|
-
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
977
|
-
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
978
|
-
if ( requestSection[i].validationAnswer ) {
|
|
979
|
-
let validateAns = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
980
|
-
if ( validateAns.length ) {
|
|
981
|
-
let splitImgUrl = validateAns.split( '/' );
|
|
982
|
-
if ( splitImgUrl.length > 1 ) {
|
|
983
|
-
splitImgUrl.splice( 0, 3 );
|
|
984
|
-
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
} else {
|
|
989
|
-
qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
990
|
-
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
991
|
-
}
|
|
992
|
-
yn.push( qaans[k] );
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
let structure = {};
|
|
996
|
-
structure.qno = qaAnswers[j].qno;
|
|
997
|
-
structure.qname = qaAnswers[j].qname;
|
|
998
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
999
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
1000
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1001
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1002
|
-
structure.remarks = requestSection[i].remarks;
|
|
1003
|
-
structure.answers = qaAnswers[j].answers;
|
|
1004
|
-
structure.userAnswer = yn;
|
|
1005
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
1006
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1007
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
1008
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1009
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1010
|
-
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1011
|
-
if ( qaAnswers[j]?.taskId ) {
|
|
1012
|
-
structure.taskId = qaAnswers[j]?.taskId;
|
|
1013
|
-
structure.task = true;
|
|
1014
|
-
}
|
|
1015
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1016
|
-
structure.redo = false;
|
|
1017
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1018
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
1019
|
-
}
|
|
1020
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
1021
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1022
|
-
};
|
|
1023
|
-
newArray.push( structure );
|
|
1024
|
-
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle' ) {
|
|
1025
|
-
let qaans = qaAnswers[j].answers;
|
|
1026
|
-
let ms = [];
|
|
1027
|
-
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1028
|
-
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1029
|
-
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1030
|
-
if ( requestSection[i].validationAnswer ) {
|
|
1031
|
-
let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
1032
|
-
if ( validationAnswer.length ) {
|
|
1033
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
1034
|
-
if ( splitImgUrl.length > 1 ) {
|
|
1035
|
-
splitImgUrl.splice( 0, 3 );
|
|
1036
|
-
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
} else {
|
|
1041
|
-
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1042
|
-
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1043
|
-
}
|
|
1044
|
-
ms.push( qaans[k] );
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
let structure = {};
|
|
1048
|
-
structure.qno = qaAnswers[j].qno;
|
|
1049
|
-
structure.qname = qaAnswers[j].qname;
|
|
1050
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
1051
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
1052
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1053
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1054
|
-
structure.remarks = requestSection[i].remarks;
|
|
1055
|
-
structure.answers = qaAnswers[j].answers;
|
|
1056
|
-
structure.userAnswer = ms;
|
|
1057
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
1058
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1059
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
1060
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1061
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1062
|
-
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1063
|
-
if ( qaAnswers[j]?.taskId ) {
|
|
1064
|
-
structure.taskId = qaAnswers[j]?.taskId;
|
|
1065
|
-
structure.task = true;
|
|
1066
|
-
}
|
|
1067
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1068
|
-
structure.redo = false;
|
|
1069
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1070
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
1071
|
-
}
|
|
1072
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
1073
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1074
|
-
};
|
|
1075
|
-
newArray.push( structure );
|
|
1076
|
-
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' ) {
|
|
1077
|
-
let qaans = qaAnswers[j].answers;
|
|
1078
|
-
let mcmo = [];
|
|
1079
|
-
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1080
|
-
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1081
|
-
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1082
|
-
if ( separatedArray[s].answer == qaans[k].answer ) {
|
|
1083
|
-
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1084
|
-
if ( separatedArray[s].validationAnswer ) {
|
|
1085
|
-
let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
|
|
1086
|
-
if ( validationAnswer.length ) {
|
|
1087
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
1088
|
-
if ( splitImgUrl.length > 1 ) {
|
|
1089
|
-
splitImgUrl.splice( 0, 3 );
|
|
1090
|
-
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
} else {
|
|
1095
|
-
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1096
|
-
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
mcmo.push( qaans[k] );
|
|
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 = mcmo;
|
|
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 if ( qaAnswers[j].answerType == 'multipleImage' ) {
|
|
1133
|
-
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1134
|
-
let mcmi = [];
|
|
1135
|
-
// for (let k = 0; k < qaans.length; k++) {
|
|
1136
|
-
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1137
|
-
if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
|
|
1138
|
-
let newAnswer = {};
|
|
1139
|
-
let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
|
|
1140
|
-
if ( validationAnswer.length ) {
|
|
1141
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
1142
|
-
if ( splitImgUrl.length > 1 ) {
|
|
1143
|
-
splitImgUrl.splice( 0, 3 );
|
|
1144
|
-
newAnswer.answer = splitImgUrl.join( '/' ) || '';
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
newAnswer.answeroptionNumber = 0;
|
|
1149
|
-
newAnswer.sopFlag = false;
|
|
1150
|
-
newAnswer.validation = false;
|
|
1151
|
-
newAnswer.validationType = '';
|
|
1152
|
-
newAnswer.referenceImage = '';
|
|
1153
|
-
newAnswer.allowUploadfromGallery = false;
|
|
1154
|
-
newAnswer.runAI = false;
|
|
1155
|
-
newAnswer.descriptivetype = '';
|
|
1156
|
-
newAnswer.showLinked = false;
|
|
1157
|
-
newAnswer.linkedQuestion = 0;
|
|
1158
|
-
newAnswer.nestedQuestion = [];
|
|
1159
|
-
newAnswer.index = s;
|
|
1160
|
-
mcmi.push( newAnswer );
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
// }
|
|
1164
|
-
let structure = {};
|
|
1165
|
-
structure.qno = qaAnswers[j].qno;
|
|
1166
|
-
structure.qname = qaAnswers[j].qname;
|
|
1167
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
1168
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
1169
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1170
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1171
|
-
structure.remarks = requestSection[i].remarks;
|
|
1172
|
-
structure.answers = qaAnswers[j].answers;
|
|
1173
|
-
structure.userAnswer = mcmi;
|
|
1174
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
1175
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1176
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
1177
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1178
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1179
|
-
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1180
|
-
if ( qaAnswers[j]?.taskId ) {
|
|
1181
|
-
structure.taskId = qaAnswers[j]?.taskId;
|
|
1182
|
-
structure.task = true;
|
|
1183
|
-
}
|
|
1184
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1185
|
-
structure.redo = false;
|
|
1186
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1187
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
1188
|
-
}
|
|
1189
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
1190
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1191
|
-
};
|
|
1192
|
-
newArray.push( structure );
|
|
1193
|
-
} else {
|
|
1194
|
-
let des = [];
|
|
1195
|
-
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1196
|
-
let validationAnswer = '';
|
|
1197
|
-
if ( requestSection[i].answer.split( '?' ).length > 1 ) {
|
|
1198
|
-
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1199
|
-
}
|
|
1200
|
-
if ( validationAnswer.length ) {
|
|
1201
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
1202
|
-
if ( splitImgUrl.length > 1 ) {
|
|
1203
|
-
splitImgUrl.splice( 0, 3 );
|
|
1204
|
-
requestSection[i].answer = splitImgUrl.join( '/' );
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
let ansstructure = {
|
|
1208
|
-
answer: requestSection[i].answer,
|
|
1209
|
-
answeroptionNumber: 1,
|
|
1210
|
-
sopFlag: false,
|
|
1211
|
-
validation: false,
|
|
1212
|
-
validationType: '',
|
|
1213
|
-
validationAnswer: '',
|
|
1214
|
-
referenceImage: qaAnswers[j].answers[0].referenceImage,
|
|
1215
|
-
showLinked: qaAnswers[j].answers[0].showLinked,
|
|
1216
|
-
linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
|
|
1217
|
-
};
|
|
1218
|
-
if ( qaAnswers[j].answerType == 'date' ) {
|
|
1219
|
-
ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
|
|
1220
|
-
}
|
|
1221
|
-
des.push( ansstructure );
|
|
1222
|
-
}
|
|
1223
|
-
let structure = {};
|
|
1224
|
-
structure.qno = qaAnswers[j].qno;
|
|
1225
|
-
structure.qname = qaAnswers[j].qname;
|
|
1226
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
1227
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
1228
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1229
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1230
|
-
structure.remarks = requestSection[i].remarks;
|
|
1231
|
-
structure.answers = qaAnswers[j].answers;
|
|
1232
|
-
structure.userAnswer = des;
|
|
1233
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
1234
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1235
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
1236
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1237
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1238
|
-
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1239
|
-
if ( qaAnswers[j]?.taskId ) {
|
|
1240
|
-
structure.taskId = qaAnswers[j]?.taskId;
|
|
1241
|
-
structure.task = true;
|
|
1242
|
-
}
|
|
1243
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1244
|
-
structure.redo = false;
|
|
1245
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
1246
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
1247
|
-
}
|
|
1248
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
1249
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1250
|
-
};
|
|
1251
|
-
newArray.push( structure );
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
let sectionData = {
|
|
1257
|
-
'section_id': section.id,
|
|
1258
|
-
'sectionName': section.name,
|
|
1259
|
-
'questions': newArray,
|
|
1260
|
-
};
|
|
1261
|
-
sectionFormat.push( sectionData );
|
|
665
|
+
if ( validationCount ) {
|
|
666
|
+
return res.sendError( 'Please Fill all Required Fields', 400 );
|
|
667
|
+
} else {
|
|
668
|
+
next();
|
|
1262
669
|
}
|
|
670
|
+
} else {
|
|
671
|
+
next();
|
|
1263
672
|
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
next();
|
|
1268
|
-
} catch ( error ) {
|
|
1269
|
-
logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
|
|
1270
|
-
return res.sendError( error, 500 );
|
|
673
|
+
} catch ( e ) {
|
|
674
|
+
logger.error( { function: 'sopMobileTaskQuestionValidator', error: e, body: req.body } );
|
|
675
|
+
return res.sendError( e, 500 );
|
|
1271
676
|
}
|
|
1272
677
|
};
|
|
1273
678
|
|
|
1274
|
-
export async function
|
|
679
|
+
export async function sopMobilechecklistMultiSectionFormatter( req, res, next ) {
|
|
1275
680
|
try {
|
|
1276
681
|
let requestData = req.body;
|
|
1277
682
|
requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
|
|
1278
683
|
let getChecklistQA = await processedchecklist.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1 } );
|
|
1279
684
|
let reqAnswers = requestData.questionAnswers;
|
|
1280
|
-
logger.error( { functionName: 'updatedPayload', message: reqAnswers } );
|
|
1281
685
|
let CLQAnswers = getChecklistQA.questionAnswers;
|
|
1282
686
|
|
|
1283
687
|
if ( requestData.submittype == 'submit' ) {
|
|
@@ -1290,58 +694,6 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1290
694
|
} );
|
|
1291
695
|
}
|
|
1292
696
|
|
|
1293
|
-
if ( requestData?.editSubmit && requestData?.editSubmit == 'true' ) {
|
|
1294
|
-
let sampleData = reqAnswers[0];
|
|
1295
|
-
CLQAnswers.forEach( ( section ) => {
|
|
1296
|
-
let requestSection = reqAnswers.filter( ( reqSection ) => reqSection.sectionName == section?.sectionOldName || reqSection.sectionName == section?.sectionName );
|
|
1297
|
-
if ( requestSection.length ) {
|
|
1298
|
-
requestSection.forEach( ( item ) => item.section_id = section.section_id );
|
|
1299
|
-
section.questions.forEach( ( question ) => {
|
|
1300
|
-
let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qname == question.oldQname || secQuestion.qname == question.qname );
|
|
1301
|
-
if ( !sectionQuestion.length ) {
|
|
1302
|
-
let data = { ...requestSection[0] };
|
|
1303
|
-
data.answerType = question.answerType;
|
|
1304
|
-
data.qno = question.qno;
|
|
1305
|
-
data.qname = question.qname;
|
|
1306
|
-
data.oldQname = question?.oldQname || question.qname;
|
|
1307
|
-
data.answer = 'null';
|
|
1308
|
-
data.remarks = '';
|
|
1309
|
-
data.validationAnswer = '';
|
|
1310
|
-
data.Multianswer = [];
|
|
1311
|
-
data.linkType = question.linkType;
|
|
1312
|
-
data.linkquestionenabled = question.linkType;
|
|
1313
|
-
data.linkedQuestion = null;
|
|
1314
|
-
data.showLinked = null;
|
|
1315
|
-
data.parentanswer = '';
|
|
1316
|
-
data.dateRangeType = false;
|
|
1317
|
-
reqAnswers.push( data );
|
|
1318
|
-
}
|
|
1319
|
-
} );
|
|
1320
|
-
} else {
|
|
1321
|
-
section.questions.forEach( ( ele ) => {
|
|
1322
|
-
let data = { ...sampleData };
|
|
1323
|
-
data.section_id = section.section_id;
|
|
1324
|
-
data.sectionName = section.sectionName;
|
|
1325
|
-
data.answerType = ele.answerType;
|
|
1326
|
-
data.qno = ele.qno;
|
|
1327
|
-
data.qname = ele.qname;
|
|
1328
|
-
data.oldQname = ele?.oldQname || ele.qname;
|
|
1329
|
-
data.answer = 'null';
|
|
1330
|
-
data.remarks = '';
|
|
1331
|
-
data.validationAnswer = '';
|
|
1332
|
-
data.Multianswer = [];
|
|
1333
|
-
data.linkType = ele.linkType;
|
|
1334
|
-
data.linkquestionenabled = ele.linkType;
|
|
1335
|
-
data.linkedQuestion = null;
|
|
1336
|
-
data.showLinked = null;
|
|
1337
|
-
data.parentanswer = '';
|
|
1338
|
-
data.dateRangeType = false;
|
|
1339
|
-
reqAnswers.push( data );
|
|
1340
|
-
} );
|
|
1341
|
-
}
|
|
1342
|
-
} );
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
697
|
let sectionFormat = [];
|
|
1346
698
|
let uniqueSections = {};
|
|
1347
699
|
reqAnswers.forEach( ( item ) => {
|
|
@@ -1352,23 +704,18 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1352
704
|
} );
|
|
1353
705
|
const uniqueArray = Object.values( uniqueSections );
|
|
1354
706
|
for ( let section of uniqueArray ) {
|
|
1355
|
-
let CLQSection = CLQAnswers.find( ( item ) => item.section_id
|
|
707
|
+
let CLQSection = CLQAnswers.find( ( item ) => item.section_id == section.id );
|
|
1356
708
|
if ( CLQSection ) {
|
|
1357
709
|
let newArray = [];
|
|
1358
710
|
let qaAnswers = CLQSection.questions;
|
|
1359
711
|
let requestSection = reqAnswers.filter( ( item ) => item.section_id == section.id );
|
|
1360
712
|
for ( let i = 0; i < requestSection.length; i++ ) {
|
|
1361
713
|
for ( let j = 0; j < qaAnswers.length; j++ ) {
|
|
1362
|
-
if (
|
|
714
|
+
if ( requestSection[i].qno == qaAnswers[j].qno ) {
|
|
1363
715
|
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
1364
716
|
let qaans = qaAnswers[j].answers;
|
|
1365
717
|
let yn = [];
|
|
1366
718
|
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1367
|
-
// let requestAnswer = typeof requestSection[i].questionAnswers == 'string' ? JSON.parse( requestSection[i].questionAnswers ) : requestSection[i].questionAnswers;
|
|
1368
|
-
// let findAnswer = requestAnswer.find( ( ele ) => ele.answer == qaans[k].answer && ele.);
|
|
1369
|
-
// if ( findAnswer ) {
|
|
1370
|
-
// qaans[k].nestedQuestion = typeof findAnswer.nestedQuestion == 'string' ? JSON.parse( findAnswer.nestedQuestion ) : findAnswer.nestedQuestion;
|
|
1371
|
-
// }
|
|
1372
719
|
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1373
720
|
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1374
721
|
if ( requestSection[i].validationAnswer ) {
|
|
@@ -1382,7 +729,7 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1382
729
|
}
|
|
1383
730
|
}
|
|
1384
731
|
} else {
|
|
1385
|
-
|
|
732
|
+
qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1386
733
|
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1387
734
|
}
|
|
1388
735
|
yn.push( qaans[k] );
|
|
@@ -1403,15 +750,14 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1403
750
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1404
751
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1405
752
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1406
|
-
structure.
|
|
1407
|
-
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
753
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1408
754
|
if ( qaAnswers[j]?.taskId ) {
|
|
1409
755
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
1410
756
|
structure.task = true;
|
|
1411
757
|
}
|
|
1412
758
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1413
759
|
structure.redo = false;
|
|
1414
|
-
} else if (
|
|
760
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1415
761
|
structure.redo = qaAnswers[j]?.redo;
|
|
1416
762
|
}
|
|
1417
763
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -1422,11 +768,6 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1422
768
|
let qaans = qaAnswers[j].answers;
|
|
1423
769
|
let ms = [];
|
|
1424
770
|
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1425
|
-
// let requestAnswer = typeof requestSection[i].questionAnswers == 'string' ? JSON.parse( requestSection[i].questionAnswers ) : requestSection[i].questionAnswers;
|
|
1426
|
-
// let findAnswer= requestAnswer.find( ( ele ) => ele.answer == qaans[k].answer );
|
|
1427
|
-
// if ( findAnswer ) {
|
|
1428
|
-
// qaans[k].nestedQuestion = typeof findAnswer.nestedQuestion == 'string' ? JSON.parse( findAnswer.nestedQuestion ) : findAnswer.nestedQuestion;
|
|
1429
|
-
// }
|
|
1430
771
|
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1431
772
|
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1432
773
|
if ( requestSection[i].validationAnswer ) {
|
|
@@ -1461,15 +802,14 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1461
802
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1462
803
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1463
804
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1464
|
-
structure.
|
|
1465
|
-
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
805
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1466
806
|
if ( qaAnswers[j]?.taskId ) {
|
|
1467
807
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
1468
808
|
structure.task = true;
|
|
1469
809
|
}
|
|
1470
810
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1471
811
|
structure.redo = false;
|
|
1472
|
-
} else if (
|
|
812
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1473
813
|
structure.redo = qaAnswers[j]?.redo;
|
|
1474
814
|
}
|
|
1475
815
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -1518,15 +858,14 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1518
858
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1519
859
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1520
860
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1521
|
-
structure.
|
|
1522
|
-
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
861
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1523
862
|
if ( qaAnswers[j]?.taskId ) {
|
|
1524
863
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
1525
864
|
structure.task = true;
|
|
1526
865
|
}
|
|
1527
866
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1528
867
|
structure.redo = false;
|
|
1529
|
-
} else if (
|
|
868
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1530
869
|
structure.redo = qaAnswers[j]?.redo;
|
|
1531
870
|
}
|
|
1532
871
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -1580,15 +919,14 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1580
919
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1581
920
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1582
921
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1583
|
-
structure.
|
|
1584
|
-
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
922
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1585
923
|
if ( qaAnswers[j]?.taskId ) {
|
|
1586
924
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
1587
925
|
structure.task = true;
|
|
1588
926
|
}
|
|
1589
927
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1590
928
|
structure.redo = false;
|
|
1591
|
-
} else if (
|
|
929
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1592
930
|
structure.redo = qaAnswers[j]?.redo;
|
|
1593
931
|
}
|
|
1594
932
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -1599,7 +937,7 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1599
937
|
let des = [];
|
|
1600
938
|
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1601
939
|
let validationAnswer = '';
|
|
1602
|
-
if ( requestSection[i].answer.
|
|
940
|
+
if ( requestSection[i].answer.split( '?' ).length > 1 ) {
|
|
1603
941
|
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1604
942
|
}
|
|
1605
943
|
if ( validationAnswer.length ) {
|
|
@@ -1640,15 +978,14 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1640
978
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1641
979
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1642
980
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1643
|
-
structure.
|
|
1644
|
-
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
981
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1645
982
|
if ( qaAnswers[j]?.taskId ) {
|
|
1646
983
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
1647
984
|
structure.task = true;
|
|
1648
985
|
}
|
|
1649
986
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1650
987
|
structure.redo = false;
|
|
1651
|
-
} else if (
|
|
988
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1652
989
|
structure.redo = qaAnswers[j]?.redo;
|
|
1653
990
|
}
|
|
1654
991
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -1670,7 +1007,6 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1670
1007
|
|
|
1671
1008
|
|
|
1672
1009
|
requestData.questionAnswers = sectionFormat;
|
|
1673
|
-
logger.error( { message: requestData.questionAnswers, error: 'QuestionanswersPayload' } );
|
|
1674
1010
|
next();
|
|
1675
1011
|
} catch ( error ) {
|
|
1676
1012
|
logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
|
|
@@ -2458,6 +1794,7 @@ export async function submitChecklist( req, res ) {
|
|
|
2458
1794
|
let flagCount = QuestionFlag( req, res );
|
|
2459
1795
|
updateData.questionFlag = flagCount;
|
|
2460
1796
|
updateData.submitTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
|
|
1797
|
+
updateData.deviceDetails = requestData?.deviceDetails || {};
|
|
2461
1798
|
if ( requestData.submittype == 'draft' ) {
|
|
2462
1799
|
logger.info( `v5 => Checklist Save => store Name: ${getchecklist[0].storeName}, User Email: ${getchecklist[0].userEmail}, Checklist Name: ${getchecklist[0].checkListName}` );
|
|
2463
1800
|
updateData.questionAnswers = requestData.questionAnswers;
|
|
@@ -2509,7 +1846,7 @@ export async function submitChecklist( req, res ) {
|
|
|
2509
1846
|
userName: getchecklist[0].userName || '',
|
|
2510
1847
|
coverage: getchecklist[0].coverage || '',
|
|
2511
1848
|
};
|
|
2512
|
-
|
|
1849
|
+
console.log( 'logInsertData=>', logInsertData );
|
|
2513
1850
|
await checklistLogs.create( logInsertData );
|
|
2514
1851
|
// let time = dayjs().format( 'HH:mm:ss' );
|
|
2515
1852
|
// let [ hours, minutes ] = time.split( ':' ).map( Number );
|
|
@@ -2544,7 +1881,6 @@ export async function submitChecklist( req, res ) {
|
|
|
2544
1881
|
// await detectionService.create( detectionData );
|
|
2545
1882
|
if ( requestData.submittype == 'submit' ) {
|
|
2546
1883
|
updateOpenSearch( req.user, requestData );
|
|
2547
|
-
|
|
2548
1884
|
let openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
2549
1885
|
console.log( 'openSearch', openSearch );
|
|
2550
1886
|
let inserttraxlogs = {
|
|
@@ -2563,13 +1899,12 @@ export async function submitChecklist( req, res ) {
|
|
|
2563
1899
|
coverage: getchecklist[0].coverage,
|
|
2564
1900
|
checkListType: getchecklist[0].checkListType,
|
|
2565
1901
|
logDetails: {},
|
|
1902
|
+
userType: req.user.userType,
|
|
2566
1903
|
};
|
|
2567
1904
|
console.log( 'inserttraxlogs', inserttraxlogs );
|
|
2568
|
-
|
|
2569
|
-
console.log( 'insertOS', insertOS );
|
|
1905
|
+
insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
|
|
2570
1906
|
}
|
|
2571
1907
|
|
|
2572
|
-
|
|
2573
1908
|
return res.sendSuccess( 'Checklist Updated Successfully' );
|
|
2574
1909
|
} else {
|
|
2575
1910
|
return res.sendError( 'something went wrong please try again', 500 );
|
|
@@ -2734,7 +2069,6 @@ export async function submitTask( req, res ) {
|
|
|
2734
2069
|
|
|
2735
2070
|
if ( submittype == 'submit' ) {
|
|
2736
2071
|
updateOpenSearchTask( user, requestData );
|
|
2737
|
-
|
|
2738
2072
|
let openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
2739
2073
|
console.log( 'openSearch', openSearch );
|
|
2740
2074
|
let inserttraxlogs = {
|
|
@@ -2753,10 +2087,10 @@ export async function submitTask( req, res ) {
|
|
|
2753
2087
|
coverage: checklist.coverage,
|
|
2754
2088
|
checkListType: checklist.checkListType,
|
|
2755
2089
|
logDetails: {},
|
|
2090
|
+
userType: req.user.userType,
|
|
2756
2091
|
};
|
|
2757
2092
|
console.log( 'inserttraxlogs', inserttraxlogs );
|
|
2758
|
-
|
|
2759
|
-
console.log( 'insertOS', insertOS );
|
|
2093
|
+
insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
|
|
2760
2094
|
}
|
|
2761
2095
|
|
|
2762
2096
|
return res.sendSuccess( 'Task Updated Successfully' );
|
|
@@ -3263,262 +2597,6 @@ export async function checklistv1( req, res ) {
|
|
|
3263
2597
|
}
|
|
3264
2598
|
}
|
|
3265
2599
|
|
|
3266
|
-
export async function questionListv1( req, res ) {
|
|
3267
|
-
try {
|
|
3268
|
-
let requestData = req.query;
|
|
3269
|
-
if ( !requestData.processedcheckListId ) {
|
|
3270
|
-
res.sendError( 'processedcheckListId is Required', 400 );
|
|
3271
|
-
}
|
|
3272
|
-
|
|
3273
|
-
let findQuery = [];
|
|
3274
|
-
let findAndQuery = [];
|
|
3275
|
-
findAndQuery.push( { _id: new ObjectId( requestData.processedcheckListId ) } );
|
|
3276
|
-
findQuery.push( { $match: { $and: findAndQuery } } );
|
|
3277
|
-
|
|
3278
|
-
findQuery.push( {
|
|
3279
|
-
$project: {
|
|
3280
|
-
checkListName: { $ifNull: [ '$checkListName', '' ] },
|
|
3281
|
-
scheduleStartTime: { $ifNull: [ '$scheduleStartTime', '' ] },
|
|
3282
|
-
scheduleStartTime_iso: { $ifNull: [ '$scheduleStartTime_iso', '' ] },
|
|
3283
|
-
scheduleEndTime: { $ifNull: [ '$scheduleEndTime', '' ] },
|
|
3284
|
-
scheduleEndTime_iso: { $ifNull: [ '$scheduleEndTime_iso', '' ] },
|
|
3285
|
-
checklistStatus: { $ifNull: [ '$checklistStatus', '' ] },
|
|
3286
|
-
checkListId: { $ifNull: [ '$checkListId', '' ] },
|
|
3287
|
-
startTime: { $ifNull: [ '$startTime', '' ] },
|
|
3288
|
-
submitTime: { $ifNull: [ '$submitTime', '' ] },
|
|
3289
|
-
allowedOverTime: { $ifNull: [ '$allowedOverTime', '' ] },
|
|
3290
|
-
// allowedStoreLocation: { $ifNull: [ '$allowedStoreLocation', '' ] },
|
|
3291
|
-
allowedStoreLocation: {
|
|
3292
|
-
$cond: {
|
|
3293
|
-
if: { $eq: [ '$client_id', '11' ] },
|
|
3294
|
-
then: false,
|
|
3295
|
-
else: {
|
|
3296
|
-
'$cond': {
|
|
3297
|
-
'if': { '$eq': [ '$coverage', 'user' ] },
|
|
3298
|
-
'then': false,
|
|
3299
|
-
'else': { '$ifNull': [ '$allowedStoreLocation', false ] },
|
|
3300
|
-
},
|
|
3301
|
-
},
|
|
3302
|
-
},
|
|
3303
|
-
},
|
|
3304
|
-
reinitiateStatus: { $ifNull: [ '$reinitiateStatus', '' ] },
|
|
3305
|
-
questionAnswers: { $ifNull: [ '$questionAnswers', '' ] },
|
|
3306
|
-
getchecklist: { $ifNull: [ '$getchecklist', '' ] },
|
|
3307
|
-
userEmail: { $ifNull: [ '$userEmail', '' ] },
|
|
3308
|
-
storeName: { $ifNull: [ '$storeName', '' ] },
|
|
3309
|
-
redoStatus: { $ifNull: [ '$redoStatus', false ] },
|
|
3310
|
-
rawImageUpload: { $ifNull: [ '$rawImageUpload', false ] },
|
|
3311
|
-
},
|
|
3312
|
-
} );
|
|
3313
|
-
|
|
3314
|
-
let getchecklist = await processedchecklist.aggregate( findQuery );
|
|
3315
|
-
if ( !getchecklist.length ) {
|
|
3316
|
-
return res.sendError( 'Check List Got Edited Please Fill Again', 422 );
|
|
3317
|
-
} else {
|
|
3318
|
-
logger.info( `v5 => Checklist Continue => store Name: ${getchecklist[0].storeName}, User Email: ${getchecklist[0].userEmail}, Checklist Name: ${getchecklist[0].checkListName}` );
|
|
3319
|
-
// let bucket = JSON.parse( process.env.BUCKET );
|
|
3320
|
-
for ( let [ secIndex, section ] of getchecklist[0].questionAnswers.entries() ) {
|
|
3321
|
-
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
3322
|
-
let Multianswer = [];
|
|
3323
|
-
if ( getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage && getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage !='' ) {
|
|
3324
|
-
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage = await signedUrl( { file_path: decodeURIComponent( getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage ), Bucket: bucket.sop } );
|
|
3325
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + getchecklist[0].questionAnswers[secIndex].questions[questionIndex].questionReferenceImage;
|
|
3326
|
-
}
|
|
3327
|
-
for ( let [ ansIndex, answer ] of question.answers.entries() ) {
|
|
3328
|
-
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3329
|
-
let checkvalidation = null;
|
|
3330
|
-
if ( answer.validationAnswer && answer.validationAnswer !='' ) {
|
|
3331
|
-
if ( answer.validationType != 'Descriptive Answer' ) {
|
|
3332
|
-
// checkvalidation = await signedUrl( { file_path: decodeURIComponent( answer.validationAnswer ), Bucket: bucket.sop } );
|
|
3333
|
-
checkvalidation = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + answer.validationAnswer;
|
|
3334
|
-
} else {
|
|
3335
|
-
checkvalidation = answer.validationAnswer;
|
|
3336
|
-
}
|
|
3337
|
-
}
|
|
3338
|
-
Multianswer.push( { 'answer': answer.answer, 'no': ansIndex, 'validationAnswer': checkvalidation } );
|
|
3339
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].index = ansIndex;
|
|
3340
|
-
}
|
|
3341
|
-
if ( answer.referenceImage != '' ) {
|
|
3342
|
-
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage = await signedUrl( { file_path: decodeURIComponent( answer.referenceImage ), Bucket: bucket.sop } );
|
|
3343
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].referenceImage = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + answer.referenceImage;
|
|
3344
|
-
}
|
|
3345
|
-
if ( ( answer.validationType == 'Capture Image' || answer.validationType == 'Capture Video' ) && answer.validationAnswer && answer.validationAnswer != '' ) {
|
|
3346
|
-
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer = await signedUrl( { file_path: decodeURIComponent( answer.validationAnswer ), Bucket: bucket.sop } );
|
|
3347
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].answers[ansIndex].validationAnswer = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + answer.validationAnswer;
|
|
3348
|
-
}
|
|
3349
|
-
}
|
|
3350
|
-
if ( question?.userAnswer ) {
|
|
3351
|
-
for ( let [ userAnsIndex, userAns ] of question.userAnswer.entries() ) {
|
|
3352
|
-
if ( ( userAns.validationType == 'Capture Image' || userAns.validationType == 'Capture Video' ) && userAns.validationAnswer && userAns.validationAnswer != '' ) {
|
|
3353
|
-
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer = await signedUrl( { file_path: decodeURIComponent( userAns.validationAnswer ), Bucket: bucket.sop } );
|
|
3354
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].validationAnswer = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + userAns.validationAnswer;
|
|
3355
|
-
}
|
|
3356
|
-
if ( [ 'image', 'descriptiveImage', 'video' ].includes( question.answerType ) && userAns.answer != '' ) {
|
|
3357
|
-
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer = await signedUrl( { file_path: decodeURIComponent( userAns.answer ), Bucket: bucket.sop } );
|
|
3358
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].answer = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + userAns.answer;
|
|
3359
|
-
}
|
|
3360
|
-
if ( userAns.referenceImage != '' ) {
|
|
3361
|
-
// getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage = await signedUrl( { file_path: decodeURIComponent( userAns.referenceImage ), Bucket: bucket.sop } );
|
|
3362
|
-
getchecklist[0].questionAnswers[secIndex].questions[questionIndex].userAnswer[userAnsIndex].referenceImage = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + userAns.referenceImage;
|
|
3363
|
-
}
|
|
3364
|
-
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3365
|
-
let ansIndex = Multianswer.findIndex( ( item ) => item.answer == userAns.answer );
|
|
3366
|
-
if ( ansIndex ) {
|
|
3367
|
-
Multianswer[ansIndex].validationAnswer = userAns.validationAnswer;
|
|
3368
|
-
}
|
|
3369
|
-
}
|
|
3370
|
-
if ( question.answerType == 'multipleImage' ) {
|
|
3371
|
-
if ( userAns && userAns.answer && userAns.answer !='' ) {
|
|
3372
|
-
// let manswer = await signedUrl( { file_path: decodeURIComponent( userAns.answer ), Bucket: bucket.sop } );
|
|
3373
|
-
let manswer = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + userAns.answer;
|
|
3374
|
-
Multianswer.push( { 'answer': manswer, 'no': userAnsIndex, 'validationAnswer': '' } );
|
|
3375
|
-
} else {
|
|
3376
|
-
|
|
3377
|
-
}
|
|
3378
|
-
}
|
|
3379
|
-
}
|
|
3380
|
-
}
|
|
3381
|
-
if ( question.answerType == 'multiplechoicemultiple' ) {
|
|
3382
|
-
Multianswer.forEach( ( item ) => {
|
|
3383
|
-
if ( item.validationAnswer == null ) {
|
|
3384
|
-
item.answer = null;
|
|
3385
|
-
}
|
|
3386
|
-
} );
|
|
3387
|
-
if ( Multianswer.length ) {
|
|
3388
|
-
question.Multianswer = Multianswer;
|
|
3389
|
-
} else {
|
|
3390
|
-
question.Multianswer = Multianswer;
|
|
3391
|
-
}
|
|
3392
|
-
}
|
|
3393
|
-
if ( question.answerType == 'multipleImage' ) {
|
|
3394
|
-
if ( Multianswer.length ) {
|
|
3395
|
-
question.Multianswer = Multianswer;
|
|
3396
|
-
} else {
|
|
3397
|
-
Multianswer.push( { 'answer': null, 'no': 0, 'validationAnswer': null } );
|
|
3398
|
-
question.Multianswer = Multianswer;
|
|
3399
|
-
}
|
|
3400
|
-
}
|
|
3401
|
-
}
|
|
3402
|
-
}
|
|
3403
|
-
|
|
3404
|
-
let questions = [];
|
|
3405
|
-
// function processQuestion( question, section, questions, nested=false ) {
|
|
3406
|
-
// let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
|
|
3407
|
-
// if ( findExists && nested ) {
|
|
3408
|
-
// let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
|
|
3409
|
-
// questions.splice( findIndex, 1 );
|
|
3410
|
-
// questions.push( question );
|
|
3411
|
-
// for ( let answer of question.answers ) {
|
|
3412
|
-
// if ( answer.showLinked && answer?.linkedQuestion != '' ) {
|
|
3413
|
-
// let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
|
|
3414
|
-
// if ( linkedQuestion ) {
|
|
3415
|
-
// processQuestion( linkedQuestion, section, questions, true );
|
|
3416
|
-
// }
|
|
3417
|
-
// }
|
|
3418
|
-
// }
|
|
3419
|
-
// }
|
|
3420
|
-
// if ( !findExists ) {
|
|
3421
|
-
// questions.push( question );
|
|
3422
|
-
// for ( let answer of question.answers ) {
|
|
3423
|
-
// if ( answer.showLinked && answer?.linkedQuestion != '' ) {
|
|
3424
|
-
// let linkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
|
|
3425
|
-
// if ( linkedQuestion ) {
|
|
3426
|
-
// processQuestion( linkedQuestion, section, questions, true );
|
|
3427
|
-
// }
|
|
3428
|
-
// }
|
|
3429
|
-
// }
|
|
3430
|
-
// }
|
|
3431
|
-
// }
|
|
3432
|
-
|
|
3433
|
-
for ( let [ index, data ] of getchecklist.entries() ) {
|
|
3434
|
-
for ( let [ secIndex, section ] of data.questionAnswers.entries() ) {
|
|
3435
|
-
questions = [];
|
|
3436
|
-
for ( let [ questionIndex, question ] of section.questions.entries() ) {
|
|
3437
|
-
let linkedQuestions;
|
|
3438
|
-
let uniqueShow = false;
|
|
3439
|
-
if ( !question.linkType ) {
|
|
3440
|
-
if ( !question?.uniqueNo ) {
|
|
3441
|
-
uniqueShow = true;
|
|
3442
|
-
question.uniqueNo = parseInt( getOtp() ) + Date.now() + questionIndex;
|
|
3443
|
-
}
|
|
3444
|
-
questions.push( question );
|
|
3445
|
-
linkedQuestions = [];
|
|
3446
|
-
let questionList;
|
|
3447
|
-
if ( uniqueShow ) {
|
|
3448
|
-
questionList = new Map( section.questions.map( ( ele ) => [ ele.qno, ele ] ) );
|
|
3449
|
-
} else {
|
|
3450
|
-
let uniqueList = question.answers.flatMap( ( ele ) => ele.nestedQuestion );
|
|
3451
|
-
let filteredQuestion = section.questions.filter( ( ele ) => uniqueList.includes( ele?.uniqueNo ) );
|
|
3452
|
-
questionList = new Map( filteredQuestion.map( ( ele ) => [ ele.uniqueNo, ele ] ) );
|
|
3453
|
-
}
|
|
3454
|
-
question.answers.forEach( ( answer ) => {
|
|
3455
|
-
if ( answer.linkedQuestion ) {
|
|
3456
|
-
let nesedQuestion = [];
|
|
3457
|
-
answer.oldNestedQuestion = !uniqueShow ? JSON.parse( JSON.stringify( answer.oldNestedQuestion ) ) : JSON.parse( JSON.stringify( answer.nestedQuestion ) );
|
|
3458
|
-
answer.nestedQuestion.forEach( ( qn, qidx ) => {
|
|
3459
|
-
let getQn = questionList.get( qn );
|
|
3460
|
-
if ( getQn ) {
|
|
3461
|
-
let randomNo;
|
|
3462
|
-
if ( !getQn?.uniqueNo || uniqueShow ) {
|
|
3463
|
-
randomNo = parseInt( getOtp() ) + Date.now() + qidx;
|
|
3464
|
-
} else {
|
|
3465
|
-
randomNo = getQn?.uniqueNo;
|
|
3466
|
-
}
|
|
3467
|
-
getQn = JSON.parse( JSON.stringify( getQn ) );
|
|
3468
|
-
getQn = { ...getQn, uniqueNo: randomNo };
|
|
3469
|
-
nesedQuestion.push( getQn );
|
|
3470
|
-
if ( answer.linkedQuestion == getQn.qno ) {
|
|
3471
|
-
answer.oldLinkedQuestion = answer.linkedQuestion;
|
|
3472
|
-
answer.linkedQuestion = randomNo;
|
|
3473
|
-
}
|
|
3474
|
-
answer.nestedQuestion[qidx] = randomNo;
|
|
3475
|
-
}
|
|
3476
|
-
} );
|
|
3477
|
-
console.log( nesedQuestion );
|
|
3478
|
-
nesedQuestion.forEach( ( ele ) => {
|
|
3479
|
-
let nestedLinkqn = [];
|
|
3480
|
-
ele.answers.forEach( ( ans ) => {
|
|
3481
|
-
if ( ans.linkedQuestion ) {
|
|
3482
|
-
ans.oldNestedQuestion = !uniqueShow ? JSON.parse( JSON.stringify( ans.oldNestedQuestion ) ) : JSON.parse( JSON.stringify( ans.nestedQuestion ) );
|
|
3483
|
-
ans.nestedQuestion.forEach( ( nested, idx ) => {
|
|
3484
|
-
console.log( nested, uniqueShow, 'nested', nestedLinkqn );
|
|
3485
|
-
let findRandom = nesedQuestion.find( ( qn ) => ( uniqueShow ? qn.qno == nested : qn.uniqueNo == nested ) && !nestedLinkqn.includes( qn.uniqueNo ) && !qn.updated );
|
|
3486
|
-
console.log( findRandom );
|
|
3487
|
-
if ( findRandom ) {
|
|
3488
|
-
if ( ans.linkedQuestion == findRandom.qno ) {
|
|
3489
|
-
ans.oldLinkedQuestion = ans.linkedQuestion;
|
|
3490
|
-
ans.linkedQuestion = findRandom.uniqueNo;
|
|
3491
|
-
}
|
|
3492
|
-
ans.nestedQuestion[idx] = findRandom.uniqueNo;
|
|
3493
|
-
nestedLinkqn.push( findRandom.uniqueNo );
|
|
3494
|
-
}
|
|
3495
|
-
} );
|
|
3496
|
-
}
|
|
3497
|
-
} );
|
|
3498
|
-
ele.updated = true;
|
|
3499
|
-
} );
|
|
3500
|
-
linkedQuestions.push( ...nesedQuestion );
|
|
3501
|
-
}
|
|
3502
|
-
} );
|
|
3503
|
-
questions.push( ...linkedQuestions );
|
|
3504
|
-
}
|
|
3505
|
-
// processQuestion( question, section, questions );
|
|
3506
|
-
}
|
|
3507
|
-
getchecklist[index].questionAnswers[secIndex].questions = questions;
|
|
3508
|
-
}
|
|
3509
|
-
}
|
|
3510
|
-
if ( !getchecklist[0].redoStatus ) {
|
|
3511
|
-
await processedchecklist.updateOne( { _id: requestData.processedcheckListId }, { questionAnswers: getchecklist[0].questionAnswers } );
|
|
3512
|
-
}
|
|
3513
|
-
|
|
3514
|
-
return res.sendSuccess( getchecklist );
|
|
3515
|
-
}
|
|
3516
|
-
} catch ( e ) {
|
|
3517
|
-
logger.error( { function: 'questionList', error: e, body: req.body } );
|
|
3518
|
-
return res.sendError( e, 500 );
|
|
3519
|
-
}
|
|
3520
|
-
}
|
|
3521
|
-
|
|
3522
2600
|
export async function questionList( req, res ) {
|
|
3523
2601
|
try {
|
|
3524
2602
|
let requestData = req.query;
|
|
@@ -3564,6 +2642,7 @@ export async function questionList( req, res ) {
|
|
|
3564
2642
|
storeName: { $ifNull: [ '$storeName', '' ] },
|
|
3565
2643
|
redoStatus: { $ifNull: [ '$redoStatus', false ] },
|
|
3566
2644
|
rawImageUpload: { $ifNull: [ '$rawImageUpload', false ] },
|
|
2645
|
+
rawVideoUpload: { $ifNull: [ '$rawVideoUpload', false ] },
|
|
3567
2646
|
},
|
|
3568
2647
|
} );
|
|
3569
2648
|
|
|
@@ -4093,12 +3172,10 @@ export async function uploadAnswerImage( req, res ) {
|
|
|
4093
3172
|
}
|
|
4094
3173
|
|
|
4095
3174
|
if ( imageUrl != '' ) {
|
|
4096
|
-
|
|
4097
|
-
imageUrl = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + imageUrl.Key;
|
|
3175
|
+
imageUrl = await signedUrl( { file_path: imageUrl.Key, Bucket: bucket.sop } );
|
|
4098
3176
|
|
|
4099
3177
|
return res.sendSuccess( {
|
|
4100
3178
|
bucketName: bucket.sop,
|
|
4101
|
-
path: imageUrl.Key,
|
|
4102
3179
|
imageUrl: imageUrl,
|
|
4103
3180
|
message: 'Image uploaded successfully!',
|
|
4104
3181
|
} );
|
|
@@ -4255,7 +3332,7 @@ export const sendSignInOtpEmail = async ( emailVars ) => {
|
|
|
4255
3332
|
const result = await sendEmailWithSES( emailVars.email, subject, html, attachments, ses.adminEmail );
|
|
4256
3333
|
return result;
|
|
4257
3334
|
} catch ( error ) {
|
|
4258
|
-
logger.error( { error: error, function: 'sendSignInOtpEmail', body:
|
|
3335
|
+
logger.error( { error: error, function: 'sendSignInOtpEmail', body: emailVars } );
|
|
4259
3336
|
return error;
|
|
4260
3337
|
}
|
|
4261
3338
|
};
|
|
@@ -4406,8 +3483,8 @@ export async function clientConfig( req, res ) {
|
|
|
4406
3483
|
try {
|
|
4407
3484
|
let requestData = req.body;
|
|
4408
3485
|
if ( requestData.clientId && requestData.clientId !='' ) {
|
|
4409
|
-
let getClientData = await clientService.findOne( { clientId: requestData.clientId }, { traxRAWImageUpload: 1, clientId: 1, clientName: 1 } );
|
|
4410
|
-
console.log( ' getClientData=>', getClientData );
|
|
3486
|
+
let getClientData = await clientService.findOne( { clientId: requestData.clientId }, { traxRAWImageUpload: 1, clientId: 1, clientName: 1, traxBlockMobileTimeUpdate: 1, traxSectionSave: 1 } );
|
|
3487
|
+
// console.log( ' getClientData=>', getClientData );
|
|
4411
3488
|
if ( getClientData ) {
|
|
4412
3489
|
return res.sendSuccess( getClientData );
|
|
4413
3490
|
} else {
|
|
@@ -4417,7 +3494,6 @@ export async function clientConfig( req, res ) {
|
|
|
4417
3494
|
return res.sendError( 'clientId is Required', 400 );
|
|
4418
3495
|
}
|
|
4419
3496
|
} catch ( e ) {
|
|
4420
|
-
console.log( 'e =>', e );
|
|
4421
3497
|
logger.error( { error: e, function: 'clientConfig' } );
|
|
4422
3498
|
return res.sendError( e, 500 );
|
|
4423
3499
|
}
|