tango-app-api-trax 3.4.0-flag-5 → 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 { activityLogRouter } from './src/routes/activityLog.router.js';
12
- export { traxDashboardRouter, traxFlagRouter, traxRouter, galleryRouter, downloadRouter, mobileRouter, internalTraxRouter, locusOrderRouter, activityLogRouter };
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,11 +1,11 @@
1
1
  {
2
2
  "name": "tango-app-api-trax",
3
- "version": "3.4.0-flag-5",
3
+ "version": "3.4.0-flag-7",
4
4
  "description": "Trax",
5
- "main": "app.js",
5
+ "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "start": "nodemon --exec \"eslint --fix . && node app.js\""
8
+ "start": "nodemon --exec \"eslint --fix . && node index.js\""
9
9
  },
10
10
  "engines": {
11
11
  "node": ">=18.10.0"
@@ -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( 'test-traxlogs', inserttraxlogs );
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( 'test-traxlogs', '5DwBYZUBcRcpuflp5oek', document );
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( 'test-traxlogs', query );
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 activityLogRouter = express.Router();
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
- activityLogRouter
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 activityLogRouter;
18
+ export default traxActivityLogRouter;
package/app.js DELETED
@@ -1,55 +0,0 @@
1
- import express from 'express';
2
- import { traxRouter, mobileRouter, traxFlagRouter, traxDashboardRouter, galleryRouter, internalTraxRouter, downloadRouter, activityLogRouter } from './index.js';
3
- import responseMiddleware from './config/response/response.js';
4
- import errorMiddleware from './config/response/response.js';
5
- import dotenv from 'dotenv';
6
- import { logger } from 'tango-app-api-middleware';
7
- import { connectdb } from './config/database/database.js';
8
- import cors from 'cors';
9
- import pkg from 'body-parser';
10
- import fileupload from 'express-fileupload';
11
- import admin from 'firebase-admin';
12
- const serviceAccountPath = JSON.parse( process.env.FIREBASE );
13
- admin.initializeApp( {
14
- credential: admin.credential.cert( serviceAccountPath ),
15
- } );
16
-
17
- const env=dotenv.config();
18
-
19
- const app = express();
20
- const PORT = process.env.PORT || 3000;
21
-
22
- const { json, urlencoded } =pkg;
23
-
24
-
25
- if ( env.error ) {
26
- logger.error( '.env not found' );
27
- process.exit( 1 );
28
- }
29
-
30
- app.use( cors() );
31
- app.use( responseMiddleware );
32
- app.use( errorMiddleware );
33
- app.use( json( { limit: '500mb' } ) );
34
- app.use( fileupload() );
35
- app.use(
36
- urlencoded( {
37
- extended: true,
38
- } ),
39
- );
40
-
41
- app.use( '/trax', traxRouter );
42
- app.use( '/trax/flag', traxFlagRouter );
43
- app.use( '/trax/mobileAPI', mobileRouter );
44
- app.use( '/trax/dashboard', traxDashboardRouter );
45
- app.use( '/gallery', galleryRouter );
46
- app.use( '/trax/internalAPI', internalTraxRouter );
47
- app.use( '/trax/downloads', downloadRouter );
48
- app.use( '/activityLog', activityLogRouter );
49
-
50
-
51
- app.listen( PORT, () => {
52
- console.log( `server is running on port= ${PORT} ` );
53
- logger.info( `server is running on port= ${PORT} ` );
54
- connectdb();
55
- } );