tango-app-api-trax 3.4.0-flag-6 → 3.4.0-flag-7
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
|
-
import {
|
|
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
|
@@ -4,7 +4,6 @@ import * as checklistService from '../services/checklist.service.js';
|
|
|
4
4
|
|
|
5
5
|
export const insertLog = async ( req, res ) => {
|
|
6
6
|
try {
|
|
7
|
-
console.log( 'insertLog' );
|
|
8
7
|
// let currentDate = new Date();
|
|
9
8
|
let inserttraxlogs = {
|
|
10
9
|
'client_id': '11',
|
|
@@ -71,8 +70,8 @@ export const insertLog = async ( req, res ) => {
|
|
|
71
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' ],
|
|
72
71
|
},
|
|
73
72
|
};
|
|
74
|
-
let insertOS = await insertOpenSearchData(
|
|
75
|
-
console.log( 'insertOS', insertOS );
|
|
73
|
+
let insertOS = await insertOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, inserttraxlogs );
|
|
74
|
+
// console.log( 'insertOS', insertOS );
|
|
76
75
|
return res.sendSuccess( 'insert successfully' );
|
|
77
76
|
// if ( insertOS && insertOS.body.result == 'created' ) {
|
|
78
77
|
// emailersIds.push( insertOS.body._id );
|
|
@@ -95,7 +94,7 @@ export const updateLog = async ( req, res ) => {
|
|
|
95
94
|
// storeIds: [ '347-1' ],
|
|
96
95
|
},
|
|
97
96
|
};
|
|
98
|
-
let updateResult = await updateOpenSearchData(
|
|
97
|
+
let updateResult = await updateOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, '5DwBYZUBcRcpuflp5oek', document );
|
|
99
98
|
console.log( 'updateResult', updateResult );
|
|
100
99
|
if ( updateResult?.statusCode == 200 && updateResult?.body?.result == 'updated' ) {
|
|
101
100
|
return res.sendSuccess( 'Email Send Successfully' );
|
|
@@ -108,39 +107,6 @@ export const updateLog = async ( req, res ) => {
|
|
|
108
107
|
return res.sendError( e, 500 );
|
|
109
108
|
}
|
|
110
109
|
};
|
|
111
|
-
export const listLogOld = async ( req, res ) => {
|
|
112
|
-
try {
|
|
113
|
-
console.log( 'list' );
|
|
114
|
-
const mustConditions = [];
|
|
115
|
-
// mustConditions.push( { match: { _id: '5DwBYZUBcRcpuflp5oek' } } );
|
|
116
|
-
let query = {
|
|
117
|
-
from: 1,
|
|
118
|
-
size: 2000,
|
|
119
|
-
query: {
|
|
120
|
-
bool: {
|
|
121
|
-
must: mustConditions,
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
sort: [
|
|
125
|
-
{
|
|
126
|
-
createAt: {
|
|
127
|
-
order: 'desc',
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
};
|
|
132
|
-
let result = await getOpenSearchData( 'test-traxlogs', query );
|
|
133
|
-
console.log( 'result', result );
|
|
134
|
-
if ( !result || !result.body.hits.hits.length ) {
|
|
135
|
-
return res.sendError( 'no data found', 204 );
|
|
136
|
-
}
|
|
137
|
-
return res.sendSuccess( { count: result.body.hits.total.value, result: result.body.hits.hits } );
|
|
138
|
-
} catch ( e ) {
|
|
139
|
-
console.log( 'listLog', e );
|
|
140
|
-
// logger.error( 'listLog =>', e );
|
|
141
|
-
return res.sendError( e, 500 );
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
110
|
export const listLog = async ( req, res ) => {
|
|
145
111
|
try {
|
|
146
112
|
let requestBody = req.body;
|
|
@@ -244,110 +210,13 @@ export const listLog = async ( req, res ) => {
|
|
|
244
210
|
},
|
|
245
211
|
],
|
|
246
212
|
};
|
|
247
|
-
let result = await getOpenSearchData(
|
|
248
|
-
// console.log( 'result', result );
|
|
249
|
-
if ( !result || !result.body.hits.hits.length ) {
|
|
250
|
-
return res.sendError( 'no data found', 204 );
|
|
251
|
-
}
|
|
252
|
-
return res.sendSuccess( { count: result.body.hits.total.value, result: result.body.hits.hits } );
|
|
253
|
-
} catch ( e ) {
|
|
254
|
-
console.log( 'listLog', e );
|
|
255
|
-
return res.sendError( e, 500 );
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
export const listLogNotwork = async ( req, res ) => {
|
|
260
|
-
try {
|
|
261
|
-
let requestBody = req.body;
|
|
262
|
-
let from = ( requestBody.offset ) * requestBody.limit;
|
|
263
|
-
|
|
264
|
-
// let start = new Date( requestBody.fromDate );
|
|
265
|
-
// let userTimezoneOffset = start.getTimezoneOffset() * 60000;
|
|
266
|
-
// start = new Date( start.getTime() - userTimezoneOffset );
|
|
267
|
-
// start.setUTCHours( 0, 0, 0, 0 );
|
|
268
|
-
// let end = new Date( requestBody.toDate );
|
|
269
|
-
// end = new Date( end.getTime() - userTimezoneOffset );
|
|
270
|
-
// end.setUTCHours( 23, 59, 59, 59 );
|
|
271
|
-
|
|
272
|
-
// console.log( 'list' );
|
|
273
|
-
const mustConditions = [];
|
|
274
|
-
// if user role is admin fetch checklist owners
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if ( requestBody.clientId ) {
|
|
278
|
-
mustConditions.push( { term: { client_id: requestBody.clientId } } );
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// if ( req.user.userType == 'client' && req.user.role == 'admin' ) {
|
|
282
|
-
// const sourceCheckListIds = await checklistService.aggregate( [
|
|
283
|
-
// { $match: { 'owner.value': req.user.email } },
|
|
284
|
-
// { $group: { _id: null, checklistIds: { $push: { $toString: '$_id' } } } },
|
|
285
|
-
// { $project: { _id: 0, checklistIds: 1 } },
|
|
286
|
-
// ] );
|
|
287
|
-
|
|
288
|
-
// mustConditions.push( { terms: { $or: [ { store_id: { $in: requestBody.storeId } }, { store_id: { $eq: '' }, userEmail: { $in: requestBody.userEmailes } }, { sourceCheckList_id: { $in: sourceCheckListIds } } ] } } );
|
|
289
|
-
// }
|
|
290
|
-
|
|
291
|
-
if ( requestBody.type ) {
|
|
292
|
-
mustConditions.push( { term: { type: requestBody.type } } );
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
if ( requestBody.action ) {
|
|
296
|
-
mustConditions.push( { terms: { action: { $in: requestBody.action } } } );
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
if ( requestBody.searchValue ) {
|
|
300
|
-
mustConditions.push( { multi_match: {
|
|
301
|
-
'query': requestBody.searchValue,
|
|
302
|
-
'fields': [ 'checkListName', 'storeName', 'userEmail' ],
|
|
303
|
-
'type': 'phrase_prefix',
|
|
304
|
-
},
|
|
305
|
-
} );
|
|
306
|
-
}
|
|
307
|
-
// console.log( 'Generated Query:', JSON.stringify( mustConditions, null, 2 ) );
|
|
308
|
-
|
|
309
|
-
// console.log( 'mustConditions =>', mustConditions );
|
|
310
|
-
// if ( requestBody.dateRange ) {
|
|
311
|
-
// mustConditions.push( {
|
|
312
|
-
// range: {
|
|
313
|
-
// createdAt: {
|
|
314
|
-
// gte: start, // Start date
|
|
315
|
-
// lte: end, // End date
|
|
316
|
-
// },
|
|
317
|
-
// },
|
|
318
|
-
// } );
|
|
319
|
-
// }
|
|
320
|
-
let sortCreatedAt = 'desc';
|
|
321
|
-
if ( requestBody.sortColumnName && requestBody.sortColumnName != '' ) {
|
|
322
|
-
if ( requestBody.sortBy == '1' ) {
|
|
323
|
-
sortCreatedAt = 'asc';
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
let query = {
|
|
327
|
-
from: parseInt( from ),
|
|
328
|
-
size: parseInt( requestBody.limit ),
|
|
329
|
-
query: {
|
|
330
|
-
bool: {
|
|
331
|
-
must: mustConditions,
|
|
332
|
-
},
|
|
333
|
-
},
|
|
334
|
-
sort: [
|
|
335
|
-
{
|
|
336
|
-
createAt: {
|
|
337
|
-
order: sortCreatedAt,
|
|
338
|
-
},
|
|
339
|
-
},
|
|
340
|
-
],
|
|
341
|
-
};
|
|
342
|
-
let result = await getOpenSearchData( 'test-traxlogs', query );
|
|
343
|
-
console.log( 'result', result );
|
|
213
|
+
let result = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).traxActivityLog, query );
|
|
344
214
|
if ( !result || !result.body.hits.hits.length ) {
|
|
345
215
|
return res.sendError( 'no data found', 204 );
|
|
346
216
|
}
|
|
347
217
|
return res.sendSuccess( { count: result.body.hits.total.value, result: result.body.hits.hits } );
|
|
348
218
|
} catch ( e ) {
|
|
349
219
|
console.log( 'listLog', e );
|
|
350
|
-
logger.error( 'listLog =>', e );
|
|
351
220
|
return res.sendError( e, 500 );
|
|
352
221
|
}
|
|
353
222
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { isAllowedInternalAPIHandler, isAllowedSessionHandler } from 'tango-app-api-middleware';
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const traxActivityLogRouter = express.Router();
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
insertLog,
|
|
@@ -9,10 +9,10 @@ import {
|
|
|
9
9
|
listLog,
|
|
10
10
|
} from '../controllers/activityLog.controller.js';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
traxActivityLogRouter
|
|
13
13
|
.post( '/insertLog', isAllowedInternalAPIHandler, insertLog )
|
|
14
14
|
.post( '/updateLog', isAllowedInternalAPIHandler, updateLog )
|
|
15
15
|
.post( '/listLog', isAllowedSessionHandler, listLog );
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
export default
|
|
18
|
+
export default traxActivityLogRouter;
|