tango-app-api-trax 3.4.0-alpha-5 → 3.4.0-beta-1
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 +2 -2
- package/package.json +3 -3
- package/src/controllers/activityLog.controller.js +239 -0
- package/src/controllers/gallery.controller.js +3 -2
- package/src/controllers/internalTrax.controller.js +53 -1
- package/src/controllers/mobileTrax.controller.js +187 -91
- package/src/controllers/teaxFlag.controller.js +408 -1
- package/src/controllers/trax.controller.js +446 -114
- package/src/routes/activityLog.router.js +18 -0
- package/src/routes/internalTraxApi.router.js +2 -1
- package/src/routes/traxFlag.router.js +9 -1
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-
|
|
3
|
+
"version": "3.4.0-beta-1",
|
|
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.
|
|
30
|
-
"tango-app-api-middleware": "^3.1.
|
|
29
|
+
"tango-api-schema": "^2.2.78",
|
|
30
|
+
"tango-app-api-middleware": "^3.1.69",
|
|
31
31
|
"url": "^0.11.4",
|
|
32
32
|
"winston": "^3.13.1",
|
|
33
33
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -0,0 +1,239 @@
|
|
|
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
|
+
let insertOS = await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, inserttraxlogs );
|
|
75
|
+
console.log( 'insertOS', insertOS );
|
|
76
|
+
return res.sendSuccess( 'insert successfully' );
|
|
77
|
+
// if ( insertOS && insertOS.body.result == 'created' ) {
|
|
78
|
+
// emailersIds.push( insertOS.body._id );
|
|
79
|
+
// }
|
|
80
|
+
} catch ( e ) {
|
|
81
|
+
// logger.error( 'insertLog =>', e );
|
|
82
|
+
console.log( 'insertLog =>', e );
|
|
83
|
+
return res.sendError( e, 500 );
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
export const updateLog = async ( req, res ) => {
|
|
87
|
+
try {
|
|
88
|
+
console.log( 'update' );
|
|
89
|
+
const document = {
|
|
90
|
+
doc: {
|
|
91
|
+
storeName: 'LKST008',
|
|
92
|
+
// fromDate: '2025-01-13',
|
|
93
|
+
// toDate: '2025-01-19',
|
|
94
|
+
// status: 'completed',
|
|
95
|
+
// storeIds: [ '347-1' ],
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
let updateResult = await updateOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, '5DwBYZUBcRcpuflp5oek', document );
|
|
99
|
+
console.log( 'updateResult', updateResult );
|
|
100
|
+
if ( updateResult?.statusCode == 200 && updateResult?.body?.result == 'updated' ) {
|
|
101
|
+
return res.sendSuccess( 'Email Send Successfully' );
|
|
102
|
+
} else {
|
|
103
|
+
return res.sendSuccess( 'Email Send Successfully' );
|
|
104
|
+
// return res.sendError( { error: error }, 500 );
|
|
105
|
+
}
|
|
106
|
+
} catch ( e ) {
|
|
107
|
+
logger.error( 'updateLog =>', e );
|
|
108
|
+
return res.sendError( e, 500 );
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
export const listLog = async ( req, res ) => {
|
|
112
|
+
try {
|
|
113
|
+
let requestBody = req.body;
|
|
114
|
+
let from = ( requestBody.offset ) * requestBody.limit;
|
|
115
|
+
|
|
116
|
+
// let start = new Date( requestBody.fromDate );
|
|
117
|
+
// let userTimezoneOffset = start.getTimezoneOffset() * 60000;
|
|
118
|
+
// start = new Date( start.getTime() - userTimezoneOffset );
|
|
119
|
+
// start.setUTCHours( 0, 0, 0, 0 );
|
|
120
|
+
// let end = new Date( requestBody.toDate );
|
|
121
|
+
// end = new Date( end.getTime() - userTimezoneOffset );
|
|
122
|
+
// end.setUTCHours( 23, 59, 59, 59 );
|
|
123
|
+
|
|
124
|
+
// console.log( 'list' );
|
|
125
|
+
const mustConditions = [];
|
|
126
|
+
|
|
127
|
+
if ( requestBody.clientId ) {
|
|
128
|
+
mustConditions.push( { term: { client_id: requestBody.clientId } } );
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if ( requestBody.type ) {
|
|
132
|
+
mustConditions.push( { term: { type: requestBody.type } } );
|
|
133
|
+
}
|
|
134
|
+
if ( requestBody.action && requestBody.action.length > 0 ) {
|
|
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
|
+
let sourceCheckListIds;
|
|
142
|
+
if ( req.user.userType === 'client' && req.user.role == 'admin' ) {
|
|
143
|
+
if ( requestBody.type === 'checklist' ) {
|
|
144
|
+
const sourceCheckListResult = await checklistService.aggregate( [
|
|
145
|
+
// { $match: { 'owner.value': req.user.email } },
|
|
146
|
+
{ $match: { $or: [ { 'owner.value': req.user.email }, { 'approver.value': req.user.email } ] } },
|
|
147
|
+
{ $group: { _id: null, checklistIds: { $push: { $toString: '$_id' } } } },
|
|
148
|
+
{ $project: { _id: 0, checklistIds: 1 } },
|
|
149
|
+
] );
|
|
150
|
+
sourceCheckListIds = sourceCheckListResult.length > 0 ? sourceCheckListResult[0].checklistIds : [];
|
|
151
|
+
console.log( 'sourceCheckListIds', sourceCheckListIds );
|
|
152
|
+
}
|
|
153
|
+
if ( requestBody.type === 'task' ) {
|
|
154
|
+
const sourceCheckListResult = await taskconfigService.aggregate( [
|
|
155
|
+
// { $match: { 'owner.value': req.user.email } },
|
|
156
|
+
{ $match: { $or: [ { 'owner.value': req.user.email }, { 'approver.value': req.user.email } ] } },
|
|
157
|
+
{ $group: { _id: null, checklistIds: { $push: { $toString: '$_id' } } } },
|
|
158
|
+
{ $project: { _id: 0, checklistIds: 1 } },
|
|
159
|
+
] );
|
|
160
|
+
|
|
161
|
+
sourceCheckListIds = sourceCheckListResult.length > 0 ? sourceCheckListResult[0].checklistIds : [];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
// mustConditions.push( { terms: { $or: [ { store_id: { $in: requestBody.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestBody.userEmailes } }, { sourceCheckList_id: { $in: sourceCheckListIds } } ] } } );
|
|
166
|
+
mustConditions.push( {
|
|
167
|
+
'bool': {
|
|
168
|
+
'should': [
|
|
169
|
+
{ 'terms': { 'store_id': requestBody.storeId } },
|
|
170
|
+
{
|
|
171
|
+
'bool': {
|
|
172
|
+
'must': [
|
|
173
|
+
{ 'term': { 'store_id': '' } },
|
|
174
|
+
{ 'terms': { 'userEmail': requestBody.userEmailes } },
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
{ 'terms': { 'sourceCheckList_id': sourceCheckListIds.map( String ) } },
|
|
179
|
+
],
|
|
180
|
+
'minimum_should_match': 1,
|
|
181
|
+
},
|
|
182
|
+
} );
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if ( requestBody.searchValue ) {
|
|
186
|
+
mustConditions.push( { multi_match: {
|
|
187
|
+
'query': requestBody.searchValue,
|
|
188
|
+
'fields': [ 'checkListName', 'storeName', 'userEmail' ],
|
|
189
|
+
'type': 'phrase_prefix',
|
|
190
|
+
},
|
|
191
|
+
} );
|
|
192
|
+
}
|
|
193
|
+
// console.log( 'Generated Query:', JSON.stringify( mustConditions, null, 2 ) );
|
|
194
|
+
|
|
195
|
+
// console.log( 'mustConditions =>', mustConditions );
|
|
196
|
+
// if ( requestBody.dateRange ) {
|
|
197
|
+
// mustConditions.push( {
|
|
198
|
+
// range: {
|
|
199
|
+
// createdAt: {
|
|
200
|
+
// gte: start, // Start date
|
|
201
|
+
// lte: end, // End date
|
|
202
|
+
// },
|
|
203
|
+
// },
|
|
204
|
+
// } );
|
|
205
|
+
// }
|
|
206
|
+
let sortCreatedAt = 'desc';
|
|
207
|
+
if ( requestBody.sortColumnName && requestBody.sortColumnName != '' ) {
|
|
208
|
+
if ( requestBody.sortBy == '1' ) {
|
|
209
|
+
sortCreatedAt = 'asc';
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
let query = {
|
|
213
|
+
from: parseInt( from ),
|
|
214
|
+
size: parseInt( requestBody.limit ),
|
|
215
|
+
query: {
|
|
216
|
+
bool: {
|
|
217
|
+
must: mustConditions,
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
sort: [
|
|
221
|
+
{
|
|
222
|
+
createAt: {
|
|
223
|
+
order: sortCreatedAt,
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
};
|
|
228
|
+
// console.log( 'Executing OpenSearch Query:', JSON.stringify( query, null, 2 ) );
|
|
229
|
+
let result = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, query );
|
|
230
|
+
// console.log( 'OpenSearch Raw Response', JSON.stringify( result, null, 2 ) );
|
|
231
|
+
if ( !result || !result.body.hits.hits.length ) {
|
|
232
|
+
return res.sendError( 'no data found', 204 );
|
|
233
|
+
}
|
|
234
|
+
return res.sendSuccess( { count: result.body.hits.total.value, result: result.body.hits.hits } );
|
|
235
|
+
} catch ( e ) {
|
|
236
|
+
console.log( 'listLog', e );
|
|
237
|
+
return res.sendError( e, 500 );
|
|
238
|
+
}
|
|
239
|
+
};
|
|
@@ -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':
|
|
336
|
+
'approved': storeNames,
|
|
336
337
|
},
|
|
337
338
|
};
|
|
338
339
|
let urlopensearch = JSON.parse( process.env.OPENSEARCH );
|
|
@@ -449,7 +450,7 @@ export async function redoChecklist( req, res ) {
|
|
|
449
450
|
submitTime: checklistDetails.submitTime,
|
|
450
451
|
};
|
|
451
452
|
await checklistLogs.create( data );
|
|
452
|
-
|
|
453
|
+
|
|
453
454
|
const requestOptions = {
|
|
454
455
|
method: 'POST',
|
|
455
456
|
headers: {
|
|
@@ -18,7 +18,7 @@ import timeZone from 'dayjs/plugin/timezone.js';
|
|
|
18
18
|
import utc from 'dayjs/plugin/utc.js';
|
|
19
19
|
import { logger } from 'tango-app-api-middleware';
|
|
20
20
|
import mongoose from 'mongoose';
|
|
21
|
-
import { sendPushNotification } from 'tango-app-api-middleware';
|
|
21
|
+
import { sendPushNotification, sendAiPushNotification } from 'tango-app-api-middleware';
|
|
22
22
|
// import * as planoService from '../services/planogram.service.js';
|
|
23
23
|
import * as clusterServices from '../services/cluster.service.js';
|
|
24
24
|
import * as teamsServices from '../services/teams.service.js';
|
|
@@ -1644,3 +1644,55 @@ 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 userData;
|
|
1667
|
+
if ( requestData.email && requestData.email !='' ) {
|
|
1668
|
+
// fcmToken = await getUserToken( requestData.clientId, requestData.email );
|
|
1669
|
+
userData = await userService.findOne( { clientId: requestData.clientId, email: requestData.email }, { fcmToken: 1, loginFrom: 1 } );
|
|
1670
|
+
} else {
|
|
1671
|
+
let storeData = await storeService.findOne( { clientId: requestData.clientId, storeId: requestData.storeId }, { spocDetails: 1 } );
|
|
1672
|
+
if ( storeData && storeData.spocDetails.length > 0 && storeData.spocDetails[0].email ) {
|
|
1673
|
+
// fcmToken = await getUserToken( storeData.spocDetails[0].email );
|
|
1674
|
+
userData = await userService.findOne( { clientId: requestData.clientId, email: requestData.email }, { fcmToken: 1, loginFrom: 1 } );
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
if ( !userData ) {
|
|
1678
|
+
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1679
|
+
}
|
|
1680
|
+
let custom = {
|
|
1681
|
+
title: requestData.title,
|
|
1682
|
+
description: requestData.description,
|
|
1683
|
+
type: req.body?.type,
|
|
1684
|
+
storeId: req.body?.storeId,
|
|
1685
|
+
date: req.body?.date,
|
|
1686
|
+
};
|
|
1687
|
+
let responseData = await sendAiPushNotification( userData.fcmToken, custom, userData.loginFrom );
|
|
1688
|
+
if ( responseData ) {
|
|
1689
|
+
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1690
|
+
} else {
|
|
1691
|
+
return res.sendSuccess( 'Notification Send Successfully' );
|
|
1692
|
+
}
|
|
1693
|
+
} catch ( e ) {
|
|
1694
|
+
logger.error( { error: e, function: 'internalAISendPushNotification' } );
|
|
1695
|
+
if ( e.name === 'ValidationError' ) res.sendBadRequest( e );
|
|
1696
|
+
else res.sendError( e, 500 );
|
|
1697
|
+
}
|
|
1698
|
+
};
|