tango-app-api-trax 3.4.1-alpha-20 → 3.4.1-approvecheck-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/index.js +2 -1
- package/package.json +3 -3
- package/src/controllers/activityLog.controller.js +292 -0
- package/src/controllers/download.controller.js +119 -3
- package/src/controllers/gallery.controller.js +195 -6
- package/src/controllers/internalTrax.controller.js +675 -10
- package/src/controllers/mobileTrax.controller.js +356 -983
- package/src/controllers/teaxFlag.controller.js +467 -2
- package/src/controllers/trax.controller.js +859 -266
- package/src/controllers/traxDashboard.controllers.js +1 -2
- package/src/dtos/downloadValidation.dtos.js +2 -1
- package/src/hbs/login-otp.hbs +943 -943
- package/src/routes/activityLog.router.js +18 -0
- package/src/routes/download.router.js +4 -0
- package/src/routes/gallery.routes.js +2 -1
- package/src/routes/internalTraxApi.router.js +3 -1
- package/src/routes/mobileTrax.routes.js +1 -3
- package/src/routes/trax.routes.js +5 -3
- package/src/routes/traxFlag.router.js +13 -1
- package/src/services/camera.service.js +14 -0
- package/src/services/processedchecklistconfig.services.js +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { logger, signedUrl, fileUpload, getOtp, sendEmailWithSES, getUuid } from 'tango-app-api-middleware';
|
|
1
|
+
import { logger, signedUrl, fileUpload, getOtp, sendEmailWithSES, getUuid, insertOpenSearchData } from 'tango-app-api-middleware';
|
|
2
2
|
import * as processedchecklist from '../services/processedchecklist.services.js';
|
|
3
3
|
import * as processedtask from '../services/processedTaskList.service.js';
|
|
4
4
|
import * as PCLconfig from '../services/processedchecklistconfig.services.js';
|
|
@@ -25,6 +25,7 @@ import handlebars from 'handlebars';
|
|
|
25
25
|
dayjs.extend( customParseFormat );
|
|
26
26
|
dayjs.extend( timeZone );
|
|
27
27
|
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore.js';
|
|
28
|
+
import * as cameraService from '../services/camera.service.js';
|
|
28
29
|
dayjs.extend( isSameOrBefore );
|
|
29
30
|
|
|
30
31
|
export async function storeList( req, res ) {
|
|
@@ -90,242 +91,6 @@ export async function storeListv1( req, res ) {
|
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
|
|
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
94
|
export async function startChecklist( req, res ) {
|
|
330
95
|
try {
|
|
331
96
|
let requestData = req.body;
|
|
@@ -498,12 +263,32 @@ export async function startChecklist( req, res ) {
|
|
|
498
263
|
getchecklist[index].questionAnswers[secIndex].questions = questions;
|
|
499
264
|
}
|
|
500
265
|
}
|
|
266
|
+
let openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
267
|
+
// console.log( 'openSearch', openSearch );
|
|
268
|
+
let inserttraxlogs = {
|
|
269
|
+
client_id: req.user.clientId,
|
|
270
|
+
createAt: new Date(),
|
|
271
|
+
sourceCheckList_id: getBeforeChecklist[0]?.sourceCheckList_id || '',
|
|
272
|
+
checkListName: getBeforeChecklist[0]?.checkListName || '',
|
|
273
|
+
fromCheckListName: '',
|
|
274
|
+
type: 'checkList',
|
|
275
|
+
action: 'start',
|
|
276
|
+
storeName: getBeforeChecklist[0]?.storeName || '',
|
|
277
|
+
store_id: getBeforeChecklist[0]?.store_id || '',
|
|
278
|
+
createdByEmail: getBeforeChecklist[0]?.userEmail || '',
|
|
279
|
+
createdBy: getBeforeChecklist[0]?.userName || '',
|
|
280
|
+
coverage: getBeforeChecklist[0]?.coverage || '',
|
|
281
|
+
logDetails: {},
|
|
282
|
+
userType: req.user.userType,
|
|
283
|
+
};
|
|
284
|
+
// let insertOS = await insertOpenSearchData( 'test-traxlogs', inserttraxlogs );
|
|
285
|
+
insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
|
|
501
286
|
return res.sendSuccess( getchecklist );
|
|
502
287
|
} else {
|
|
503
288
|
return res.sendError( 'something went wrong please try again', 500 );
|
|
504
289
|
}
|
|
505
290
|
} catch ( e ) {
|
|
506
|
-
console.log( 'e =>', e );
|
|
291
|
+
// console.log( 'e =>', e );
|
|
507
292
|
logger.error( { function: 'startChecklist', error: e, body: req.body } );
|
|
508
293
|
return res.sendError( e, 500 );
|
|
509
294
|
}
|
|
@@ -669,6 +454,27 @@ export async function startTask( req, res ) {
|
|
|
669
454
|
};
|
|
670
455
|
await checklistLogs.create( logData );
|
|
671
456
|
|
|
457
|
+
let openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
458
|
+
// console.log( 'openSearch', openSearch );
|
|
459
|
+
let inserttraxlogs = {
|
|
460
|
+
client_id: req.user.clientId,
|
|
461
|
+
createAt: new Date(),
|
|
462
|
+
sourceCheckList_id: task.sourceCheckList_id || '',
|
|
463
|
+
checkListName: task.checkListName || '',
|
|
464
|
+
fromCheckListName: '',
|
|
465
|
+
type: 'task',
|
|
466
|
+
action: 'start',
|
|
467
|
+
storeName: task.storeName || '',
|
|
468
|
+
store_id: task.store_id || '',
|
|
469
|
+
createdByEmail: task.userEmail || '',
|
|
470
|
+
createdBy: task.userName || '',
|
|
471
|
+
coverage: task.coverage || '',
|
|
472
|
+
logDetails: {},
|
|
473
|
+
userType: req.user.userType,
|
|
474
|
+
};
|
|
475
|
+
// let insertOS = await insertOpenSearchData( 'test-traxlogs', inserttraxlogs );
|
|
476
|
+
// console.log( 'inserttraxlogs', inserttraxlogs );
|
|
477
|
+
insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
|
|
672
478
|
return res.sendSuccess( getUpdatedTask );
|
|
673
479
|
} catch ( error ) {
|
|
674
480
|
logger.error( { function: 'startTask', error, body: req.body } );
|
|
@@ -1210,7 +1016,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
1210
1016
|
}
|
|
1211
1017
|
};
|
|
1212
1018
|
|
|
1213
|
-
export async function
|
|
1019
|
+
export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next ) {
|
|
1214
1020
|
try {
|
|
1215
1021
|
let requestData = req.body;
|
|
1216
1022
|
requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
|
|
@@ -1298,16 +1104,11 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1298
1104
|
let requestSection = reqAnswers.filter( ( item ) => item.section_id == section.id );
|
|
1299
1105
|
for ( let i = 0; i < requestSection.length; i++ ) {
|
|
1300
1106
|
for ( let j = 0; j < qaAnswers.length; j++ ) {
|
|
1301
|
-
if (
|
|
1107
|
+
if ( requestSection[i].qname == qaAnswers[j].oldQname || requestSection[i].qname == qaAnswers[j].qname ) {
|
|
1302
1108
|
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
1303
1109
|
let qaans = qaAnswers[j].answers;
|
|
1304
1110
|
let yn = [];
|
|
1305
1111
|
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
1112
|
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1312
1113
|
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1313
1114
|
if ( requestSection[i].validationAnswer ) {
|
|
@@ -1342,7 +1143,7 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1342
1143
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1343
1144
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1344
1145
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1345
|
-
structure.
|
|
1146
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1346
1147
|
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1347
1148
|
if ( qaAnswers[j]?.taskId ) {
|
|
1348
1149
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
@@ -1361,11 +1162,6 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1361
1162
|
let qaans = qaAnswers[j].answers;
|
|
1362
1163
|
let ms = [];
|
|
1363
1164
|
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
1165
|
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
1370
1166
|
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1371
1167
|
if ( requestSection[i].validationAnswer ) {
|
|
@@ -1400,7 +1196,7 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1400
1196
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1401
1197
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1402
1198
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1403
|
-
structure.
|
|
1199
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1404
1200
|
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1405
1201
|
if ( qaAnswers[j]?.taskId ) {
|
|
1406
1202
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
@@ -1457,7 +1253,7 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1457
1253
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1458
1254
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1459
1255
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1460
|
-
structure.
|
|
1256
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1461
1257
|
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1462
1258
|
if ( qaAnswers[j]?.taskId ) {
|
|
1463
1259
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
@@ -1519,7 +1315,7 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1519
1315
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1520
1316
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1521
1317
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1522
|
-
structure.
|
|
1318
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1523
1319
|
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1524
1320
|
if ( qaAnswers[j]?.taskId ) {
|
|
1525
1321
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
@@ -1538,7 +1334,7 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1538
1334
|
let des = [];
|
|
1539
1335
|
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1540
1336
|
let validationAnswer = '';
|
|
1541
|
-
if ( requestSection[i].answer.
|
|
1337
|
+
if ( requestSection[i].answer.split( '?' ).length > 1 ) {
|
|
1542
1338
|
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1543
1339
|
}
|
|
1544
1340
|
if ( validationAnswer.length ) {
|
|
@@ -1579,7 +1375,7 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1579
1375
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1580
1376
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1581
1377
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1582
|
-
structure.
|
|
1378
|
+
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1583
1379
|
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1584
1380
|
if ( qaAnswers[j]?.taskId ) {
|
|
1585
1381
|
structure.taskId = qaAnswers[j]?.taskId;
|
|
@@ -1617,13 +1413,12 @@ export async function sopMobilechecklistMultiSectionFormatterv2( req, res, next
|
|
|
1617
1413
|
}
|
|
1618
1414
|
};
|
|
1619
1415
|
|
|
1620
|
-
export async function
|
|
1416
|
+
export async function sopMobileTaskMultiSectionFormatter( req, res, next ) {
|
|
1621
1417
|
try {
|
|
1622
1418
|
let requestData = req.body;
|
|
1623
1419
|
requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
|
|
1624
|
-
let getChecklistQA = await
|
|
1420
|
+
let getChecklistQA = await processedTask.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1 } );
|
|
1625
1421
|
let reqAnswers = requestData.questionAnswers;
|
|
1626
|
-
logger.error( { functionName: 'updatedPayload', message: reqAnswers } );
|
|
1627
1422
|
let CLQAnswers = getChecklistQA.questionAnswers;
|
|
1628
1423
|
|
|
1629
1424
|
if ( requestData.submittype == 'submit' ) {
|
|
@@ -1636,58 +1431,6 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1636
1431
|
} );
|
|
1637
1432
|
}
|
|
1638
1433
|
|
|
1639
|
-
if ( requestData?.editSubmit && requestData?.editSubmit == 'true' ) {
|
|
1640
|
-
let sampleData = reqAnswers[0];
|
|
1641
|
-
CLQAnswers.forEach( ( section ) => {
|
|
1642
|
-
let requestSection = reqAnswers.filter( ( reqSection ) => reqSection.sectionName == section?.sectionOldName || reqSection.sectionName == section?.sectionName );
|
|
1643
|
-
if ( requestSection.length ) {
|
|
1644
|
-
requestSection.forEach( ( item ) => item.section_id = section.section_id );
|
|
1645
|
-
section.questions.forEach( ( question ) => {
|
|
1646
|
-
let sectionQuestion = requestSection.filter( ( secQuestion ) => secQuestion.qname == question.oldQname || secQuestion.qname == question.qname );
|
|
1647
|
-
if ( !sectionQuestion.length ) {
|
|
1648
|
-
let data = { ...requestSection[0] };
|
|
1649
|
-
data.answerType = question.answerType;
|
|
1650
|
-
data.qno = question.qno;
|
|
1651
|
-
data.qname = question.qname;
|
|
1652
|
-
data.oldQname = question?.oldQname || question.qname;
|
|
1653
|
-
data.answer = 'null';
|
|
1654
|
-
data.remarks = '';
|
|
1655
|
-
data.validationAnswer = '';
|
|
1656
|
-
data.Multianswer = [];
|
|
1657
|
-
data.linkType = question.linkType;
|
|
1658
|
-
data.linkquestionenabled = question.linkType;
|
|
1659
|
-
data.linkedQuestion = null;
|
|
1660
|
-
data.showLinked = null;
|
|
1661
|
-
data.parentanswer = '';
|
|
1662
|
-
data.dateRangeType = false;
|
|
1663
|
-
reqAnswers.push( data );
|
|
1664
|
-
}
|
|
1665
|
-
} );
|
|
1666
|
-
} else {
|
|
1667
|
-
section.questions.forEach( ( ele ) => {
|
|
1668
|
-
let data = { ...sampleData };
|
|
1669
|
-
data.section_id = section.section_id;
|
|
1670
|
-
data.sectionName = section.sectionName;
|
|
1671
|
-
data.answerType = ele.answerType;
|
|
1672
|
-
data.qno = ele.qno;
|
|
1673
|
-
data.qname = ele.qname;
|
|
1674
|
-
data.oldQname = ele?.oldQname || ele.qname;
|
|
1675
|
-
data.answer = 'null';
|
|
1676
|
-
data.remarks = '';
|
|
1677
|
-
data.validationAnswer = '';
|
|
1678
|
-
data.Multianswer = [];
|
|
1679
|
-
data.linkType = ele.linkType;
|
|
1680
|
-
data.linkquestionenabled = ele.linkType;
|
|
1681
|
-
data.linkedQuestion = null;
|
|
1682
|
-
data.showLinked = null;
|
|
1683
|
-
data.parentanswer = '';
|
|
1684
|
-
data.dateRangeType = false;
|
|
1685
|
-
reqAnswers.push( data );
|
|
1686
|
-
} );
|
|
1687
|
-
}
|
|
1688
|
-
} );
|
|
1689
|
-
}
|
|
1690
|
-
|
|
1691
1434
|
let sectionFormat = [];
|
|
1692
1435
|
let uniqueSections = {};
|
|
1693
1436
|
reqAnswers.forEach( ( item ) => {
|
|
@@ -1698,14 +1441,14 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1698
1441
|
} );
|
|
1699
1442
|
const uniqueArray = Object.values( uniqueSections );
|
|
1700
1443
|
for ( let section of uniqueArray ) {
|
|
1701
|
-
let CLQSection = CLQAnswers.find( ( item ) => item.section_id
|
|
1444
|
+
let CLQSection = CLQAnswers.find( ( item ) => item.section_id == section.id );
|
|
1702
1445
|
if ( CLQSection ) {
|
|
1703
1446
|
let newArray = [];
|
|
1704
1447
|
let qaAnswers = CLQSection.questions;
|
|
1705
1448
|
let requestSection = reqAnswers.filter( ( item ) => item.section_id == section.id );
|
|
1706
1449
|
for ( let i = 0; i < requestSection.length; i++ ) {
|
|
1707
1450
|
for ( let j = 0; j < qaAnswers.length; j++ ) {
|
|
1708
|
-
if ( requestSection[i].
|
|
1451
|
+
if ( requestSection[i].qno == qaAnswers[j].qno ) {
|
|
1709
1452
|
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
1710
1453
|
let qaans = qaAnswers[j].answers;
|
|
1711
1454
|
let yn = [];
|
|
@@ -1723,7 +1466,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1723
1466
|
}
|
|
1724
1467
|
}
|
|
1725
1468
|
} else {
|
|
1726
|
-
|
|
1469
|
+
qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1727
1470
|
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1728
1471
|
}
|
|
1729
1472
|
yn.push( qaans[k] );
|
|
@@ -1744,15 +1487,10 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1744
1487
|
structure.parentanswer = requestSection[i].parentanswer;
|
|
1745
1488
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1746
1489
|
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1747
|
-
|
|
1748
|
-
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1749
|
-
if ( qaAnswers[j]?.taskId ) {
|
|
1750
|
-
structure.taskId = qaAnswers[j]?.taskId;
|
|
1751
|
-
structure.task = true;
|
|
1752
|
-
}
|
|
1490
|
+
|
|
1753
1491
|
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1754
1492
|
structure.redo = false;
|
|
1755
|
-
} else if (
|
|
1493
|
+
} else if ( requestData.submittype === 'draft' ) {
|
|
1756
1494
|
structure.redo = qaAnswers[j]?.redo;
|
|
1757
1495
|
}
|
|
1758
1496
|
if ( qaAnswers[j]?.redoComment ) {
|
|
@@ -1776,346 +1514,7 @@ export async function sopMobilechecklistMultiSectionFormatterv1( req, res, next
|
|
|
1776
1514
|
}
|
|
1777
1515
|
}
|
|
1778
1516
|
} else {
|
|
1779
|
-
|
|
1780
|
-
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
1781
|
-
}
|
|
1782
|
-
ms.push( qaans[k] );
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
let structure = {};
|
|
1786
|
-
structure.qno = qaAnswers[j].qno;
|
|
1787
|
-
structure.qname = qaAnswers[j].qname;
|
|
1788
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
1789
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
1790
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1791
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1792
|
-
structure.remarks = requestSection[i].remarks;
|
|
1793
|
-
structure.answers = qaAnswers[j].answers;
|
|
1794
|
-
structure.userAnswer = ms;
|
|
1795
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
1796
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1797
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
1798
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1799
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1800
|
-
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1801
|
-
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1802
|
-
if ( qaAnswers[j]?.taskId ) {
|
|
1803
|
-
structure.taskId = qaAnswers[j]?.taskId;
|
|
1804
|
-
structure.task = true;
|
|
1805
|
-
}
|
|
1806
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1807
|
-
structure.redo = false;
|
|
1808
|
-
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1809
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
1810
|
-
}
|
|
1811
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
1812
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1813
|
-
};
|
|
1814
|
-
newArray.push( structure );
|
|
1815
|
-
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' ) {
|
|
1816
|
-
let qaans = qaAnswers[j].answers;
|
|
1817
|
-
let mcmo = [];
|
|
1818
|
-
for ( let k = 0; k < qaans.length; k++ ) {
|
|
1819
|
-
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1820
|
-
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1821
|
-
if ( separatedArray[s].answer == qaans[k].answer ) {
|
|
1822
|
-
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
1823
|
-
if ( separatedArray[s].validationAnswer ) {
|
|
1824
|
-
let validationAnswer = decodeURIComponent( separatedArray[s].validationAnswer.split( '?' )[0] );
|
|
1825
|
-
if ( validationAnswer.length ) {
|
|
1826
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
1827
|
-
if ( splitImgUrl.length > 1 ) {
|
|
1828
|
-
splitImgUrl.splice( 0, 3 );
|
|
1829
|
-
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
} else {
|
|
1834
|
-
// qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1835
|
-
qaans[k].validationAnswer = separatedArray[s].validationAnswer || '';
|
|
1836
|
-
}
|
|
1837
|
-
|
|
1838
|
-
mcmo.push( qaans[k] );
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
let structure = {};
|
|
1843
|
-
structure.qno = qaAnswers[j].qno;
|
|
1844
|
-
structure.qname = qaAnswers[j].qname;
|
|
1845
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
1846
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
1847
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1848
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1849
|
-
structure.remarks = requestSection[i].remarks;
|
|
1850
|
-
structure.answers = qaAnswers[j].answers;
|
|
1851
|
-
structure.userAnswer = mcmo;
|
|
1852
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
1853
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1854
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
1855
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1856
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1857
|
-
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1858
|
-
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1859
|
-
if ( qaAnswers[j]?.taskId ) {
|
|
1860
|
-
structure.taskId = qaAnswers[j]?.taskId;
|
|
1861
|
-
structure.task = true;
|
|
1862
|
-
}
|
|
1863
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1864
|
-
structure.redo = false;
|
|
1865
|
-
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1866
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
1867
|
-
}
|
|
1868
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
1869
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1870
|
-
};
|
|
1871
|
-
newArray.push( structure );
|
|
1872
|
-
} else if ( qaAnswers[j].answerType == 'multipleImage' ) {
|
|
1873
|
-
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
1874
|
-
let mcmi = [];
|
|
1875
|
-
// for (let k = 0; k < qaans.length; k++) {
|
|
1876
|
-
for ( let s = 0; s < separatedArray.length; s++ ) {
|
|
1877
|
-
if ( separatedArray[s].answer && separatedArray[s].answer !='' ) {
|
|
1878
|
-
let newAnswer = {};
|
|
1879
|
-
let validationAnswer = decodeURIComponent( separatedArray[s].answer.split( '?' )[0] );
|
|
1880
|
-
if ( validationAnswer.length ) {
|
|
1881
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
1882
|
-
if ( splitImgUrl.length > 1 ) {
|
|
1883
|
-
splitImgUrl.splice( 0, 3 );
|
|
1884
|
-
newAnswer.answer = splitImgUrl.join( '/' ) || '';
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
|
|
1888
|
-
newAnswer.answeroptionNumber = 0;
|
|
1889
|
-
newAnswer.sopFlag = false;
|
|
1890
|
-
newAnswer.validation = false;
|
|
1891
|
-
newAnswer.validationType = '';
|
|
1892
|
-
newAnswer.referenceImage = '';
|
|
1893
|
-
newAnswer.allowUploadfromGallery = false;
|
|
1894
|
-
newAnswer.runAI = false;
|
|
1895
|
-
newAnswer.descriptivetype = '';
|
|
1896
|
-
newAnswer.showLinked = false;
|
|
1897
|
-
newAnswer.linkedQuestion = 0;
|
|
1898
|
-
newAnswer.nestedQuestion = [];
|
|
1899
|
-
newAnswer.index = s;
|
|
1900
|
-
mcmi.push( newAnswer );
|
|
1901
|
-
}
|
|
1902
|
-
}
|
|
1903
|
-
// }
|
|
1904
|
-
let structure = {};
|
|
1905
|
-
structure.qno = qaAnswers[j].qno;
|
|
1906
|
-
structure.qname = qaAnswers[j].qname;
|
|
1907
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
1908
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
1909
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1910
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1911
|
-
structure.remarks = requestSection[i].remarks;
|
|
1912
|
-
structure.answers = qaAnswers[j].answers;
|
|
1913
|
-
structure.userAnswer = mcmi;
|
|
1914
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
1915
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1916
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
1917
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1918
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1919
|
-
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1920
|
-
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1921
|
-
if ( qaAnswers[j]?.taskId ) {
|
|
1922
|
-
structure.taskId = qaAnswers[j]?.taskId;
|
|
1923
|
-
structure.task = true;
|
|
1924
|
-
}
|
|
1925
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1926
|
-
structure.redo = false;
|
|
1927
|
-
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1928
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
1929
|
-
}
|
|
1930
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
1931
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1932
|
-
};
|
|
1933
|
-
newArray.push( structure );
|
|
1934
|
-
} else {
|
|
1935
|
-
let des = [];
|
|
1936
|
-
if ( requestSection[i].answer != 'null' && requestSection[i].answer != '' && requestSection[i].answer != null ) {
|
|
1937
|
-
let validationAnswer = '';
|
|
1938
|
-
if ( requestSection[i].answer.split( '?' ).length > 1 ) {
|
|
1939
|
-
validationAnswer = decodeURIComponent( requestSection[i].answer.split( '?' )[0] );
|
|
1940
|
-
}
|
|
1941
|
-
if ( validationAnswer.length ) {
|
|
1942
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
1943
|
-
if ( splitImgUrl.length > 1 ) {
|
|
1944
|
-
splitImgUrl.splice( 0, 3 );
|
|
1945
|
-
requestSection[i].answer = splitImgUrl.join( '/' );
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
1948
|
-
let ansstructure = {
|
|
1949
|
-
answer: requestSection[i].answer,
|
|
1950
|
-
answeroptionNumber: 1,
|
|
1951
|
-
sopFlag: false,
|
|
1952
|
-
validation: false,
|
|
1953
|
-
validationType: '',
|
|
1954
|
-
validationAnswer: '',
|
|
1955
|
-
referenceImage: qaAnswers[j].answers[0].referenceImage,
|
|
1956
|
-
showLinked: qaAnswers[j].answers[0].showLinked,
|
|
1957
|
-
linkedQuestion: qaAnswers[j].answers[0].linkedQuestion,
|
|
1958
|
-
};
|
|
1959
|
-
if ( qaAnswers[j].answerType == 'date' ) {
|
|
1960
|
-
ansstructure.dateRangeType = requestSection[i].dateRangeType || false;
|
|
1961
|
-
}
|
|
1962
|
-
des.push( ansstructure );
|
|
1963
|
-
}
|
|
1964
|
-
let structure = {};
|
|
1965
|
-
structure.qno = qaAnswers[j].qno;
|
|
1966
|
-
structure.qname = qaAnswers[j].qname;
|
|
1967
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
1968
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
1969
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
1970
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
1971
|
-
structure.remarks = requestSection[i].remarks;
|
|
1972
|
-
structure.answers = qaAnswers[j].answers;
|
|
1973
|
-
structure.userAnswer = des;
|
|
1974
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
1975
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
1976
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
1977
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
1978
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
1979
|
-
// structure.parentQuestion = requestSection[i]?.parentQuestion || qaAnswers[j].qno;
|
|
1980
|
-
structure.oldQname = qaAnswers[j]?.oldQname || qaAnswers[j].qname;
|
|
1981
|
-
if ( qaAnswers[j]?.taskId ) {
|
|
1982
|
-
structure.taskId = qaAnswers[j]?.taskId;
|
|
1983
|
-
structure.task = true;
|
|
1984
|
-
}
|
|
1985
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
1986
|
-
structure.redo = false;
|
|
1987
|
-
} else if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'draft' ) {
|
|
1988
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
1989
|
-
}
|
|
1990
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
1991
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
1992
|
-
};
|
|
1993
|
-
newArray.push( structure );
|
|
1994
|
-
}
|
|
1995
|
-
}
|
|
1996
|
-
}
|
|
1997
|
-
}
|
|
1998
|
-
let sectionData = {
|
|
1999
|
-
'section_id': section.id,
|
|
2000
|
-
'sectionName': section.name,
|
|
2001
|
-
'questions': newArray,
|
|
2002
|
-
};
|
|
2003
|
-
sectionFormat.push( sectionData );
|
|
2004
|
-
}
|
|
2005
|
-
}
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
requestData.questionAnswers = sectionFormat;
|
|
2009
|
-
logger.error( { message: requestData.questionAnswers, error: 'QuestionanswersPayload' } );
|
|
2010
|
-
next();
|
|
2011
|
-
} catch ( error ) {
|
|
2012
|
-
logger.error( { function: 'sopMobilechecklistMultiSectionFormatter', error: error, body: req.body } );
|
|
2013
|
-
return res.sendError( error, 500 );
|
|
2014
|
-
}
|
|
2015
|
-
};
|
|
2016
|
-
|
|
2017
|
-
export async function sopMobileTaskMultiSectionFormatter( req, res, next ) {
|
|
2018
|
-
try {
|
|
2019
|
-
let requestData = req.body;
|
|
2020
|
-
requestData.questionAnswers = typeof requestData.questionAnswers == 'string' ? JSON.parse( requestData.questionAnswers ) : requestData.questionAnswers;
|
|
2021
|
-
let getChecklistQA = await processedTask.findOne( { _id: new ObjectId( requestData.processedcheckListId ) }, { questionAnswers: 1 } );
|
|
2022
|
-
let reqAnswers = requestData.questionAnswers;
|
|
2023
|
-
let CLQAnswers = getChecklistQA.questionAnswers;
|
|
2024
|
-
|
|
2025
|
-
if ( requestData.submittype == 'submit' ) {
|
|
2026
|
-
reqAnswers.forEach( ( reqA ) => {
|
|
2027
|
-
if ( ![ 'multiplechoicemultiple', 'multipleImage' ].includes( reqA?.answerType ) ) {
|
|
2028
|
-
if ( ( !reqA.linkType && ( reqA.answer == null || reqA.answer == '' ) ) || ( reqA.linkType && reqA.linkquestionenabled && ( reqA.answer == null || reqA.answer == '' ) ) ) {
|
|
2029
|
-
return res.sendError( 'Please Fill All Fields', 400 );
|
|
2030
|
-
}
|
|
2031
|
-
}
|
|
2032
|
-
} );
|
|
2033
|
-
}
|
|
2034
|
-
|
|
2035
|
-
let sectionFormat = [];
|
|
2036
|
-
let uniqueSections = {};
|
|
2037
|
-
reqAnswers.forEach( ( item ) => {
|
|
2038
|
-
const key = `${item.section_id}-${item.sectionName}`;
|
|
2039
|
-
if ( !uniqueSections[key] ) {
|
|
2040
|
-
uniqueSections[key] = { id: item.section_id, name: item.sectionName };
|
|
2041
|
-
}
|
|
2042
|
-
} );
|
|
2043
|
-
const uniqueArray = Object.values( uniqueSections );
|
|
2044
|
-
for ( let section of uniqueArray ) {
|
|
2045
|
-
let CLQSection = CLQAnswers.find( ( item ) => item.section_id == section.id );
|
|
2046
|
-
if ( CLQSection ) {
|
|
2047
|
-
let newArray = [];
|
|
2048
|
-
let qaAnswers = CLQSection.questions;
|
|
2049
|
-
let requestSection = reqAnswers.filter( ( item ) => item.section_id == section.id );
|
|
2050
|
-
for ( let i = 0; i < requestSection.length; i++ ) {
|
|
2051
|
-
for ( let j = 0; j < qaAnswers.length; j++ ) {
|
|
2052
|
-
if ( requestSection[i].qno == qaAnswers[j].qno ) {
|
|
2053
|
-
if ( qaAnswers[j].answerType == 'yes/no' ) {
|
|
2054
|
-
let qaans = qaAnswers[j].answers;
|
|
2055
|
-
let yn = [];
|
|
2056
|
-
for ( let k = 0; k < qaans.length; k++ ) {
|
|
2057
|
-
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
2058
|
-
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
2059
|
-
if ( requestSection[i].validationAnswer ) {
|
|
2060
|
-
let validateAns = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
2061
|
-
if ( validateAns.length ) {
|
|
2062
|
-
let splitImgUrl = validateAns.split( '/' );
|
|
2063
|
-
if ( splitImgUrl.length > 1 ) {
|
|
2064
|
-
splitImgUrl.splice( 0, 3 );
|
|
2065
|
-
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
2066
|
-
}
|
|
2067
|
-
}
|
|
2068
|
-
}
|
|
2069
|
-
} else {
|
|
2070
|
-
qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
2071
|
-
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
2072
|
-
}
|
|
2073
|
-
yn.push( qaans[k] );
|
|
2074
|
-
}
|
|
2075
|
-
}
|
|
2076
|
-
let structure = {};
|
|
2077
|
-
structure.qno = qaAnswers[j].qno;
|
|
2078
|
-
structure.qname = qaAnswers[j].qname;
|
|
2079
|
-
structure.answerType = qaAnswers[j].answerType;
|
|
2080
|
-
structure.runAI = qaAnswers[j].runAI;
|
|
2081
|
-
structure.runAIDescription = qaAnswers[j].runAIDescription;
|
|
2082
|
-
structure.allowUploadfromGallery = qaAnswers[j].allowUploadfromGallery;
|
|
2083
|
-
structure.remarks = requestSection[i].remarks;
|
|
2084
|
-
structure.answers = qaAnswers[j].answers;
|
|
2085
|
-
structure.userAnswer = yn;
|
|
2086
|
-
structure.linkType = qaAnswers[j].linkType;
|
|
2087
|
-
structure.linkquestionenabled = requestSection[i].linkquestionenabled;
|
|
2088
|
-
structure.parentanswer = requestSection[i].parentanswer;
|
|
2089
|
-
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage;
|
|
2090
|
-
structure.descriptivetype = qaAnswers[j].descriptivetype;
|
|
2091
|
-
|
|
2092
|
-
if ( typeof qaAnswers[j]?.redo === 'boolean' && requestData.submittype === 'submit' ) {
|
|
2093
|
-
structure.redo = false;
|
|
2094
|
-
} else if ( requestData.submittype === 'draft' ) {
|
|
2095
|
-
structure.redo = qaAnswers[j]?.redo;
|
|
2096
|
-
}
|
|
2097
|
-
if ( qaAnswers[j]?.redoComment ) {
|
|
2098
|
-
structure.redoComment = qaAnswers[j]?.redoComment;
|
|
2099
|
-
};
|
|
2100
|
-
newArray.push( structure );
|
|
2101
|
-
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle' ) {
|
|
2102
|
-
let qaans = qaAnswers[j].answers;
|
|
2103
|
-
let ms = [];
|
|
2104
|
-
for ( let k = 0; k < qaans.length; k++ ) {
|
|
2105
|
-
if ( requestSection[i].answer == qaans[k].answer ) {
|
|
2106
|
-
if ( qaans[k].validationType == 'Capture Image' || qaans[k].validationType == 'Capture Video' ) {
|
|
2107
|
-
if ( requestSection[i].validationAnswer ) {
|
|
2108
|
-
let validationAnswer = decodeURIComponent( requestSection[i].validationAnswer.split( '?' )[0] );
|
|
2109
|
-
if ( validationAnswer.length ) {
|
|
2110
|
-
let splitImgUrl = validationAnswer.split( '/' );
|
|
2111
|
-
if ( splitImgUrl.length > 1 ) {
|
|
2112
|
-
splitImgUrl.splice( 0, 3 );
|
|
2113
|
-
qaans[k].validationAnswer = splitImgUrl.join( '/' ) || '';
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
} else {
|
|
2118
|
-
qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
1517
|
+
qaans[k].descriptivetype = qaAnswers[j].descriptivetype || '';
|
|
2119
1518
|
qaans[k].validationAnswer = requestSection[i].validationAnswer || '';
|
|
2120
1519
|
}
|
|
2121
1520
|
ms.push( qaans[k] );
|
|
@@ -2397,6 +1796,7 @@ export async function submitChecklist( req, res ) {
|
|
|
2397
1796
|
let flagCount = QuestionFlag( req, res );
|
|
2398
1797
|
updateData.questionFlag = flagCount;
|
|
2399
1798
|
updateData.submitTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
|
|
1799
|
+
updateData.deviceDetails = requestData?.deviceDetails || {};
|
|
2400
1800
|
if ( requestData.submittype == 'draft' ) {
|
|
2401
1801
|
logger.info( `v5 => Checklist Save => store Name: ${getchecklist[0].storeName}, User Email: ${getchecklist[0].userEmail}, Checklist Name: ${getchecklist[0].checkListName}` );
|
|
2402
1802
|
updateData.questionAnswers = requestData.questionAnswers;
|
|
@@ -2434,72 +1834,299 @@ export async function submitChecklist( req, res ) {
|
|
|
2434
1834
|
}
|
|
2435
1835
|
}
|
|
2436
1836
|
|
|
2437
|
-
let logInsertData = {
|
|
2438
|
-
store_id: getchecklist[0].store_id || '',
|
|
2439
|
-
storeName: getchecklist[0].storeName || '',
|
|
2440
|
-
action: requestData?.submittype === 'draft' ? 'saved' : 'submitted',
|
|
2441
|
-
checklistId: getchecklist[0].sourceCheckList_id,
|
|
2442
|
-
processedChecklistId: getchecklist[0]._id,
|
|
2443
|
-
checkListName: getchecklist[0].checkListName,
|
|
2444
|
-
type: getchecklist[0].checkListType,
|
|
1837
|
+
let logInsertData = {
|
|
1838
|
+
store_id: getchecklist[0].store_id || '',
|
|
1839
|
+
storeName: getchecklist[0].storeName || '',
|
|
1840
|
+
action: requestData?.submittype === 'draft' ? 'saved' : 'submitted',
|
|
1841
|
+
checklistId: getchecklist[0].sourceCheckList_id,
|
|
1842
|
+
processedChecklistId: getchecklist[0]._id,
|
|
1843
|
+
checkListName: getchecklist[0].checkListName,
|
|
1844
|
+
type: getchecklist[0].checkListType,
|
|
1845
|
+
client_id: req.user.clientId,
|
|
1846
|
+
redoStatus: requestData?.redoStatus ? true : false,
|
|
1847
|
+
userEmail: getchecklist[0].userEmail || '',
|
|
1848
|
+
userName: getchecklist[0].userName || '',
|
|
1849
|
+
coverage: getchecklist[0].coverage || '',
|
|
1850
|
+
};
|
|
1851
|
+
// console.log( 'logInsertData=>', logInsertData );
|
|
1852
|
+
await checklistLogs.create( logInsertData );
|
|
1853
|
+
// let time = dayjs().format( 'HH:mm:ss' );
|
|
1854
|
+
// let [ hours, minutes ] = time.split( ':' ).map( Number );
|
|
1855
|
+
// let nearestMultipleOf10Minutes = Math.floor( minutes / 10 ) * 10;
|
|
1856
|
+
// let roundedHours = hours + Math.floor( ( minutes - nearestMultipleOf10Minutes ) / 60 );
|
|
1857
|
+
// let roundedMinutes = nearestMultipleOf10Minutes;
|
|
1858
|
+
// let roundedSeconds = 0;
|
|
1859
|
+
// let roundedTime = `${String( roundedHours ).padStart( 2, '0' )}:${String( roundedMinutes ).padStart( 2, '0' )}:${String( roundedSeconds ).padStart( 2, '0' )}`;
|
|
1860
|
+
// let createdAtDate;
|
|
1861
|
+
// if ( storeTimeZone?.timezone ) {
|
|
1862
|
+
// createdAtDate = dayjs( `${getchecklist[0].date_string} ${time}`, 'YYYY-MM-DD hh:mm:ss' ).tz( storeTimeZone?.timezone ).utc( '+00:00' );
|
|
1863
|
+
// } else {
|
|
1864
|
+
// createdAtDate = dayjs( `${getchecklist[0].date_string} ${time}`, 'YYYY-MM-DD hh:mm:ss' ).utc( '+00:00' );
|
|
1865
|
+
// }
|
|
1866
|
+
// let detectionData = {
|
|
1867
|
+
// client_id: req.user.clientId,
|
|
1868
|
+
// store_id: getchecklist[0].store_id,
|
|
1869
|
+
// userName: req.user.name,
|
|
1870
|
+
// userId: req.user._id,
|
|
1871
|
+
// time: time,
|
|
1872
|
+
// type: 'positive',
|
|
1873
|
+
// checklistName: getchecklist[0].checkListName,
|
|
1874
|
+
// checklistId: getchecklist[0].checkListId,
|
|
1875
|
+
// sourceChecklist_id: getchecklist[0].sourceCheckList_id,
|
|
1876
|
+
// category: 'custom',
|
|
1877
|
+
// scheduleTime: getchecklist[0].scheduleEndTime_iso,
|
|
1878
|
+
// startRange: roundedTime,
|
|
1879
|
+
// date_iso: getchecklist[0].date_iso,
|
|
1880
|
+
// date_string: getchecklist[0].date_string,
|
|
1881
|
+
// createdAt: createdAtDate,
|
|
1882
|
+
// };
|
|
1883
|
+
// await detectionService.create( detectionData );
|
|
1884
|
+
if ( requestData.submittype == 'submit' ) {
|
|
1885
|
+
updateOpenSearch( req.user, requestData );
|
|
1886
|
+
let openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
1887
|
+
// console.log( 'openSearch', openSearch );
|
|
1888
|
+
let inserttraxlogs = {
|
|
1889
|
+
client_id: req.user.clientId,
|
|
1890
|
+
createAt: new Date(),
|
|
1891
|
+
sourceCheckList_id: getchecklist[0].sourceCheckList_id,
|
|
1892
|
+
checkListName: getchecklist[0].checkListName,
|
|
1893
|
+
type: 'checkList',
|
|
1894
|
+
action: requestData?.submittype === 'draft' ? 'save' : 'submit',
|
|
1895
|
+
storeName: getchecklist[0].storeName,
|
|
1896
|
+
store_id: getchecklist[0].store_id,
|
|
1897
|
+
userName: getchecklist[0].userName,
|
|
1898
|
+
userEmail: getchecklist[0].userEmail,
|
|
1899
|
+
createdByEmail: getchecklist[0].userEmail,
|
|
1900
|
+
createdBy: getchecklist[0].userName,
|
|
1901
|
+
coverage: getchecklist[0].coverage,
|
|
1902
|
+
checkListType: getchecklist[0].checkListType,
|
|
1903
|
+
logDetails: {},
|
|
1904
|
+
userType: req.user.userType,
|
|
1905
|
+
};
|
|
1906
|
+
// console.log( 'inserttraxlogs', inserttraxlogs );
|
|
1907
|
+
insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
return res.sendSuccess( 'Checklist Updated Successfully' );
|
|
1911
|
+
} else {
|
|
1912
|
+
return res.sendError( 'something went wrong please try again', 500 );
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
} catch ( e ) {
|
|
1916
|
+
logger.error( { function: 'submitChecklist', error: e, body: req.body } );
|
|
1917
|
+
return res.sendError( e, 500 );
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
export async function submitTask( req, res ) {
|
|
1922
|
+
try {
|
|
1923
|
+
const { body: requestData, user } = req;
|
|
1924
|
+
const { processedcheckListId, date, submittype, currentTime, questionAnswers } = requestData;
|
|
1925
|
+
|
|
1926
|
+
const findQuery = [
|
|
1927
|
+
{
|
|
1928
|
+
$match: {
|
|
1929
|
+
_id: new ObjectId( processedcheckListId ),
|
|
1930
|
+
userId: user._id,
|
|
1931
|
+
date_string: date,
|
|
1932
|
+
},
|
|
1933
|
+
},
|
|
1934
|
+
];
|
|
1935
|
+
|
|
1936
|
+
const [ checklist ] = await processedTask.aggregate( findQuery );
|
|
1937
|
+
|
|
1938
|
+
if ( !checklist ) {
|
|
1939
|
+
return res.sendError( 'Task edited. Please fill again', 422 );
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
// eslint-disable-next-line camelcase
|
|
1943
|
+
const { checklistStatus, storeName, userEmail, checkListName, store_id } = checklist;
|
|
1944
|
+
|
|
1945
|
+
if ( checklistStatus === 'open' ) {
|
|
1946
|
+
return res.sendError( 'Checklist is in open status. Please start.', 400 );
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
if ( checklistStatus === 'submit' ) {
|
|
1950
|
+
return res.sendError( 'Checklist already submitted', 400 );
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
const storeTimeZone = await storeService.findOne( { storeName }, { 'storeProfile.timeZone': 1 } );
|
|
1954
|
+
const currentDateTime = storeTimeZone?.storeProfile?.timeZone ?
|
|
1955
|
+
dayjs().tz( storeTimeZone.storeProfile.timeZone ) :
|
|
1956
|
+
dayjs();
|
|
1957
|
+
|
|
1958
|
+
const updateQuery = {
|
|
1959
|
+
_id: new ObjectId( processedcheckListId ),
|
|
1960
|
+
userId: user._id,
|
|
1961
|
+
date_string: date,
|
|
1962
|
+
};
|
|
1963
|
+
|
|
1964
|
+
// questionAnswers.forEach( ( section ) => {
|
|
1965
|
+
// section.questions.forEach( ( question ) => {
|
|
1966
|
+
// if ( question.redo === true ) {
|
|
1967
|
+
// question.redo = false;
|
|
1968
|
+
// }
|
|
1969
|
+
// } );
|
|
1970
|
+
// } );
|
|
1971
|
+
|
|
1972
|
+
const updateData = {
|
|
1973
|
+
questionAnswers,
|
|
1974
|
+
updatedAt: dayjs.utc( currentDateTime.format( 'hh:mm:ss A, DD MMM YYYY' ), 'hh:mm:ss A, DD MMM YYYY' ).format(),
|
|
1975
|
+
questionFlag: QuestionFlag( req, res ),
|
|
1976
|
+
};
|
|
1977
|
+
|
|
1978
|
+
if ( submittype === 'draft' ) {
|
|
1979
|
+
logger.info(
|
|
1980
|
+
`v5 => Checklist Save => store Name: ${storeName}, User Email: ${userEmail}, Checklist Name: ${checkListName}`,
|
|
1981
|
+
);
|
|
1982
|
+
updateData.submitTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
|
|
1983
|
+
} else if ( submittype === 'submit' ) {
|
|
1984
|
+
logger.info(
|
|
1985
|
+
`v5 => Checklist Submit => store Name: ${storeName}, User Email: ${userEmail}, Checklist Name: ${checkListName}`,
|
|
1986
|
+
);
|
|
1987
|
+
Object.assign( updateData, {
|
|
1988
|
+
submitTime: dayjs.utc( currentDateTime.format( 'hh:mm:ss A, DD MMM YYYY' ), 'hh:mm:ss A, DD MMM YYYY' ).format(),
|
|
1989
|
+
checklistStatus: 'submit',
|
|
1990
|
+
submitMobileTime: currentTime,
|
|
1991
|
+
submitTime_string: currentDateTime.format( 'hh:mm A, DD MMM YYYY' ),
|
|
1992
|
+
} );
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
const updateResult = await processedTask.updateOne( updateQuery, updateData );
|
|
1996
|
+
|
|
1997
|
+
if ( updateResult.modifiedCount > 0 ) {
|
|
1998
|
+
if ( submittype === 'submit' ) {
|
|
1999
|
+
const query1 = [
|
|
2000
|
+
{
|
|
2001
|
+
$match: {
|
|
2002
|
+
userId: user._id,
|
|
2003
|
+
sourceCheckList_id: checklist.sourceCheckList_id,
|
|
2004
|
+
checklistStatus: { $in: [ 'open', 'inprogress' ] },
|
|
2005
|
+
},
|
|
2006
|
+
},
|
|
2007
|
+
{
|
|
2008
|
+
$project: {
|
|
2009
|
+
_id: 1,
|
|
2010
|
+
date_iso: 1,
|
|
2011
|
+
date_string: 1,
|
|
2012
|
+
},
|
|
2013
|
+
},
|
|
2014
|
+
];
|
|
2015
|
+
|
|
2016
|
+
const processedTasksToDelete = await processedTask.aggregate( query1 );
|
|
2017
|
+
|
|
2018
|
+
if ( processedTasksToDelete?.length ) {
|
|
2019
|
+
const deleteIds = processedTasksToDelete?.filter( ( val ) => val?.date_string !== date )?.map( ( val ) => val?._id );
|
|
2020
|
+
|
|
2021
|
+
if ( deleteIds?.length ) {
|
|
2022
|
+
await processedTask.deleteMany( { _id: { $in: deleteIds } } );
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
} else if ( submittype === 'draft' ) {
|
|
2026
|
+
const query2 = [
|
|
2027
|
+
{
|
|
2028
|
+
$match: {
|
|
2029
|
+
_id: checklist.sourceCheckList_id,
|
|
2030
|
+
},
|
|
2031
|
+
},
|
|
2032
|
+
];
|
|
2033
|
+
const [ taskConfig ] = await taskConfigService.aggregate( query2 );
|
|
2034
|
+
|
|
2035
|
+
if ( taskConfig.scheduleEndTimeISO ) {
|
|
2036
|
+
const endDate = dayjs( taskConfig.scheduleEndTimeISO ).utc();
|
|
2037
|
+
const startDate = dayjs().add( 1, 'day' );
|
|
2038
|
+
|
|
2039
|
+
let currentDate = startDate;
|
|
2040
|
+
|
|
2041
|
+
while ( currentDate.isSameOrBefore( endDate ) ) {
|
|
2042
|
+
const updateDate = currentDate.format( 'YYYY-MM-DD' );
|
|
2043
|
+
|
|
2044
|
+
const updateQuery = {
|
|
2045
|
+
sourceCheckList_id: taskConfig._id,
|
|
2046
|
+
date_string: updateDate,
|
|
2047
|
+
userId: user._id,
|
|
2048
|
+
};
|
|
2049
|
+
|
|
2050
|
+
if ( Object.values( updateQuery ).length === 3 ) {
|
|
2051
|
+
await processedTask.updateOne( updateQuery, { questionAnswers, checklistStatus: 'inprogress' } );
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
currentDate = currentDate.add( 1, 'day' );
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
const logInsertData = {
|
|
2059
|
+
// eslint-disable-next-line camelcase
|
|
2060
|
+
store_id,
|
|
2061
|
+
storeName,
|
|
2062
|
+
action: submittype === 'draft' ? 'saved' : 'submitted',
|
|
2063
|
+
checklistId: checklist.sourceCheckList_id,
|
|
2064
|
+
processedChecklistId: checklist._id,
|
|
2065
|
+
type: checklist.checkListType,
|
|
2066
|
+
checkListName,
|
|
2067
|
+
client_id: user.clientId,
|
|
2068
|
+
redoStatus: requestData?.redoStatus ? true : false,
|
|
2069
|
+
};
|
|
2070
|
+
await checklistLogs.create( logInsertData );
|
|
2071
|
+
|
|
2072
|
+
if ( submittype == 'submit' ) {
|
|
2073
|
+
updateOpenSearchTask( user, requestData );
|
|
2074
|
+
let openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
2075
|
+
// console.log( 'openSearch', openSearch );
|
|
2076
|
+
let inserttraxlogs = {
|
|
2445
2077
|
client_id: req.user.clientId,
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2078
|
+
createAt: new Date(),
|
|
2079
|
+
sourceCheckList_id: checklist.sourceCheckList_id,
|
|
2080
|
+
checkListName: checklist.checkListName,
|
|
2081
|
+
type: 'task',
|
|
2082
|
+
action: requestData?.submittype === 'draft' ? 'save' : 'submit',
|
|
2083
|
+
storeName: checklist.storeName,
|
|
2084
|
+
store_id: checklist.store_id,
|
|
2085
|
+
userName: checklist.userName,
|
|
2086
|
+
userEmail: checklist.userEmail,
|
|
2087
|
+
createdByEmail: checklist.userEmail,
|
|
2088
|
+
createdBy: checklist.userName,
|
|
2089
|
+
coverage: checklist.coverage,
|
|
2090
|
+
checkListType: checklist.checkListType,
|
|
2091
|
+
logDetails: {},
|
|
2092
|
+
userType: req.user.userType,
|
|
2450
2093
|
};
|
|
2451
|
-
console.log( '
|
|
2452
|
-
|
|
2453
|
-
// let time = dayjs().format( 'HH:mm:ss' );
|
|
2454
|
-
// let [ hours, minutes ] = time.split( ':' ).map( Number );
|
|
2455
|
-
// let nearestMultipleOf10Minutes = Math.floor( minutes / 10 ) * 10;
|
|
2456
|
-
// let roundedHours = hours + Math.floor( ( minutes - nearestMultipleOf10Minutes ) / 60 );
|
|
2457
|
-
// let roundedMinutes = nearestMultipleOf10Minutes;
|
|
2458
|
-
// let roundedSeconds = 0;
|
|
2459
|
-
// let roundedTime = `${String( roundedHours ).padStart( 2, '0' )}:${String( roundedMinutes ).padStart( 2, '0' )}:${String( roundedSeconds ).padStart( 2, '0' )}`;
|
|
2460
|
-
// let createdAtDate;
|
|
2461
|
-
// if ( storeTimeZone?.timezone ) {
|
|
2462
|
-
// createdAtDate = dayjs( `${getchecklist[0].date_string} ${time}`, 'YYYY-MM-DD hh:mm:ss' ).tz( storeTimeZone?.timezone ).utc( '+00:00' );
|
|
2463
|
-
// } else {
|
|
2464
|
-
// createdAtDate = dayjs( `${getchecklist[0].date_string} ${time}`, 'YYYY-MM-DD hh:mm:ss' ).utc( '+00:00' );
|
|
2465
|
-
// }
|
|
2466
|
-
// let detectionData = {
|
|
2467
|
-
// client_id: req.user.clientId,
|
|
2468
|
-
// store_id: getchecklist[0].store_id,
|
|
2469
|
-
// userName: req.user.name,
|
|
2470
|
-
// userId: req.user._id,
|
|
2471
|
-
// time: time,
|
|
2472
|
-
// type: 'positive',
|
|
2473
|
-
// checklistName: getchecklist[0].checkListName,
|
|
2474
|
-
// checklistId: getchecklist[0].checkListId,
|
|
2475
|
-
// sourceChecklist_id: getchecklist[0].sourceCheckList_id,
|
|
2476
|
-
// category: 'custom',
|
|
2477
|
-
// scheduleTime: getchecklist[0].scheduleEndTime_iso,
|
|
2478
|
-
// startRange: roundedTime,
|
|
2479
|
-
// date_iso: getchecklist[0].date_iso,
|
|
2480
|
-
// date_string: getchecklist[0].date_string,
|
|
2481
|
-
// createdAt: createdAtDate,
|
|
2482
|
-
// };
|
|
2483
|
-
// await detectionService.create( detectionData );
|
|
2484
|
-
if ( requestData.submittype == 'submit' ) {
|
|
2485
|
-
updateOpenSearch( req.user, requestData );
|
|
2486
|
-
}
|
|
2487
|
-
|
|
2488
|
-
return res.sendSuccess( 'Checklist Updated Successfully' );
|
|
2489
|
-
} else {
|
|
2490
|
-
return res.sendError( 'something went wrong please try again', 500 );
|
|
2094
|
+
// console.log( 'inserttraxlogs', inserttraxlogs );
|
|
2095
|
+
insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
|
|
2491
2096
|
}
|
|
2097
|
+
|
|
2098
|
+
return res.sendSuccess( 'Task Updated Successfully' );
|
|
2099
|
+
} else {
|
|
2100
|
+
return res.sendError( 'Something went wrong. Please try again', 500 );
|
|
2492
2101
|
}
|
|
2493
|
-
} catch (
|
|
2494
|
-
logger.error( { function: '
|
|
2495
|
-
return res.sendError(
|
|
2102
|
+
} catch ( error ) {
|
|
2103
|
+
logger.error( { function: 'submitTask', error, body: req.body } );
|
|
2104
|
+
return res.sendError( error.message || 'Internal Server Error', 500 );
|
|
2496
2105
|
}
|
|
2497
2106
|
}
|
|
2498
|
-
|
|
2499
|
-
export async function submitTask( req, res ) {
|
|
2107
|
+
export async function submiteyeTestTask( req, res ) {
|
|
2500
2108
|
try {
|
|
2501
2109
|
const { body: requestData, user } = req;
|
|
2502
|
-
const { processedcheckListId, date, submittype, currentTime, questionAnswers } = requestData;
|
|
2110
|
+
const { processedcheckListId, date, submittype, currentTime, questionAnswers, streamId, qrCode } = requestData;
|
|
2111
|
+
// console.log( requestData );
|
|
2112
|
+
if ( !streamId ) {
|
|
2113
|
+
return res.sendError( 'streamId is required', 400 );
|
|
2114
|
+
}
|
|
2115
|
+
if ( !qrCode||qrCode=='' ) {
|
|
2116
|
+
return res.sendError( 'qrCode is required', 400 );
|
|
2117
|
+
}
|
|
2118
|
+
let findoldQrExists = await cameraService.findOne( { qrCode: qrCode } );
|
|
2119
|
+
if ( findoldQrExists ) {
|
|
2120
|
+
return res.sendError( 'Qr code already Exists', 400 );
|
|
2121
|
+
}
|
|
2122
|
+
let findQrExists = await cameraService.findOne( { streamName: streamId, qrCode: qrCode } );
|
|
2123
|
+
// console.log( findQrExists );
|
|
2124
|
+
if ( findQrExists ) {
|
|
2125
|
+
return res.sendError( 'Qr code already Exists', 400 );
|
|
2126
|
+
}
|
|
2127
|
+
|
|
2128
|
+
await cameraService.updateOne( { streamName: streamId }, { qrCode: qrCode } );
|
|
2129
|
+
return res.sendSuccess( 'Qr code added successfully' );
|
|
2503
2130
|
|
|
2504
2131
|
const findQuery = [
|
|
2505
2132
|
{
|
|
@@ -2656,7 +2283,7 @@ export async function submitTask( req, res ) {
|
|
|
2656
2283
|
return res.sendError( 'Something went wrong. Please try again', 500 );
|
|
2657
2284
|
}
|
|
2658
2285
|
} catch ( error ) {
|
|
2659
|
-
logger.error( { function: '
|
|
2286
|
+
logger.error( { function: 'submiteyeTestTask', error, body: req.body } );
|
|
2660
2287
|
return res.sendError( error.message || 'Internal Server Error', 500 );
|
|
2661
2288
|
}
|
|
2662
2289
|
}
|
|
@@ -2931,7 +2558,7 @@ export async function dashboardv1( req, res ) {
|
|
|
2931
2558
|
|
|
2932
2559
|
return res.sendSuccess( totalResult );
|
|
2933
2560
|
} catch ( e ) {
|
|
2934
|
-
console.log( 'v1 =>', e );
|
|
2561
|
+
// console.log( 'v1 =>', e );
|
|
2935
2562
|
logger.error( { function: 'dashboardv1', error: e, body: req.body } );
|
|
2936
2563
|
return res.sendError( e, 500 );
|
|
2937
2564
|
}
|
|
@@ -3106,6 +2733,7 @@ export async function checklistv1( req, res ) {
|
|
|
3106
2733
|
client_id: { $ifNull: [ '$client_id', '' ] },
|
|
3107
2734
|
coverage: { $ifNull: [ '$coverage', '' ] },
|
|
3108
2735
|
taskType: { $ifNull: [ '$planoType', '' ] },
|
|
2736
|
+
streamId: { $ifNull: [ '$streamId', '' ] },
|
|
3109
2737
|
},
|
|
3110
2738
|
},
|
|
3111
2739
|
];
|
|
@@ -3155,261 +2783,6 @@ export async function checklistv1( req, res ) {
|
|
|
3155
2783
|
}
|
|
3156
2784
|
}
|
|
3157
2785
|
|
|
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
2786
|
export async function questionList( req, res ) {
|
|
3414
2787
|
try {
|
|
3415
2788
|
let requestData = req.query;
|
|
@@ -3455,6 +2828,9 @@ export async function questionList( req, res ) {
|
|
|
3455
2828
|
storeName: { $ifNull: [ '$storeName', '' ] },
|
|
3456
2829
|
redoStatus: { $ifNull: [ '$redoStatus', false ] },
|
|
3457
2830
|
rawImageUpload: { $ifNull: [ '$rawImageUpload', false ] },
|
|
2831
|
+
rawVideoUpload: { $ifNull: [ '$rawVideoUpload', false ] },
|
|
2832
|
+
taskType: { $ifNull: [ '$planoType', '' ] },
|
|
2833
|
+
streamId: { $ifNull: [ '$streamId', '' ] },
|
|
3458
2834
|
},
|
|
3459
2835
|
} );
|
|
3460
2836
|
|
|
@@ -3984,12 +3360,10 @@ export async function uploadAnswerImage( req, res ) {
|
|
|
3984
3360
|
}
|
|
3985
3361
|
|
|
3986
3362
|
if ( imageUrl != '' ) {
|
|
3987
|
-
|
|
3988
|
-
imageUrl = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN + imageUrl.Key;
|
|
3363
|
+
imageUrl = await signedUrl( { file_path: imageUrl.Key, Bucket: bucket.sop } );
|
|
3989
3364
|
|
|
3990
3365
|
return res.sendSuccess( {
|
|
3991
3366
|
bucketName: bucket.sop,
|
|
3992
|
-
path: imageUrl.Key,
|
|
3993
3367
|
imageUrl: imageUrl,
|
|
3994
3368
|
message: 'Image uploaded successfully!',
|
|
3995
3369
|
} );
|
|
@@ -4146,7 +3520,7 @@ export const sendSignInOtpEmail = async ( emailVars ) => {
|
|
|
4146
3520
|
const result = await sendEmailWithSES( emailVars.email, subject, html, attachments, ses.adminEmail );
|
|
4147
3521
|
return result;
|
|
4148
3522
|
} catch ( error ) {
|
|
4149
|
-
logger.error( { error: error, function: 'sendSignInOtpEmail', body:
|
|
3523
|
+
logger.error( { error: error, function: 'sendSignInOtpEmail', body: emailVars } );
|
|
4150
3524
|
return error;
|
|
4151
3525
|
}
|
|
4152
3526
|
};
|
|
@@ -4297,8 +3671,8 @@ export async function clientConfig( req, res ) {
|
|
|
4297
3671
|
try {
|
|
4298
3672
|
let requestData = req.body;
|
|
4299
3673
|
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 );
|
|
3674
|
+
let getClientData = await clientService.findOne( { clientId: requestData.clientId }, { traxRAWImageUpload: 1, clientId: 1, clientName: 1, traxBlockMobileTimeUpdate: 1, traxSectionSave: 1 } );
|
|
3675
|
+
// console.log( ' getClientData=>', getClientData );
|
|
4302
3676
|
if ( getClientData ) {
|
|
4303
3677
|
return res.sendSuccess( getClientData );
|
|
4304
3678
|
} else {
|
|
@@ -4308,7 +3682,6 @@ export async function clientConfig( req, res ) {
|
|
|
4308
3682
|
return res.sendError( 'clientId is Required', 400 );
|
|
4309
3683
|
}
|
|
4310
3684
|
} catch ( e ) {
|
|
4311
|
-
console.log( 'e =>', e );
|
|
4312
3685
|
logger.error( { error: e, function: 'clientConfig' } );
|
|
4313
3686
|
return res.sendError( e, 500 );
|
|
4314
3687
|
}
|