tango-app-api-trax 1.0.0-task.122 → 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.122",
3
+ "version": "1.0.0-task.124",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -253,22 +253,48 @@ export const checklistDropdown = async ( req, res ) => {
253
253
 
254
254
  export async function approveChecklist( req, res ) {
255
255
  try {
256
- if ( !req.body.id ) {
257
- return res.sendError( 'id is required', 400 );
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 };
258
263
  }
259
- let checklistDetails = await processedChecklist.findOne( { _id: req.body.id }, { approvalEnable: 1, approvalStatus: 1 } );
260
- if ( !checklistDetails ) {
264
+ let checklistDetails = await processedChecklist.find( query, { _id: 1 } );
265
+ if ( !checklistDetails.length ) {
261
266
  return res.sendError( 'No data found', 204 );
262
267
  }
263
- if ( !checklistDetails.approvalEnable ) {
264
- return res.sendError( 'Checklist has no approver', 400 );
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
+ }
265
297
  }
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
298
  } catch ( e ) {
273
299
  logger.error( { function: 'approveChecklist', error: e } );
274
300
  return res.sendError( e, 500 );
@@ -1952,33 +1952,43 @@ export async function taskQuestionList( req, res ) {
1952
1952
  const { answerType, answers = [], userAnswer = [] } = question;
1953
1953
  const multiAnswer = [];
1954
1954
 
1955
- 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
+ }
1956
1966
 
1957
1967
  for ( const [ ansIndex, answer ] of answers.entries() ) {
1958
1968
  answer.index = ansIndex;
1959
1969
 
1960
- answer.referenceImage = await getSignedUrl( answer.referenceImage );
1970
+ answer.referenceImage = answer?.referenceImage ? await getSignedUrl( answer.referenceImage ) : '';
1961
1971
 
1962
- if ( [ 'Capture Image', 'Capture Video' ].includes( answer.validationType ) ) {
1972
+ if ( [ 'Capture Image', 'Capture Video' ].includes( answer.validationType ) && answer.validationAnswer ) {
1963
1973
  answer.validationAnswer = await getSignedUrl( answer.validationAnswer );
1964
1974
  }
1965
1975
 
1966
- if ( answerType === 'multiplechoicemultiple' ) {
1976
+ if ( answerType === 'multiplechoicemultiple'&& answer.validationAnswer ) {
1967
1977
  const validationAnswer = await getSignedUrl( answer.validationAnswer );
1968
1978
  multiAnswer.push( { answer: answer.answer, no: ansIndex, validationAnswer } );
1969
1979
  }
1970
1980
  }
1971
1981
 
1972
1982
  for ( const [ userAnsIndex, userAns ] of userAnswer.entries() ) {
1973
- if ( [ 'Capture Image', 'Capture Video' ].includes( userAns.validationType ) ) {
1983
+ if ( [ 'Capture Image', 'Capture Video' ].includes( userAns.validationType ) && userAns.validationAnswer ) {
1974
1984
  userAns.validationAnswer = await getSignedUrl( userAns.validationAnswer );
1975
1985
  }
1976
1986
 
1977
- if ( [ 'image', 'descriptiveImage', 'video' ].includes( answerType ) ) {
1987
+ if ( [ 'image', 'descriptiveImage', 'video' ].includes( answerType ) && userAns.answer ) {
1978
1988
  userAns.answer = await getSignedUrl( userAns.answer );
1979
1989
  }
1980
1990
 
1981
- userAns.referenceImage = await getSignedUrl( userAns.referenceImage );
1991
+ userAns.referenceImage = userAns.referenceImage ? await getSignedUrl( userAns.referenceImage ) : '';
1982
1992
 
1983
1993
  if ( answerType === 'multiplechoicemultiple' ) {
1984
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 ) {
@@ -22,5 +22,5 @@ galleryRouter
22
22
 
23
23
 
24
24
  galleryRouter
25
- .post( '/upateApprove', isAllowedSessionHandler, approveChecklist )
25
+ .post( '/updateApprove', isAllowedSessionHandler, approveChecklist )
26
26
  .post( '/redo', isAllowedSessionHandler, redoChecklist );