tango-app-api-store-zone 3.0.11-dev → 3.0.13-dev

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-store-zone",
3
- "version": "3.0.11-dev",
3
+ "version": "3.0.13-dev",
4
4
  "description": "zone",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -21,8 +21,8 @@
21
21
  "mongodb": "^6.5.0",
22
22
  "nodemon": "^3.1.0",
23
23
  "swagger-ui-express": "^5.0.0",
24
- "tango-api-schema": "^2.0.102",
25
- "tango-app-api-middleware": "^1.0.71-test",
24
+ "tango-api-schema": "^2.0.110",
25
+ "tango-app-api-middleware": "^3.1.12",
26
26
  "winston": "^3.13.0",
27
27
  "winston-daily-rotate-file": "^5.0.0"
28
28
  },
@@ -1,6 +1,7 @@
1
1
  import { logger } from 'tango-app-api-middleware';
2
2
  import * as cameraService from '../services/camera.service.js';
3
3
  import * as taggingService from '../services/tagging.service.js';
4
+ import * as storeService from '../services/store.service.js';
4
5
  import { appConfig, signedUrl, listFileByPath, fileUpload, insertOpenSearchData } from 'tango-app-api-middleware';
5
6
  import axios from 'axios';
6
7
  export const addCustomTag = async ( req, res ) => {
@@ -23,12 +24,13 @@ export const addCustomTag = async ( req, res ) => {
23
24
  userName: req.user?.userName,
24
25
  email: req.user?.email,
25
26
  date: new Date(),
26
- logType: 'add Zone',
27
- logSubType: inputData.tagName,
28
- changes: [ ],
29
- eventType: 'add',
27
+ logType: 'zone',
28
+ logSubType: 'addCustomTag',
29
+ changes: [ `${inputData.tagName} customtag Created.` ],
30
+ eventType: '',
31
+ showTo: [ 'client', 'tango' ],
30
32
  };
31
- insertOpenSearchData( 'tango-retail-activity-logs', logObj );
33
+ insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
32
34
  return res.sendSuccess( 'Tag Created Successfully' );
33
35
  } catch ( e ) {
34
36
  logger.error( { error: 'e', function: 'addCustomTag' } );
@@ -39,7 +41,13 @@ export const addCustomTag = async ( req, res ) => {
39
41
  export const customTagList = async ( req, res ) => {
40
42
  try {
41
43
  let customTagList = [];
42
- let defaultZone = [ 'Entry', 'Exit', 'Billing', 'Excluded Area' ];
44
+ let storeDetails = await storeService.findOne( { storeId: req.query.storeId }, { product: 1 } );
45
+ let defaultZone;
46
+ if ( storeDetails && storeDetails?.product.includes( 'tangoZone' ) ) {
47
+ defaultZone = [ 'Excluded Area', 'Passer By', 'Entry/Exit', 'Billing' ];
48
+ } else {
49
+ defaultZone = [ 'Excluded Area', 'Passer By' ];
50
+ }
43
51
  customTagList.push( ...defaultZone );
44
52
  let tagInfo = await taggingService.find( { clientId: req.query.clientId }, { tagName: 1 } );
45
53
  let deletedTag = await taggingService.find( { clientId: req.query.clientId, isDeleted: true }, { storeId: 1, tagName: 1 } );
@@ -93,6 +101,7 @@ export const customTagList = async ( req, res ) => {
93
101
  }
94
102
  return { tagName: item, count: count };
95
103
  } );
104
+ customTagList.sort( ( a, b ) => a.count > b.count ? -1 : 1 );
96
105
  return res.sendSuccess( customTagList );
97
106
  } catch ( e ) {
98
107
  logger.error( { error: e, function: 'customTagList' } );
@@ -114,12 +123,13 @@ export const tagging = async ( req, res ) => {
114
123
  userName: req.user?.userName,
115
124
  email: req.user?.email,
116
125
  date: new Date(),
117
- logType: 'add Zone Tagging',
118
- logSubType: InputData.tagName,
119
- changes: [ 'coordinates' ],
120
- eventType: 'add Tagging',
126
+ logType: 'zone',
127
+ logSubType: 'addZoneTagging',
128
+ changes: [ `${InputData.tagName} zone added tagging` ],
129
+ eventType: '',
130
+ showTo: [ 'client', 'tango' ],
121
131
  };
122
- insertOpenSearchData( 'tango-retail-activity-logs', logObj );
132
+ insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
123
133
  let response = await taggingService.create( InputData );
124
134
  await taggingService.deleteOne( { clientId: InputData.clientId, storeId: InputData.storeId, cameraId: { $exists: false }, tagName: InputData.tagName } );
125
135
  await axios.post( `${appConfig.url.oldapidomain}/tagging/oldTaggingAdd`, [ response ], { headers: { Authorization: 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66' } } ).then( ( res ) => logger.info( res?.data ) ).catch( ( error ) => logger.error( { error: error } ) );
@@ -130,17 +140,20 @@ export const tagging = async ( req, res ) => {
130
140
  userName: req.user?.userName,
131
141
  email: req.user?.email,
132
142
  date: new Date(),
133
- logType: 'add Zone Tagging',
134
- logSubType: InputData.tagName,
135
- changes: [ 'coordinates' ],
136
- eventType: 'update Tagging',
143
+ logType: 'zone',
144
+ logSubType: 'updateZoneTagging',
145
+ changes: [ `${InputData.tagName} zone Updated tagging` ],
146
+ eventType: '',
137
147
  };
138
- insertOpenSearchData( 'tango-retail-activity-logs', logObj );
148
+ insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
139
149
  taggingDetails.cameraId = InputData.cameraId;
140
150
  taggingDetails.streamName = InputData.streamName;
141
151
  if ( req.body?.redoPoint ) {
142
152
  taggingDetails.coordinates = InputData.coordinates[0];
143
153
  taggingDetails.save();
154
+ } else if ( req.body?.redraw ) {
155
+ taggingDetails.coordinates = InputData.coordinates;
156
+ taggingDetails.save();
144
157
  } else {
145
158
  if ( InputData.coordinates[0].coor.length ) {
146
159
  taggingDetails.coordinates.push( InputData.coordinates[0] );
@@ -181,7 +194,7 @@ export const tagging = async ( req, res ) => {
181
194
 
182
195
  export const getCameraList = async ( req, res ) => {
183
196
  try {
184
- let cameraDetails = await cameraService.find( { clientId: req.query.clientId, storeId: req.query.storeId, isActivated: true, isUp: true }, { cameraNumber: 1, streamName: 1 } );
197
+ let cameraDetails = await cameraService.find( { clientId: req.query.clientId, storeId: req.query.storeId }, { cameraNumber: 1, streamName: 1, isActivated: 1, isUp: 1 } );
185
198
  if ( !cameraDetails.length ) {
186
199
  return res.sendError( 'no data found', 204 );
187
200
  }
@@ -281,12 +294,13 @@ export const updateTag = async ( req, res ) => {
281
294
  userName: req.user?.userName,
282
295
  email: req.user?.email,
283
296
  date: new Date(),
284
- logType: 'add Zone Tagging',
285
- logSubType: req.body.existTag,
286
- changes: [ 'tagName' ],
287
- eventType: 'update Custom Tag Name',
297
+ logType: 'zone',
298
+ logSubType: 'updateCustomTag',
299
+ changes: [ `${req.body.tagName} tagName Updated` ],
300
+ eventType: '',
301
+ showTo: [ 'client', 'tango' ],
288
302
  };
289
- insertOpenSearchData( 'tango-retail-activity-logs', logObj );
303
+ insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
290
304
  logger.error( { error: 'something went wrong', function: 'updateTag' } );
291
305
  return res.sendError( 'something went wrong', 500 );
292
306
  } catch ( e ) {
@@ -340,12 +354,13 @@ export const deleteTag = async ( req, res ) => {
340
354
  userName: req.user?.userName,
341
355
  email: req.user?.email,
342
356
  date: new Date(),
343
- logType: 'add Zone Tagging',
344
- logSubType: req.body?.tagName,
345
- changes: [ 'tagName' ],
346
- eventType: 'Delete Tagging Name',
357
+ logType: 'zone',
358
+ logSubType: 'deleteTag',
359
+ changes: [ `${req.body.tagName} tag Deleted` ],
360
+ eventType: '',
361
+ showTo: [ 'client', 'tango' ],
347
362
  };
348
- insertOpenSearchData( 'tango-retail-activity-logs', logObj );
363
+ insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
349
364
  await updatezoneTagging( req, res );
350
365
  // return res.sendSuccess( 'Tag Deleted Successfully' );
351
366
  } catch ( e ) {
@@ -422,7 +437,7 @@ async function getCamTaggingDetails( req, res ) {
422
437
  try {
423
438
  let camDetails = await cameraService.find( { storeId: req.body.storeId, isActivated: true, isUp: true } );
424
439
  if ( !camDetails.length ) {
425
- return res.sendError( 'no data found', 204 );
440
+ return false;
426
441
  }
427
442
  let result = [];
428
443
  for ( let camera of camDetails ) {
@@ -515,8 +530,8 @@ export const updateOldData = async ( req, res ) => {
515
530
  if ( !upload.Key ) {
516
531
  logger.error( { message: `JSON Upload Error`, store: item.storeId } );
517
532
  }
518
- if ( index == tagDetails.length-1 ) {
519
- return res.sendSuccess( 'Zone Updated Successfully' );
533
+ if ( index == 0 ) {
534
+ res.sendSuccess( 'Zone Updated Successfully' );
520
535
  }
521
536
  } else {
522
537
  logger.error( { message: 'no data', store: item.storeId } );
@@ -528,4 +543,4 @@ export const updateOldData = async ( req, res ) => {
528
543
  logger.error( { error: e, function: 'updateOldData' } );
529
544
  return res.sendError( e, 500 );
530
545
  }
531
- };
546
+ };
@@ -49,6 +49,7 @@ export const validateTaggingSchema = joi.object( {
49
49
  coordinates: joi.array().required(),
50
50
  streamName: joi.string().required(),
51
51
  redoPoint: joi.boolean().optional(),
52
+ redraw: joi.boolean().optional(),
52
53
  } );
53
54
 
54
55
  export const validateTaggingParams = {
@@ -0,0 +1,5 @@
1
+ import model from 'tango-api-schema';
2
+
3
+ export const findOne = async ( query = {}, record = {} ) => {
4
+ return await model.storeModel.findOne( query, record );
5
+ };