tango-app-api-trax 1.0.0-alpha-task.131 → 1.0.0-alpha-task.132

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-task.131",
3
+ "version": "1.0.0-alpha-task.132",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -2,7 +2,10 @@ import { logger, signedUrl, sendMessageToQueue } from 'tango-app-api-middleware'
2
2
  import dayjs from 'dayjs';
3
3
  import * as downloadService from '../services/download.services.js';
4
4
  import * as processedchecklistService from '../services/processedchecklist.services.js';
5
+ import * as processedTaskService from '../services/processedTaskList.service.js';
6
+ import * as taskConfigService from '../services/taskConfig.service.js';
5
7
  import * as checklistService from '../services/checklist.service.js';
8
+ // import * as processedTaskconfigService from '../services/processedTaskConfig.service.js';
6
9
  import * as clientService from '../services/clients.services.js';
7
10
  import * as storeService from '../services/store.service.js';
8
11
 
@@ -40,7 +43,7 @@ export const downloadInsert = async ( req, res ) => {
40
43
  }
41
44
  }
42
45
 
43
- if ( requestData.sourceCheckList_id && requestData.sourceCheckList_id !='' ) {
46
+ if ( requestData.sourceCheckList_id && requestData.sourceCheckList_id != '' ) {
44
47
  let getChecklistQuery = [];
45
48
  getChecklistQuery.push( { $project: { sourceCheckList_id: 1, date_iso: 1, store_id: 1, checklistStatus: 1 } } );
46
49
  getChecklistQuery.push( {
@@ -54,9 +57,12 @@ export const downloadInsert = async ( req, res ) => {
54
57
  },
55
58
  } );
56
59
  getChecklistQuery.push( { $count: 'totalCount' } );
57
- let getChecklistCount = await processedchecklistService.aggregate( getChecklistQuery );
58
60
 
59
- if ( getChecklistCount && getChecklistCount[0]?.totalCount && getChecklistCount[0].totalCount >0 ) {
61
+ let getChecklistCount = await processedchecklistService.aggregate( getChecklistQuery );
62
+ if ( requestData.insertType === 'task' ) {
63
+ getChecklistCount = await processedTaskService.aggregate( getChecklistQuery );
64
+ }
65
+ if ( getChecklistCount && getChecklistCount[0]?.totalCount && getChecklistCount[0].totalCount > 0 ) {
60
66
  // console.log( 'if' );
61
67
  // console.log( 'getChecklistCountgetChecklistCount[0].totalCount =>', getChecklistCount[0]?.totalCount );
62
68
  } else {
@@ -65,7 +71,7 @@ export const downloadInsert = async ( req, res ) => {
65
71
  }
66
72
 
67
73
  if ( requestData.fileType == 'pdf' ) {
68
- if ( requestData?.sourceCheckList_id && requestData?.sourceCheckList_id !='' ) {
74
+ if ( requestData?.sourceCheckList_id && requestData?.sourceCheckList_id != '' ) {
69
75
  fileType = 'pdfzip';
70
76
  }
71
77
  if ( requestData?.checklistId && requestData?.checklistId.length > 1 ) {
@@ -76,7 +82,7 @@ export const downloadInsert = async ( req, res ) => {
76
82
  if ( requestData.checklistName != '' ) {
77
83
  name = requestData.checklistName + '_' + dayjs( requestData.fromDate ).format( 'DD/MM/YYYY' );
78
84
  if ( requestData?.toDate ) {
79
- name = name + '-'+ dayjs( requestData?.toDate ).format( 'DD/MM/YYYY' );
85
+ name = name + '-' + dayjs( requestData?.toDate ).format( 'DD/MM/YYYY' );
80
86
  }
81
87
  let regexName = new RegExp( `^${name.split( '(' )[0]} \\(.*\\)$`, 'i' );
82
88
  let type = requestData.fileType || 'pdfzip';
@@ -88,7 +94,7 @@ export const downloadInsert = async ( req, res ) => {
88
94
  name = requestData?.checklistName;
89
95
  }
90
96
 
91
- name = name+'-'+requestData.fileType;
97
+ name = name + '-' + requestData.fileType;
92
98
  let insertData = {
93
99
  'date_string': requestData.fromDate || '',
94
100
  'sourceCheckList_id': requestData?.sourceCheckList_id || '',
@@ -110,6 +116,9 @@ export const downloadInsert = async ( req, res ) => {
110
116
  'downloadInsertFrom': requestData.downloadInsertFrom || '',
111
117
  'answerType': requestData.answerType || '',
112
118
  'searchValue': requestData.searchValue || '',
119
+ 'insertType': requestData.insertType || '',
120
+ 'viewRedo': requestData.viewRedo || false,
121
+
113
122
  };
114
123
  let resultData = await downloadService.insert( insertData );
115
124
  if ( resultData ) {
@@ -151,10 +160,10 @@ export const downloadInsertOld = async ( req, res ) => {
151
160
  { date_iso: { $lte: todate } },
152
161
  { checklistStatus: 'submit' },
153
162
  );
154
- if ( requestData.storeIds && requestData.storeIds.length >0 ) {
163
+ if ( requestData.storeIds && requestData.storeIds.length > 0 ) {
155
164
  findAndQuery.push( { store_id: { $in: requestData.storeIds } } );
156
165
  }
157
- if ( requestData.sourceCheckList_id && requestData.sourceCheckList_id !='' ) {
166
+ if ( requestData.sourceCheckList_id && requestData.sourceCheckList_id != '' ) {
158
167
  findAndQuery.push( { sourceCheckList_id: new mongoose.Types.ObjectId( requestData.sourceCheckList_id ) } );
159
168
  }
160
169
  if ( requestData.checklistId && requestData.checklistId.length > 0 ) {
@@ -175,11 +184,11 @@ export const downloadInsertOld = async ( req, res ) => {
175
184
  },
176
185
  } );
177
186
  let checklistDetails = await processedchecklistService.aggregate( findQuery );
178
- if ( checklistDetails && checklistDetails.length >0 ) {
187
+ if ( checklistDetails && checklistDetails.length > 0 ) {
179
188
  let name;
180
189
  let fileType = requestData?.fileType || 'pdfzip';
181
190
  if ( requestData.fileType == 'pdf' ) {
182
- if ( requestData?.sourceCheckList_id && requestData?.sourceCheckList_id !='' ) {
191
+ if ( requestData?.sourceCheckList_id && requestData?.sourceCheckList_id != '' ) {
183
192
  fileType = 'pdfzip';
184
193
  }
185
194
  if ( requestData?.checklistId && requestData?.checklistId.length > 1 ) {
@@ -191,7 +200,7 @@ export const downloadInsertOld = async ( req, res ) => {
191
200
  if ( requestData.checklistName != '' ) {
192
201
  name = requestData.checklistName + '_' + dayjs( requestData.fromDate ).format( 'DD/MM/YYYY' );
193
202
  if ( requestData?.toDate ) {
194
- name = name + '-'+ dayjs( requestData?.toDate ).format( 'DD/MM/YYYY' );
203
+ name = name + '-' + dayjs( requestData?.toDate ).format( 'DD/MM/YYYY' );
195
204
  }
196
205
  let regexName = new RegExp( `^${name.split( '(' )[0]} \\(.*\\)$`, 'i' );
197
206
  let type = requestData.fileType || 'pdfzip';
@@ -203,7 +212,7 @@ export const downloadInsertOld = async ( req, res ) => {
203
212
  name = requestData?.checklistName;
204
213
  }
205
214
 
206
- name = name+'-'+requestData.fileType;
215
+ name = name + '-' + requestData.fileType;
207
216
  let insertData = {
208
217
  'date_string': requestData.fromDate || '',
209
218
  'sourceCheckList_id': requestData?.sourceCheckList_id || '',
@@ -296,7 +305,7 @@ export const downloadList = async ( req, res ) => {
296
305
  return res.sendError( { error: 'No Data Found' }, 204 );
297
306
  }
298
307
 
299
- if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy !='' ) {
308
+ if ( requestData.sortColumnName && requestData.sortColumnName != '' && requestData.sortBy && requestData.sortBy != '' ) {
300
309
  findQuery.push( { $sort: { [requestData.sortColumnName]: requestData.sortBy } } );
301
310
  } else {
302
311
  findQuery.push( { $sort: { ['_id']: -1 } } );
@@ -307,8 +316,8 @@ export const downloadList = async ( req, res ) => {
307
316
  findQuery.push( { $skip: skip }, { $limit: limit } );
308
317
  let getDownlaodData = await downloadService.aggregate( findQuery );
309
318
  let bucket = JSON.parse( process.env.BUCKET );
310
- for ( let i=0; i<getDownlaodData.length; i++ ) {
311
- if ( getDownlaodData[i].url && getDownlaodData[i].url !='' ) {
319
+ for ( let i = 0; i < getDownlaodData.length; i++ ) {
320
+ if ( getDownlaodData[i].url && getDownlaodData[i].url != '' ) {
312
321
  let inputData1 = {
313
322
  Bucket: bucket.sop,
314
323
  file_path: getDownlaodData[i].url,
@@ -367,12 +376,11 @@ export const getChecklistFromZipId = async ( req, res ) => {
367
376
  brandLogo: '',
368
377
  checkListDescription: '',
369
378
  };
370
-
371
379
  if ( getzipdata ) {
372
380
  let getClientData = await clientService.findOne( { clientId: getzipdata.client_id } );
373
381
  if ( getClientData ) {
374
382
  brandInfo.clientName = getClientData.clientName;
375
- brandInfo.brandLogo = getzipdata.client_id+'/logo/'+getClientData.profileDetails.logo;
383
+ brandInfo.brandLogo = getzipdata.client_id + '/logo/' + getClientData.profileDetails.logo;
376
384
  }
377
385
 
378
386
  // if ( getzipdata.fileType == 'zipfiles' ) {
@@ -387,7 +395,12 @@ export const getChecklistFromZipId = async ( req, res ) => {
387
395
 
388
396
  if ( getzipdata.sourceCheckList_id && getzipdata.sourceCheckList_id != '' ) {
389
397
  let getChecklistDescription = await checklistService.findOne( { _id: getzipdata.sourceCheckList_id }, { checkListName: 1, checkListDescription: 1 } );
390
- brandInfo.checkListDescription = getChecklistDescription.checkListDescription || '';
398
+ if ( getzipdata.insertType == 'task' ) {
399
+ let getChecklistDescription = await taskConfigService.findOne( { _id: getzipdata.sourceCheckList_id }, { checkListName: 1, checkListDescription: 1 } );
400
+ brandInfo.checkListDescription = getChecklistDescription.checkListDescription || '';
401
+ } else {
402
+ brandInfo.checkListDescription = getChecklistDescription.checkListDescription || '';
403
+ }
391
404
 
392
405
  resultData.brandInfo = brandInfo;
393
406
  if ( getzipdata.sourceCheckList_id && getzipdata.sourceCheckList_id != '' ) {
@@ -404,13 +417,21 @@ export const getChecklistFromZipId = async ( req, res ) => {
404
417
  resultData.viewFlag = getzipdata.viewFlag;
405
418
  resultData.previewType = getzipdata.previewType || '';
406
419
  resultData.answerType = getzipdata.answerType || '';
420
+ resultData.insertType = getzipdata.insertType;
407
421
  return res.sendSuccess( resultData );
408
422
  } else {
409
423
  let getchecklistsQuery = {};
410
424
  getchecklistsQuery._id = new mongoose.Types.ObjectId( getzipdata.checklistIdList[0] );
411
425
  let getchecklistsData = await processedchecklistService.findOne( getchecklistsQuery, { _id: 1, sourceCheckList_id: 1 } );
426
+ if ( getzipdata.insertType == 'task' ) {
427
+ getchecklistsData = await processedTaskService.findOne( getchecklistsQuery, { _id: 1, sourceCheckList_id: 1 } );
428
+ }
429
+
412
430
  if ( getchecklistsData ) {
413
431
  let getChecklistDescription = await checklistService.findOne( { _id: getchecklistsData.sourceCheckList_id }, { checkListName: 1, checkListDescription: 1 } );
432
+ if ( getzipdata.insertType == 'task' ) {
433
+ getChecklistDescription = await taskConfigService.findOne( { _id: getzipdata.sourceCheckList_id }, { checkListName: 1, checkListDescription: 1 } );
434
+ }
414
435
  brandInfo.checkListDescription = getChecklistDescription.checkListDescription || '';
415
436
  }
416
437
 
@@ -418,6 +439,7 @@ export const getChecklistFromZipId = async ( req, res ) => {
418
439
  resultData.checklistIds = getzipdata.checklistIdList;
419
440
  resultData.fileType = getzipdata.fileType;
420
441
  resultData.questions = getzipdata.questions;
442
+ resultData.insertType = getzipdata.insertType;
421
443
  return res.sendSuccess( resultData );
422
444
  }
423
445
  } else {
@@ -459,12 +481,14 @@ export const getPDFCSVChecklistDetails = async ( req, res ) => {
459
481
  ];
460
482
 
461
483
  let getchecklistsData = await processedchecklistService.aggregate( query );
462
- if ( getchecklistsData && getchecklistsData.length >0 ) {
484
+
485
+
486
+ if ( getchecklistsData && getchecklistsData.length > 0 ) {
463
487
  let getbrand = await clientService.findOne( { clientId: getchecklistsData[0].client_id }, { clientName: 1 } );
464
488
  let brandInfo = {};
465
489
  if ( getbrand ) {
466
490
  brandInfo.clientName = getbrand.clientName;
467
- brandInfo.brandLogo = getchecklistsData[0].client_id+'/logo/brandLogo.png';
491
+ brandInfo.brandLogo = getchecklistsData[0].client_id + '/logo/brandLogo.png';
468
492
  }
469
493
 
470
494
  let getstore = await storeService.findOne( { id: getchecklistsData[0].store_id }, { storeProfile: 1 } );
@@ -472,7 +496,7 @@ export const getPDFCSVChecklistDetails = async ( req, res ) => {
472
496
  getchecklistsData[0].city = getstore?.storeProfile?.city || '--';
473
497
  getchecklistsData[0].state = getstore?.storeProfile?.state || '--';
474
498
  let questions = [];
475
- function processQuestion( question, section, questions, nested=false ) {
499
+ function processQuestion( question, section, questions, nested = false ) {
476
500
  let findExists = questions.find( ( item ) => item?.qno && item.qno == question.qno );
477
501
  if ( findExists && nested ) {
478
502
  let findIndex = questions.findIndex( ( item ) => item?.qno && item.qno == question.qno );
@@ -433,14 +433,19 @@ export async function getLogs( req, res ) {
433
433
 
434
434
  export async function approvalstatus( req, res ) {
435
435
  try {
436
- let Approver = await ApproverModel.findOne( { checkListId: req.body.checklistId } );
437
- if ( !Approver||Approver&&Approver.email!=req.user.email ) {
436
+ let Approver = await ApproverModel.find( { checkListId: req.body.checklistId } );
437
+ if ( Approver.length === 0 ) {
438
+ return res.sendError( 'No Content', 204 );
439
+ }
440
+ let filterApprover = Approver.filter( ( data ) => data.userEmail=== req.user.email );
441
+ if ( filterApprover.length === 0 ) {
438
442
  return res.sendError( 'No Content', 204 );
439
443
  }
440
444
 
441
445
 
442
446
  let url = JSON.parse( process.env.LAMBDAURL );
443
447
  let resultData = await LamdaServiceCall( url.approvalstatus, req.body );
448
+ console.log( resultData );
444
449
  if ( resultData ) {
445
450
  if ( resultData.status_code == '200' ) {
446
451
  return res.sendSuccess( resultData );
@@ -20,6 +20,9 @@ export const validateDownloadInsertSchema = joi.object( {
20
20
  userId: joi.string().optional().allow( '' ),
21
21
  answerType: joi.string().optional().allow( '' ),
22
22
  searchValue: joi.string().optional().allow( '' ),
23
+ viewRedo: joi.boolean().optional().allow( '' ),
24
+ insertType: joi.string().optional().allow( '' ),
25
+
23
26
  } );
24
27
 
25
28
  export const validateDownloadInsertParams = {
@@ -0,0 +1,32 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export const find = async ( query = {}, field={} ) => {
4
+ return model.taskConfigModel.find( query, field );
5
+ };
6
+
7
+ export const findOne = async ( query = {}, field={} ) => {
8
+ return model.taskConfigModel.findOne( query, field );
9
+ };
10
+
11
+ export const updateMany = async ( query = {}, record={} ) => {
12
+ return model.taskConfigModel.updateMany( query, { $set: record } );
13
+ };
14
+ export const updateOne = async ( query = {}, record={} ) => {
15
+ return model.taskConfigModel.updateOne( query, { $set: record } );
16
+ };
17
+
18
+ export const insertMany = async ( data = [] ) => {
19
+ return model.taskConfigModel.insertMany( data );
20
+ };
21
+
22
+ export const deleteMany = async ( query = [] ) => {
23
+ return model.taskConfigModel.deleteMany( query );
24
+ };
25
+
26
+ export const aggregate = async ( query = [] ) => {
27
+ return model.taskConfigModel.aggregate( query );
28
+ };
29
+
30
+ export const insert = async ( data = [] ) => {
31
+ return model.taskConfigModel.create( data );
32
+ };