tango-app-api-trax 3.4.0-alpha-5 → 3.4.0-beta-0

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/index.js CHANGED
@@ -8,5 +8,5 @@ import { downloadRouter } from './src/routes/download.router.js';
8
8
  import { mobileRouter } from './src/routes/mobileTrax.routes.js';
9
9
  import { internalTraxRouter } from './src/routes/internalTraxApi.router.js';
10
10
  import { locusOrderRouter } from './src/routes/locus.router.js';
11
-
12
- export { traxDashboardRouter, traxFlagRouter, traxRouter, galleryRouter, downloadRouter, mobileRouter, internalTraxRouter, locusOrderRouter };
11
+ import { traxActivityLogRouter } from './src/routes/activityLog.router.js';
12
+ export { traxDashboardRouter, traxFlagRouter, traxRouter, galleryRouter, downloadRouter, mobileRouter, internalTraxRouter, locusOrderRouter, traxActivityLogRouter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-trax",
3
- "version": "3.4.0-alpha-5",
3
+ "version": "3.4.0-beta-0",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -0,0 +1,222 @@
1
+ // import mongoose from 'mongoose';
2
+ import { insertOpenSearchData, updateOpenSearchData, getOpenSearchData } from 'tango-app-api-middleware';
3
+ import * as checklistService from '../services/checklist.service.js';
4
+
5
+ export const insertLog = async ( req, res ) => {
6
+ try {
7
+ // let currentDate = new Date();
8
+ let inserttraxlogs = {
9
+ 'client_id': '11',
10
+ 'createAt': new Date(),
11
+ 'sourceCheckList_id': '668e3e1807d5312fa49b0046',
12
+ 'checkListName': 'Daily Store Checklistnafi33',
13
+ 'fromCheckListName': '',
14
+ 'type': 'checklist',
15
+ 'action': 'updated',
16
+ 'storeName': 'LKST007',
17
+ 'store_id': '',
18
+ 'createdByEmail': 'lkst007bc1@lenskart.co.in',
19
+ 'createdBy': 'lkst007bc1',
20
+ 'coverage': 'store',
21
+ 'logDetails': {
22
+ 'schedule': {
23
+ 'previous': {
24
+ 'schedule': 'repeats',
25
+ // "repeats":"daily",
26
+ 'time': '10:00 AM to 11:00 PM',
27
+ // "occurs":[],
28
+ 'scheduleRepeatedDay': [ '01' ],
29
+ 'scheduleRepeatedType': 'daily',
30
+ 'scheduleStartTime_iso': '2025-02-10T23:30:00.000+00:00',
31
+ 'scheduleEndTime_iso': '2025-02-10T23:30:00.000+00:00',
32
+ 'configStartDate': '2025-03-11T00:00:00.000+00:00',
33
+ 'configEndDate': '2025-03-12T00:00:00.000+00:00',
34
+ 'scheduleWeekDays': [ 'Monday', 'Tuesday' ],
35
+ 'scheduleRepeatedMonthWeek': '2 Tuesday',
36
+ 'specificDate': [ '10', '11' ],
37
+
38
+ },
39
+ 'new': {
40
+ 'schedule': 'onetime',
41
+ // "repeats":"weekly",
42
+ 'time': '10:00 AM to 11:00 PM',
43
+ // "occurs":["Mondy","Tuesday"],
44
+ 'scheduleRepeatedDay': [ '01' ],
45
+ 'scheduleRepeatedType': 'daily',
46
+ 'configStartDate': '2025-03-11T00:00:00.000+00:00',
47
+ 'configEndDate': '2025-03-12T00:00:00.000+00:00',
48
+ 'scheduleStartTime_iso': '2025-02-10T23:30:00.000+00:00',
49
+ 'scheduleEndTime_iso': '2025-02-10T23:30:00.000+00:00',
50
+ 'scheduleWeekDays': [ 'Monday', 'Tuesday' ],
51
+ 'scheduleRepeatedMonthWeek': '2 Tuesday',
52
+ 'specificDate': [ '10', '11' ],
53
+ },
54
+ },
55
+ 'response': {
56
+ 'previous': [ 'Geo Facing', 'Allow Multiple response' ],
57
+ 'new': [ 'Geo Facing 2', 'Allow Multiple response 2' ],
58
+ },
59
+ 'owner': {
60
+ 'previous': [ 'Ajinkya Malshe' ],
61
+ 'new': [ 'Ajinkya Malshe' ],
62
+ },
63
+ 'approver': {
64
+ 'previous': [ 'raju', 'rajuapprover' ],
65
+ 'new': [ 'raju 1', 'rajuapprover 2' ],
66
+ },
67
+ 'storeAdded': [ 'LKST011', 'LKST022', 'LKST3444', 'LKST455', 'LKST566', 'LKST666', 'LKST766', 'LKST866', 'LkST966' ],
68
+ 'storeRemoved': [ 'LKST1166', 'LKST1177', 'LKST1188', 'LKST1199', 'LKST1155', 'LKST1144', 'LKST1133', 'LKST1122', 'LkST1111' ],
69
+ 'userAdded': [ 'LKST011@yopmail.com', 'LKST022@yopmail.com', 'LKST3444@yopmail.com', 'LKST455@yopmail.com', 'LKST566@yopmail.com', 'LKST666@yopmail.com', 'LKST766@yopmail.com', 'LKST866@yopmail.com', 'LkST966@yopmail.com' ],
70
+ 'userRemoved': [ 'LKST1166@yopmail.com', 'LKST1177@yopmail.com', 'LKST1188@yopmail.com', 'LKST1199@yopmail.com', 'LKST1155@yopmail.com', 'LKST1144@yopmail.com', 'LKST1133@yopmail.com', 'LKST1122@yopmail.com', 'LkST1111@yopmail.com' ],
71
+ },
72
+ };
73
+ let insertOS = await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, inserttraxlogs );
74
+ console.log( 'insertOS', insertOS );
75
+ return res.sendSuccess( 'insert successfully' );
76
+ // if ( insertOS && insertOS.body.result == 'created' ) {
77
+ // emailersIds.push( insertOS.body._id );
78
+ // }
79
+ } catch ( e ) {
80
+ // logger.error( 'insertLog =>', e );
81
+ console.log( 'insertLog =>', e );
82
+ return res.sendError( e, 500 );
83
+ }
84
+ };
85
+ export const updateLog = async ( req, res ) => {
86
+ try {
87
+ console.log( 'update' );
88
+ const document = {
89
+ doc: {
90
+ storeName: 'LKST008',
91
+ // fromDate: '2025-01-13',
92
+ // toDate: '2025-01-19',
93
+ // status: 'completed',
94
+ // storeIds: [ '347-1' ],
95
+ },
96
+ };
97
+ let updateResult = await updateOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, '5DwBYZUBcRcpuflp5oek', document );
98
+ console.log( 'updateResult', updateResult );
99
+ if ( updateResult?.statusCode == 200 && updateResult?.body?.result == 'updated' ) {
100
+ return res.sendSuccess( 'Email Send Successfully' );
101
+ } else {
102
+ return res.sendSuccess( 'Email Send Successfully' );
103
+ // return res.sendError( { error: error }, 500 );
104
+ }
105
+ } catch ( e ) {
106
+ logger.error( 'updateLog =>', e );
107
+ return res.sendError( e, 500 );
108
+ }
109
+ };
110
+ export const listLog = async ( req, res ) => {
111
+ try {
112
+ let requestBody = req.body;
113
+ let from = ( requestBody.offset ) * requestBody.limit;
114
+
115
+ // let start = new Date( requestBody.fromDate );
116
+ // let userTimezoneOffset = start.getTimezoneOffset() * 60000;
117
+ // start = new Date( start.getTime() - userTimezoneOffset );
118
+ // start.setUTCHours( 0, 0, 0, 0 );
119
+ // let end = new Date( requestBody.toDate );
120
+ // end = new Date( end.getTime() - userTimezoneOffset );
121
+ // end.setUTCHours( 23, 59, 59, 59 );
122
+
123
+ // console.log( 'list' );
124
+ const mustConditions = [];
125
+
126
+ if ( requestBody.clientId ) {
127
+ mustConditions.push( { term: { client_id: requestBody.clientId } } );
128
+ }
129
+
130
+ if ( requestBody.type ) {
131
+ mustConditions.push( { term: { type: requestBody.type } } );
132
+ }
133
+
134
+ if ( requestBody.action ) {
135
+ mustConditions.push( { terms: { action: requestBody.action } } );
136
+ }
137
+
138
+ if ( req.user.userType == 'client' && req.user.role == 'user' ) {
139
+ return res.sendError( 'no data found', 204 );
140
+ }
141
+
142
+ if ( req.user.userType == 'client' && req.user.role == 'admin' ) {
143
+ const sourceCheckListResult = await checklistService.aggregate( [
144
+ { $match: { 'owner.value': req.user.email } },
145
+ { $group: { _id: null, checklistIds: { $push: { $toString: '$_id' } } } },
146
+ { $project: { _id: 0, checklistIds: 1 } },
147
+ ] );
148
+ const sourceCheckListIds = sourceCheckListResult.length > 0 ? sourceCheckListResult[0].checklistIds : [];
149
+ console.log( 'sourceCheckListIds', sourceCheckListIds );
150
+ // mustConditions.push( { terms: { $or: [ { store_id: { $in: requestBody.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestBody.userEmailes } }, { sourceCheckList_id: { $in: sourceCheckListIds } } ] } } );
151
+ mustConditions.push( {
152
+ 'bool': {
153
+ 'should': [
154
+ { 'terms': { 'store_id': requestBody.storeId } },
155
+ {
156
+ 'bool': {
157
+ 'must': [
158
+ { 'term': { 'store_id': '' } },
159
+ { 'terms': { 'userEmail': requestBody.userEmailes } },
160
+ ],
161
+ },
162
+ },
163
+ { 'terms': { 'sourceCheckList_id': sourceCheckListIds.map( String ) } },
164
+ ],
165
+ 'minimum_should_match': 1,
166
+ },
167
+ } );
168
+ }
169
+
170
+ if ( requestBody.searchValue ) {
171
+ mustConditions.push( { multi_match: {
172
+ 'query': requestBody.searchValue,
173
+ 'fields': [ 'checkListName', 'storeName', 'userEmail' ],
174
+ 'type': 'phrase_prefix',
175
+ },
176
+ } );
177
+ }
178
+ // console.log( 'Generated Query:', JSON.stringify( mustConditions, null, 2 ) );
179
+
180
+ // console.log( 'mustConditions =>', mustConditions );
181
+ // if ( requestBody.dateRange ) {
182
+ // mustConditions.push( {
183
+ // range: {
184
+ // createdAt: {
185
+ // gte: start, // Start date
186
+ // lte: end, // End date
187
+ // },
188
+ // },
189
+ // } );
190
+ // }
191
+ let sortCreatedAt = 'desc';
192
+ if ( requestBody.sortColumnName && requestBody.sortColumnName != '' ) {
193
+ if ( requestBody.sortBy == '1' ) {
194
+ sortCreatedAt = 'asc';
195
+ }
196
+ }
197
+ let query = {
198
+ from: parseInt( from ),
199
+ size: parseInt( requestBody.limit ),
200
+ query: {
201
+ bool: {
202
+ must: mustConditions,
203
+ },
204
+ },
205
+ sort: [
206
+ {
207
+ createAt: {
208
+ order: sortCreatedAt,
209
+ },
210
+ },
211
+ ],
212
+ };
213
+ let result = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, query );
214
+ if ( !result || !result.body.hits.hits.length ) {
215
+ return res.sendError( 'no data found', 204 );
216
+ }
217
+ return res.sendSuccess( { count: result.body.hits.total.value, result: result.body.hits.hits } );
218
+ } catch ( e ) {
219
+ console.log( 'listLog', e );
220
+ return res.sendError( e, 500 );
221
+ }
222
+ };
@@ -291,6 +291,7 @@ export async function approveChecklist( req, res ) {
291
291
  let updateResponse = await processedChecklist.updateMany( { _id: { $in: idList } }, { approvalStatus: true } );
292
292
  if ( updateResponse.modifiedCount || updateResponse.matchedCount ) {
293
293
  let inputstores = checklistDetails.filter( ( data ) => data.checklistStatus == 'submit' );
294
+ let storeNames = inputstores.map((data)=>data.storeName)
294
295
 
295
296
 
296
297
  let params = {
@@ -332,7 +333,7 @@ export async function approveChecklist( req, res ) {
332
333
  'createdBy': req.user._id,
333
334
  'coverage': checklistDetails[0].coverage,
334
335
  'logDetails': {
335
- 'approved': [ 'LKST011', 'LKST022', 'LKST3444', 'LKST455', 'LKST566', 'LKST666', 'LKST766', 'LKST866', 'LkST966' ],
336
+ 'approved': storeNames
336
337
  },
337
338
  };
338
339
  let urlopensearch = JSON.parse( process.env.OPENSEARCH );
@@ -1644,3 +1644,51 @@ async function getUserToken( clientId, userEmail ) {
1644
1644
  return false;
1645
1645
  }
1646
1646
  }
1647
+
1648
+ export async function internalAISendPushNotification( req, res ) {
1649
+ try {
1650
+ let requestData = req.body;
1651
+ if ( !requestData.clientId ) {
1652
+ return res.sendError( 'clientId is Required', 400 );
1653
+ }
1654
+ if ( !( requestData?.email || requestData?.storeId ) ) {
1655
+ return res.sendError( 'Email or StoreId is Required', 400 );
1656
+ }
1657
+
1658
+ if ( !requestData.title ) {
1659
+ return res.sendError( 'Title is Required', 400 );
1660
+ }
1661
+
1662
+ if ( !requestData.description ) {
1663
+ return res.sendError( 'Description is Required', 400 );
1664
+ }
1665
+
1666
+ let fcmToken;
1667
+ if ( requestData.email && requestData.email !='' ) {
1668
+ fcmToken = await getUserToken( requestData.clientId, requestData.email );
1669
+ } else {
1670
+ let storeData = await storeService.findOne( { clientId: requestData.clientId, storeId: requestData.storeId }, { spocDetails: 1 } );
1671
+ if ( storeData && storeData.spocDetails.length > 0 && storeData.spocDetails[0].email ) {
1672
+ fcmToken = await getUserToken( storeData.spocDetails[0].email );
1673
+ }
1674
+ }
1675
+ if ( !fcmToken ) {
1676
+ return res.sendSuccess( 'Notification Send Successfully' );
1677
+ }
1678
+ let custom = {
1679
+ type: req.body?.type,
1680
+ storeId: req.body?.storeId,
1681
+ date: req.body?.date,
1682
+ };
1683
+ let responseData = await sendPushNotification( requestData.title, requestData.description, fcmToken, custom );
1684
+ if ( responseData ) {
1685
+ return res.sendSuccess( 'Notification Send Successfully' );
1686
+ } else {
1687
+ return res.sendSuccess( 'Notification Send Successfully' );
1688
+ }
1689
+ } catch ( e ) {
1690
+ logger.error( { error: e, function: 'internalAISendPushNotification' } );
1691
+ if ( e.name === 'ValidationError' ) res.sendBadRequest( e );
1692
+ else res.sendError( e, 500 );
1693
+ }
1694
+ };
@@ -1,4 +1,4 @@
1
- import { logger, signedUrl, fileUpload, getOtp, sendEmailWithSES, getUuid } from 'tango-app-api-middleware';
1
+ import { logger, signedUrl, fileUpload, getOtp, sendEmailWithSES, getUuid, insertOpenSearchData } from 'tango-app-api-middleware';
2
2
  import * as processedchecklist from '../services/processedchecklist.services.js';
3
3
  import * as processedtask from '../services/processedTaskList.service.js';
4
4
  import * as PCLconfig from '../services/processedchecklistconfig.services.js';
@@ -27,6 +27,7 @@ dayjs.extend( timeZone );
27
27
  import isSameOrBefore from 'dayjs/plugin/isSameOrBefore.js';
28
28
  dayjs.extend( isSameOrBefore );
29
29
 
30
+
30
31
  export async function storeList( req, res ) {
31
32
  try {
32
33
  if ( !req.query?.date ) {
@@ -516,6 +517,27 @@ export async function startChecklist( req, res ) {
516
517
  getchecklist[index].questionAnswers[secIndex].questions = questions;
517
518
  }
518
519
  }
520
+ let openSearch = JSON.parse( process.env.OPENSEARCH );
521
+ console.log( 'openSearch', openSearch );
522
+ let inserttraxlogs = {
523
+ client_id: req.user.clientId,
524
+ createAt: new Date(),
525
+ sourceCheckList_id: getBeforeChecklist[0]?.sourceCheckList_id || '',
526
+ checkListName: getBeforeChecklist[0]?.checkListName || '',
527
+ fromCheckListName: '',
528
+ type: 'checkList',
529
+ action: 'start',
530
+ storeName: getBeforeChecklist[0]?.storeName || '',
531
+ store_id: getBeforeChecklist[0]?.store_id || '',
532
+ createdByEmail: getBeforeChecklist[0]?.userEmail || '',
533
+ createdBy: getBeforeChecklist[0]?.userName || '',
534
+ coverage: getBeforeChecklist[0]?.coverage || '',
535
+ logDetails: {},
536
+ };
537
+ // let insertOS = await insertOpenSearchData( 'test-traxlogs', inserttraxlogs );
538
+ console.log( 'inserttraxlogs', inserttraxlogs );
539
+ let insertOS = await insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
540
+ console.log( 'insertOS', insertOS );
519
541
  return res.sendSuccess( getchecklist );
520
542
  } else {
521
543
  return res.sendError( 'something went wrong please try again', 500 );
@@ -687,6 +709,27 @@ export async function startTask( req, res ) {
687
709
  };
688
710
  await checklistLogs.create( logData );
689
711
 
712
+ let openSearch = JSON.parse( process.env.OPENSEARCH );
713
+ console.log( 'openSearch', openSearch );
714
+ let inserttraxlogs = {
715
+ client_id: req.user.clientId,
716
+ createAt: new Date(),
717
+ sourceCheckList_id: task.sourceCheckList_id || '',
718
+ checkListName: task.checkListName || '',
719
+ fromCheckListName: '',
720
+ type: 'task',
721
+ action: 'start',
722
+ storeName: task.storeName || '',
723
+ store_id: task.store_id || '',
724
+ createdByEmail: task.userEmail || '',
725
+ createdBy: task.userName || '',
726
+ coverage: task.coverage || '',
727
+ logDetails: {},
728
+ };
729
+ // let insertOS = await insertOpenSearchData( 'test-traxlogs', inserttraxlogs );
730
+ console.log( 'inserttraxlogs', inserttraxlogs );
731
+ let insertOS = await insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
732
+ console.log( 'insertOS', insertOS );
690
733
  return res.sendSuccess( getUpdatedTask );
691
734
  } catch ( error ) {
692
735
  logger.error( { function: 'startTask', error, body: req.body } );
@@ -2466,7 +2509,7 @@ export async function submitChecklist( req, res ) {
2466
2509
  userName: getchecklist[0].userName || '',
2467
2510
  coverage: getchecklist[0].coverage || '',
2468
2511
  };
2469
- console.log( 'logInsertData=>', logInsertData );
2512
+ // console.log( 'logInsertData=>', logInsertData );s
2470
2513
  await checklistLogs.create( logInsertData );
2471
2514
  // let time = dayjs().format( 'HH:mm:ss' );
2472
2515
  // let [ hours, minutes ] = time.split( ':' ).map( Number );
@@ -2501,8 +2544,32 @@ export async function submitChecklist( req, res ) {
2501
2544
  // await detectionService.create( detectionData );
2502
2545
  if ( requestData.submittype == 'submit' ) {
2503
2546
  updateOpenSearch( req.user, requestData );
2547
+
2548
+ let openSearch = JSON.parse( process.env.OPENSEARCH );
2549
+ console.log( 'openSearch', openSearch );
2550
+ let inserttraxlogs = {
2551
+ client_id: req.user.clientId,
2552
+ createAt: new Date(),
2553
+ sourceCheckList_id: getchecklist[0].sourceCheckList_id,
2554
+ checkListName: getchecklist[0].checkListName,
2555
+ type: 'checkList',
2556
+ action: requestData?.submittype === 'draft' ? 'save' : 'submit',
2557
+ storeName: getchecklist[0].storeName,
2558
+ store_id: getchecklist[0].store_id,
2559
+ userName: getchecklist[0].userName,
2560
+ userEmail: getchecklist[0].userEmail,
2561
+ createdByEmail: getchecklist[0].userEmail,
2562
+ createdBy: getchecklist[0].userName,
2563
+ coverage: getchecklist[0].coverage,
2564
+ checkListType: getchecklist[0].checkListType,
2565
+ logDetails: {},
2566
+ };
2567
+ console.log( 'inserttraxlogs', inserttraxlogs );
2568
+ let insertOS = await insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
2569
+ console.log( 'insertOS', insertOS );
2504
2570
  }
2505
2571
 
2572
+
2506
2573
  return res.sendSuccess( 'Checklist Updated Successfully' );
2507
2574
  } else {
2508
2575
  return res.sendError( 'something went wrong please try again', 500 );
@@ -2667,6 +2734,29 @@ export async function submitTask( req, res ) {
2667
2734
 
2668
2735
  if ( submittype == 'submit' ) {
2669
2736
  updateOpenSearchTask( user, requestData );
2737
+
2738
+ let openSearch = JSON.parse( process.env.OPENSEARCH );
2739
+ console.log( 'openSearch', openSearch );
2740
+ let inserttraxlogs = {
2741
+ client_id: req.user.clientId,
2742
+ createAt: new Date(),
2743
+ sourceCheckList_id: checklist.sourceCheckList_id,
2744
+ checkListName: checklist.checkListName,
2745
+ type: 'task',
2746
+ action: requestData?.submittype === 'draft' ? 'save' : 'submit',
2747
+ storeName: checklist.storeName,
2748
+ store_id: checklist.store_id,
2749
+ userName: checklist.userName,
2750
+ userEmail: checklist.userEmail,
2751
+ createdByEmail: checklist.userEmail,
2752
+ createdBy: checklist.userName,
2753
+ coverage: checklist.coverage,
2754
+ checkListType: checklist.checkListType,
2755
+ logDetails: {},
2756
+ };
2757
+ console.log( 'inserttraxlogs', inserttraxlogs );
2758
+ let insertOS = await insertOpenSearchData( openSearch.traxActivityLog, inserttraxlogs );
2759
+ console.log( 'insertOS', insertOS );
2670
2760
  }
2671
2761
 
2672
2762
  return res.sendSuccess( 'Task Updated Successfully' );