tango-app-api-trax 1.0.0-task.121 → 1.0.0-task.124

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.121",
3
+ "version": "1.0.0-task.124",
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
- "tango-api-schema": "^2.1.87",
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
- "path": "^0.12.7",
32
- "firebase-admin": "^13.0.0",
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,129 @@ 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
+ let toDate = new Date( req.body.toDate );
257
+ let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
258
+ toDate = new Date( toDate.getTime() - userTimezoneOffset );
259
+ toDate.setUTCHours( 23, 59, 59, 59 );
260
+ let query = { sourceCheckList_id: req.body.sourceCheckList_id, date_iso: { $gte: req.body.fromDate, $lte: toDate }, checklistStatus: 'submit', approvalEnable: true };
261
+ if ( req.body?.storeId?.length ) {
262
+ query['store_id'] = { $in: req.body.storeId };
263
+ }
264
+ let checklistDetails = await processedChecklist.find( query, { _id: 1 } );
265
+ if ( !checklistDetails.length ) {
266
+ return res.sendError( 'No data found', 204 );
267
+ }
268
+ let idList = checklistDetails.map( ( item ) => item._id );
269
+ let updateResponse = await processedChecklist.updateMany( { _id: { $in: idList } }, { approvalStatus: true } );
270
+ if ( updateResponse.modifiedCount || updateResponse.matchedCount ) {
271
+ let params = {
272
+ 'payload': {
273
+ sourceCheckList_id: req.body.sourceCheckList_id,
274
+ fromDate: req.body.fromDate,
275
+ toDate: req.body.toDate,
276
+ store_id: req.body.storeId,
277
+ },
278
+ 'upsert': {
279
+ approvalStatus: true,
280
+ },
281
+ };
282
+ const requestOptions = {
283
+ method: 'POST',
284
+ headers: {
285
+ 'Content-Type': 'application/json',
286
+ },
287
+ body: JSON.stringify( params ),
288
+ };
289
+ let searchResponse = await fetch( 'https://wnx32v5mtyqx6kh3nt6xuosjqa0xvdfq.lambda-url.ap-south-1.on.aws', requestOptions );
290
+ console.log( searchResponse );
291
+
292
+ if ( searchResponse.ok ) {
293
+ return res.sendSuccess( 'Checklist Approved successfully' );
294
+ } else {
295
+ return res.sendError( 'Something went wrong', 500 );
296
+ }
297
+ }
298
+ } catch ( e ) {
299
+ logger.error( { function: 'approveChecklist', error: e } );
300
+ return res.sendError( e, 500 );
301
+ }
302
+ }
303
+
304
+ export async function redoChecklist( req, res ) {
305
+ try {
306
+ if ( !req.body.payload._id ) {
307
+ return res.sendError( 'Id is Required', 400 );
308
+ }
309
+ if ( !req.body.payload.section_id ) {
310
+ return res.sendError( 'Section id is Required', 400 );
311
+ }
312
+ if ( !req.body.payload.qno ) {
313
+ return res.sendError( 'Question number is Required', 400 );
314
+ }
315
+
316
+ 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 } );
317
+ if ( !checklistDetails ) {
318
+ return res.sendError( 'No data found', 204 );
319
+ }
320
+ let question = checklistDetails.questionAnswers;
321
+ let sectionIndex = question.findIndex( ( sec ) => sec.section_id == req.body.payload.section_id );
322
+ if ( sectionIndex == -1 ) {
323
+ return res.sendError( 'section is not found', 400 );
324
+ }
325
+ let data = { ...question[sectionIndex].questions[req.body.payload.qno - 1], redo: true };
326
+ let userAnswer = data.userAnswer;
327
+ question[sectionIndex].questions[req.body.payload.qno - 1] = data;
328
+ question[sectionIndex].questions[req.body.payload.qno - 1].userAnswer = [];
329
+ checklistDetails.questionAnswers = question;
330
+ let updateData = {
331
+ checklistStatus: 'open',
332
+ redoStatus: true,
333
+ questionAnswers: question,
334
+ };
335
+
336
+ let response = await processedChecklist.updateOne( { _id: req.body.payload._id }, updateData );
337
+ if ( response.modifiedCount || response.matchedCount ) {
338
+ data = {
339
+ checklistId: checklistDetails.sourceCheckList_id,
340
+ checkListName: checklistDetails.checkListName,
341
+ sectionId: req.body.payload.section_id,
342
+ sectionName: question[sectionIndex].sectionName,
343
+ questionName: question[sectionIndex].questions[req.body.payload.qno - 1].qname,
344
+ action: 'redo',
345
+ store_id: checklistDetails.store_id,
346
+ storeName: checklistDetails.storeName,
347
+ client_id: checklistDetails.client_id,
348
+ processedChecklistId: checklistDetails._id,
349
+ type: checklistDetails.checkListType,
350
+ userAnswer: userAnswer,
351
+ };
352
+ await checklistLogs.create( data );
353
+ const requestOptions = {
354
+ method: 'POST',
355
+ headers: {
356
+ 'Content-Type': 'application/json',
357
+ },
358
+ body: JSON.stringify( req.body ),
359
+ };
360
+ let searchResponse = await fetch( 'https://7et6pebvmii725tcntww4w56yq0rjpqw.lambda-url.ap-south-1.on.aws/', requestOptions );
361
+ console.log( searchResponse );
362
+
363
+ if ( searchResponse.ok ) {
364
+ return res.sendSuccess( 'Question redo successfully' );
365
+ } else {
366
+ return res.sendError( 'Something went wrong', 500 );
367
+ }
368
+ } else {
369
+ return res.sendError( 'Something went wrong', 500 );
370
+ }
371
+ } catch ( e ) {
372
+ logger.error( { function: 'redoChecklist', error: e } );
373
+ return res.sendError( e, 500 );
374
+ }
375
+ }
376
+
377
+
@@ -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 = PCLQusestion.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: processedTaskConfig.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,40 +1945,50 @@ 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
- null;
1948
+ '';
1923
1949
 
1924
1950
  for ( const section of checklist.questionAnswers || [] ) {
1925
1951
  for ( const question of section.questions || [] ) {
1926
1952
  const { answerType, answers = [], userAnswer = [] } = question;
1927
1953
  const multiAnswer = [];
1928
1954
 
1929
- question.questionReferenceImage = await getSignedUrl( question.questionReferenceImage );
1955
+ if ( typeof question.questionReferenceImage == 'string' && question.questionReferenceImage ) {
1956
+ question.questionReferenceImage = await getSignedUrl( question.questionReferenceImage );
1957
+ } else {
1958
+ if ( question.questionReferenceImage.length ) {
1959
+ let image = [];
1960
+ for ( let img of question.questionReferenceImage ) {
1961
+ image.push( await getSignedUrl( img ) );
1962
+ }
1963
+ question.questionReferenceImage = image;
1964
+ }
1965
+ }
1930
1966
 
1931
1967
  for ( const [ ansIndex, answer ] of answers.entries() ) {
1932
1968
  answer.index = ansIndex;
1933
1969
 
1934
- answer.referenceImage = await getSignedUrl( answer.referenceImage );
1970
+ answer.referenceImage = answer?.referenceImage ? await getSignedUrl( answer.referenceImage ) : '';
1935
1971
 
1936
- if ( [ 'Capture Image', 'Capture Video' ].includes( answer.validationType ) ) {
1972
+ if ( [ 'Capture Image', 'Capture Video' ].includes( answer.validationType ) && answer.validationAnswer ) {
1937
1973
  answer.validationAnswer = await getSignedUrl( answer.validationAnswer );
1938
1974
  }
1939
1975
 
1940
- if ( answerType === 'multiplechoicemultiple' ) {
1976
+ if ( answerType === 'multiplechoicemultiple'&& answer.validationAnswer ) {
1941
1977
  const validationAnswer = await getSignedUrl( answer.validationAnswer );
1942
1978
  multiAnswer.push( { answer: answer.answer, no: ansIndex, validationAnswer } );
1943
1979
  }
1944
1980
  }
1945
1981
 
1946
1982
  for ( const [ userAnsIndex, userAns ] of userAnswer.entries() ) {
1947
- if ( [ 'Capture Image', 'Capture Video' ].includes( userAns.validationType ) ) {
1983
+ if ( [ 'Capture Image', 'Capture Video' ].includes( userAns.validationType ) && userAns.validationAnswer ) {
1948
1984
  userAns.validationAnswer = await getSignedUrl( userAns.validationAnswer );
1949
1985
  }
1950
1986
 
1951
- if ( [ 'image', 'descriptiveImage', 'video' ].includes( answerType ) ) {
1987
+ if ( [ 'image', 'descriptiveImage', 'video' ].includes( answerType ) && userAns.answer ) {
1952
1988
  userAns.answer = await getSignedUrl( userAns.answer );
1953
1989
  }
1954
1990
 
1955
- userAns.referenceImage = await getSignedUrl( userAns.referenceImage );
1991
+ userAns.referenceImage = userAns.referenceImage ? await getSignedUrl( userAns.referenceImage ) : '';
1956
1992
 
1957
1993
  if ( answerType === 'multiplechoicemultiple' ) {
1958
1994
  const ansIndex = multiAnswer.findIndex( ( item ) => item.answer === userAns.answer );
@@ -826,7 +826,6 @@ export const runAIInsert = async ( req, res ) => {
826
826
  InsertTicket.reason = 'Run AI Request';
827
827
  InsertTicket.from_email = req.user.email;
828
828
  InsertTicket.to_email = 'praveenraju@tangotech.co.in';
829
- // InsertTicket.brandId = req.user.brandId;
830
829
  InsertTicket.client_id = req.body.clientId;
831
830
 
832
831
  let ticket = await reisedTicketService.create( req.body );
@@ -1229,7 +1228,6 @@ export const updatePublish = async ( req, res ) => {
1229
1228
 
1230
1229
  let checklistLogQuery = {};
1231
1230
  checklistLogQuery.checkListName = getCheckDetails.checkListName;
1232
- checklistLogQuery.brandId = getCheckDetails.brandId;
1233
1231
  checklistLogQuery.createdAt = { $gte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) };
1234
1232
  await checklistLogs.deleteMany( checklistLogQuery );
1235
1233
 
@@ -1800,7 +1798,6 @@ export async function insertSingleProcessData( checklistId, processId = 0, oldDa
1800
1798
  insertdata.allowedOverTime = getCLconfig.allowedOverTime;
1801
1799
  insertdata.allowedStoreLocation = getCLconfig.allowedStoreLocation;
1802
1800
  insertdata.client_id = getCLconfig.client_id;
1803
- insertdata.brandId = getCLconfig.brandId;
1804
1801
  insertdata.createdBy = new ObjectId( getCLconfig.createdBy );
1805
1802
  insertdata.createdByName = getCLconfig.createdByName;
1806
1803
  insertdata.checkListType = getCLconfig.checkListType;
@@ -1835,7 +1832,6 @@ export async function insertSingleProcessData( checklistId, processId = 0, oldDa
1835
1832
  insertdataquery.date_string = insertdata.date_string;
1836
1833
  insertdataquery.date_iso = insertdata.date_iso;
1837
1834
  insertdataquery.client_id = insertdata.client_id;
1838
- insertdataquery.brandId = insertdata.brandId;
1839
1835
  insertdataquery.sourceCheckList_id = insertdata.sourceCheckList_id;
1840
1836
  let updatedchecklist;
1841
1837
  let checklistDetails = await processedchecklistConfig.findOne( insertdataquery );
@@ -1879,7 +1875,6 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
1879
1875
  'checkFlag': { $first: '$checkFlag' },
1880
1876
  'checkListId': { $first: '$checkListId' },
1881
1877
  'checkListName': { $first: '$checkListName' },
1882
- 'brandId': { $first: '$brandId' },
1883
1878
  'country': { $first: '$country' },
1884
1879
  'createdAt': { $first: '$createdAt' },
1885
1880
  'updatedAt': { $first: '$updatedAt' },
@@ -1999,7 +1994,6 @@ async function insertPCBulkV3( getCLconfig, checklistId, currentdate, updatedche
1999
1994
  assigndeletequery.date_string = insertdata.date_string;
2000
1995
  assigndeletequery.date_iso = insertdata.date_iso;
2001
1996
  assigndeletequery.client_id = insertdata.client_id;
2002
- assigndeletequery.brandId = insertdata.brandId;
2003
1997
  assigndeletequery.checkListId = updatedchecklist._id;
2004
1998
  assigndeletequery.checklistStatus = { $nin: [ 'submit' ] };
2005
1999
  if ( getCLconfig?.allowedMultiSubmit && processId ) {