tango-app-api-trax 3.4.1-alpha-20 → 3.4.1-approvecheck-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,6 @@ 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
+ import { traxActivityLogRouter } from './src/routes/activityLog.router.js';
11
12
 
12
- export { traxDashboardRouter, traxFlagRouter, traxRouter, galleryRouter, downloadRouter, mobileRouter, internalTraxRouter, locusOrderRouter };
13
+ 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.1-alpha-20",
3
+ "version": "3.4.1-approvecheck-0",
4
4
  "description": "Trax",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "mongodb": "^6.8.0",
27
27
  "nodemon": "^3.1.4",
28
28
  "path": "^0.12.7",
29
- "tango-api-schema": "^2.2.73",
30
- "tango-app-api-middleware": "^3.1.66",
29
+ "tango-api-schema": "^2.2.101",
30
+ "tango-app-api-middleware": "^3.1.72",
31
31
  "url": "^0.11.4",
32
32
  "winston": "^3.13.1",
33
33
  "winston-daily-rotate-file": "^5.0.0"
@@ -0,0 +1,292 @@
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
+ import * as taskconfigService from '../services/taskConfig.service.js';
5
+
6
+ export const insertLog = async ( req, res ) => {
7
+ try {
8
+ // let currentDate = new Date();
9
+ // let inserttraxlogs = {
10
+ // 'client_id': '11',
11
+ // 'createAt': new Date(),
12
+ // 'sourceCheckList_id': '668e3e1807d5312fa49b0046',
13
+ // 'checkListName': 'Daily Store Checklistnafi33',
14
+ // 'fromCheckListName': '',
15
+ // 'type': 'checklist',
16
+ // 'action': 'updated',
17
+ // 'storeName': 'LKST007',
18
+ // 'store_id': '',
19
+ // 'createdByEmail': 'lkst007bc1@lenskart.co.in',
20
+ // 'createdBy': 'lkst007bc1',
21
+ // 'coverage': 'store',
22
+ // 'logDetails': {
23
+ // 'schedule': {
24
+ // 'previous': {
25
+ // 'schedule': 'repeats',
26
+ // // "repeats":"daily",
27
+ // 'time': '10:00 AM to 11:00 PM',
28
+ // // "occurs":[],
29
+ // 'scheduleRepeatedDay': [ '01' ],
30
+ // 'scheduleRepeatedType': 'daily',
31
+ // 'scheduleStartTime_iso': '2025-02-10T23:30:00.000+00:00',
32
+ // 'scheduleEndTime_iso': '2025-02-10T23:30:00.000+00:00',
33
+ // 'configStartDate': '2025-03-11T00:00:00.000+00:00',
34
+ // 'configEndDate': '2025-03-12T00:00:00.000+00:00',
35
+ // 'scheduleWeekDays': [ 'Monday', 'Tuesday' ],
36
+ // 'scheduleRepeatedMonthWeek': '2 Tuesday',
37
+ // 'specificDate': [ '10', '11' ],
38
+
39
+ // },
40
+ // 'new': {
41
+ // 'schedule': 'onetime',
42
+ // // "repeats":"weekly",
43
+ // 'time': '10:00 AM to 11:00 PM',
44
+ // // "occurs":["Mondy","Tuesday"],
45
+ // 'scheduleRepeatedDay': [ '01' ],
46
+ // 'scheduleRepeatedType': 'daily',
47
+ // 'configStartDate': '2025-03-11T00:00:00.000+00:00',
48
+ // 'configEndDate': '2025-03-12T00:00:00.000+00:00',
49
+ // 'scheduleStartTime_iso': '2025-02-10T23:30:00.000+00:00',
50
+ // 'scheduleEndTime_iso': '2025-02-10T23:30:00.000+00:00',
51
+ // 'scheduleWeekDays': [ 'Monday', 'Tuesday' ],
52
+ // 'scheduleRepeatedMonthWeek': '2 Tuesday',
53
+ // 'specificDate': [ '10', '11' ],
54
+ // },
55
+ // },
56
+ // 'response': {
57
+ // 'previous': [ 'Geo Facing', 'Allow Multiple response' ],
58
+ // 'new': [ 'Geo Facing 2', 'Allow Multiple response 2' ],
59
+ // },
60
+ // 'owner': {
61
+ // 'previous': [ 'Ajinkya Malshe' ],
62
+ // 'new': [ 'Ajinkya Malshe' ],
63
+ // },
64
+ // 'approver': {
65
+ // 'previous': [ 'raju', 'rajuapprover' ],
66
+ // 'new': [ 'raju 1', 'rajuapprover 2' ],
67
+ // },
68
+ // 'storeAdded': [ 'LKST011', 'LKST022', 'LKST3444', 'LKST455', 'LKST566', 'LKST666', 'LKST766', 'LKST866', 'LkST966' ],
69
+ // 'storeRemoved': [ 'LKST1166', 'LKST1177', 'LKST1188', 'LKST1199', 'LKST1155', 'LKST1144', 'LKST1133', 'LKST1122', 'LkST1111' ],
70
+ // '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' ],
71
+ // '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' ],
72
+ // },
73
+ // };
74
+
75
+ let inserttraxlogs = {
76
+ client_id: '201',
77
+ createAt: new Date( '2025-04-21T14:43:22.603Z' ),
78
+ sourceCheckList_id: '68065496feb4eaeb4515cf1d',
79
+ checkListName: 'Ghk',
80
+ fromCheckListName: '',
81
+ type: 'checklist',
82
+ action: 'draft',
83
+ storeName: '',
84
+ store_id: '',
85
+ createdByEmail: 'praveenraju@tangotech.co.in',
86
+ createdBy: 'Praveen Raju',
87
+ coverage: 'store',
88
+ logDetails: {
89
+ schedule: {
90
+ previous: {
91
+ scheduleDateString: '28 Apr, 2025',
92
+ schedule: 'onetime',
93
+ time: '10:00 AM to 10:00 PM',
94
+ scheduleRepeatedDay: '',
95
+ scheduleRepeatedType: 'onetime',
96
+ scheduleWeekDays: [],
97
+ scheduleRepeatedMonthWeek: '',
98
+ specificDate: [],
99
+ },
100
+ new: {
101
+ scheduleDateString: '29 Apr, 2025',
102
+ schedule: 'onetime',
103
+ time: '10:00 AM to 10:00 PM',
104
+ scheduleRepeatedDay: '',
105
+ scheduleRepeatedType: 'onetime',
106
+ scheduleWeekDays: [],
107
+ scheduleRepeatedMonthWeek: '',
108
+ specificDate: [],
109
+ },
110
+ },
111
+ response: { previous: [], new: [] },
112
+ approver: {},
113
+ owner: {},
114
+ storeAdded: [ 'test_Eye52', 'test_Eye53' ],
115
+ storeRemoved: [],
116
+ userAdded: [],
117
+ userRemoved: [],
118
+ },
119
+ userType: 'tango',
120
+ };
121
+ // console.log( 'inserttraxlogs =>', inserttraxlogs );
122
+ let insertOS = await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, inserttraxlogs );
123
+ console.log( 'insertOS', insertOS );
124
+ return res.sendSuccess( 'insert successfully' );
125
+ // if ( insertOS && insertOS.body.result == 'created' ) {
126
+ // emailersIds.push( insertOS.body._id );
127
+ // }
128
+ } catch ( e ) {
129
+ // logger.error( 'insertLog =>', e );
130
+ // console.log( 'insertLog =>', e );
131
+ return res.sendError( e, 500 );
132
+ }
133
+ };
134
+ export const updateLog = async ( req, res ) => {
135
+ try {
136
+ // console.log( 'update' );
137
+ const document = {
138
+ doc: {
139
+ storeName: 'LKST008',
140
+ // fromDate: '2025-01-13',
141
+ // toDate: '2025-01-19',
142
+ // status: 'completed',
143
+ // storeIds: [ '347-1' ],
144
+ },
145
+ };
146
+ let updateResult = await updateOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, '5DwBYZUBcRcpuflp5oek', document );
147
+ // console.log( 'updateResult', updateResult );
148
+ if ( updateResult?.statusCode == 200 && updateResult?.body?.result == 'updated' ) {
149
+ return res.sendSuccess( 'Email Send Successfully' );
150
+ } else {
151
+ return res.sendSuccess( 'Email Send Successfully' );
152
+ // return res.sendError( { error: error }, 500 );
153
+ }
154
+ } catch ( e ) {
155
+ logger.error( 'updateLog =>', e );
156
+ return res.sendError( e, 500 );
157
+ }
158
+ };
159
+ export const listLog = async ( req, res ) => {
160
+ try {
161
+ let requestBody = req.body;
162
+ let from = ( requestBody.offset ) * requestBody.limit;
163
+
164
+ let start = new Date( requestBody.fromDate );
165
+ let userTimezoneOffset = start.getTimezoneOffset() * 60000;
166
+ start = new Date( start.getTime() - userTimezoneOffset );
167
+ start.setUTCHours( 0, 0, 0, 0 );
168
+ let end = new Date( requestBody.toDate );
169
+ end = new Date( end.getTime() - userTimezoneOffset );
170
+ end.setUTCHours( 23, 59, 59, 59 );
171
+
172
+ // console.log( 'list' );
173
+ const mustConditions = [];
174
+
175
+ if ( requestBody.clientId ) {
176
+ mustConditions.push( { term: { client_id: requestBody.clientId } } );
177
+ }
178
+
179
+ if ( requestBody.type ) {
180
+ mustConditions.push( { term: { type: requestBody.type } } );
181
+ }
182
+ if ( requestBody.action && requestBody.action.length > 0 ) {
183
+ mustConditions.push( { terms: { action: requestBody.action } } );
184
+ }
185
+
186
+ if ( req.user.userType == 'client' && req.user.role == 'user' ) {
187
+ return res.sendError( 'no data found', 204 );
188
+ }
189
+ let sourceCheckListIds;
190
+ if ( req.user.userType === 'client' && req.user.role == 'admin' ) {
191
+ if ( requestBody.type === 'checklist' ) {
192
+ const sourceCheckListResult = await checklistService.aggregate( [
193
+ // { $match: { 'owner.value': req.user.email } },
194
+ { $match: { $or: [ { 'owner.value': req.user.email }, { 'approver.value': req.user.email } ] } },
195
+ { $group: { _id: null, checklistIds: { $push: { $toString: '$_id' } } } },
196
+ { $project: { _id: 0, checklistIds: 1 } },
197
+ ] );
198
+ sourceCheckListIds = sourceCheckListResult.length > 0 ? sourceCheckListResult[0].checklistIds : [];
199
+ // console.log( 'sourceCheckListIds', sourceCheckListIds );
200
+ }
201
+ if ( requestBody.type === 'task' ) {
202
+ const sourceCheckListResult = await taskconfigService.aggregate( [
203
+ { $match: { createdBy: req.user._id } },
204
+ // { $match: { $or: [ { 'owner.value': req.user.email }, { 'approver.value': req.user.email } ] } },
205
+ { $group: { _id: null, checklistIds: { $push: { $toString: '$_id' } } } },
206
+ { $project: { _id: 0, checklistIds: 1 } },
207
+ ] );
208
+ sourceCheckListIds = sourceCheckListResult.length > 0 ? sourceCheckListResult[0].checklistIds : [];
209
+ // console.log( 'sourceCheckListIds', sourceCheckListIds );
210
+ }
211
+
212
+ // mustConditions.push( { terms: { $or: [ { store_id: { $in: requestBody.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestBody.userEmailes } }, { sourceCheckList_id: { $in: sourceCheckListIds } } ] } } );
213
+ mustConditions.push( {
214
+ 'bool': {
215
+ 'should': [
216
+ { 'terms': { 'store_id': requestBody.storeId } },
217
+ {
218
+ 'bool': {
219
+ 'must': [
220
+ { 'term': { 'store_id': '' } },
221
+ { 'terms': { 'userEmail': requestBody.userEmailes } },
222
+ ],
223
+ },
224
+ },
225
+ { 'terms': { 'sourceCheckList_id': sourceCheckListIds.map( String ) } },
226
+ ],
227
+ 'minimum_should_match': 1,
228
+ },
229
+ } );
230
+ }
231
+ if ( req.user.userType === 'client' ) {
232
+ mustConditions.push( {
233
+ term: { userType: 'client' },
234
+ } );
235
+ }
236
+
237
+
238
+ if ( requestBody.searchValue ) {
239
+ mustConditions.push( { multi_match: {
240
+ 'query': requestBody.searchValue,
241
+ 'fields': [ 'checkListName', 'storeName', 'createdByEmail' ],
242
+ 'type': 'phrase_prefix',
243
+ },
244
+ } );
245
+ }
246
+ // console.log( 'Generated Query:', JSON.stringify( mustConditions, null, 2 ) );
247
+
248
+ // console.log( 'mustConditions =>', mustConditions );
249
+ if ( requestBody.fromDate && requestBody.toDate ) {
250
+ mustConditions.push( {
251
+ range: {
252
+ createAt: {
253
+ gte: start, // Start date
254
+ lte: end, // End date
255
+ },
256
+ },
257
+ } );
258
+ }
259
+ let sortCreatedAt = 'desc';
260
+ if ( requestBody.sortColumnName && requestBody.sortColumnName != '' ) {
261
+ if ( requestBody.sortBy == '1' ) {
262
+ sortCreatedAt = 'asc';
263
+ }
264
+ }
265
+ let query = {
266
+ from: parseInt( from ),
267
+ size: parseInt( requestBody.limit ),
268
+ query: {
269
+ bool: {
270
+ must: mustConditions,
271
+ },
272
+ },
273
+ sort: [
274
+ {
275
+ createAt: {
276
+ order: sortCreatedAt,
277
+ },
278
+ },
279
+ ],
280
+ };
281
+ // console.log( 'Executing OpenSearch Query:', JSON.stringify( query, null, 2 ) );
282
+ let result = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, query );
283
+ // console.log( 'OpenSearch Raw Response', JSON.stringify( result, null, 2 ) );
284
+ if ( !result || !result.body.hits.hits.length ) {
285
+ return res.sendError( 'no data found', 204 );
286
+ }
287
+ return res.sendSuccess( { count: result.body.hits.total.value, result: result.body.hits.hits } );
288
+ } catch ( e ) {
289
+ // console.log( 'listLog', e );
290
+ return res.sendError( e, 500 );
291
+ }
292
+ };
@@ -6,6 +6,7 @@ import * as processedTaskService from '../services/processedTaskList.service.js'
6
6
  import * as taskConfigService from '../services/taskConfig.service.js';
7
7
  import * as checklistService from '../services/checklist.service.js';
8
8
  // import * as processedTaskconfigService from '../services/processedTaskConfig.service.js';
9
+ import * as processedcheklistconfigService from '../services/processedchecklistconfig.services.js';
9
10
  import * as clientService from '../services/clients.services.js';
10
11
  import * as storeService from '../services/store.service.js';
11
12
 
@@ -143,8 +144,9 @@ export const downloadInsert = async ( req, res ) => {
143
144
  'viewRedo': requestData.viewRedo || false,
144
145
  'userEmailList': requestData.userEmailList || [],
145
146
  'filtertype': requestData.filtertype || 'Clusters',
146
-
147
+ 'checkListType': requestData.checkListType,
147
148
  };
149
+ console.log( insertData );
148
150
  let resultData = await downloadService.insert( insertData );
149
151
  if ( resultData ) {
150
152
  let sqsMessageRequestData = {
@@ -171,7 +173,93 @@ export const downloadInsert = async ( req, res ) => {
171
173
  return res.sendError( e, 500 );
172
174
  }
173
175
  };
174
-
176
+ export const downloadInsertAI = async ( req, res ) => {
177
+ try {
178
+ let requestData = req.body;
179
+ let name;
180
+ let fileType = requestData?.fileType || 'pdfzip';
181
+ if ( requestData.fileType == 'pdf' ) {
182
+ if ( requestData?.sourceCheckList_id && requestData?.sourceCheckList_id != '' ) {
183
+ fileType = 'pdfzip';
184
+ }
185
+ if ( requestData?.checklistId && requestData?.checklistId.length > 1 ) {
186
+ fileType = 'pdfzip';
187
+ }
188
+ }
189
+ if ( requestData.checklistName != '' ) {
190
+ name = requestData.checklistName + '_' + dayjs( requestData.fromDate ).format( 'DD/MM/YYYY' );
191
+ if ( requestData?.toDate ) {
192
+ name = name + '-' + dayjs( requestData?.toDate ).format( 'DD/MM/YYYY' );
193
+ }
194
+ let regexName = new RegExp( `^${name.split( '(' )[0]} \\(.*\\)$`, 'i' );
195
+ let type = requestData.fileType || 'pdfzip';
196
+ let downloadDetails = await downloadService.getCount( { $and: [ { $or: [ { name: { $regex: regexName } }, { name: name } ] }, { fileType: type } ] } );
197
+ if ( downloadDetails ) {
198
+ name = name + ' (' + downloadDetails + ')';
199
+ }
200
+ } else {
201
+ name = requestData?.checklistName;
202
+ }
203
+ let findchecklist = await processedcheklistconfigService.findOne( { 'checkListType': requestData.checkListType, 'client_id': requestData.clientId } ).sort( { _id: -1 } );
204
+ console.log( findchecklist );
205
+ name = name + '-' + requestData.fileType;
206
+ let insertData = {
207
+ 'date_string': requestData.fromDate || '',
208
+ 'sourceCheckList_id': requestData?.sourceCheckList_id || '',
209
+ 'checklistIdList': requestData?.checklistId || [],
210
+ 'status': 'inprogress',
211
+ 'client_id': requestData.clientId || '',
212
+ 'date_iso': new Date( requestData.fromDate ) || '',
213
+ 'createdBy': req.user._id || '',
214
+ 'name': name,
215
+ 'fileType': fileType,
216
+ 'storeIds': requestData.storeIds || [],
217
+ 'questions': requestData.questions || [],
218
+ 'fromDate': requestData.fromDate || '',
219
+ 'toDate': requestData.toDate || '',
220
+ 'previewType': requestData.previewType || '',
221
+ 'viewFlag': requestData.viewFlag || false,
222
+ 'userEmail': req.user.email || '',
223
+ 'createdBy': req.user._id || '',
224
+ 'downloadInsertFrom': requestData.downloadInsertFrom || '',
225
+ 'answerType': requestData.answerType || '',
226
+ 'searchValue': requestData.searchValue || '',
227
+ 'insertType': requestData.insertType || '',
228
+ 'viewRedo': requestData.viewRedo || false,
229
+ 'userEmailList': requestData.userEmailList || [],
230
+ 'filtertype': requestData.filtertype || 'Clusters',
231
+ 'checkListType': requestData.checkListType,
232
+ 'checkListName': findchecklist.checkListName,
233
+ 'checkListDescription': findchecklist.checkListDescription,
234
+ };
235
+ console.log( requestData );
236
+ console.log( insertData );
237
+ let resultData = await downloadService.insert( insertData );
238
+ console.log( resultData );
239
+ if ( resultData ) {
240
+ let sqsMessageRequestData = {
241
+ 'zipId': resultData._id,
242
+ 'fileType': fileType || 'zip',
243
+ 'storeId': requestData.storeIds || [],
244
+ };
245
+ console.log( sqsMessageRequestData );
246
+ if ( fileType === 'csv' || fileType === 'pdf' || fileType === 'csvzip' || fileType === 'pdfzip' || fileType === 'zipfiles' ) {
247
+ const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).AIchecklistExport}`, JSON.stringify( sqsMessageRequestData ) );
248
+ console.log( 'Send SQS Message CSV/PDF=>', msg );
249
+ }
250
+ if ( fileType === 'ppt' || fileType === 'pptzip' ) {
251
+ const msg = await sendMessageToQueue( `${JSON.parse( process.env.SQS ).url}${JSON.parse( process.env.SQS ).AIchecklistExport}`, JSON.stringify( sqsMessageRequestData ) );
252
+ console.log( 'Send SQS Message PPT=>', msg );
253
+ }
254
+ res.sendSuccess( 'Success' );
255
+ } else {
256
+ return res.sendError( 'something went wrong, please try again', 500 );
257
+ }
258
+ } catch ( e ) {
259
+ console.log( 'insertdownloadRequest =>', e );
260
+ return res.sendError( e, 500 );
261
+ }
262
+ };
175
263
  export const downloadInsertOld = async ( req, res ) => {
176
264
  try {
177
265
  let requestData = req.body;
@@ -471,6 +559,8 @@ export const getChecklistFromZipId = async ( req, res ) => {
471
559
  resultData.questions = getzipdata.questions;
472
560
  resultData.insertType = getzipdata.insertType;
473
561
  resultData.status = getzipdata.status;
562
+ resultData.fromDate = getzipdata.fromDate;
563
+ resultData.toDate = getzipdata.toDate;
474
564
  return res.sendSuccess( resultData );
475
565
  }
476
566
  } else {
@@ -482,7 +572,33 @@ export const getChecklistFromZipId = async ( req, res ) => {
482
572
  return res.sendError( error, 500 );
483
573
  }
484
574
  };
485
-
575
+ export const getAiChecklistDataFromZipId = async ( req, res ) => {
576
+ try {
577
+ let reqquery = req.query;
578
+ let getzipdata = await downloadService.findOne( { _id: new mongoose.Types.ObjectId( reqquery.zipId ) } );
579
+ let brandInfo = {
580
+ clientName: '',
581
+ brandLogo: '',
582
+ checkListDescription: '',
583
+ };
584
+ if ( getzipdata ) {
585
+ let getClientData = await clientService.findOne( { clientId: getzipdata.client_id } );
586
+ if ( getClientData ) {
587
+ brandInfo.clientName = getClientData.clientName;
588
+ brandInfo.brandLogo = getzipdata.client_id + '/logo/' + getClientData.profileDetails.logo;
589
+ }
590
+ getzipdata.brandInfo = brandInfo;
591
+ console.log( getzipdata );
592
+ return res.sendSuccess( getzipdata );
593
+ } else {
594
+ return res.sendError( { error: 'No Data Found' }, 204 );
595
+ }
596
+ } catch ( error ) {
597
+ console.log( 'error =>', error );
598
+ logger.error( { error: error, function: 'getChecklistFromZipId' } );
599
+ return res.sendError( error, 500 );
600
+ }
601
+ };
486
602
  export const getPDFCSVChecklistDetails = async ( req, res ) => {
487
603
  try {
488
604
  let requestData = req.body;