tango-app-api-trax 1.0.0-task.121 → 1.0.0-task.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-trax",
|
|
3
|
-
"version": "1.0.0-task.
|
|
3
|
+
"version": "1.0.0-task.122",
|
|
4
4
|
"description": "Trax",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
"dotenv": "^16.4.5",
|
|
20
20
|
"express": "^4.21.1",
|
|
21
21
|
"express-fileupload": "^1.5.1",
|
|
22
|
+
"firebase-admin": "^13.0.0",
|
|
23
|
+
"fs": "^0.0.1-security",
|
|
22
24
|
"handlebars": "^4.7.8",
|
|
23
25
|
"lodash": "^4.17.21",
|
|
24
26
|
"mongodb": "^6.8.0",
|
|
25
27
|
"nodemon": "^3.1.4",
|
|
26
|
-
"
|
|
28
|
+
"path": "^0.12.7",
|
|
29
|
+
"tango-api-schema": "^2.1.91",
|
|
27
30
|
"tango-app-api-middleware": "^3.1.43-alpha.10",
|
|
28
|
-
"winston": "^3.13.1",
|
|
29
|
-
"winston-daily-rotate-file": "^5.0.0",
|
|
30
31
|
"url": "^0.11.4",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"fs": "^0.0.1-security"
|
|
32
|
+
"winston": "^3.13.1",
|
|
33
|
+
"winston-daily-rotate-file": "^5.0.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"eslint": "^8.57.0",
|
|
@@ -4,6 +4,8 @@ import { logger } from 'tango-app-api-middleware';
|
|
|
4
4
|
import * as storeService from '../services/store.service.js';
|
|
5
5
|
import * as groupService from '../services/group.service.js';
|
|
6
6
|
import * as processedchecklistconfigService from '../services/processedchecklistconfig.services.js';
|
|
7
|
+
import * as processedChecklist from '../services/processedchecklist.services.js';
|
|
8
|
+
import * as checklistLogs from '../services/checklistlog.service.js';
|
|
7
9
|
// import axios from 'axios';
|
|
8
10
|
async function LamdaServiceCall( url, data ) {
|
|
9
11
|
try {
|
|
@@ -247,3 +249,103 @@ export const checklistDropdown = async ( req, res ) => {
|
|
|
247
249
|
return res.sendError( { error: error }, 500 );
|
|
248
250
|
}
|
|
249
251
|
};
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
export async function approveChecklist( req, res ) {
|
|
255
|
+
try {
|
|
256
|
+
if ( !req.body.id ) {
|
|
257
|
+
return res.sendError( 'id is required', 400 );
|
|
258
|
+
}
|
|
259
|
+
let checklistDetails = await processedChecklist.findOne( { _id: req.body.id }, { approvalEnable: 1, approvalStatus: 1 } );
|
|
260
|
+
if ( !checklistDetails ) {
|
|
261
|
+
return res.sendError( 'No data found', 204 );
|
|
262
|
+
}
|
|
263
|
+
if ( !checklistDetails.approvalEnable ) {
|
|
264
|
+
return res.sendError( 'Checklist has no approver', 400 );
|
|
265
|
+
}
|
|
266
|
+
checklistDetails.approvalStatus = true;
|
|
267
|
+
checklistDetails.save().then( () => {
|
|
268
|
+
return res.sendSuccess( 'Checklist Approved Successfully' );
|
|
269
|
+
} ).catch( ( e ) => {
|
|
270
|
+
return res.sendError( e, 500 );
|
|
271
|
+
} );
|
|
272
|
+
} catch ( e ) {
|
|
273
|
+
logger.error( { function: 'approveChecklist', error: e } );
|
|
274
|
+
return res.sendError( e, 500 );
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export async function redoChecklist( req, res ) {
|
|
279
|
+
try {
|
|
280
|
+
if ( !req.body.payload._id ) {
|
|
281
|
+
return res.sendError( 'Id is Required', 400 );
|
|
282
|
+
}
|
|
283
|
+
if ( !req.body.payload.section_id ) {
|
|
284
|
+
return res.sendError( 'Section id is Required', 400 );
|
|
285
|
+
}
|
|
286
|
+
if ( !req.body.payload.qno ) {
|
|
287
|
+
return res.sendError( 'Question number is Required', 400 );
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
let checklistDetails = await processedChecklist.findOne( { _id: req.body.payload._id }, { questionAnswers: 1, redoStatus: 1, checklistStatus: 1, client_id: 1, store_id: 1, storeName: 1, checkListType: 1, sourceCheckList_id: 1, checkListName: 1 } );
|
|
291
|
+
if ( !checklistDetails ) {
|
|
292
|
+
return res.sendError( 'No data found', 204 );
|
|
293
|
+
}
|
|
294
|
+
let question = checklistDetails.questionAnswers;
|
|
295
|
+
let sectionIndex = question.findIndex( ( sec ) => sec.section_id == req.body.payload.section_id );
|
|
296
|
+
if ( sectionIndex == -1 ) {
|
|
297
|
+
return res.sendError( 'section is not found', 400 );
|
|
298
|
+
}
|
|
299
|
+
let data = { ...question[sectionIndex].questions[req.body.payload.qno - 1], redo: true };
|
|
300
|
+
let userAnswer = data.userAnswer;
|
|
301
|
+
question[sectionIndex].questions[req.body.payload.qno - 1] = data;
|
|
302
|
+
question[sectionIndex].questions[req.body.payload.qno - 1].userAnswer = [];
|
|
303
|
+
checklistDetails.questionAnswers = question;
|
|
304
|
+
let updateData = {
|
|
305
|
+
checklistStatus: 'open',
|
|
306
|
+
redoStatus: true,
|
|
307
|
+
questionAnswers: question,
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
let response = await processedChecklist.updateOne( { _id: req.body.payload._id }, updateData );
|
|
311
|
+
if ( response.modifiedCount || response.matchedCount ) {
|
|
312
|
+
data = {
|
|
313
|
+
checklistId: checklistDetails.sourceCheckList_id,
|
|
314
|
+
checkListName: checklistDetails.checkListName,
|
|
315
|
+
sectionId: req.body.payload.section_id,
|
|
316
|
+
sectionName: question[sectionIndex].sectionName,
|
|
317
|
+
questionName: question[sectionIndex].questions[req.body.payload.qno - 1].qname,
|
|
318
|
+
action: 'redo',
|
|
319
|
+
store_id: checklistDetails.store_id,
|
|
320
|
+
storeName: checklistDetails.storeName,
|
|
321
|
+
client_id: checklistDetails.client_id,
|
|
322
|
+
processedChecklistId: checklistDetails._id,
|
|
323
|
+
type: checklistDetails.checkListType,
|
|
324
|
+
userAnswer: userAnswer,
|
|
325
|
+
};
|
|
326
|
+
await checklistLogs.create( data );
|
|
327
|
+
const requestOptions = {
|
|
328
|
+
method: 'POST',
|
|
329
|
+
headers: {
|
|
330
|
+
'Content-Type': 'application/json',
|
|
331
|
+
},
|
|
332
|
+
body: JSON.stringify( req.body ),
|
|
333
|
+
};
|
|
334
|
+
let searchResponse = await fetch( 'https://7et6pebvmii725tcntww4w56yq0rjpqw.lambda-url.ap-south-1.on.aws/', requestOptions );
|
|
335
|
+
console.log( searchResponse );
|
|
336
|
+
|
|
337
|
+
if ( searchResponse.ok ) {
|
|
338
|
+
return res.sendSuccess( 'Question redo successfully' );
|
|
339
|
+
} else {
|
|
340
|
+
return res.sendError( 'Something went wrong', 500 );
|
|
341
|
+
}
|
|
342
|
+
} else {
|
|
343
|
+
return res.sendError( 'Something went wrong', 500 );
|
|
344
|
+
}
|
|
345
|
+
} catch ( e ) {
|
|
346
|
+
logger.error( { function: 'redoChecklist', error: e } );
|
|
347
|
+
return res.sendError( e, 500 );
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
|
|
@@ -154,7 +154,7 @@ export async function startChecklist( req, res ) {
|
|
|
154
154
|
}
|
|
155
155
|
updateData.checklistStatus = 'inprogress';
|
|
156
156
|
updateData.startMobileTime = requestData?.currentTime;
|
|
157
|
-
updateData.questionAnswers =
|
|
157
|
+
updateData.questionAnswers = getBeforeChecklist.redoStatus ? getBeforeChecklist.questionAnswers : PCLQusestion.questionAnswers;
|
|
158
158
|
// const newDateTime = currentDateTime.add(5, 'hours').add(30, 'minutes');
|
|
159
159
|
// updateData.startTime_string = newDateTime.format('hh:mm A, DD MMM');
|
|
160
160
|
updateData.startTime_string = currentDateTime.format( 'hh:mm A, DD MMM YYYY' );
|
|
@@ -304,7 +304,7 @@ export async function startTask( req, res ) {
|
|
|
304
304
|
const updateData = {
|
|
305
305
|
checklistStatus: 'inprogress',
|
|
306
306
|
startMobileTime: requestData?.currentTime,
|
|
307
|
-
questionAnswers:
|
|
307
|
+
questionAnswers: task.redoStatus ? task.questionAnswers : processedTaskConfig.questionAnswers,
|
|
308
308
|
startTime_string: currentDateTime.format( 'hh:mm A, DD MMM YYYY' ),
|
|
309
309
|
startTime: dayjs
|
|
310
310
|
.utc( currentDateTime.format( 'hh:mm A, DD MMM YYYY' ), 'hh:mm A, DD MMM YYYY' )
|
|
@@ -579,6 +579,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
579
579
|
structure.parentanswer = requestSection[i].parentanswer,
|
|
580
580
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage,
|
|
581
581
|
structure.descriptivetype = qaAnswers[j].descriptivetype,
|
|
582
|
+
structure.redo = qaAnswers[j]?.redo,
|
|
582
583
|
newArray.push( structure );
|
|
583
584
|
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle' ) {
|
|
584
585
|
let qaans = qaAnswers[j].answers;
|
|
@@ -618,6 +619,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
618
619
|
structure.parentanswer = requestSection[i].parentanswer,
|
|
619
620
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage,
|
|
620
621
|
structure.descriptivetype = qaAnswers[j].descriptivetype,
|
|
622
|
+
structure.redo = qaAnswers[j]?.redo,
|
|
621
623
|
newArray.push( structure );
|
|
622
624
|
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' ) {
|
|
623
625
|
let qaans = qaAnswers[j].answers;
|
|
@@ -661,6 +663,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
661
663
|
structure.parentanswer = requestSection[i].parentanswer,
|
|
662
664
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage,
|
|
663
665
|
structure.descriptivetype = qaAnswers[j].descriptivetype,
|
|
666
|
+
structure.redo = qaAnswers[j]?.redo,
|
|
664
667
|
newArray.push( structure );
|
|
665
668
|
} else if ( qaAnswers[j].answerType == 'multipleImage' ) {
|
|
666
669
|
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
@@ -709,6 +712,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
709
712
|
structure.parentanswer = requestSection[i].parentanswer,
|
|
710
713
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage,
|
|
711
714
|
structure.descriptivetype = qaAnswers[j].descriptivetype,
|
|
715
|
+
structure.redo = qaAnswers[j]?.redo,
|
|
712
716
|
newArray.push( structure );
|
|
713
717
|
} else {
|
|
714
718
|
let des = [];
|
|
@@ -752,6 +756,7 @@ export async function sopMobilechecklistMultiSectionFormatter( req, res, next )
|
|
|
752
756
|
structure.parentanswer = requestSection[i].parentanswer,
|
|
753
757
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage,
|
|
754
758
|
structure.descriptivetype = qaAnswers[j].descriptivetype,
|
|
759
|
+
structure.redo = qaAnswers[j]?.redo,
|
|
755
760
|
newArray.push( structure );
|
|
756
761
|
}
|
|
757
762
|
}
|
|
@@ -849,6 +854,7 @@ export async function sopMobileTaskMultiSectionFormatter( req, res, next ) {
|
|
|
849
854
|
structure.parentanswer = requestSection[i].parentanswer,
|
|
850
855
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage,
|
|
851
856
|
structure.descriptivetype = qaAnswers[j].descriptivetype,
|
|
857
|
+
structure.redo = qaAnswers[j]?.redo,
|
|
852
858
|
newArray.push( structure );
|
|
853
859
|
} else if ( qaAnswers[j].answerType == 'multiplechoicesingle' ) {
|
|
854
860
|
let qaans = qaAnswers[j].answers;
|
|
@@ -888,6 +894,7 @@ export async function sopMobileTaskMultiSectionFormatter( req, res, next ) {
|
|
|
888
894
|
structure.parentanswer = requestSection[i].parentanswer,
|
|
889
895
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage,
|
|
890
896
|
structure.descriptivetype = qaAnswers[j].descriptivetype,
|
|
897
|
+
structure.redo = qaAnswers[j]?.redo,
|
|
891
898
|
newArray.push( structure );
|
|
892
899
|
} else if ( qaAnswers[j].answerType == 'multiplechoicemultiple' ) {
|
|
893
900
|
let qaans = qaAnswers[j].answers;
|
|
@@ -931,6 +938,7 @@ export async function sopMobileTaskMultiSectionFormatter( req, res, next ) {
|
|
|
931
938
|
structure.parentanswer = requestSection[i].parentanswer,
|
|
932
939
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage,
|
|
933
940
|
structure.descriptivetype = qaAnswers[j].descriptivetype,
|
|
941
|
+
structure.redo = qaAnswers[j]?.redo,
|
|
934
942
|
newArray.push( structure );
|
|
935
943
|
} else if ( qaAnswers[j].answerType == 'multipleImage' ) {
|
|
936
944
|
let separatedArray = typeof requestSection[i].Multianswer == 'string' ? JSON.parse( requestSection[i].Multianswer ) : requestSection[i].Multianswer;
|
|
@@ -979,6 +987,7 @@ export async function sopMobileTaskMultiSectionFormatter( req, res, next ) {
|
|
|
979
987
|
structure.parentanswer = requestSection[i].parentanswer,
|
|
980
988
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage,
|
|
981
989
|
structure.descriptivetype = qaAnswers[j].descriptivetype,
|
|
990
|
+
structure.redo = qaAnswers[j]?.redo,
|
|
982
991
|
newArray.push( structure );
|
|
983
992
|
} else {
|
|
984
993
|
let des = [];
|
|
@@ -1022,6 +1031,7 @@ export async function sopMobileTaskMultiSectionFormatter( req, res, next ) {
|
|
|
1022
1031
|
structure.parentanswer = requestSection[i].parentanswer,
|
|
1023
1032
|
structure.questionReferenceImage = qaAnswers[j].questionReferenceImage,
|
|
1024
1033
|
structure.descriptivetype = qaAnswers[j].descriptivetype,
|
|
1034
|
+
structure.redo = qaAnswers[j]?.redo,
|
|
1025
1035
|
newArray.push( structure );
|
|
1026
1036
|
}
|
|
1027
1037
|
}
|
|
@@ -1120,6 +1130,13 @@ export async function submitChecklist( req, res ) {
|
|
|
1120
1130
|
updateData.updatedAt = dayjs.utc( currentDateTime.format( 'hh:mm:ss A, DD MMM YYYY' ), 'hh:mm:ss A, DD MMM YYYY' ).format();
|
|
1121
1131
|
updateData.submitMobileTime = requestData?.currentTime;
|
|
1122
1132
|
}
|
|
1133
|
+
updateData.questionAnswers.forEach( ( section ) => {
|
|
1134
|
+
section.questions.forEach( ( question ) => {
|
|
1135
|
+
if ( question.redo === true ) {
|
|
1136
|
+
question.redo = false;
|
|
1137
|
+
}
|
|
1138
|
+
} );
|
|
1139
|
+
} );
|
|
1123
1140
|
let updatechecklist = await processedchecklist.updateOne( updateQuery, updateData );
|
|
1124
1141
|
if ( updatechecklist ) {
|
|
1125
1142
|
if ( checklistDetails && checklistDetails.allowedMultiSubmit && requestData.submittype == 'submit' ) {
|
|
@@ -1196,6 +1213,7 @@ export async function submitTask( req, res ) {
|
|
|
1196
1213
|
const { body: requestData, user } = req;
|
|
1197
1214
|
const { processedcheckListId, date, submittype, currentTime, questionAnswers } = requestData;
|
|
1198
1215
|
|
|
1216
|
+
|
|
1199
1217
|
const findQuery = [
|
|
1200
1218
|
{
|
|
1201
1219
|
$match: {
|
|
@@ -1234,6 +1252,14 @@ export async function submitTask( req, res ) {
|
|
|
1234
1252
|
date_string: date,
|
|
1235
1253
|
};
|
|
1236
1254
|
|
|
1255
|
+
questionAnswers.forEach( ( section ) => {
|
|
1256
|
+
section.questions.forEach( ( question ) => {
|
|
1257
|
+
if ( question.redo === true ) {
|
|
1258
|
+
question.redo = false;
|
|
1259
|
+
}
|
|
1260
|
+
} );
|
|
1261
|
+
} );
|
|
1262
|
+
|
|
1237
1263
|
const updateData = {
|
|
1238
1264
|
questionAnswers,
|
|
1239
1265
|
updatedAt: dayjs.utc( currentDateTime.format( 'hh:mm:ss A, DD MMM YYYY' ), 'hh:mm:ss A, DD MMM YYYY' ).format(),
|
|
@@ -1919,7 +1945,7 @@ export async function taskQuestionList( req, res ) {
|
|
|
1919
1945
|
const getSignedUrl = async ( filePath ) =>
|
|
1920
1946
|
filePath && filePath !== '' ?
|
|
1921
1947
|
await signedUrl( { file_path: decodeURIComponent( filePath ), Bucket: sopBucket } ) :
|
|
1922
|
-
|
|
1948
|
+
'';
|
|
1923
1949
|
|
|
1924
1950
|
for ( const section of checklist.questionAnswers || [] ) {
|
|
1925
1951
|
for ( const question of section.questions || [] ) {
|