tango-app-api-trax 1.0.0-alpha.98 → 1.0.0-task.118

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-alpha.98",
3
+ "version": "1.0.0-task.118",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -23,8 +23,8 @@
23
23
  "lodash": "^4.17.21",
24
24
  "mongodb": "^6.8.0",
25
25
  "nodemon": "^3.1.4",
26
- "tango-api-schema": "^2.1.63",
27
- "tango-app-api-middleware": "^3.1.43-alpha.8",
26
+ "tango-api-schema": "^2.1.87",
27
+ "tango-app-api-middleware": "^3.1.43-alpha.9",
28
28
  "winston": "^3.13.1",
29
29
  "winston-daily-rotate-file": "^5.0.0"
30
30
  },
@@ -12,6 +12,133 @@ dayjs.extend( utc );
12
12
  import mongoose from 'mongoose';
13
13
 
14
14
  export const downloadInsert = async ( req, res ) => {
15
+ try {
16
+ let requestData = req.body;
17
+ let fromDate = new Date( requestData.fromDate );
18
+ let toDate = new Date( requestData.toDate );
19
+ let userTimezoneOffset = toDate.getTimezoneOffset() * 60000;
20
+ toDate = new Date( toDate.getTime() - userTimezoneOffset );
21
+ toDate.setUTCHours( 23, 59, 59, 59 );
22
+ let name;
23
+ let fileType = requestData?.fileType || 'pdfzip';
24
+
25
+ if ( requestData.searchValue && requestData.searchValue != '' ) {
26
+ let storeList = requestData.searchValue.split( ',' ).map( ( item ) => item.trim().toLowerCase() );
27
+ let getStoreIDQuery = [];
28
+ if ( storeList.length > 0 ) {
29
+ getStoreIDQuery.push( { $project: { storeName: 1, storeId: 1 } } );
30
+ getStoreIDQuery.push( { $addFields: { store: { $toLower: '$storeName' } } } );
31
+ getStoreIDQuery.push( { $match: { store: { $in: storeList } } } );
32
+ getStoreIDQuery.push( { $group: { _id: null, storeId: { $push: '$storeId' } } } );
33
+ getStoreIDQuery.push( { $project: { storeId: 1, _id: 0 } } );
34
+ }
35
+ let getStoreId = await storeService.aggregate( getStoreIDQuery );
36
+ if ( getStoreId.length > 0 ) {
37
+ if ( getStoreId[0].storeId && getStoreId[0].storeId.length > 0 ) {
38
+ requestData.storeIds = getStoreId[0].storeId;
39
+ }
40
+ }
41
+ }
42
+
43
+ if ( requestData.sourceCheckList_id && requestData.sourceCheckList_id !='' ) {
44
+ let getChecklistQuery = [];
45
+ getChecklistQuery.push( { $project: { sourceCheckList_id: 1, date_iso: 1, store_id: 1, checklistStatus: 1 } } );
46
+ getChecklistQuery.push( {
47
+ $match: {
48
+ $and: [
49
+ { sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) },
50
+ { date_iso: { $gte: fromDate, $lte: toDate } },
51
+ { store_id: { $in: requestData.storeIds } },
52
+ { checklistStatus: 'submit' },
53
+ ],
54
+ },
55
+ } );
56
+ getChecklistQuery.push( { $count: 'totalCount' } );
57
+ let getChecklistCount = await processedchecklistService.aggregate( getChecklistQuery );
58
+
59
+ if ( getChecklistCount && getChecklistCount[0]?.totalCount && getChecklistCount[0].totalCount >0 ) {
60
+ // console.log( 'if' );
61
+ // console.log( 'getChecklistCountgetChecklistCount[0].totalCount =>', getChecklistCount[0]?.totalCount );
62
+ } else {
63
+ return res.sendError( { error: 'No Data Found' }, 400 );
64
+ }
65
+ }
66
+
67
+ if ( requestData.fileType == 'pdf' ) {
68
+ if ( requestData?.sourceCheckList_id && requestData?.sourceCheckList_id !='' ) {
69
+ fileType = 'pdfzip';
70
+ }
71
+ if ( requestData?.checklistId && requestData?.checklistId.length > 1 ) {
72
+ fileType = 'pdfzip';
73
+ }
74
+ }
75
+
76
+ if ( requestData.checklistName != '' ) {
77
+ name = requestData.checklistName + '_' + dayjs( requestData.fromDate ).format( 'DD/MM/YYYY' );
78
+ if ( requestData?.toDate ) {
79
+ name = name + '-'+ dayjs( requestData?.toDate ).format( 'DD/MM/YYYY' );
80
+ }
81
+ let regexName = new RegExp( `^${name.split( '(' )[0]} \\(.*\\)$`, 'i' );
82
+ let type = requestData.fileType || 'pdfzip';
83
+ let downloadDetails = await downloadService.getCount( { $and: [ { $or: [ { name: { $regex: regexName } }, { name: name } ] }, { fileType: type } ] } );
84
+ if ( downloadDetails ) {
85
+ name = name + ' (' + downloadDetails + ')';
86
+ }
87
+ } else {
88
+ name = requestData?.checklistName;
89
+ }
90
+
91
+ name = name+'-'+requestData.fileType;
92
+ let insertData = {
93
+ 'date_string': requestData.fromDate || '',
94
+ 'sourceCheckList_id': requestData?.sourceCheckList_id || '',
95
+ 'checklistIdList': requestData?.checklistId || [],
96
+ 'status': 'inprogress',
97
+ 'client_id': requestData.clientId || '',
98
+ 'date_iso': new Date( requestData.fromDate ) || '',
99
+ 'createdBy': req.user._id || '',
100
+ 'name': name,
101
+ 'fileType': fileType,
102
+ 'storeIds': requestData.storeIds || [],
103
+ 'questions': requestData.questions || [],
104
+ 'fromDate': requestData.fromDate || '',
105
+ 'toDate': requestData.toDate || '',
106
+ 'previewType': requestData.previewType || '',
107
+ 'viewFlag': requestData.viewFlag || false,
108
+ 'userEmail': req.user.email || '',
109
+ 'createdBy': req.user._id || '',
110
+ 'downloadInsertFrom': requestData.downloadInsertFrom || '',
111
+ 'answerType': requestData.answerType || '',
112
+ 'searchValue': requestData.searchValue || '',
113
+ };
114
+ let resultData = await downloadService.insert( insertData );
115
+ if ( resultData ) {
116
+ let sqsMessageRequestData = {
117
+ 'zipId': resultData._id,
118
+ 'fileType': fileType || 'zip',
119
+ 'storeId': requestData.storeIds || [],
120
+ };
121
+ if ( fileType === 'csv' || fileType === 'pdf' || fileType === 'csvzip' || fileType === 'pdfzip' || fileType === 'zipfiles' ) {
122
+ const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).new_sqs_sop}`, JSON.stringify( sqsMessageRequestData ) );
123
+ console.log( 'Send SQS Message CSV/PDF=>', msg );
124
+ }
125
+
126
+ if ( fileType === 'ppt' || fileType === 'pptzip' ) {
127
+ const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).new_sqs_sop_ppt}`, JSON.stringify( sqsMessageRequestData ) );
128
+ console.log( 'Send SQS Message PPT=>', msg );
129
+ }
130
+
131
+ res.sendSuccess( 'Success' );
132
+ } else {
133
+ return res.sendError( 'something went wrong, please try again', 500 );
134
+ }
135
+ } catch ( e ) {
136
+ console.log( 'insertdownloadRequest =>', e );
137
+ return res.sendError( e, 500 );
138
+ }
139
+ };
140
+
141
+ export const downloadInsertOld = async ( req, res ) => {
15
142
  try {
16
143
  let requestData = req.body;
17
144
  let findQuery = [];
@@ -190,8 +317,8 @@ export const downloadList = async ( req, res ) => {
190
317
  } else {
191
318
  getDownlaodData[i].url = '';
192
319
  }
193
- getDownlaodData[i].downloadedTime = dayjs( getDownlaodData[i].createdAt ).format( 'hh:mm A' );
194
- getDownlaodData[i].downloadedDate = dayjs( getDownlaodData[i].createdAt ).format( 'DD MMM, YYYY' );
320
+ getDownlaodData[i].downloadedTime = dayjs( getDownlaodData[i].createdAt ).add( 5, 'hour' ).add( 30, 'minute' ).format( 'hh:mm A' );
321
+ getDownlaodData[i].downloadedDate = dayjs( getDownlaodData[i].createdAt ).add( 5, 'hour' ).add( 30, 'minute' ).format( 'DD MMM, YYYY' );
195
322
  }
196
323
 
197
324
  result.count = getTotalCount.length;
@@ -275,7 +402,8 @@ export const getChecklistFromZipId = async ( req, res ) => {
275
402
  resultData.questions = getzipdata.questions;
276
403
  resultData.fileType = getzipdata.fileType;
277
404
  resultData.viewFlag = getzipdata.viewFlag;
278
- resultData.previewType = getzipdata.previewType;
405
+ resultData.previewType = getzipdata.previewType || '';
406
+ resultData.answerType = getzipdata.answerType || '';
279
407
  return res.sendSuccess( resultData );
280
408
  } else {
281
409
  let getchecklistsQuery = {};
@@ -289,6 +417,7 @@ export const getChecklistFromZipId = async ( req, res ) => {
289
417
  resultData.brandInfo = brandInfo;
290
418
  resultData.checklistIds = getzipdata.checklistIdList;
291
419
  resultData.fileType = getzipdata.fileType;
420
+ resultData.questions = getzipdata.questions;
292
421
  return res.sendSuccess( resultData );
293
422
  }
294
423
  } else {
@@ -205,6 +205,7 @@ export const checklistDropdown = async ( req, res ) => {
205
205
  {
206
206
  $project: {
207
207
  checkListName: 1,
208
+ checkListDescription: 1,
208
209
  publish: 1,
209
210
  },
210
211
  },
@@ -222,6 +223,7 @@ export const checklistDropdown = async ( req, res ) => {
222
223
  scheduleRepeatedType: 1,
223
224
  scheduleStartTime: 1,
224
225
  scheduleEndTime: 1,
226
+ checkListDescription: '$checklistconfigs.checkListDescription',
225
227
  publish: '$checklistconfigs.publish',
226
228
  },
227
229
  } );
@@ -8,12 +8,14 @@ import * as lenskartEmployeeMapping from '../services/lenskartEmployeeMapping.se
8
8
  import * as storeService from '../services/store.service.js';
9
9
  import dayjs from 'dayjs';
10
10
  import customParseFormat from 'dayjs/plugin/customParseFormat.js';
11
+ import timeZone from 'dayjs/plugin/timezone.js';
11
12
  import utc from 'dayjs/plugin/utc.js';
12
13
  import { logger } from 'tango-app-api-middleware';
13
14
  import mongoose from 'mongoose';
14
15
  const ObjectId = mongoose.Types.ObjectId;
15
16
  dayjs.extend( customParseFormat );
16
17
  dayjs.extend( utc );
18
+ dayjs.extend( timeZone );
17
19
 
18
20
  export async function PCLchecklistCreationValidator( req, res, next ) {
19
21
  try {
@@ -496,23 +498,6 @@ export async function insertTimeDelayFlags( req, res ) {
496
498
  timeFlag: 0,
497
499
  },
498
500
  } ];
499
- let currentTime = dayjs().format( 'HH:mm:ss' );
500
- console.log( currentTime );
501
- console.log( dayjs.utc( new Date() ).format( 'HH:mm:ss' ) );
502
-
503
- if ( req.body.time ) {
504
- query.push( {
505
- $match: {
506
- scheduleEndTime_iso: { $lt: new Date( `${req.body.date}T${req.body.time}Z` ) },
507
- },
508
- } );
509
- } else {
510
- query.push( {
511
- $match: {
512
- scheduleEndTime_iso: { $lt: new Date( `${req.body.date}T${currentTime}Z` ) },
513
- },
514
- } );
515
- }
516
501
 
517
502
  if ( req.body.client_id && req.body.client_id.length ) {
518
503
  query.push( {
@@ -522,6 +507,18 @@ export async function insertTimeDelayFlags( req, res ) {
522
507
  } );
523
508
  }
524
509
 
510
+ query.push( {
511
+ $project: {
512
+ scheduleEndTime_iso: 1,
513
+ store_id: 1,
514
+ storeName: 1,
515
+ checkListId: 1,
516
+ checkListName: 1,
517
+ client_id: 1,
518
+ date_iso: 1,
519
+ },
520
+ } );
521
+
525
522
 
526
523
  let checkList = await processedchecklist.aggregate( query );
527
524
 
@@ -531,21 +528,43 @@ export async function insertTimeDelayFlags( req, res ) {
531
528
 
532
529
  let checklistId = [];
533
530
 
534
- checkList.forEach( async ( item ) => {
535
- checklistId.push( item._id );
536
- let logInsertData = {
537
- store_id: item.store_id,
538
- storeName: item.storeName,
539
- action: 'lapsed',
540
- checklistId: item.checkListId,
541
- checkListName: item.checkListName,
542
- client_id: item.client_id,
543
- date_iso: item.date_iso,
544
- processedChecklistId: item._id,
545
- };
546
- await checklistLogs.create( logInsertData );
531
+ let promises = checkList.map( async ( item ) => {
532
+ await checkTimeZone( [ item ] );
547
533
  } );
548
534
 
535
+ await Promise.all( promises );
536
+
537
+ async function checkTimeZone( ele ) {
538
+ return Promise.all(
539
+ ele.map( async ( data ) => {
540
+ let getStoreZone = await storeService.findOne(
541
+ { storeId: data.store_id, clientId: data.client_id },
542
+ { storeProfile: 1 },
543
+ );
544
+ if ( getStoreZone ) {
545
+ let checklistDate = dayjs.utc( data.scheduleEndTime_iso ).format();
546
+ console.log( checklistDate );
547
+ let date = dayjs.utc().tz( getStoreZone.storeProfile.timeZone ).format();
548
+ console.log( date );
549
+ if ( checklistDate < date ) {
550
+ let logInsertData = {
551
+ store_id: data.store_id,
552
+ storeName: data.storeName,
553
+ action: 'lapsed',
554
+ checklistId: data.checkListId,
555
+ checkListName: data.checkListName,
556
+ client_id: data.client_id,
557
+ date_iso: data.date_iso,
558
+ processedChecklistId: data._id,
559
+ };
560
+ await checklistLogs.create( logInsertData );
561
+ checklistId.push( data._id );
562
+ }
563
+ }
564
+ } ),
565
+ );
566
+ }
567
+
549
568
  let updatedDetails = await processedchecklist.updateMany( { _id: { $in: checklistId } }, { timeFlag: 1 } );
550
569
 
551
570
  if ( updatedDetails ) {