tango-app-api-trax 3.4.0-alpha-1 → 3.4.0-alpha-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/controllers/mobileTrax.controller.js +932 -24
- package/src/controllers/trax.controller.js +146 -39
- package/src/controllers/traxDashboard.controllers.js +2 -1
- package/src/hbs/login-otp.hbs +943 -943
- package/src/routes/mobileTrax.routes.js +3 -0
- package/src/routes/trax.routes.js +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fileUpload, chunkArray, logger, sendPushNotification } from 'tango-app-api-middleware';
|
|
2
2
|
import * as checklistService from '../services/checklist.service.js';
|
|
3
3
|
import * as questionService from '../services/checklistQuestion.service.js';
|
|
4
4
|
import * as assignedService from '../services/checklistAssign.service.js';
|
|
@@ -247,14 +247,15 @@ export const create = async ( req, res ) => {
|
|
|
247
247
|
section.questions[qIdx].answers[index].nestedQuestion = [];
|
|
248
248
|
}
|
|
249
249
|
if ( answer.showLinked ) {
|
|
250
|
+
// section.questions[qIdx].answers[nestedIndex].nestedQuestion.push( answer.linkedQuestion );
|
|
250
251
|
if ( nestedIndex != -1 ) {
|
|
251
|
-
if ( !section.questions[qIdx].answers[nestedIndex].nestedQuestion.includes( answer.linkedQuestion ) ) {
|
|
252
|
-
|
|
253
|
-
}
|
|
252
|
+
// if ( !section.questions[qIdx].answers[nestedIndex].nestedQuestion.includes( answer.linkedQuestion ) ) {
|
|
253
|
+
section.questions[qIdx].answers[nestedIndex].nestedQuestion.push( answer.linkedQuestion );
|
|
254
|
+
// }
|
|
254
255
|
} else {
|
|
255
|
-
if ( !section.questions[qIdx].answers[index].nestedQuestion.includes( answer.linkedQuestion ) ) {
|
|
256
|
-
|
|
257
|
-
}
|
|
256
|
+
// if ( !section.questions[qIdx].answers[index].nestedQuestion.includes( answer.linkedQuestion ) ) {
|
|
257
|
+
section.questions[qIdx].answers[index].nestedQuestion.push( answer.linkedQuestion );
|
|
258
|
+
// }
|
|
258
259
|
}
|
|
259
260
|
let nestedLinkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
|
|
260
261
|
if ( nestedLinkedQuestion ) {
|
|
@@ -271,6 +272,18 @@ export const create = async ( req, res ) => {
|
|
|
271
272
|
}
|
|
272
273
|
}
|
|
273
274
|
}
|
|
275
|
+
let checkNestedLevel = false;
|
|
276
|
+
section.questions.forEach( ( qns ) => {
|
|
277
|
+
qns.answers.forEach( ( answ ) => {
|
|
278
|
+
if ( answ.nestedQuestion.length > 20 ) {
|
|
279
|
+
checkNestedLevel = true;
|
|
280
|
+
}
|
|
281
|
+
} );
|
|
282
|
+
} );
|
|
283
|
+
|
|
284
|
+
if ( checkNestedLevel ) {
|
|
285
|
+
return res.sendError( { message: 'Unable to create more than 20 linked questions.' }, 400 );
|
|
286
|
+
}
|
|
274
287
|
|
|
275
288
|
let sectionList = {
|
|
276
289
|
section: section.name,
|
|
@@ -286,6 +299,7 @@ export const create = async ( req, res ) => {
|
|
|
286
299
|
return res.sendSuccess( { checklistId: checkListId, msg: 'CheckList Created Successfully' } );
|
|
287
300
|
}
|
|
288
301
|
} ).catch( ( e ) => {
|
|
302
|
+
console.log( e );
|
|
289
303
|
return res.sendError( e, 500 );
|
|
290
304
|
} );
|
|
291
305
|
}
|
|
@@ -295,6 +309,7 @@ export const create = async ( req, res ) => {
|
|
|
295
309
|
}
|
|
296
310
|
}
|
|
297
311
|
} ).catch( async ( e ) => {
|
|
312
|
+
console.log( e );
|
|
298
313
|
await checklistService.deleteOne( { _id: checkListId } );
|
|
299
314
|
return res.sendError( e, 500 );
|
|
300
315
|
} );
|
|
@@ -358,23 +373,23 @@ export const getConfigDetails = async ( req, res ) => {
|
|
|
358
373
|
let questionDetails = await questionService.find( query );
|
|
359
374
|
if ( questionDetails.length ) {
|
|
360
375
|
let sections = [];
|
|
361
|
-
let bucket = JSON.parse( process.env.BUCKET );
|
|
376
|
+
// let bucket = JSON.parse( process.env.BUCKET );
|
|
362
377
|
questionDetails.forEach( ( item ) => {
|
|
363
378
|
item.question.forEach( async ( question ) => {
|
|
364
379
|
if ( question.questionReferenceImage && question.questionReferenceImage !='' ) {
|
|
365
|
-
let inputData = {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
};
|
|
369
|
-
question.questionReferenceImage =
|
|
380
|
+
// let inputData = {
|
|
381
|
+
// Bucket: bucket.sop,
|
|
382
|
+
// file_path: decodeURIComponent( question.questionReferenceImage ),
|
|
383
|
+
// };
|
|
384
|
+
question.questionReferenceImage = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN+question.questionReferenceImage;
|
|
370
385
|
}
|
|
371
386
|
question.answers.forEach( async ( answer ) => {
|
|
372
387
|
if ( answer.referenceImage != '' ) {
|
|
373
|
-
let inputData = {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
};
|
|
377
|
-
answer.referenceImage =
|
|
388
|
+
// let inputData = {
|
|
389
|
+
// Bucket: bucket.sop,
|
|
390
|
+
// file_path: decodeURIComponent( answer.referenceImage ),
|
|
391
|
+
// };
|
|
392
|
+
answer.referenceImage = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN+answer.referenceImage;
|
|
378
393
|
}
|
|
379
394
|
} );
|
|
380
395
|
} );
|
|
@@ -777,13 +792,13 @@ export const update = async ( req, res ) => {
|
|
|
777
792
|
}
|
|
778
793
|
if ( answer.showLinked ) {
|
|
779
794
|
if ( nestedIndex != -1 ) {
|
|
780
|
-
if ( !section.questions[qIdx].answers[nestedIndex].nestedQuestion.includes( answer.linkedQuestion ) ) {
|
|
781
|
-
|
|
782
|
-
}
|
|
795
|
+
// if ( !section.questions[qIdx].answers[nestedIndex].nestedQuestion.includes( answer.linkedQuestion ) ) {
|
|
796
|
+
section.questions[qIdx].answers[nestedIndex].nestedQuestion.push( answer.linkedQuestion );
|
|
797
|
+
// }
|
|
783
798
|
} else {
|
|
784
|
-
if ( !section.questions[qIdx].answers[index].nestedQuestion.includes( answer.linkedQuestion ) ) {
|
|
785
|
-
|
|
786
|
-
}
|
|
799
|
+
// if ( !section.questions[qIdx].answers[index].nestedQuestion.includes( answer.linkedQuestion ) ) {
|
|
800
|
+
section.questions[qIdx].answers[index].nestedQuestion.push( answer.linkedQuestion );
|
|
801
|
+
// }
|
|
787
802
|
}
|
|
788
803
|
let nestedLinkedQuestion = section.questions.find( ( item ) => item.qno == answer.linkedQuestion );
|
|
789
804
|
if ( nestedLinkedQuestion ) {
|
|
@@ -801,6 +816,21 @@ export const update = async ( req, res ) => {
|
|
|
801
816
|
}
|
|
802
817
|
}
|
|
803
818
|
|
|
819
|
+
let checkNestedLevel = false;
|
|
820
|
+
section.questions.forEach( ( qns ) => {
|
|
821
|
+
qns.answers.forEach( ( answ ) => {
|
|
822
|
+
if ( answ.nestedQuestion.length > 20 ) {
|
|
823
|
+
checkNestedLevel = true;
|
|
824
|
+
}
|
|
825
|
+
} );
|
|
826
|
+
} );
|
|
827
|
+
|
|
828
|
+
console.log( checkNestedLevel, 'lebej' );
|
|
829
|
+
|
|
830
|
+
if ( checkNestedLevel ) {
|
|
831
|
+
return res.sendError( { message: 'Unable to create more than 20 linked questions' }, 400 );
|
|
832
|
+
}
|
|
833
|
+
|
|
804
834
|
let sectionList = {
|
|
805
835
|
section: section.name,
|
|
806
836
|
sectionOldName: section.oldName,
|
|
@@ -859,11 +889,11 @@ export const uploadImage = async ( req, res ) => {
|
|
|
859
889
|
};
|
|
860
890
|
imgUrl = await fileUpload( params );
|
|
861
891
|
|
|
862
|
-
let inputData = {
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
};
|
|
866
|
-
imgUrl =
|
|
892
|
+
// let inputData = {
|
|
893
|
+
// Bucket: bucket.sop,
|
|
894
|
+
// file_path: imgUrl.Key,
|
|
895
|
+
// };
|
|
896
|
+
imgUrl = JSON.parse( process.env.CDNURL )?.TraxAnswerCDN+imgUrl.Key;
|
|
867
897
|
if ( !imgUrl ) {
|
|
868
898
|
return res.sendError( { message: 'Something went Wrong' }, 500 );
|
|
869
899
|
}
|
|
@@ -3145,7 +3175,6 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3145
3175
|
}
|
|
3146
3176
|
if ( getsubmitDetails ) {
|
|
3147
3177
|
getsubmitDetails = [ getsubmitDetails ];
|
|
3148
|
-
console.log( submittedDetails, getsubmitDetails );
|
|
3149
3178
|
}
|
|
3150
3179
|
function findDifferences( obj1, obj2 ) {
|
|
3151
3180
|
return Object.keys( obj1 ).reduce( ( diff, key ) => {
|
|
@@ -3181,6 +3210,7 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3181
3210
|
delete data.parentanswer;
|
|
3182
3211
|
delete data.remarks;
|
|
3183
3212
|
delete data.linkquestionenabled;
|
|
3213
|
+
delete data.uniqueNo;
|
|
3184
3214
|
if ( data.descriptivetype == null ) {
|
|
3185
3215
|
delete data.descriptivetype;
|
|
3186
3216
|
}
|
|
@@ -3192,29 +3222,101 @@ async function insertPCBulkV4( getCLconfig, checklistId, currentdate, updatedche
|
|
|
3192
3222
|
delete ans.index;
|
|
3193
3223
|
delete ans.validationAnswer;
|
|
3194
3224
|
delete ans.answeroptionNumber;
|
|
3225
|
+
ans.nestedQuestion = ans?.oldNestedQuestion ? ans.oldNestedQuestion : ans.nestedQuestion;
|
|
3226
|
+
ans.linkedQuestion = ans?.oldLinkedQuestion ? ans.oldLinkedQuestion : ans.linkedQuestion;
|
|
3227
|
+
delete ans.oldNestedQuestion;
|
|
3228
|
+
delete ans.oldLinkedQuestion;
|
|
3195
3229
|
} );
|
|
3196
3230
|
const compare = findDifferences( data, qns );
|
|
3197
3231
|
if ( compare?.answerType || compare?.answers || compare?.linkType ) {
|
|
3198
3232
|
logger.info( 'compare =>', compare );
|
|
3233
|
+
logger.info( 'compareSection =>', { section: section.sectionName } );
|
|
3234
|
+
logger.info( 'qno =>', { qno: data.qno } );
|
|
3199
3235
|
modifiedCount++;
|
|
3200
|
-
question.push( qns );
|
|
3236
|
+
question.push( { question: qns, type: 'qnEdit' } );
|
|
3201
3237
|
} else {
|
|
3202
|
-
getsubmitDetails[0].questionAnswers[index].questions[findQuestion].qname
|
|
3203
|
-
|
|
3238
|
+
if ( getsubmitDetails[0].questionAnswers[index].questions[findQuestion].qname != qns.qname ) {
|
|
3239
|
+
question.push( { type: 'nameChange', question: qns } );
|
|
3240
|
+
}
|
|
3241
|
+
// getsubmitDetails[0].questionAnswers[index].questions[findQuestion].qname = qns.qname;
|
|
3204
3242
|
}
|
|
3205
3243
|
} else {
|
|
3206
3244
|
modifiedCount++;
|
|
3207
|
-
question.push( qns );
|
|
3245
|
+
question.push( { question: qns, type: 'add' } );
|
|
3208
3246
|
}
|
|
3209
3247
|
} );
|
|
3210
|
-
getsubmitDetails[0].questionAnswers[index].questions = question;
|
|
3211
|
-
sectionList.push(
|
|
3248
|
+
// getsubmitDetails[0].questionAnswers[index].questions = question;
|
|
3249
|
+
sectionList.push( { sectionName: section.sectionName, oldName: section.sectionOldName, question: question, type: 'edit' } );
|
|
3212
3250
|
} else {
|
|
3213
3251
|
modifiedCount++;
|
|
3214
|
-
sectionList.push( section );
|
|
3252
|
+
sectionList.push( { section: section, type: 'add' } );
|
|
3215
3253
|
}
|
|
3216
3254
|
}
|
|
3217
|
-
getsubmitDetails[0].questionAnswers = sectionList;
|
|
3255
|
+
// getsubmitDetails[0].questionAnswers = sectionList;
|
|
3256
|
+
sectionList.forEach( ( sec ) => {
|
|
3257
|
+
if ( sec.type == 'add' ) {
|
|
3258
|
+
getsubmitDetails[0].questionAnswers.push( sec.section );
|
|
3259
|
+
} else {
|
|
3260
|
+
sec.question.forEach( ( qn ) => {
|
|
3261
|
+
let sectionDetails = getsubmitDetails[0].questionAnswers.findIndex( ( section ) => section.sectionName == sec?.oldName || section.sectionName == sec.sectionName );
|
|
3262
|
+
if ( qn.type == 'add' ) {
|
|
3263
|
+
getsubmitDetails[0].questionAnswers[sectionDetails].questions.push( qn.question );
|
|
3264
|
+
} else {
|
|
3265
|
+
let questions = getsubmitDetails[0].questionAnswers[sectionDetails].questions.reduce( ( acc, ele, idx ) => {
|
|
3266
|
+
if ( ele.qname.trim() == qn?.question?.oldQname?.trim() || ele.qname.trim() == qn.question.qname.trim() ) {
|
|
3267
|
+
acc.push( idx );
|
|
3268
|
+
}
|
|
3269
|
+
return acc;
|
|
3270
|
+
}, [] );
|
|
3271
|
+
if ( questions.length && [ 'qnEdit', 'nameChange' ].includes( qn.type ) ) {
|
|
3272
|
+
if ( qn.type == 'qnEdit' ) {
|
|
3273
|
+
let checkLinkType = getsubmitDetails[0].questionAnswers[sectionDetails].questions[questions[0]].linkType;
|
|
3274
|
+
if ( checkLinkType && !qn.question.linkType ) {
|
|
3275
|
+
questions.forEach( ( qnIdx, index ) => {
|
|
3276
|
+
if ( index != 0 ) {
|
|
3277
|
+
getsubmitDetails[0].questionAnswers[sectionDetails].questions.splice( qnIdx, 1 );
|
|
3278
|
+
}
|
|
3279
|
+
} );
|
|
3280
|
+
questions = [ questions[0] ];
|
|
3281
|
+
}
|
|
3282
|
+
}
|
|
3283
|
+
questions.forEach( ( qnIdx ) => {
|
|
3284
|
+
if ( qn.type == 'qnEdit' ) {
|
|
3285
|
+
getsubmitDetails[0].questionAnswers[sectionDetails].questions[qnIdx].answers.forEach( ( ele ) => {
|
|
3286
|
+
console.log( ele?.nestedQuestion );
|
|
3287
|
+
if ( ele?.nestedQuestion.length ) {
|
|
3288
|
+
ele?.nestedQuestion.forEach( ( nested ) => {
|
|
3289
|
+
let findIndex = getsubmitDetails[0].questionAnswers[sectionDetails].questions.findIndex( ( qn ) => qn.uniqueNo == nested );
|
|
3290
|
+
if ( findIndex != -1 ) {
|
|
3291
|
+
delete getsubmitDetails[0].questionAnswers[sectionDetails].questions[findIndex].userAnswer;
|
|
3292
|
+
let questionDetails = getsubmitDetails[0].questionAnswers[sectionDetails].questions[findIndex];
|
|
3293
|
+
let checkQuestionExists = getsubmitDetails[0].questionAnswers[sectionDetails].questions.filter( ( qnDetails ) => qnDetails.qname == questionDetails.qname );
|
|
3294
|
+
if ( checkQuestionExists.length > 1 ) {
|
|
3295
|
+
getsubmitDetails[0].questionAnswers[sectionDetails].questions.splice( findIndex, 1 );
|
|
3296
|
+
} else {
|
|
3297
|
+
delete getsubmitDetails[0].questionAnswers[sectionDetails].questions[findIndex].uniqueNo;
|
|
3298
|
+
getsubmitDetails[0].questionAnswers[sectionDetails].questions[findIndex].linkquestionenabled = false;
|
|
3299
|
+
getsubmitDetails[0].questionAnswers[sectionDetails].questions[findIndex].answers.forEach( ( ele ) => {
|
|
3300
|
+
if ( ele?.oldNestedQuestion?.length ) {
|
|
3301
|
+
ele.nestedQuestion = ele.oldNestedQuestion;
|
|
3302
|
+
ele.linkedQuestion = ele.oldLinkedQuestion;
|
|
3303
|
+
}
|
|
3304
|
+
} );
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
} );
|
|
3308
|
+
}
|
|
3309
|
+
} );
|
|
3310
|
+
getsubmitDetails[0].questionAnswers[sectionDetails].questions[qnIdx] = qn.question;
|
|
3311
|
+
} else {
|
|
3312
|
+
getsubmitDetails[0].questionAnswers[sectionDetails].questions[qnIdx].qname = qn.question.qname;
|
|
3313
|
+
}
|
|
3314
|
+
} );
|
|
3315
|
+
}
|
|
3316
|
+
}
|
|
3317
|
+
} );
|
|
3318
|
+
}
|
|
3319
|
+
} );
|
|
3218
3320
|
if ( modifiedCount ) {
|
|
3219
3321
|
getsubmitDetails[0].checklistStatus = 'inprogress';
|
|
3220
3322
|
getsubmitDetails[0].date_string = dayjs( currentdate ).format( 'YYYY-MM-DD' );
|
|
@@ -3622,7 +3724,12 @@ export const selectAssign = async ( req, res ) => {
|
|
|
3622
3724
|
// //Select Store and cluster
|
|
3623
3725
|
if ( requestData.assignType == 'store' ) {
|
|
3624
3726
|
let storeQuery = [
|
|
3625
|
-
{
|
|
3727
|
+
{
|
|
3728
|
+
$match: {
|
|
3729
|
+
...( req.user.userType==='client'&&req.user.role!='superadmin' ) ? { storeId: { $in: requestData?.assignedStores } } :{ clientId: requestData.clientId },
|
|
3730
|
+
status: 'active',
|
|
3731
|
+
},
|
|
3732
|
+
},
|
|
3626
3733
|
{
|
|
3627
3734
|
$project: {
|
|
3628
3735
|
storeName: 1,
|
|
@@ -3809,7 +3809,8 @@ export async function sendAlert( req, res ) {
|
|
|
3809
3809
|
}
|
|
3810
3810
|
const fcmToken = item.token;
|
|
3811
3811
|
try {
|
|
3812
|
-
await sendPushNotification( title, description, fcmToken );
|
|
3812
|
+
let response = await sendPushNotification( title, description, fcmToken );
|
|
3813
|
+
console.log( response, 'response' );
|
|
3813
3814
|
} catch ( e ) {
|
|
3814
3815
|
logger.error( { message: 'send alert', error: e, details: data } );
|
|
3815
3816
|
}
|